1
|
|
|
<?php |
2
|
|
|
/* @description Transformation Style Sheets - Revolutionising PHP templating * |
3
|
|
|
* @author Tom Butler [email protected] * |
4
|
|
|
* @copyright 2015 Tom Butler <[email protected]> | https://r.je/ * |
5
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License * |
6
|
|
|
* @version 1.0 */ |
7
|
|
|
namespace Transphporm; |
8
|
|
|
class Config { |
9
|
|
|
private $properties = []; |
10
|
|
|
private $pseudo = []; |
11
|
|
|
private $functionSet; |
12
|
|
|
private $headers; |
13
|
|
|
private $formatter; |
14
|
|
|
private $baseDir; |
15
|
|
|
|
16
|
|
|
public function __construct(Functionset $functionSet, Hook\ElementData $elementData, Hook\Formatter $formatter, &$headers, &$baseDir) { |
17
|
|
|
$this->formatter = $formatter; |
18
|
|
|
$this->headers = &$headers; |
19
|
|
|
$this->baseDir = &$baseDir; |
20
|
|
|
$this->functionSet = $functionSet; |
21
|
|
|
$this->elementData = $elementData; |
|
|
|
|
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function getFormatter() { |
25
|
|
|
return $this->formatter; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function &getHeaders() { |
29
|
|
|
return $this->headers; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function &getBaseDir() { |
33
|
|
|
return $this->baseDir; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function registerFormatter($formatter) { |
37
|
|
|
$this->formatter->register($formatter); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function getFunctionSet() { |
41
|
|
|
return $this->functionSet; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getElementData() { |
45
|
|
|
return $this->elementData; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function registerProperty($name, Property $property) { |
49
|
|
|
$this->properties[$name] = $property; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function registerPseudo(Pseudo $pseudo) { |
53
|
|
|
$this->pseudo[] = $pseudo; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function loadProperties(Hook\PropertyHook $hook) { |
57
|
|
|
foreach ($this->properties as $name => $property) $hook->registerProperty($name, $property); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function createPseudoMatcher($pseudo) { |
61
|
|
|
$pseudoMatcher = new Hook\PseudoMatcher($pseudo); |
62
|
|
|
foreach ($this->pseudo as $pseudoFunction) $pseudoMatcher->registerFunction($pseudoFunction); |
63
|
|
|
return $pseudoMatcher; |
64
|
|
|
} |
65
|
|
|
} |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: