@@ -2,5 +2,5 @@ |
||
2 | 2 | namespace Transphporm\Property; |
3 | 3 | |
4 | 4 | interface ContentPseudo { |
5 | - public function run($value, $pseudoArgs, $element, \Transphporm\Hook\PseudoMatcher $pseudoMatcher); |
|
5 | + public function run($value, $pseudoArgs, $element, \Transphporm\Hook\PseudoMatcher $pseudoMatcher); |
|
6 | 6 | } |
@@ -6,9 +6,9 @@ |
||
6 | 6 | * @version 1.2 */ |
7 | 7 | namespace Transphporm; |
8 | 8 | class RunException extends \Exception { |
9 | - public function __construct($operationType, $operationName, \Exception $previous = null) { |
|
10 | - $message = 'TSS Error: Problem carrying out ' . $operationType . ' "' . $operationName . '"'; |
|
9 | + public function __construct($operationType, $operationName, \Exception $previous = null) { |
|
10 | + $message = 'TSS Error: Problem carrying out ' . $operationType . ' "' . $operationName . '"'; |
|
11 | 11 | |
12 | - parent::__construct($message, 0, $previous); |
|
13 | - } |
|
12 | + parent::__construct($message, 0, $previous); |
|
13 | + } |
|
14 | 14 | } |
@@ -7,7 +7,7 @@ |
||
7 | 7 | namespace Transphporm; |
8 | 8 | class RunException extends \Exception { |
9 | 9 | public function __construct($operationType, $operationName, \Exception $previous = null) { |
10 | - $message = 'TSS Error: Problem carrying out ' . $operationType . ' "' . $operationName . '"'; |
|
10 | + $message = 'TSS Error: Problem carrying out '.$operationType.' "'.$operationName.'"'; |
|
11 | 11 | |
12 | 12 | parent::__construct($message, 0, $previous); |
13 | 13 | } |
@@ -13,14 +13,17 @@ discard block |
||
13 | 13 | $this->error = null; |
14 | 14 | $tokens = $this->tokenize($tss); |
15 | 15 | |
16 | - foreach ($tokens as $token) |
|
17 | - if (!$this->validateRule($token)) return false; |
|
16 | + foreach ($tokens as $token) { |
|
17 | + if (!$this->validateRule($token)) return false; |
|
18 | + } |
|
18 | 19 | |
19 | 20 | return true; |
20 | 21 | } |
21 | 22 | |
22 | 23 | private function validateRule($token) { |
23 | - if ($token['type'] !== Tokenizer::OPEN_BRACE) return true; |
|
24 | + if ($token['type'] !== Tokenizer::OPEN_BRACE) { |
|
25 | + return true; |
|
26 | + } |
|
24 | 27 | |
25 | 28 | return $this->checkBraces($token) && $this->checkSemicolons($token) |
26 | 29 | && $this->checkParenthesis($token); |
@@ -33,8 +36,9 @@ discard block |
||
33 | 36 | private function checkSemicolons($braceToken) { |
34 | 37 | $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON); |
35 | 38 | array_shift($splitTokens); array_pop($splitTokens); |
36 | - foreach ($splitTokens as $tokens) |
|
37 | - if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false; |
|
39 | + foreach ($splitTokens as $tokens) { |
|
40 | + if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false; |
|
41 | + } |
|
38 | 42 | |
39 | 43 | return true; |
40 | 44 | } |
@@ -44,7 +48,9 @@ discard block |
||
44 | 48 | } |
45 | 49 | |
46 | 50 | private function tokenize($tss) { |
47 | - if (is_file($tss)) $tss = file_get_contents($tss); |
|
51 | + if (is_file($tss)) { |
|
52 | + $tss = file_get_contents($tss); |
|
53 | + } |
|
48 | 54 | return (new Parser\Tokenizer($tss))->getTokens(); |
49 | 55 | } |
50 | 56 | } |
@@ -7,44 +7,44 @@ |
||
7 | 7 | namespace Transphporm; |
8 | 8 | use Transphporm\Parser\Tokenizer; |
9 | 9 | class TSSValidator { |
10 | - private $error; |
|
10 | + private $error; |
|
11 | 11 | |
12 | - public function validate($tss) { |
|
13 | - $this->error = null; |
|
14 | - $tokens = $this->tokenize($tss); |
|
12 | + public function validate($tss) { |
|
13 | + $this->error = null; |
|
14 | + $tokens = $this->tokenize($tss); |
|
15 | 15 | |
16 | - foreach ($tokens as $token) |
|
17 | - if (!$this->validateRule($token)) return false; |
|
16 | + foreach ($tokens as $token) |
|
17 | + if (!$this->validateRule($token)) return false; |
|
18 | 18 | |
19 | - return true; |
|
20 | - } |
|
19 | + return true; |
|
20 | + } |
|
21 | 21 | |
22 | - private function validateRule($token) { |
|
23 | - if ($token['type'] !== Tokenizer::OPEN_BRACE) return true; |
|
22 | + private function validateRule($token) { |
|
23 | + if ($token['type'] !== Tokenizer::OPEN_BRACE) return true; |
|
24 | 24 | |
25 | - return $this->checkBraces($token) && $this->checkSemicolons($token) |
|
26 | - && $this->checkParenthesis($token); |
|
27 | - } |
|
25 | + return $this->checkBraces($token) && $this->checkSemicolons($token) |
|
26 | + && $this->checkParenthesis($token); |
|
27 | + } |
|
28 | 28 | |
29 | - private function checkBraces($token) { |
|
30 | - return strpos($token['string'], '{') === false; |
|
31 | - } |
|
29 | + private function checkBraces($token) { |
|
30 | + return strpos($token['string'], '{') === false; |
|
31 | + } |
|
32 | 32 | |
33 | - private function checkSemicolons($braceToken) { |
|
34 | - $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON); |
|
35 | - array_shift($splitTokens); array_pop($splitTokens); |
|
36 | - foreach ($splitTokens as $tokens) |
|
37 | - if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false; |
|
33 | + private function checkSemicolons($braceToken) { |
|
34 | + $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON); |
|
35 | + array_shift($splitTokens); array_pop($splitTokens); |
|
36 | + foreach ($splitTokens as $tokens) |
|
37 | + if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false; |
|
38 | 38 | |
39 | - return true; |
|
40 | - } |
|
39 | + return true; |
|
40 | + } |
|
41 | 41 | |
42 | - private function checkParenthesis($token) { |
|
43 | - return substr_count($token['string'], '(') === substr_count($token['string'], ')'); |
|
44 | - } |
|
42 | + private function checkParenthesis($token) { |
|
43 | + return substr_count($token['string'], '(') === substr_count($token['string'], ')'); |
|
44 | + } |
|
45 | 45 | |
46 | - private function tokenize($tss) { |
|
47 | - if (is_file($tss)) $tss = file_get_contents($tss); |
|
48 | - return (new Parser\Tokenizer($tss))->getTokens(); |
|
49 | - } |
|
46 | + private function tokenize($tss) { |
|
47 | + if (is_file($tss)) $tss = file_get_contents($tss); |
|
48 | + return (new Parser\Tokenizer($tss))->getTokens(); |
|
49 | + } |
|
50 | 50 | } |
@@ -19,15 +19,15 @@ |
||
19 | 19 | |
20 | 20 | public function getFilePath($filePath) { |
21 | 21 | if (is_file($filePath)) return $filePath; |
22 | - else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) return $this->baseDir . DIRECTORY_SEPARATOR . $filePath; |
|
22 | + else if (is_file($this->baseDir.DIRECTORY_SEPARATOR.$filePath)) return $this->baseDir.DIRECTORY_SEPARATOR.$filePath; |
|
23 | 23 | else return $this->loadFromPaths($filePath); |
24 | 24 | } |
25 | 25 | |
26 | 26 | private function loadFromPaths($filePath) { |
27 | 27 | foreach ($this->paths as $path) { |
28 | - if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) return $path . DIRECTORY_SEPARATOR . $filePath; |
|
28 | + if (is_file($path.DIRECTORY_SEPARATOR.$filePath)) return $path.DIRECTORY_SEPARATOR.$filePath; |
|
29 | 29 | } |
30 | 30 | |
31 | - throw new \Exception('File ' . $filePath . ' not found in paths (' . implode(', ', $this->paths) . ')'); |
|
31 | + throw new \Exception('File '.$filePath.' not found in paths ('.implode(', ', $this->paths).')'); |
|
32 | 32 | } |
33 | 33 | } |
@@ -18,14 +18,20 @@ |
||
18 | 18 | } |
19 | 19 | |
20 | 20 | public function getFilePath($filePath) { |
21 | - if (is_file($filePath)) return $filePath; |
|
22 | - else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) return $this->baseDir . DIRECTORY_SEPARATOR . $filePath; |
|
23 | - else return $this->loadFromPaths($filePath); |
|
21 | + if (is_file($filePath)) { |
|
22 | + return $filePath; |
|
23 | + } else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) { |
|
24 | + return $this->baseDir . DIRECTORY_SEPARATOR . $filePath; |
|
25 | + } else { |
|
26 | + return $this->loadFromPaths($filePath); |
|
27 | + } |
|
24 | 28 | } |
25 | 29 | |
26 | 30 | private function loadFromPaths($filePath) { |
27 | 31 | foreach ($this->paths as $path) { |
28 | - if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) return $path . DIRECTORY_SEPARATOR . $filePath; |
|
32 | + if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) { |
|
33 | + return $path . DIRECTORY_SEPARATOR . $filePath; |
|
34 | + } |
|
29 | 35 | } |
30 | 36 | |
31 | 37 | throw new \Exception('File ' . $filePath . ' not found in paths (' . implode(', ', $this->paths) . ')'); |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | $this->save = function($content = null) { |
39 | 39 | return $this->document->saveHtml($content); |
40 | 40 | }; |
41 | - $this->document->loadHtml('<' . '?xml encoding="UTF-8">' . $doc, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); |
|
41 | + $this->document->loadHtml('<'.'?xml encoding="UTF-8">'.$doc, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); |
|
42 | 42 | |
43 | 43 | } |
44 | 44 | else { |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | if ($document) return $this->document; |
90 | 90 | |
91 | 91 | //Print the doctype... saveHtml inexplicably does not support $doc->doctype as an argument |
92 | - $output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype) . "\n" : ''; |
|
92 | + $output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype)."\n" : ''; |
|
93 | 93 | |
94 | 94 | if ($this->document->documentElement->tagName !== 'template') $output .= call_user_func($this->save, $this->document->documentElement); |
95 | 95 | else $output = $this->printDocument(); |
@@ -40,8 +40,7 @@ discard block |
||
40 | 40 | }; |
41 | 41 | $this->document->loadHtml('<' . '?xml encoding="UTF-8">' . $doc, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); |
42 | 42 | |
43 | - } |
|
44 | - else { |
|
43 | + } else { |
|
45 | 44 | $this->document->loadXml($doc); |
46 | 45 | //XML was loaded, save as XML. |
47 | 46 | $this->save = function($content = null) { |
@@ -66,7 +65,9 @@ discard block |
||
66 | 65 | /** Loops through all assigned hooks, runs the Xpath query and calls the hook */ |
67 | 66 | private function processHooks() { |
68 | 67 | foreach ($this->hooks as list($query, $hook)) { |
69 | - foreach ($this->xpath->query($query) as $element) $hook->run($element); |
|
68 | + foreach ($this->xpath->query($query) as $element) { |
|
69 | + $hook->run($element); |
|
70 | + } |
|
70 | 71 | } |
71 | 72 | $this->hooks = []; |
72 | 73 | } |
@@ -74,7 +75,9 @@ discard block |
||
74 | 75 | /** Prints out the current DomDocument as HTML */ |
75 | 76 | private function printDocument() { |
76 | 77 | $output = ''; |
77 | - foreach ($this->document->documentElement->childNodes as $node) $output .= call_user_func($this->save, $node); |
|
78 | + foreach ($this->document->documentElement->childNodes as $node) { |
|
79 | + $output .= call_user_func($this->save, $node); |
|
80 | + } |
|
78 | 81 | return $output; |
79 | 82 | } |
80 | 83 | |
@@ -86,13 +89,18 @@ discard block |
||
86 | 89 | //Generate the document by taking only the childnodes of the template, ignoring the <template> and </template> tags |
87 | 90 | //TODO: Is there a faster way of doing this without string manipulation on the output or this loop through childnodes? |
88 | 91 | //Either return a whole DomDocument or return the output HTML |
89 | - if ($document) return $this->document; |
|
92 | + if ($document) { |
|
93 | + return $this->document; |
|
94 | + } |
|
90 | 95 | |
91 | 96 | //Print the doctype... saveHtml inexplicably does not support $doc->doctype as an argument |
92 | 97 | $output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype) . "\n" : ''; |
93 | 98 | |
94 | - if ($this->document->documentElement->tagName !== 'template') $output .= call_user_func($this->save, $this->document->documentElement); |
|
95 | - else $output = $this->printDocument(); |
|
99 | + if ($this->document->documentElement->tagName !== 'template') { |
|
100 | + $output .= call_user_func($this->save, $this->document->documentElement); |
|
101 | + } else { |
|
102 | + $output = $this->printDocument(); |
|
103 | + } |
|
96 | 104 | |
97 | 105 | //repair empty tags. Browsers break on <script /> and <div /> so can't avoid LIBXML_NOEMPTYTAG but they also break on <base></base> so repair them |
98 | 106 | $output = str_replace(['></img>', '></br>', '></meta>', '></base>', '></link>', '></hr>', '></input>'], ' />', $output); |
@@ -17,13 +17,13 @@ |
||
17 | 17 | |
18 | 18 | if ($this->isJsonFile($json)) { |
19 | 19 | $path = $this->filePath->getFilePath($json); |
20 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
20 | + if (!file_exists($path)) throw new \Exception('File does not exist at: '.$path); |
|
21 | 21 | $json = file_get_contents($path); |
22 | 22 | } |
23 | 23 | |
24 | 24 | $map = json_decode($json, true); |
25 | 25 | |
26 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
26 | + if (!is_array($map)) throw new \Exception('Could not decode json: '.json_last_error_msg()); |
|
27 | 27 | |
28 | 28 | return $map; |
29 | 29 | } |
@@ -17,13 +17,17 @@ |
||
17 | 17 | |
18 | 18 | if ($this->isJsonFile($json)) { |
19 | 19 | $path = $this->filePath->getFilePath($json); |
20 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
20 | + if (!file_exists($path)) { |
|
21 | + throw new \Exception('File does not exist at: ' . $path); |
|
22 | + } |
|
21 | 23 | $json = file_get_contents($path); |
22 | 24 | } |
23 | 25 | |
24 | 26 | $map = json_decode($json, true); |
25 | 27 | |
26 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
28 | + if (!is_array($map)) { |
|
29 | + throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
30 | + } |
|
27 | 31 | |
28 | 32 | return $map; |
29 | 33 | } |
@@ -25,7 +25,9 @@ |
||
25 | 25 | /** 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*/ |
26 | 26 | public function getData(\DomElement $element = null, $type = 'data') { |
27 | 27 | while ($element) { |
28 | - if (isset($this->elementMap[$element]) && array_key_exists($type, $this->elementMap[$element])) return $this->elementMap[$element][$type]; |
|
28 | + if (isset($this->elementMap[$element]) && array_key_exists($type, $this->elementMap[$element])) { |
|
29 | + return $this->elementMap[$element][$type]; |
|
30 | + } |
|
29 | 31 | $element = $element->parentNode; |
30 | 32 | } |
31 | 33 | return $this->data; |
@@ -33,14 +33,17 @@ |
||
33 | 33 | ]; |
34 | 34 | |
35 | 35 | if ($funcs[$this->mode] === 'concat' && is_numeric($newValue) |
36 | - && is_numeric($this->result[count($this->result)-1])) |
|
37 | - $this->add($newValue); |
|
38 | - else |
|
39 | - $this->{$funcs[$this->mode]}($newValue); |
|
36 | + && is_numeric($this->result[count($this->result)-1])) { |
|
37 | + $this->add($newValue); |
|
38 | + } else { |
|
39 | + $this->{$funcs[$this->mode]}($newValue); |
|
40 | + } |
|
40 | 41 | } |
41 | 42 | |
42 | 43 | public function in($value) { |
43 | - if (!is_array($value)) throw new \Exception(' `in` can only be used with arrays'); |
|
44 | + if (!is_array($value)) { |
|
45 | + throw new \Exception(' `in` can only be used with arrays'); |
|
46 | + } |
|
44 | 47 | $this->result[count($this->result)-1] = in_array($this->result[count($this->result)-1], $value); |
45 | 48 | } |
46 | 49 |
@@ -37,9 +37,13 @@ |
||
37 | 37 | } |
38 | 38 | |
39 | 39 | private function processLiterals($tokens, $name, $str) { |
40 | - if (is_numeric($name)) $tokens->add(['type' => Tokenizer::NUMERIC, 'value' => $name]); |
|
41 | - else if (method_exists($this, $name)) $this->$name($tokens); |
|
42 | - else $tokens->add(['type' => Tokenizer::NAME, 'value' => $name, 'line' => $str->lineNo()]); |
|
40 | + if (is_numeric($name)) { |
|
41 | + $tokens->add(['type' => Tokenizer::NUMERIC, 'value' => $name]); |
|
42 | + } else if (method_exists($this, $name)) { |
|
43 | + $this->$name($tokens); |
|
44 | + } else { |
|
45 | + $tokens->add(['type' => Tokenizer::NAME, 'value' => $name, 'line' => $str->lineNo()]); |
|
46 | + } |
|
43 | 47 | } |
44 | 48 | |
45 | 49 | private function true($tokens) { |