Skip to content

Commit d8cde0c

Browse files
ilianivBenFradet
authored andcommitted
PHP: use protected fields in order to be extendable (closes snowplow-referer-parser#182)
1 parent 55aeac2 commit d8cde0c

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

php/src/Snowplow/RefererParser/Config/ConfigFileReaderTrait.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
trait ConfigFileReaderTrait
77
{
88
/** @var string */
9-
private $fileName;
9+
protected $fileName;
1010

1111
/** @var array */
12-
private $referers = [];
12+
protected $referers = [];
1313

14-
private function init($fileName)
14+
protected function init($fileName)
1515
{
1616
if (!file_exists($fileName)) {
1717
throw InvalidArgumentException::fileNotExists($fileName);
@@ -24,7 +24,7 @@ private function init($fileName)
2424

2525
abstract protected function parse($content);
2626

27-
private function read()
27+
protected function read()
2828
{
2929
if ($this->referers) {
3030
return;

php/src/Snowplow/RefererParser/Parser.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
class Parser
88
{
99
/** @var ConfigReaderInterface */
10-
private $configReader;
10+
protected $configReader;
1111

1212
/**
1313
* @var string[]
1414
*/
15-
private $internalHosts = [];
15+
protected $internalHosts = [];
1616

1717
public function __construct(ConfigReaderInterface $configReader = null, array $internalHosts = [])
1818
{
@@ -59,7 +59,7 @@ public function parse($refererUrl, $pageUrl = null)
5959
return Referer::createKnown($referer['medium'], $referer['source'], $searchTerm);
6060
}
6161

62-
private static function parseUrl($url)
62+
protected static function parseUrl($url)
6363
{
6464
if ($url === null) {
6565
return null;
@@ -73,7 +73,7 @@ private static function parseUrl($url)
7373
return array_merge(['query' => null, 'path' => '/'], $parts);
7474
}
7575

76-
private function lookup($host, $path)
76+
protected function lookup($host, $path)
7777
{
7878
$referer = $this->lookupPath($host, $path);
7979

@@ -84,7 +84,7 @@ private function lookup($host, $path)
8484
return $this->lookupHost($host);
8585
}
8686

87-
private function lookupPath($host, $path)
87+
protected function lookupPath($host, $path)
8888
{
8989
$referer = $this->lookupHost($host, $path);
9090

@@ -101,7 +101,7 @@ private function lookupPath($host, $path)
101101
return $this->lookupPath($host, $path);
102102
}
103103

104-
private function lookupHost($host, $path = null)
104+
protected function lookupHost($host, $path = null)
105105
{
106106
do {
107107
$referer = $this->configReader->lookup($host . $path);
@@ -111,7 +111,7 @@ private function lookupHost($host, $path = null)
111111
return $referer;
112112
}
113113

114-
private static function createDefaultConfigReader()
114+
protected static function createDefaultConfigReader()
115115
{
116116
return new JsonConfigReader(__DIR__ . '/../../../data/referers.json');
117117
}

php/src/Snowplow/RefererParser/Referer.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
class Referer
55
{
66
/** @var string */
7-
private $medium;
7+
protected $medium;
88

99
/** @var string */
10-
private $source;
10+
protected $source;
1111

1212
/** @var string|null */
13-
private $searchTerm;
13+
protected $searchTerm;
1414

15-
private function __construct()
15+
protected function __construct()
1616
{}
1717

1818
public static function createKnown($medium, $source, $searchTerm = null)

0 commit comments

Comments
 (0)