@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | } |
29 | 29 | |
30 | 30 | $selector = trim(substr($this->tss, $pos, $next-$pos)); |
31 | - $pos = strpos($this->tss, '}', $next)+1; |
|
31 | + $pos = strpos($this->tss, '}', $next)+1; |
|
32 | 32 | $newRules = $this->cssToRules($selector, count($rules)+$indexStart, $this->getProperties(trim(substr($this->tss, $next+1, $pos-2-$next)))); |
33 | 33 | $rules = $this->writeRule($rules, $newRules); |
34 | 34 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | private function processingInstructions($tss, $pos, $next, $indexStart) { |
63 | 63 | $rules = []; |
64 | 64 | while (($atPos = strpos($tss, '@', $pos)) !== false) { |
65 | - if ($atPos <= (int) $next) { |
|
65 | + if ($atPos <= (int) $next) { |
|
66 | 66 | $spacePos = strpos($tss, ' ', $atPos); |
67 | 67 | $funcName = substr($tss, $atPos+1, $spacePos-$atPos-1); |
68 | 68 | $pos = strpos($tss, ';', $spacePos); |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | } |
79 | 79 | |
80 | 80 | private function import($args, $indexStart) { |
81 | - if (is_file(trim($args,'\'" '))) $fileName = trim($args,'\'" '); |
|
81 | + if (is_file(trim($args, '\'" '))) $fileName = trim($args, '\'" '); |
|
82 | 82 | else $fileName = $this->valueParser->parse($args)[0]; |
83 | 83 | |
84 | - if (is_file($this->baseDir . $fileName)) $tssFile = $this->baseDir . $fileName; |
|
84 | + if (is_file($this->baseDir.$fileName)) $tssFile = $this->baseDir.$fileName; |
|
85 | 85 | elseif (is_file($fileName)) $tssFile = $fileName; |
86 | - else throw new \Exception('Imported TSS File "' . $fileName .'" does not exist'); |
|
86 | + else throw new \Exception('Imported TSS File "'.$fileName.'" does not exist'); |
|
87 | 87 | |
88 | 88 | $sheet = new Sheet(file_get_contents($tssFile), $this->baseDir, $this->xPath, $this->valueParser); |
89 | 89 | return $sheet->parse(0, [], $indexStart); |
@@ -33,7 +33,9 @@ discard block |
||
33 | 33 | $rules = $this->writeRule($rules, $newRules); |
34 | 34 | } |
35 | 35 | //there may be processing instructions at the end |
36 | - if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss), count($rules)+$indexStart)) $rules = array_merge($rules, $processing['rules']); |
|
36 | + if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss), count($rules)+$indexStart)) { |
|
37 | + $rules = array_merge($rules, $processing['rules']); |
|
38 | + } |
|
37 | 39 | usort($rules, [$this, 'sortRules']); |
38 | 40 | return $rules; |
39 | 41 | } |
@@ -68,8 +70,7 @@ discard block |
||
68 | 70 | $pos = strpos($tss, ';', $spacePos); |
69 | 71 | $args = substr($tss, $spacePos+1, $pos-$spacePos-1); |
70 | 72 | $rules = array_merge($rules, $this->$funcName($args, $indexStart)); |
71 | - } |
|
72 | - else { |
|
73 | + } else { |
|
73 | 74 | break; |
74 | 75 | } |
75 | 76 | } |
@@ -78,12 +79,19 @@ discard block |
||
78 | 79 | } |
79 | 80 | |
80 | 81 | private function import($args, $indexStart) { |
81 | - if (is_file(trim($args,'\'" '))) $fileName = trim($args,'\'" '); |
|
82 | - else $fileName = $this->valueParser->parse($args)[0]; |
|
82 | + if (is_file(trim($args,'\'" '))) { |
|
83 | + $fileName = trim($args,'\'" '); |
|
84 | + } else { |
|
85 | + $fileName = $this->valueParser->parse($args)[0]; |
|
86 | + } |
|
83 | 87 | |
84 | - if (is_file($this->baseDir . $fileName)) $tssFile = $this->baseDir . $fileName; |
|
85 | - elseif (is_file($fileName)) $tssFile = $fileName; |
|
86 | - else throw new \Exception('Imported TSS File "' . $fileName .'" does not exist'); |
|
88 | + if (is_file($this->baseDir . $fileName)) { |
|
89 | + $tssFile = $this->baseDir . $fileName; |
|
90 | + } elseif (is_file($fileName)) { |
|
91 | + $tssFile = $fileName; |
|
92 | + } else { |
|
93 | + throw new \Exception('Imported TSS File "' . $fileName .'" does not exist'); |
|
94 | + } |
|
87 | 95 | |
88 | 96 | $sheet = new Sheet(file_get_contents($tssFile), $this->baseDir, $this->xPath, $this->valueParser); |
89 | 97 | return $sheet->parse(0, [], $indexStart); |
@@ -91,7 +99,9 @@ discard block |
||
91 | 99 | |
92 | 100 | private function sortRules($a, $b) { |
93 | 101 | //If they have the same depth, compare on index |
94 | - if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1; |
|
102 | + if ($a->depth === $b->depth) { |
|
103 | + return $a->index < $b->index ? -1 : 1; |
|
104 | + } |
|
95 | 105 | |
96 | 106 | return ($a->depth < $b->depth) ? -1 : 1; |
97 | 107 | } |
@@ -100,7 +110,9 @@ discard block |
||
100 | 110 | $pos = 0; |
101 | 111 | while (($pos = strpos($str, $open, $pos)) !== false) { |
102 | 112 | $end = strpos($str, $close, $pos); |
103 | - if ($end === false) break; |
|
113 | + if ($end === false) { |
|
114 | + break; |
|
115 | + } |
|
104 | 116 | $str = substr_replace($str, '', $pos, $end-$pos+2); |
105 | 117 | } |
106 | 118 | |
@@ -113,7 +125,9 @@ discard block |
||
113 | 125 | $return = []; |
114 | 126 | |
115 | 127 | foreach ($rules as $rule) { |
116 | - if (trim($rule) === '') continue; |
|
128 | + if (trim($rule) === '') { |
|
129 | + continue; |
|
130 | + } |
|
117 | 131 | $parts = explode(':', $rule, 2); |
118 | 132 | $parts[1] = $stringExtractor->rebuild($parts[1]); |
119 | 133 | $return[trim($parts[0])] = isset($parts[1]) ? trim($parts[1]) : ''; |
@@ -1,27 +1,27 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Transphporm\TSSFunction; |
3 | 3 | class Json implements \Transphporm\TSSFunction { |
4 | - private $baseDir; |
|
4 | + private $baseDir; |
|
5 | 5 | |
6 | - public function __construct(&$baseDir) { |
|
7 | - $this->baseDir = &$baseDir; |
|
8 | - } |
|
6 | + public function __construct(&$baseDir) { |
|
7 | + $this->baseDir = &$baseDir; |
|
8 | + } |
|
9 | 9 | |
10 | - public function run(array $args, \DomElement $element = null) { |
|
11 | - $json = $args[0]; |
|
10 | + public function run(array $args, \DomElement $element = null) { |
|
11 | + $json = $args[0]; |
|
12 | 12 | |
13 | - if (trim($json)[0] != '{') { |
|
14 | - if (is_file($this->baseDir . $args[0])) $jsonFile = $this->baseDir . $json; |
|
15 | - elseif (is_file($args[0])) $jsonFile = $json; |
|
16 | - else throw new \Exception('JSON File "' . $json .'" does not exist'); |
|
13 | + if (trim($json)[0] != '{') { |
|
14 | + if (is_file($this->baseDir . $args[0])) $jsonFile = $this->baseDir . $json; |
|
15 | + elseif (is_file($args[0])) $jsonFile = $json; |
|
16 | + else throw new \Exception('JSON File "' . $json .'" does not exist'); |
|
17 | 17 | |
18 | - $json = file_get_contents($jsonFile); |
|
19 | - } |
|
18 | + $json = file_get_contents($jsonFile); |
|
19 | + } |
|
20 | 20 | |
21 | - $map = json_decode($json, true); |
|
21 | + $map = json_decode($json, true); |
|
22 | 22 | |
23 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
23 | + if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
24 | 24 | |
25 | - return $map; |
|
26 | - } |
|
25 | + return $map; |
|
26 | + } |
|
27 | 27 | } |
@@ -11,16 +11,16 @@ |
||
11 | 11 | $json = $args[0]; |
12 | 12 | |
13 | 13 | if (trim($json)[0] != '{') { |
14 | - if (is_file($this->baseDir . $args[0])) $jsonFile = $this->baseDir . $json; |
|
14 | + if (is_file($this->baseDir.$args[0])) $jsonFile = $this->baseDir.$json; |
|
15 | 15 | elseif (is_file($args[0])) $jsonFile = $json; |
16 | - else throw new \Exception('JSON File "' . $json .'" does not exist'); |
|
16 | + else throw new \Exception('JSON File "'.$json.'" does not exist'); |
|
17 | 17 | |
18 | 18 | $json = file_get_contents($jsonFile); |
19 | 19 | } |
20 | 20 | |
21 | 21 | $map = json_decode($json, true); |
22 | 22 | |
23 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
23 | + if (!is_array($map)) throw new \Exception('Could not decode json: '.json_last_error_msg()); |
|
24 | 24 | |
25 | 25 | return $map; |
26 | 26 | } |
@@ -11,16 +11,22 @@ |
||
11 | 11 | $json = $args[0]; |
12 | 12 | |
13 | 13 | if (trim($json)[0] != '{') { |
14 | - if (is_file($this->baseDir . $args[0])) $jsonFile = $this->baseDir . $json; |
|
15 | - elseif (is_file($args[0])) $jsonFile = $json; |
|
16 | - else throw new \Exception('JSON File "' . $json .'" does not exist'); |
|
14 | + if (is_file($this->baseDir . $args[0])) { |
|
15 | + $jsonFile = $this->baseDir . $json; |
|
16 | + } elseif (is_file($args[0])) { |
|
17 | + $jsonFile = $json; |
|
18 | + } else { |
|
19 | + throw new \Exception('JSON File "' . $json .'" does not exist'); |
|
20 | + } |
|
17 | 21 | |
18 | 22 | $json = file_get_contents($jsonFile); |
19 | 23 | } |
20 | 24 | |
21 | 25 | $map = json_decode($json, true); |
22 | 26 | |
23 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
27 | + if (!is_array($map)) { |
|
28 | + throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
29 | + } |
|
24 | 30 | |
25 | 31 | return $map; |
26 | 32 | } |
@@ -27,14 +27,14 @@ |
||
27 | 27 | $selector = $this->readArray($args, 1); |
28 | 28 | $tss = $this->readArray($args, 2); |
29 | 29 | |
30 | - if (is_file($this->baseDir . $args[0])) $xmlFile = $this->baseDir . $args[0]; |
|
30 | + if (is_file($this->baseDir.$args[0])) $xmlFile = $this->baseDir.$args[0]; |
|
31 | 31 | elseif (is_file($args[0])) $xmlFile = $args[0]; |
32 | - else throw new \Exception('XML File "' . $args[0] .'" does not exist'); |
|
32 | + else throw new \Exception('XML File "'.$args[0].'" does not exist'); |
|
33 | 33 | |
34 | 34 | if ($tss) { |
35 | - if (is_file($this->baseDir . $tss)) $tssFile = $this->baseDir . $tss; |
|
35 | + if (is_file($this->baseDir.$tss)) $tssFile = $this->baseDir.$tss; |
|
36 | 36 | elseif (is_file($args[0])) $tssFile = $tss; |
37 | - else throw new \Exception('TSS File "' . $tss .'" does not exist'); |
|
37 | + else throw new \Exception('TSS File "'.$tss.'" does not exist'); |
|
38 | 38 | } |
39 | 39 | else $tssFile = null; |
40 | 40 |
@@ -27,21 +27,32 @@ discard block |
||
27 | 27 | $selector = $this->readArray($args, 1); |
28 | 28 | $tss = $this->readArray($args, 2); |
29 | 29 | |
30 | - if (is_file($this->baseDir . $args[0])) $xmlFile = $this->baseDir . $args[0]; |
|
31 | - elseif (is_file($args[0])) $xmlFile = $args[0]; |
|
32 | - else throw new \Exception('XML File "' . $args[0] .'" does not exist'); |
|
30 | + if (is_file($this->baseDir . $args[0])) { |
|
31 | + $xmlFile = $this->baseDir . $args[0]; |
|
32 | + } elseif (is_file($args[0])) { |
|
33 | + $xmlFile = $args[0]; |
|
34 | + } else { |
|
35 | + throw new \Exception('XML File "' . $args[0] .'" does not exist'); |
|
36 | + } |
|
33 | 37 | |
34 | 38 | if ($tss) { |
35 | - if (is_file($this->baseDir . $tss)) $tssFile = $this->baseDir . $tss; |
|
36 | - elseif (is_file($args[0])) $tssFile = $tss; |
|
37 | - else throw new \Exception('TSS File "' . $tss .'" does not exist'); |
|
39 | + if (is_file($this->baseDir . $tss)) { |
|
40 | + $tssFile = $this->baseDir . $tss; |
|
41 | + } elseif (is_file($args[0])) { |
|
42 | + $tssFile = $tss; |
|
43 | + } else { |
|
44 | + throw new \Exception('TSS File "' . $tss .'" does not exist'); |
|
45 | + } |
|
46 | + } else { |
|
47 | + $tssFile = null; |
|
38 | 48 | } |
39 | - else $tssFile = null; |
|
40 | 49 | |
41 | 50 | $newTemplate = new \Transphporm\Builder($xmlFile, $tssFile); |
42 | 51 | |
43 | 52 | $doc = $newTemplate->output($this->elementData->getData($element), true)->body; |
44 | - if ($selector != '') return $this->templateSubsection($doc, $selector); |
|
53 | + if ($selector != '') { |
|
54 | + return $this->templateSubsection($doc, $selector); |
|
55 | + } |
|
45 | 56 | |
46 | 57 | return $this->getTemplateContent($doc, $tss); |
47 | 58 | |
@@ -71,7 +82,9 @@ discard block |
||
71 | 82 | |
72 | 83 | private function getClonedElement($node, $tss) { |
73 | 84 | $clone = $node->cloneNode(true); |
74 | - if ($tss != null && $clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate'); |
|
85 | + if ($tss != null && $clone instanceof \DomElement) { |
|
86 | + $clone->setAttribute('transphporm', 'includedtemplate'); |
|
87 | + } |
|
75 | 88 | return $clone; |
76 | 89 | } |
77 | 90 | } |