@@ -61,10 +61,10 @@ |
||
61 | 61 | * @return array |
62 | 62 | */ |
63 | 63 | private function getPath($string) { |
64 | - if(strpos($string, '.') === false) { |
|
64 | + if (strpos($string, '.') === false) { |
|
65 | 65 | return array($string); |
66 | 66 | } |
67 | - if(strpos($string, '\\') !== false) { |
|
67 | + if (strpos($string, '\\') !== false) { |
|
68 | 68 | return preg_split("/\\\\.(*SKIP)(*FAIL)|{$this->delimiter}/s", $string); |
69 | 69 | } |
70 | 70 | return explode('.', $string); |
@@ -12,9 +12,9 @@ discard block |
||
12 | 12 | if (!$count) { |
13 | 13 | return false; |
14 | 14 | } |
15 | - for($idx = 0; $idx < $count; $idx++) { |
|
15 | + for ($idx = 0; $idx < $count; $idx++) { |
|
16 | 16 | $part = $path[$idx]; |
17 | - if(!array_key_exists($part, $array)) { |
|
17 | + if (!array_key_exists($part, $array)) { |
|
18 | 18 | return false; |
19 | 19 | } |
20 | 20 | $array = $array[$part]; |
@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | if (!$count) { |
34 | 34 | return $default; |
35 | 35 | } |
36 | - for($idx = 0; $idx < $count; $idx++) { |
|
36 | + for ($idx = 0; $idx < $count; $idx++) { |
|
37 | 37 | $part = $path[$idx]; |
38 | - if(!array_key_exists($part, $array)) { |
|
38 | + if (!array_key_exists($part, $array)) { |
|
39 | 39 | return $default; |
40 | 40 | } |
41 | 41 | $array = $array[$part]; |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | public static function del($array, array $path) { |
72 | 72 | while (count($path)) { // Try as long as a valid path is given |
73 | 73 | $key = array_shift($path); // Get the current key |
74 | - if(array_key_exists($key, $array)) { // If the current key is present in the current recursion-level... |
|
75 | - if(count($path)) { // After involving array_shift, the path could now be empty. If not... |
|
76 | - if(is_array($array[$key])) { // If it is an array we need to step into the next recursion-level... |
|
74 | + if (array_key_exists($key, $array)) { // If the current key is present in the current recursion-level... |
|
75 | + if (count($path)) { // After involving array_shift, the path could now be empty. If not... |
|
76 | + if (is_array($array[$key])) { // If it is an array we need to step into the next recursion-level... |
|
77 | 77 | $array[$key] = self::del($array[$key], $path); |
78 | 78 | } |
79 | 79 | // If it is not an array, the sub-path can't be reached - stop. |
@@ -27,16 +27,16 @@ |
||
27 | 27 | * @return ObjectProxy|mixed |
28 | 28 | */ |
29 | 29 | public function create($object) { |
30 | - if($object === null) { |
|
30 | + if ($object === null) { |
|
31 | 31 | $proxy = ''; |
32 | - } elseif(is_resource($object)) { |
|
32 | + } elseif (is_resource($object)) { |
|
33 | 33 | $proxy = $object; |
34 | - } elseif(is_object($object)) { |
|
35 | - if(!is_object($object)) { |
|
34 | + } elseif (is_object($object)) { |
|
35 | + if (!is_object($object)) { |
|
36 | 36 | $object = (object) $object; |
37 | 37 | } |
38 | 38 | $proxy = new ObjectProxy($object, $this); |
39 | - } elseif(is_array($object) || $object instanceof Traversable) { |
|
39 | + } elseif (is_array($object) || $object instanceof Traversable) { |
|
40 | 40 | $proxy = new ArrayProxy($object, $this); |
41 | 41 | } else { |
42 | 42 | $proxy = $this->context->escape($object); |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function getIterator() { |
29 | 29 | $result = []; |
30 | - foreach($this->getArray() as $key => $value) { |
|
30 | + foreach ($this->getArray() as $key => $value) { |
|
31 | 31 | $result[$key] = $this->objectProxyFactory->create($value); |
32 | 32 | } |
33 | 33 | return new ArrayIterator($result); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function offsetGet($offset) { |
49 | 49 | $array = $this->getArray(); |
50 | - if(array_key_exists($offset, $array)) { |
|
50 | + if (array_key_exists($offset, $array)) { |
|
51 | 51 | $value = $this->objectProxyFactory->create($this->array[$offset]); |
52 | 52 | return $value; |
53 | 53 | } |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | * @return array |
95 | 95 | */ |
96 | 96 | private function getArray() { |
97 | - if($this->array instanceof Traversable) { |
|
97 | + if ($this->array instanceof Traversable) { |
|
98 | 98 | $tmp = []; |
99 | - foreach($tmp as $key => $value) { |
|
99 | + foreach ($tmp as $key => $value) { |
|
100 | 100 | $tmp[$key] = $value; |
101 | 101 | } |
102 | 102 | $this->array = $tmp; |
@@ -21,13 +21,13 @@ |
||
21 | 21 | * @param ObjectProxyFactory $objectProxyFactory |
22 | 22 | */ |
23 | 23 | public function __construct(Context $context = null, RecursiveStringPath $recursiveAccessor = null, ObjectProxyFactory $objectProxyFactory = null) { |
24 | - if($context === null) { |
|
24 | + if ($context === null) { |
|
25 | 25 | $context = new HtmlContext(); |
26 | 26 | } |
27 | - if($recursiveAccessor === null) { |
|
27 | + if ($recursiveAccessor === null) { |
|
28 | 28 | $recursiveAccessor = new RecursiveStringPath(); |
29 | 29 | } |
30 | - if($objectProxyFactory === null) { |
|
30 | + if ($objectProxyFactory === null) { |
|
31 | 31 | $objectProxyFactory = new ObjectProxyFactory($context); |
32 | 32 | } |
33 | 33 | $this->context = $context; |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @return mixed |
45 | 45 | */ |
46 | 46 | public function get($key, $default = null) { |
47 | - if(!$this->has($key)) { |
|
47 | + if (!$this->has($key)) { |
|
48 | 48 | return $default; |
49 | 49 | } |
50 | 50 | return $this->configuration->getRecursiveAccessor()->get($this->vars, $key, $default); |
@@ -56,11 +56,11 @@ discard block |
||
56 | 56 | * @return string |
57 | 57 | */ |
58 | 58 | public function getStr($key, $default = '') { |
59 | - if(!$this->has($key)) { |
|
59 | + if (!$this->has($key)) { |
|
60 | 60 | return $default; |
61 | 61 | } |
62 | 62 | $value = $this->get($key); |
63 | - if(!is_scalar($value)) { |
|
63 | + if (!is_scalar($value)) { |
|
64 | 64 | $value = ''; |
65 | 65 | } |
66 | 66 | return $this->configuration->getContext()->escape($value); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * @return bool |
73 | 73 | */ |
74 | 74 | public function getBool($key, $default = false) { |
75 | - if(!$this->has($key)) { |
|
75 | + if (!$this->has($key)) { |
|
76 | 76 | return $default; |
77 | 77 | } |
78 | 78 | return !!$this->getStr($key); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @return int |
85 | 85 | */ |
86 | 86 | public function getInt($key, $default = false) { |
87 | - if(!$this->has($key)) { |
|
87 | + if (!$this->has($key)) { |
|
88 | 88 | return $default; |
89 | 89 | } |
90 | 90 | return (int) $this->getStr($key); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @return float |
97 | 97 | */ |
98 | 98 | public function getFloat($key, $default = false) { |
99 | - if(!$this->has($key)) { |
|
99 | + if (!$this->has($key)) { |
|
100 | 100 | return $default; |
101 | 101 | } |
102 | 102 | return (float) $this->getStr($key); |
@@ -108,14 +108,14 @@ discard block |
||
108 | 108 | * @return array|Generator|Traversable |
109 | 109 | */ |
110 | 110 | public function getArray($key, $default = '') { |
111 | - if(!$this->has($key)) { |
|
111 | + if (!$this->has($key)) { |
|
112 | 112 | return $default; |
113 | 113 | } |
114 | 114 | $value = $this->get($key); |
115 | - if($value instanceof ArrayObject) { |
|
115 | + if ($value instanceof ArrayObject) { |
|
116 | 116 | $value = $value->getArrayCopy(); |
117 | 117 | } |
118 | - if(!is_array($value)) { |
|
118 | + if (!is_array($value)) { |
|
119 | 119 | $value = []; |
120 | 120 | } |
121 | 121 | return $value; |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | * @return array|Generator|Traversable |
128 | 128 | */ |
129 | 129 | public function getArrayObj($key, $default = '') { |
130 | - if(!$this->has($key)) { |
|
130 | + if (!$this->has($key)) { |
|
131 | 131 | return $default; |
132 | 132 | } |
133 | 133 | $value = $this->get($key); |
134 | - if(!is_array($value) && !$value instanceof Traversable) { |
|
134 | + if (!is_array($value) && !$value instanceof Traversable) { |
|
135 | 135 | $value = []; |
136 | 136 | } |
137 | 137 | return new ArrayProxy($value, $this->configuration->getObjectProxyFactory()); |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @return string |
193 | 193 | */ |
194 | 194 | public function getRegion($name) { |
195 | - if(array_key_exists($name, $this->regions)) { |
|
195 | + if (array_key_exists($name, $this->regions)) { |
|
196 | 196 | return (string) $this->regions[$name]; |
197 | 197 | } |
198 | 198 | return ''; |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | * @return $this |
220 | 220 | */ |
221 | 221 | public function region($name) { |
222 | - ob_start(function ($content) use ($name) { |
|
222 | + ob_start(function($content) use ($name) { |
|
223 | 223 | $this->regions[$name] = new StringBucket($content); |
224 | 224 | }); |
225 | 225 | return $this; |
@@ -230,12 +230,12 @@ discard block |
||
230 | 230 | * @return $this |
231 | 231 | */ |
232 | 232 | public function getRegionOr($name) { |
233 | - if(!array_key_exists($name, $this->regions)) { |
|
234 | - ob_start(function ($content) { |
|
233 | + if (!array_key_exists($name, $this->regions)) { |
|
234 | + ob_start(function($content) { |
|
235 | 235 | return $content; |
236 | 236 | }); |
237 | 237 | } else { |
238 | - ob_start(function () use ($name) { |
|
238 | + ob_start(function() use ($name) { |
|
239 | 239 | return $this->regions[$name]; |
240 | 240 | }); |
241 | 241 | } |
@@ -33,8 +33,8 @@ |
||
33 | 33 | * @return $this |
34 | 34 | */ |
35 | 35 | public function addAll(array $map) { |
36 | - foreach($map as $key => $value) { |
|
37 | - if(is_numeric($key) || !is_string($key)) { |
|
36 | + foreach ($map as $key => $value) { |
|
37 | + if (is_numeric($key) || !is_string($key)) { |
|
38 | 38 | throw new \Exception("Invalid key type: ".gettype($key)); |
39 | 39 | } |
40 | 40 | $this->add($key, $value); |
@@ -22,10 +22,10 @@ discard block |
||
22 | 22 | * @param Delegate $parent |
23 | 23 | */ |
24 | 24 | public function __construct($basePath, $fileExt = null, array $vars = array(), WorkerConfiguration $configuration = null, Delegate $parent = null) { |
25 | - if($fileExt === null) { |
|
25 | + if ($fileExt === null) { |
|
26 | 26 | $fileExt = '.phtml'; |
27 | 27 | } |
28 | - if($configuration === null) { |
|
28 | + if ($configuration === null) { |
|
29 | 29 | $configuration = new FileWorkerConfiguration(); |
30 | 30 | } |
31 | 31 | parent::__construct($vars, [], $configuration); |
@@ -64,23 +64,23 @@ discard block |
||
64 | 64 | $this->setRegions($regions); |
65 | 65 | |
66 | 66 | try { |
67 | - $content = $this->obRecord(function () use ($filename, $resource, $vars) { |
|
67 | + $content = $this->obRecord(function() use ($filename, $resource, $vars) { |
|
68 | 68 | $templateFilename = Directories::concat($this->currentWorkDir, $filename); |
69 | 69 | $templateFilename = $this->normalize($templateFilename); |
70 | - $templatePath = stream_resolve_include_path($templateFilename . $this->fileExt); |
|
71 | - if($templatePath === false) { |
|
70 | + $templatePath = stream_resolve_include_path($templateFilename.$this->fileExt); |
|
71 | + if ($templatePath === false) { |
|
72 | 72 | $templatePath = stream_resolve_include_path($templateFilename); |
73 | 73 | } |
74 | - if($templatePath !== false) { |
|
74 | + if ($templatePath !== false) { |
|
75 | 75 | $templateFilename = $templatePath; |
76 | - $fn = function () use ($templateFilename) { |
|
76 | + $fn = function() use ($templateFilename) { |
|
77 | 77 | /** @noinspection PhpIncludeInspection */ |
78 | 78 | require $templateFilename; |
79 | 79 | }; |
80 | 80 | $fn->bindTo(new \stdClass()); |
81 | 81 | call_user_func($fn); |
82 | 82 | } else { |
83 | - if($this->parent !== null) { |
|
83 | + if ($this->parent !== null) { |
|
84 | 84 | echo $this->parent->render($resource, $vars); |
85 | 85 | } else { |
86 | 86 | throw new Exception("Resource not found: {$resource}"); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * @throws \Exception |
101 | 101 | */ |
102 | 102 | private function generateLayoutContent($content) { |
103 | - if($this->getLayout() !== null) { |
|
103 | + if ($this->getLayout() !== null) { |
|
104 | 104 | $regions = $this->getRegions(); |
105 | 105 | $regions['content'] = $content; |
106 | 106 | $layoutResource = $this->getLayout(); |
@@ -132,16 +132,16 @@ discard block |
||
132 | 132 | * @return string |
133 | 133 | */ |
134 | 134 | private function normalize($templateFilename) { |
135 | - if(strpos($templateFilename, '..')) { |
|
135 | + if (strpos($templateFilename, '..')) { |
|
136 | 136 | $templateFilename = strtr($templateFilename, [DIRECTORY_SEPARATOR => '/']); |
137 | 137 | $templateFilename = preg_replace('/\\/+/', '/', $templateFilename); |
138 | 138 | $parts = explode('/', $templateFilename); |
139 | 139 | $correctedParts = []; |
140 | - foreach($parts as $part) { |
|
141 | - if($part === '.') { |
|
140 | + foreach ($parts as $part) { |
|
141 | + if ($part === '.') { |
|
142 | 142 | // Skip |
143 | - } elseif($part === '..') { |
|
144 | - if(count($correctedParts)) { |
|
143 | + } elseif ($part === '..') { |
|
144 | + if (count($correctedParts)) { |
|
145 | 145 | array_pop($correctedParts); |
146 | 146 | } else { |
147 | 147 | // Skip |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | public static function concat() { |
9 | 9 | $parts = func_get_args(); |
10 | 10 | $result = array_shift($parts); |
11 | - foreach($parts as $part) { |
|
11 | + foreach ($parts as $part) { |
|
12 | 12 | $result = self::concatPaths($result, $part); |
13 | 13 | } |
14 | 14 | return $result; |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | private static function concatPaths($a, $b) { |
23 | 23 | $basePath = str_replace('\\', '/', $a); |
24 | 24 | $filename = str_replace('\\', '/', $b); |
25 | - if($basePath && $filename) { |
|
26 | - return rtrim($basePath, '/') . '/' . ltrim($filename, '/'); |
|
25 | + if ($basePath && $filename) { |
|
26 | + return rtrim($basePath, '/').'/'.ltrim($filename, '/'); |
|
27 | 27 | } |
28 | - return $basePath . $filename; |
|
28 | + return $basePath.$filename; |
|
29 | 29 | } |
30 | 30 | } |