@@ -19,6 +19,9 @@ discard block |
||
19 | 19 | '\\Transphporm\\Module\\Format' |
20 | 20 | ]; |
21 | 21 | |
22 | + /** |
|
23 | + * @param string $template |
|
24 | + */ |
|
22 | 25 | public function __construct($template, $tss = '', $modules = null) { |
23 | 26 | $this->template = $template; |
24 | 27 | $this->tss = $tss; |
@@ -60,6 +63,11 @@ discard block |
||
60 | 63 | return (object) $result; |
61 | 64 | } |
62 | 65 | |
66 | + /** |
|
67 | + * @param Template $template |
|
68 | + * @param Hook\DataFunction $data |
|
69 | + * @param FeatureSet $featureSet |
|
70 | + */ |
|
63 | 71 | private function processRules($template, $data, $featureSet) { |
64 | 72 | $valueParser = new Parser\Value($data); |
65 | 73 | foreach ($this->getRules($template, $valueParser) as $rule) { |
@@ -68,12 +76,20 @@ discard block |
||
68 | 76 | } |
69 | 77 | |
70 | 78 | //Add a postprocessing hook. This cleans up anything transphporm has added to the markup which needs to be removed |
79 | + |
|
80 | + /** |
|
81 | + * @param Template $template |
|
82 | + */ |
|
71 | 83 | private function doPostProcessing($template) { |
72 | 84 | $template->addHook('//*[@transphporm]', new Hook\PostProcess()); |
73 | 85 | return $template; |
74 | 86 | } |
75 | 87 | |
76 | 88 | //Process a TSS rule e.g. `ul li {content: "foo"; format: bar} |
89 | + |
|
90 | + /** |
|
91 | + * @param Parser\Value $valueParser |
|
92 | + */ |
|
77 | 93 | private function executeTssRule($rule, $template, $valueParser, $featureSet) { |
78 | 94 | $rule->touch(); |
79 | 95 | $pseudoMatcher = new Hook\PseudoMatcher($rule->pseudo); |
@@ -96,6 +112,10 @@ discard block |
||
96 | 112 | |
97 | 113 | //Load the TSS rules either from a file or as a string |
98 | 114 | //N.b. only files can be cached |
115 | + |
|
116 | + /** |
|
117 | + * @param Parser\Value $valueParser |
|
118 | + */ |
|
99 | 119 | private function getRules($template, $valueParser) { |
100 | 120 | if (is_file($this->tss)) { |
101 | 121 | $this->baseDir = dirname(realpath($this->tss)) . DIRECTORY_SEPARATOR; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | |
50 | 50 | $cachedOutput = $this->loadTemplate(); |
51 | 51 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
52 | - $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>' . $cachedOutput['body'] . '</template>' ); |
|
52 | + $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>'.$cachedOutput['body'].'</template>'); |
|
53 | 53 | |
54 | 54 | $this->processRules($template, $data, $featureSet); |
55 | 55 | |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | //N.b. only files can be cached |
99 | 99 | private function getRules($template, $valueParser) { |
100 | 100 | if (is_file($this->tss)) { |
101 | - $this->baseDir = dirname(realpath($this->tss)) . DIRECTORY_SEPARATOR; |
|
101 | + $this->baseDir = dirname(realpath($this->tss)).DIRECTORY_SEPARATOR; |
|
102 | 102 | //The cache for the key: the filename and template prefix |
103 | 103 | //Each template may have a different prefix which changes the parsed TSS, |
104 | 104 | //Because of this the cache needs to be generated for each template prefix. |
105 | - $key = $this->tss . $template->getPrefix() . $this->baseDir; |
|
105 | + $key = $this->tss.$template->getPrefix().$this->baseDir; |
|
106 | 106 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
107 | 107 | $rules = $this->cache->load($key, filemtime($this->tss)); |
108 | 108 | if (!$rules) return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
@@ -25,7 +25,9 @@ discard block |
||
25 | 25 | $this->cache = new Cache(new \ArrayObject()); |
26 | 26 | |
27 | 27 | $modules = is_array($modules) ? $modules : $this->defaultModules; |
28 | - foreach ($modules as $module) $this->loadModule(new $module); |
|
28 | + foreach ($modules as $module) { |
|
29 | + $this->loadModule(new $module); |
|
30 | + } |
|
29 | 31 | } |
30 | 32 | |
31 | 33 | //Allow setting the time used by Transphporm for caching. This is for testing purposes |
@@ -44,7 +46,9 @@ discard block |
||
44 | 46 | $data = new Hook\DataFunction(new \SplObjectStorage(), $data, $this->baseDir); |
45 | 47 | $featureSet = new FeatureSet($data, new Hook\Formatter(), $headers); |
46 | 48 | |
47 | - foreach ($this->modules as $module) $module->load($featureSet); |
|
49 | + foreach ($this->modules as $module) { |
|
50 | + $module->load($featureSet); |
|
51 | + } |
|
48 | 52 | //$locale = $this->getLocale(); |
49 | 53 | |
50 | 54 | $cachedOutput = $this->loadTemplate(); |
@@ -63,7 +67,9 @@ discard block |
||
63 | 67 | private function processRules($template, $data, $featureSet) { |
64 | 68 | $valueParser = new Parser\Value($data); |
65 | 69 | foreach ($this->getRules($template, $valueParser) as $rule) { |
66 | - if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $valueParser, $featureSet); |
|
70 | + if ($rule->shouldRun($this->time)) { |
|
71 | + $this->executeTssRule($rule, $template, $valueParser, $featureSet); |
|
72 | + } |
|
67 | 73 | } |
68 | 74 | } |
69 | 75 | |
@@ -90,8 +96,9 @@ discard block |
||
90 | 96 | if (trim($this->template)[0] !== '<') { |
91 | 97 | $xml = $this->cache->load($this->template, filemtime($this->template)); |
92 | 98 | return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
99 | + } else { |
|
100 | + return ['body' => $this->template, 'headers' => []]; |
|
93 | 101 | } |
94 | - else return ['body' => $this->template, 'headers' => []]; |
|
95 | 102 | } |
96 | 103 | |
97 | 104 | //Load the TSS rules either from a file or as a string |
@@ -105,10 +112,14 @@ discard block |
||
105 | 112 | $key = $this->tss . $template->getPrefix() . $this->baseDir; |
106 | 113 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
107 | 114 | $rules = $this->cache->load($key, filemtime($this->tss)); |
108 | - if (!$rules) return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
|
109 | - else return $rules; |
|
115 | + if (!$rules) { |
|
116 | + return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
|
117 | + } else { |
|
118 | + return $rules; |
|
119 | + } |
|
120 | + } else { |
|
121 | + return (new Parser\Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse(); |
|
110 | 122 | } |
111 | - else return (new Parser\Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse(); |
|
112 | 123 | } |
113 | 124 | |
114 | 125 | public function setCache(\ArrayAccess $cache) { |
@@ -14,6 +14,9 @@ discard block |
||
14 | 14 | return $this->data; |
15 | 15 | } |
16 | 16 | |
17 | + /** |
|
18 | + * @return Hook\Formatter |
|
19 | + */ |
|
17 | 20 | public function getFormatter() { |
18 | 21 | return $this->formatter; |
19 | 22 | } |
@@ -26,6 +29,9 @@ discard block |
||
26 | 29 | $this->formatter->register($formatter); |
27 | 30 | } |
28 | 31 | |
32 | + /** |
|
33 | + * @param string $name |
|
34 | + */ |
|
29 | 35 | public function registerProperty($name, Property $property) { |
30 | 36 | $this->properties[$name] = $property; |
31 | 37 | } |
@@ -35,12 +35,16 @@ |
||
35 | 35 | } |
36 | 36 | |
37 | 37 | public function loadProperties(Hook\PropertyHook $hook) { |
38 | - foreach ($this->properties as $name => $property) $hook->registerProperty($name, $property); |
|
38 | + foreach ($this->properties as $name => $property) { |
|
39 | + $hook->registerProperty($name, $property); |
|
40 | + } |
|
39 | 41 | } |
40 | 42 | |
41 | 43 | public function createPseudoMatcher($pseudo) { |
42 | 44 | $pseudoMatcher = new Hook\PseudoMatcher($pseudo); |
43 | - foreach ($this->pseudo as $pseudoFunction) $pseudoMatcher->registerFunction($pseudoFunction); |
|
45 | + foreach ($this->pseudo as $pseudoFunction) { |
|
46 | + $pseudoMatcher->registerFunction($pseudoFunction); |
|
47 | + } |
|
44 | 48 | return $pseudoMatcher; |
45 | 49 | } |
46 | 50 | } |
47 | 51 | \ No newline at end of file |
@@ -14,8 +14,8 @@ |
||
14 | 14 | |
15 | 15 | private function getLocale() { |
16 | 16 | if (is_array($this->locale)) return $this->locale; |
17 | - else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../' . $this->locale . '.json'), true); |
|
18 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
17 | + else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'../'.$this->locale.'.json'), true); |
|
18 | + else return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'../Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.'enGB.json'), true); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | public function load(\Transphporm\FeatureSet $featureSet) { |
@@ -13,9 +13,13 @@ |
||
13 | 13 | } |
14 | 14 | |
15 | 15 | private function getLocale() { |
16 | - if (is_array($this->locale)) return $this->locale; |
|
17 | - else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../' . $this->locale . '.json'), true); |
|
18 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
16 | + if (is_array($this->locale)) { |
|
17 | + return $this->locale; |
|
18 | + } else if (strlen($this->locale) > 0) { |
|
19 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../' . $this->locale . '.json'), true); |
|
20 | + } else { |
|
21 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
22 | + } |
|
19 | 23 | } |
20 | 24 | |
21 | 25 | public function load(\Transphporm\FeatureSet $featureSet) { |