1
|
|
|
<?php |
2
|
|
|
/* @description Transformation Style Sheets - Revolutionising PHP templating * |
3
|
|
|
* @author Tom Butler [email protected] * |
4
|
|
|
* @copyright 2017 Tom Butler <[email protected]> | https://r.je/ * |
5
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License * |
6
|
|
|
* @version 1.2 */ |
7
|
|
|
namespace Transphporm; |
8
|
|
|
class Config { |
9
|
|
|
private $properties = []; |
10
|
|
|
private $pseudo = []; |
11
|
|
|
private $functionSet; |
12
|
|
|
private $headers; |
13
|
|
|
private $filePath; |
14
|
|
|
private $formatter; |
15
|
|
|
private $line = 0; |
16
|
|
|
private $elementData; |
17
|
|
|
private $xPath; |
18
|
|
|
private $valueParser; |
19
|
|
|
|
20
|
|
View Code Duplication |
public function __construct(Functionset $functionSet, Parser\Value $valueParser, Hook\ElementData $elementData, Hook\Formatter $formatter, Parser\CssToXpath $xPath, FilePath $filePath, &$headers) { |
|
|
|
|
21
|
|
|
$this->formatter = $formatter; |
22
|
|
|
$this->headers = &$headers; |
23
|
|
|
$this->filePath = $filePath; |
24
|
|
|
$this->functionSet = $functionSet; |
25
|
|
|
$this->elementData = $elementData; |
26
|
|
|
$this->xPath = $xPath; |
27
|
|
|
$this->valueParser = $valueParser; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function getFormatter() { |
31
|
|
|
return $this->formatter; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function &getHeaders() { |
35
|
|
|
return $this->headers; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getFilePath() { |
39
|
|
|
return $this->filePath; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function &getLine() { |
43
|
|
|
$line = &$this->line; |
44
|
|
|
return $line; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function registerFormatter($formatter) { |
48
|
|
|
$this->formatter->register($formatter); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getFunctionSet() { |
52
|
|
|
return $this->functionSet; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getElementData() { |
56
|
|
|
return $this->elementData; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getCssToXpath() { |
60
|
|
|
return $this->xPath; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function getValueParser() { |
64
|
|
|
return $this->valueParser; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function registerProperty($name, Property $property) { |
68
|
|
|
$this->properties[$name] = $property; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function registerContentPseudo($name, Property\ContentPseudo $pseudo) { |
72
|
|
|
if (isset($this->properties['content'])) $this->properties['content']->addContentPseudo($name, $pseudo); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function registerPseudo($name, Pseudo $pseudo) { |
76
|
|
|
$this->pseudo[$name] = $pseudo; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function loadProperties(Hook\PropertyHook $hook) { |
80
|
|
|
foreach ($this->properties as $name => $property) $hook->registerProperty($name, $property); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function createPseudoMatcher($pseudo) { |
84
|
|
|
$pseudoMatcher = new Hook\PseudoMatcher($pseudo, $this->valueParser); |
85
|
|
|
foreach ($this->pseudo as $name => $pseudoFunction) $pseudoMatcher->registerFunction($name, clone $pseudoFunction); |
86
|
|
|
return $pseudoMatcher; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.