@@ -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 |
@@ -51,7 +53,9 @@ discard block |
||
51 | 53 | $valueParser = new Parser\Value($data); |
52 | 54 | $config = new Config($data, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($valueParser, $data, $template->getPrefix()), $headers, $this->baseDir); |
53 | 55 | |
54 | - foreach ($this->modules as $module) $module->load($config); |
|
56 | + foreach ($this->modules as $module) { |
|
57 | + $module->load($config); |
|
58 | + } |
|
55 | 59 | |
56 | 60 | $this->processRules($template, $config); |
57 | 61 | |
@@ -66,7 +70,9 @@ discard block |
||
66 | 70 | $rules = $this->getRules($template, $config); |
67 | 71 | |
68 | 72 | foreach ($rules as $rule) { |
69 | - if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $config); |
|
73 | + if ($rule->shouldRun($this->time)) { |
|
74 | + $this->executeTssRule($rule, $template, $config); |
|
75 | + } |
|
70 | 76 | } |
71 | 77 | } |
72 | 78 | |
@@ -91,8 +97,9 @@ discard block |
||
91 | 97 | if (trim($this->template)[0] !== '<') { |
92 | 98 | $xml = $this->cache->load($this->template, filemtime($this->template)); |
93 | 99 | return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
100 | + } else { |
|
101 | + return ['body' => $this->template, 'headers' => []]; |
|
94 | 102 | } |
95 | - else return ['body' => $this->template, 'headers' => []]; |
|
96 | 103 | } |
97 | 104 | |
98 | 105 | //Load the TSS rules either from a file or as a string |
@@ -107,10 +114,14 @@ discard block |
||
107 | 114 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
108 | 115 | $rules = $this->cache->load($key, filemtime($this->tss)); |
109 | 116 | |
110 | - if (!$rules) return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $config->getCssToXpath(), $config->getValueParser()))->parse()); |
|
111 | - else return $rules; |
|
117 | + if (!$rules) { |
|
118 | + return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $config->getCssToXpath(), $config->getValueParser()))->parse()); |
|
119 | + } else { |
|
120 | + return $rules; |
|
121 | + } |
|
122 | + } else { |
|
123 | + return (new Parser\Sheet($this->tss, $this->baseDir, $config->getCssToXpath(), $config->getValueParser()))->parse(); |
|
112 | 124 | } |
113 | - else return (new Parser\Sheet($this->tss, $this->baseDir, $config->getCssToXpath(), $config->getValueParser()))->parse(); |
|
114 | 125 | } |
115 | 126 | |
116 | 127 | public function setCache(\ArrayAccess $cache) { |
@@ -20,12 +20,12 @@ |
||
20 | 20 | $this->functionSet = $functionSet; |
21 | 21 | |
22 | 22 | $this->translators = [ |
23 | - Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//' . $prefix . $string; }, |
|
24 | - '' => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
25 | - Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
26 | - Tokenizer::NUM_SIGN => function($string) { return '[@id=\'' . $string . '\']'; }, |
|
27 | - Tokenizer::DOT => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' ' . $string . ' \')]'; }, |
|
28 | - Tokenizer::OPEN_SQUARE_BRACKET => function($string) use ($hash) { return '[' .'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \'' . json_encode($string) . '\', ., "' . $hash . '")' . ']'; }, |
|
23 | + Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//'.$prefix.$string; }, |
|
24 | + '' => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
25 | + Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
26 | + Tokenizer::NUM_SIGN => function($string) { return '[@id=\''.$string.'\']'; }, |
|
27 | + Tokenizer::DOT => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' '.$string.' \')]'; }, |
|
28 | + Tokenizer::OPEN_SQUARE_BRACKET => function($string) use ($hash) { return '['.'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \''.json_encode($string).'\', ., "'.$hash.'")'.']'; }, |
|
29 | 29 | //']' => function() { return ''; } |
30 | 30 | ]; |
31 | 31 | } |
@@ -51,7 +51,9 @@ discard block |
||
51 | 51 | |
52 | 52 | $parts = self::$instances[$hash]->splitOnToken($attr, Tokenizer::EQUALS); |
53 | 53 | |
54 | - if ($parts[0] === $attr) return $element[0]->getAttribute($valueParser->parseTokens($attr)[0]) !== ''; |
|
54 | + if ($parts[0] === $attr) { |
|
55 | + return $element[0]->getAttribute($valueParser->parseTokens($attr)[0]) !== ''; |
|
56 | + } |
|
55 | 57 | |
56 | 58 | if ($parts[0][count($parts[0])-1]['type'] === Tokenizer::NOT) { |
57 | 59 | $attr = [ |
@@ -61,8 +63,7 @@ discard block |
||
61 | 63 | ['type' => Tokenizer::EQUALS] |
62 | 64 | ]; |
63 | 65 | $attr = array_merge($attr, $parts[1]); |
64 | - } |
|
65 | - else { |
|
66 | + } else { |
|
66 | 67 | $attr = [ |
67 | 68 | ['type' => Tokenizer::NAME, 'value' => 'attr'], |
68 | 69 | ['type' => Tokenizer::OPEN_BRACKET, 'value' => $parts[0]], |
@@ -77,8 +78,11 @@ discard block |
||
77 | 78 | $splitTokens = []; |
78 | 79 | $i = 0; |
79 | 80 | foreach ($tokens as $token) { |
80 | - if ($token['type'] === $splitOn) $i++; |
|
81 | - else $splitTokens[$i][] = $token; |
|
81 | + if ($token['type'] === $splitOn) { |
|
82 | + $i++; |
|
83 | + } else { |
|
84 | + $splitTokens[$i][] = $token; |
|
85 | + } |
|
82 | 86 | } |
83 | 87 | return $splitTokens; |
84 | 88 | } |
@@ -95,7 +99,9 @@ discard block |
||
95 | 99 | $selector->type = $token['type']; |
96 | 100 | $selectors[] = $selector; |
97 | 101 | } |
98 | - if (isset($token['value'])) $selectors[count($selectors)-1]->string = $token['value']; |
|
102 | + if (isset($token['value'])) { |
|
103 | + $selectors[count($selectors)-1]->string = $token['value']; |
|
104 | + } |
|
99 | 105 | } |
100 | 106 | return $selectors; |
101 | 107 | |
@@ -104,8 +110,9 @@ discard block |
||
104 | 110 | $selector = $this->createSelector(); |
105 | 111 | $selector->type = $css[$i]; |
106 | 112 | $selectors[] = $selector; |
113 | + } else { |
|
114 | + $selector->string .= $css[$i]; |
|
107 | 115 | } |
108 | - else $selector->string .= $css[$i]; |
|
109 | 116 | } |
110 | 117 | return $selectors; |
111 | 118 | } |
@@ -114,15 +121,20 @@ discard block |
||
114 | 121 | //$this->css = str_replace([' >', '> '],['>', '>'], trim($css)); |
115 | 122 | foreach ($css as $key => $token) { |
116 | 123 | if ($token['type'] === Tokenizer::WHITESPACE && |
117 | - (isset($css[$key+1]) && $css[$key+1]['type'] === Tokenizer::GREATER_THAN)) unset($css[$key]); |
|
118 | - else if ($token['type'] === Tokenizer::WHITESPACE && |
|
119 | - (isset($css[$key-1]) && $css[$key-1]['type'] === Tokenizer::GREATER_THAN)) unset($css[$key]); |
|
124 | + (isset($css[$key+1]) && $css[$key+1]['type'] === Tokenizer::GREATER_THAN)) { |
|
125 | + unset($css[$key]); |
|
126 | + } else if ($token['type'] === Tokenizer::WHITESPACE && |
|
127 | + (isset($css[$key-1]) && $css[$key-1]['type'] === Tokenizer::GREATER_THAN)) { |
|
128 | + unset($css[$key]); |
|
129 | + } |
|
120 | 130 | } |
121 | 131 | $css = $this->splitOnToken(array_values($css), Tokenizer::COLON)[0]; |
122 | 132 | $selectors = $this->split($css); |
123 | 133 | $xpath = '/'; |
124 | 134 | foreach ($selectors as $selector) { |
125 | - if (isset($this->translators[$selector->type])) $xpath .= $this->translators[$selector->type]($selector->string, $xpath); |
|
135 | + if (isset($this->translators[$selector->type])) { |
|
136 | + $xpath .= $this->translators[$selector->type]($selector->string, $xpath); |
|
137 | + } |
|
126 | 138 | } |
127 | 139 | |
128 | 140 | $xpath = str_replace('/[', '/*[', $xpath); |