@@ -34,6 +34,9 @@ |
||
34 | 34 | return false; |
35 | 35 | } |
36 | 36 | |
37 | + /** |
|
38 | + * @param \Transphporm\Hook\PseudoMatcher $pseudoMatcher |
|
39 | + */ |
|
37 | 40 | private function createHook($newRules, $pseudoMatcher, $properties) { |
38 | 41 | $hook = new \Transphporm\Hook\PropertyHook($newRules, $pseudoMatcher, new \Transphporm\Parser\Value($this->data)); |
39 | 42 | foreach ($properties as $name => $property) $hook->registerProperty($name, $property); |
@@ -13,6 +13,9 @@ discard block |
||
13 | 13 | private $formatter; |
14 | 14 | private $baseDir; |
15 | 15 | |
16 | + /** |
|
17 | + * @param string $baseDir |
|
18 | + */ |
|
16 | 19 | public function __construct(Functionset $functionSet, Hook\ElementData $elementData, Hook\Formatter $formatter, &$headers, &$baseDir) { |
17 | 20 | $this->formatter = $formatter; |
18 | 21 | $this->headers = &$headers; |
@@ -41,10 +44,16 @@ discard block |
||
41 | 44 | return $this->functionSet; |
42 | 45 | } |
43 | 46 | |
47 | + /** |
|
48 | + * @return Hook\ElementData |
|
49 | + */ |
|
44 | 50 | public function getElementData() { |
45 | 51 | return $this->elementData; |
46 | 52 | } |
47 | 53 | |
54 | + /** |
|
55 | + * @param string $name |
|
56 | + */ |
|
48 | 57 | public function registerProperty($name, Property $property) { |
49 | 58 | $this->properties[$name] = $property; |
50 | 59 | } |
@@ -11,6 +11,9 @@ discard block |
||
11 | 11 | private $data; |
12 | 12 | private $baseDir; |
13 | 13 | |
14 | + /** |
|
15 | + * @param string $baseDir |
|
16 | + */ |
|
14 | 17 | public function __construct(Hook\ElementData $elementData, &$baseDir) { |
15 | 18 | $this->baseDir = &$baseDir; |
16 | 19 | $this->elementData = $elementData; |
@@ -23,6 +26,9 @@ discard block |
||
23 | 26 | else return \Transphporm\Parser\Value::IS_NOT_FUNCTION; |
24 | 27 | } |
25 | 28 | |
29 | + /** |
|
30 | + * @param string $name |
|
31 | + */ |
|
26 | 32 | public function addFunction($name, \Transphporm\TSSFunction $function) { |
27 | 33 | $this->functions[$name] = $function; |
28 | 34 | } |
@@ -19,8 +19,9 @@ |
||
19 | 19 | public function __call($name, $args) { |
20 | 20 | if (isset($this->functions[$name])) { |
21 | 21 | return $this->functions[$name]->run($args[0], $args[1]); |
22 | + } else { |
|
23 | + return \Transphporm\Parser\Value::IS_NOT_FUNCTION; |
|
22 | 24 | } |
23 | - else return \Transphporm\Parser\Value::IS_NOT_FUNCTION; |
|
24 | 25 | } |
25 | 26 | |
26 | 27 | public function addFunction($name, \Transphporm\TSSFunction $function) { |
@@ -11,6 +11,9 @@ discard block |
||
11 | 11 | private $formatter; |
12 | 12 | |
13 | 13 | |
14 | + /** |
|
15 | + * @param \Transphporm\FunctionSet $data |
|
16 | + */ |
|
14 | 17 | public function __construct($data, &$headers, \Transphporm\Hook\Formatter $formatter) { |
15 | 18 | $this->data = $data; |
16 | 19 | $this->headers = &$headers; |
@@ -30,6 +33,9 @@ discard block |
||
30 | 33 | } |
31 | 34 | } |
32 | 35 | |
36 | + /** |
|
37 | + * @param \DOMElement $element |
|
38 | + */ |
|
33 | 39 | private function shouldRun($element) { |
34 | 40 | if ($element->getAttribute('transphporm') === 'remove') return false; |
35 | 41 | do { |
@@ -43,6 +49,10 @@ discard block |
||
43 | 49 | return (isset($rules['content-mode'])) ? $rules['content-mode'] : 'append'; |
44 | 50 | } |
45 | 51 | |
52 | + /** |
|
53 | + * @param \DOMElement $element |
|
54 | + * @param \Transphporm\Hook\PseudoMatcher $pseudoMatcher |
|
55 | + */ |
|
46 | 56 | private function processPseudo($value, $element, $pseudoMatcher) { |
47 | 57 | $pseudoContent = ['attr', 'header', 'before', 'after']; |
48 | 58 | foreach ($pseudoContent as $pseudo) { |
@@ -93,6 +103,9 @@ discard block |
||
93 | 103 | } |
94 | 104 | } |
95 | 105 | |
106 | + /** |
|
107 | + * @param \DOMElement $element |
|
108 | + */ |
|
96 | 109 | private function replaceContent($element, $content) { |
97 | 110 | //If this rule was cached, the elements that were added last time need to be removed prior to running the rule again. |
98 | 111 | foreach ($this->getNode($content, $element->ownerDocument) as $node) { |
@@ -101,12 +114,18 @@ discard block |
||
101 | 114 | $element->setAttribute('transphporm', 'remove'); |
102 | 115 | } |
103 | 116 | |
117 | + /** |
|
118 | + * @param \DOMElement $element |
|
119 | + */ |
|
104 | 120 | private function appendContent($element, $content) { |
105 | 121 | foreach ($this->getNode($content, $element->ownerDocument) as $node) { |
106 | 122 | $element->appendChild($node); |
107 | 123 | } |
108 | 124 | } |
109 | 125 | |
126 | + /** |
|
127 | + * @param \DOMElement $element |
|
128 | + */ |
|
110 | 129 | private function removeAllChildren($element) { |
111 | 130 | while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
112 | 131 | } |
@@ -18,22 +18,31 @@ discard block |
||
18 | 18 | } |
19 | 19 | |
20 | 20 | public function run($value, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
21 | - if (!$this->shouldRun($element)) return false; |
|
21 | + if (!$this->shouldRun($element)) { |
|
22 | + return false; |
|
23 | + } |
|
22 | 24 | |
23 | 25 | $value = $this->formatter->format($value, $rules); |
24 | 26 | if (!$this->processPseudo($value, $element, $pseudoMatcher)) { |
25 | 27 | //Remove the current contents |
26 | 28 | $this->removeAllChildren($element); |
27 | 29 | //Now make a text node |
28 | - if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $value); |
|
29 | - else $this->appendContent($element, $value); |
|
30 | + if ($this->getContentMode($rules) === 'replace') { |
|
31 | + $this->replaceContent($element, $value); |
|
32 | + } else { |
|
33 | + $this->appendContent($element, $value); |
|
34 | + } |
|
30 | 35 | } |
31 | 36 | } |
32 | 37 | |
33 | 38 | private function shouldRun($element) { |
34 | - if ($element->getAttribute('transphporm') === 'remove') return false; |
|
39 | + if ($element->getAttribute('transphporm') === 'remove') { |
|
40 | + return false; |
|
41 | + } |
|
35 | 42 | do { |
36 | - if ($element->getAttribute('transphporm') == 'includedtemplate') return false; |
|
43 | + if ($element->getAttribute('transphporm') == 'includedtemplate') { |
|
44 | + return false; |
|
45 | + } |
|
37 | 46 | } |
38 | 47 | while (($element = $element->parentNode) instanceof \DomElement); |
39 | 48 | return true; |
@@ -60,9 +69,10 @@ discard block |
||
60 | 69 | $new = $document->importNode($n, true); |
61 | 70 | //Removing this might cause problems with caching... |
62 | 71 | //$new->setAttribute('transphporm', 'added'); |
63 | - } |
|
64 | - else { |
|
65 | - if ($n instanceof \DomText) $n = $n->nodeValue; |
|
72 | + } else { |
|
73 | + if ($n instanceof \DomText) { |
|
74 | + $n = $n->nodeValue; |
|
75 | + } |
|
66 | 76 | $new = $document->createElement('text'); |
67 | 77 | $new->appendChild($document->createTextNode($n)); |
68 | 78 | $new->setAttribute('transphporm', 'text'); |
@@ -108,6 +118,8 @@ discard block |
||
108 | 118 | } |
109 | 119 | |
110 | 120 | private function removeAllChildren($element) { |
111 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
121 | + while ($element->hasChildNodes()) { |
|
122 | + $element->removeChild($element->firstChild); |
|
123 | + } |
|
112 | 124 | } |
113 | 125 | } |
114 | 126 | \ No newline at end of file |
@@ -17,6 +17,9 @@ discard block |
||
17 | 17 | $this->functionSet = $functionSet; |
18 | 18 | } |
19 | 19 | |
20 | + /** |
|
21 | + * @param \DOMElement $element |
|
22 | + */ |
|
20 | 23 | private function traverse($name, $data, $element) { |
21 | 24 | $name = str_replace(['[', ']'], ['.', ''], $name); |
22 | 25 | $parts = explode('.', $name); |
@@ -37,6 +40,9 @@ discard block |
||
37 | 40 | return $obj; |
38 | 41 | } |
39 | 42 | |
43 | + /** |
|
44 | + * @param \Transphporm\Parser\Value $valueParser |
|
45 | + */ |
|
40 | 46 | private function traverseObj($part, $obj, $valueParser, $element) { |
41 | 47 | if (strpos($part, '(') !== false) { |
42 | 48 | $subObjParser = new \Transphporm\Parser\Value($obj, $valueParser, false); |
@@ -6,12 +6,12 @@ |
||
6 | 6 | * @version 1.0 */ |
7 | 7 | namespace Transphporm\TSSFunction; |
8 | 8 | /* Handles data() and iteration() function calls from the stylesheet */ |
9 | -class Data implements \Transphporm\TSSFunction{ |
|
9 | +class Data implements \Transphporm\TSSFunction { |
|
10 | 10 | private $data; |
11 | 11 | private $dataType; |
12 | 12 | private $functionSet; |
13 | 13 | |
14 | - public function __construct(\Transphporm\Hook\ElementData $data, \Transphporm\FunctionSet $functionSet, $dataKey = 'data') { |
|
14 | + public function __construct(\Transphporm\Hook\ElementData $data, \Transphporm\FunctionSet $functionSet, $dataKey = 'data') { |
|
15 | 15 | $this->data = $data; |
16 | 16 | $this->dataKey = $dataKey; |
17 | 17 | $this->functionSet = $functionSet; |
@@ -25,14 +25,18 @@ discard block |
||
25 | 25 | $valueParser = new \Transphporm\Parser\Value($this->functionSet); |
26 | 26 | |
27 | 27 | foreach ($parts as $part) { |
28 | - if ($part === '') continue; |
|
28 | + if ($part === '') { |
|
29 | + continue; |
|
30 | + } |
|
29 | 31 | $part = $valueParser->parse($part, $element)[0]; |
30 | 32 | |
31 | 33 | $funcResult = $this->traverseObj($part, $obj, $valueParser, $element); |
32 | 34 | |
33 | - if ($funcResult !== false) $obj = $funcResult; |
|
34 | - |
|
35 | - else $obj = $this->ifNull($obj, $part); |
|
35 | + if ($funcResult !== false) { |
|
36 | + $obj = $funcResult; |
|
37 | + } else { |
|
38 | + $obj = $this->ifNull($obj, $part); |
|
39 | + } |
|
36 | 40 | } |
37 | 41 | return $obj; |
38 | 42 | } |
@@ -41,14 +45,19 @@ discard block |
||
41 | 45 | if (strpos($part, '(') !== false) { |
42 | 46 | $subObjParser = new \Transphporm\Parser\Value($obj, $valueParser, false); |
43 | 47 | return $subObjParser->parse($part, $element)[0]; |
48 | + } else if (method_exists($obj, $part)) { |
|
49 | + return call_user_func([$obj, $part]); |
|
50 | + } else { |
|
51 | + return false; |
|
44 | 52 | } |
45 | - else if (method_exists($obj, $part)) return call_user_func([$obj, $part]); |
|
46 | - else return false; |
|
47 | 53 | } |
48 | 54 | |
49 | 55 | private function ifNull($obj, $key) { |
50 | - if (is_array($obj)) return isset($obj[$key]) ? $obj[$key] : null; |
|
51 | - else return isset($obj->$key) ? $obj->$key : null; |
|
56 | + if (is_array($obj)) { |
|
57 | + return isset($obj[$key]) ? $obj[$key] : null; |
|
58 | + } else { |
|
59 | + return isset($obj->$key) ? $obj->$key : null; |
|
60 | + } |
|
52 | 61 | } |
53 | 62 | |
54 | 63 |
@@ -18,7 +18,9 @@ discard block |
||
18 | 18 | /** Binds data to an element */ |
19 | 19 | public function bind(\DomNode $element, $data, $type = 'data') { |
20 | 20 | //This is a bit of a hack to workaround #24, might need a better way of doing this if it causes a problem |
21 | - if (is_array($data) && $this->isObjectArray($data)) $data = $data[0]; |
|
21 | + if (is_array($data) && $this->isObjectArray($data)) { |
|
22 | + $data = $data[0]; |
|
23 | + } |
|
22 | 24 | $content = isset($this->elementMap[$element]) ? $this->elementMap[$element] : []; |
23 | 25 | $content[$type] = $data; |
24 | 26 | $this->elementMap[$element] = $content; |
@@ -31,7 +33,9 @@ discard block |
||
31 | 33 | /** Returns the data that has been bound to $element, or, if no data is bound to $element climb the DOM tree to find the data bound to a parent node*/ |
32 | 34 | public function getData(\DomElement $element = null, $type = 'data') { |
33 | 35 | while ($element) { |
34 | - if (isset($this->elementMap[$element]) && isset($this->elementMap[$element][$type])) return $this->elementMap[$element][$type]; |
|
36 | + if (isset($this->elementMap[$element]) && isset($this->elementMap[$element][$type])) { |
|
37 | + return $this->elementMap[$element][$type]; |
|
38 | + } |
|
35 | 39 | $element = $element->parentNode; |
36 | 40 | } |
37 | 41 | return $this->data; |
@@ -14,10 +14,14 @@ discard block |
||
14 | 14 | |
15 | 15 | public function match($pseudo, \DomElement $element) { |
16 | 16 | $pos = strpos($pseudo, '['); |
17 | - if ($pos === false) return true; |
|
17 | + if ($pos === false) { |
|
18 | + return true; |
|
19 | + } |
|
18 | 20 | |
19 | 21 | $name = substr($pseudo, 0, $pos); |
20 | - if (!is_callable([$this->functionSet, $name])) return true; |
|
22 | + if (!is_callable([$this->functionSet, $name])) { |
|
23 | + return true; |
|
24 | + } |
|
21 | 25 | |
22 | 26 | $bracketMatcher = new \Transphporm\Parser\BracketMatcher($pseudo); |
23 | 27 | $criteria = $bracketMatcher->match('[', ']'); |
@@ -41,16 +45,21 @@ discard block |
||
41 | 45 | } |
42 | 46 | |
43 | 47 | private function parseValue($value) { |
44 | - if ($value == 'true') return true; |
|
45 | - else if ($value == 'false') return false; |
|
46 | - else return $value; |
|
48 | + if ($value == 'true') { |
|
49 | + return true; |
|
50 | + } else if ($value == 'false') { |
|
51 | + return false; |
|
52 | + } else { |
|
53 | + return $value; |
|
54 | + } |
|
47 | 55 | } |
48 | 56 | |
49 | 57 | private function getOperator($field) { |
50 | 58 | if ($field[strlen($field)-1] == '!') { |
51 | 59 | return '!'; |
60 | + } else { |
|
61 | + return ''; |
|
52 | 62 | } |
53 | - else return ''; |
|
54 | 63 | } |
55 | 64 | |
56 | 65 | } |
57 | 66 | \ No newline at end of file |
@@ -22,9 +22,9 @@ |
||
22 | 22 | |
23 | 23 | public function run(array $args, \DomElement $element) { |
24 | 24 | $selector = $this->readArray($args, 1); |
25 | - $tss = $this->baseDir . $this->readArray($args, 2); |
|
25 | + $tss = $this->baseDir.$this->readArray($args, 2); |
|
26 | 26 | |
27 | - $newTemplate = new \Transphporm\Builder($this->baseDir . $args[0], $tss); |
|
27 | + $newTemplate = new \Transphporm\Builder($this->baseDir.$args[0], $tss); |
|
28 | 28 | |
29 | 29 | $doc = $newTemplate->output($this->elementData->getData($element), true)->body; |
30 | 30 | if ($selector != '') return $this->templateSubsection($doc, $selector); |
@@ -27,7 +27,9 @@ discard block |
||
27 | 27 | $newTemplate = new \Transphporm\Builder($this->baseDir . $args[0], $tss); |
28 | 28 | |
29 | 29 | $doc = $newTemplate->output($this->elementData->getData($element), true)->body; |
30 | - if ($selector != '') return $this->templateSubsection($doc, $selector); |
|
30 | + if ($selector != '') { |
|
31 | + return $this->templateSubsection($doc, $selector); |
|
32 | + } |
|
31 | 33 | |
32 | 34 | $newNode = $doc->documentElement; |
33 | 35 | $result = []; |
@@ -54,7 +56,9 @@ discard block |
||
54 | 56 | |
55 | 57 | private function getClonedElement($node, $tss) { |
56 | 58 | $clone = $node->cloneNode(true); |
57 | - if ($tss !== null && $clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate'); |
|
59 | + if ($tss !== null && $clone instanceof \DomElement) { |
|
60 | + $clone->setAttribute('transphporm', 'includedtemplate'); |
|
61 | + } |
|
58 | 62 | return $clone; |
59 | 63 | } |
60 | 64 | } |
61 | 65 | \ No newline at end of file |
@@ -26,7 +26,9 @@ discard block |
||
26 | 26 | $this->cache = new Cache(new \ArrayObject()); |
27 | 27 | |
28 | 28 | $modules = is_array($modules) ? $modules : $this->defaultModules; |
29 | - foreach ($modules as $module) $this->loadModule(new $module); |
|
29 | + foreach ($modules as $module) { |
|
30 | + $this->loadModule(new $module); |
|
31 | + } |
|
30 | 32 | } |
31 | 33 | |
32 | 34 | //Allow setting the time used by Transphporm for caching. This is for testing purposes |
@@ -47,7 +49,9 @@ discard block |
||
47 | 49 | $data = new FunctionSet($elementData, $this->baseDir); |
48 | 50 | $config = new Config($data, $elementData, new Hook\Formatter(), $headers, $this->baseDir); |
49 | 51 | |
50 | - foreach ($this->modules as $module) $module->load($config); |
|
52 | + foreach ($this->modules as $module) { |
|
53 | + $module->load($config); |
|
54 | + } |
|
51 | 55 | |
52 | 56 | $cachedOutput = $this->loadTemplate(); |
53 | 57 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
@@ -67,7 +71,9 @@ discard block |
||
67 | 71 | $rules = $this->getRules($template, $valueParser); |
68 | 72 | |
69 | 73 | foreach ($rules as $rule) { |
70 | - if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $valueParser, $config); |
|
74 | + if ($rule->shouldRun($this->time)) { |
|
75 | + $this->executeTssRule($rule, $template, $valueParser, $config); |
|
76 | + } |
|
71 | 77 | } |
72 | 78 | } |
73 | 79 | |
@@ -92,8 +98,9 @@ discard block |
||
92 | 98 | if (trim($this->template)[0] !== '<') { |
93 | 99 | $xml = $this->cache->load($this->template, filemtime($this->template)); |
94 | 100 | return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
101 | + } else { |
|
102 | + return ['body' => $this->template, 'headers' => []]; |
|
95 | 103 | } |
96 | - else return ['body' => $this->template, 'headers' => []]; |
|
97 | 104 | } |
98 | 105 | |
99 | 106 | //Load the TSS rules either from a file or as a string |
@@ -107,10 +114,14 @@ discard block |
||
107 | 114 | $key = $this->tss . $template->getPrefix() . $this->baseDir; |
108 | 115 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
109 | 116 | $rules = $this->cache->load($key, filemtime($this->tss)); |
110 | - if (!$rules) return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
|
111 | - else return $rules; |
|
117 | + if (!$rules) { |
|
118 | + return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
|
119 | + } else { |
|
120 | + return $rules; |
|
121 | + } |
|
122 | + } else { |
|
123 | + return (new Parser\Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse(); |
|
112 | 124 | } |
113 | - else return (new Parser\Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse(); |
|
114 | 125 | } |
115 | 126 | |
116 | 127 | public function setCache(\ArrayAccess $cache) { |