@@ -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; |
@@ -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); |
@@ -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 | } |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | * @return Renderer |
45 | 45 | */ |
46 | 46 | public function create($baseDir = null, array $vars = []) { |
47 | - if($baseDir === null) { |
|
47 | + if ($baseDir === null) { |
|
48 | 48 | $baseDir = $this->baseDir; |
49 | - } elseif($this->baseDir !== null) { |
|
49 | + } elseif ($this->baseDir !== null) { |
|
50 | 50 | $baseDir = Directories::concat($this->baseDir, $baseDir); |
51 | 51 | } |
52 | 52 | return call_user_func($this->callback, $baseDir, $vars, $this->config); |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | * @return $this |
59 | 59 | */ |
60 | 60 | public function deriveFactory($baseDir = null, array $vars = []) { |
61 | - if($baseDir === null) { |
|
61 | + if ($baseDir === null) { |
|
62 | 62 | $baseDir = $this->baseDir; |
63 | - } elseif($this->baseDir !== null) { |
|
63 | + } elseif ($this->baseDir !== null) { |
|
64 | 64 | $baseDir = Directories::concat($this->baseDir, $baseDir); |
65 | 65 | } |
66 | 66 | return new static($this->callback, $baseDir, array_merge($this->vars, $vars), $this->config); |
@@ -25,10 +25,10 @@ discard block |
||
25 | 25 | * @param Delegate $parent |
26 | 26 | */ |
27 | 27 | public function __construct($basePath, $fileExt = null, array $vars = array(), WorkerConfiguration $configuration = null, Delegate $parent = null) { |
28 | - if($fileExt === null) { |
|
28 | + if ($fileExt === null) { |
|
29 | 29 | $fileExt = '.phtml'; |
30 | 30 | } |
31 | - if($configuration === null) { |
|
31 | + if ($configuration === null) { |
|
32 | 32 | $configuration = new FileWorkerConfiguration(); |
33 | 33 | } |
34 | 34 | parent::__construct($vars, [], $configuration); |
@@ -67,24 +67,24 @@ discard block |
||
67 | 67 | $this->setVars($vars); |
68 | 68 | $this->setRegions($regions); |
69 | 69 | |
70 | - return ViewTryFinallySimulator::tryThis(function () use ($filename, $resource, $vars) { |
|
71 | - $content = $this->obRecord(function () use ($filename, $resource, $vars) { |
|
70 | + return ViewTryFinallySimulator::tryThis(function() use ($filename, $resource, $vars) { |
|
71 | + $content = $this->obRecord(function() use ($filename, $resource, $vars) { |
|
72 | 72 | $templateFilename = Directories::concat($this->currentWorkDir, $filename); |
73 | 73 | $templateFilename = $this->normalize($templateFilename); |
74 | - $templatePath = stream_resolve_include_path($templateFilename . $this->fileExt); |
|
75 | - if($templatePath === false) { |
|
74 | + $templatePath = stream_resolve_include_path($templateFilename.$this->fileExt); |
|
75 | + if ($templatePath === false) { |
|
76 | 76 | $templatePath = stream_resolve_include_path($templateFilename); |
77 | 77 | } |
78 | - if($templatePath !== false) { |
|
78 | + if ($templatePath !== false) { |
|
79 | 79 | $templateFilename = $templatePath; |
80 | - $fn = function () use ($templateFilename) { |
|
80 | + $fn = function() use ($templateFilename) { |
|
81 | 81 | /** @noinspection PhpIncludeInspection */ |
82 | 82 | require $templateFilename; |
83 | 83 | }; |
84 | 84 | $fn->bindTo(new \stdClass()); |
85 | 85 | call_user_func($fn); |
86 | 86 | } else { |
87 | - if($this->parent !== null) { |
|
87 | + if ($this->parent !== null) { |
|
88 | 88 | echo $this->parent->render($resource, $vars); |
89 | 89 | } else { |
90 | 90 | throw new ResourceNotFoundException("Resource not found: {$resource}"); |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | } |
93 | 93 | }); |
94 | 94 | return $this->generateLayoutContent($content); |
95 | - }, function () use ($oldVars, $oldRegions) { |
|
95 | + }, function() use ($oldVars, $oldRegions) { |
|
96 | 96 | $this->setVars($oldVars); |
97 | 97 | $this->setRegions($oldRegions); |
98 | 98 | }); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @throws \Exception |
105 | 105 | */ |
106 | 106 | private function generateLayoutContent($content) { |
107 | - if($this->getLayout() !== null) { |
|
107 | + if ($this->getLayout() !== null) { |
|
108 | 108 | $regions = $this->getRegions(); |
109 | 109 | $regions['content'] = $content; |
110 | 110 | $layoutResource = $this->getLayout(); |
@@ -136,16 +136,16 @@ discard block |
||
136 | 136 | * @return string |
137 | 137 | */ |
138 | 138 | private function normalize($templateFilename) { |
139 | - if(strpos($templateFilename, '..')) { |
|
139 | + if (strpos($templateFilename, '..')) { |
|
140 | 140 | $templateFilename = strtr($templateFilename, [DIRECTORY_SEPARATOR => '/']); |
141 | 141 | $templateFilename = preg_replace('/\\/+/', '/', $templateFilename); |
142 | 142 | $parts = explode('/', $templateFilename); |
143 | 143 | $correctedParts = []; |
144 | - foreach($parts as $part) { |
|
145 | - if($part === '.') { |
|
144 | + foreach ($parts as $part) { |
|
145 | + if ($part === '.') { |
|
146 | 146 | // Skip |
147 | - } elseif($part === '..') { |
|
148 | - if(count($correctedParts)) { |
|
147 | + } elseif ($part === '..') { |
|
148 | + if (count($correctedParts)) { |
|
149 | 149 | array_pop($correctedParts); |
150 | 150 | } else { |
151 | 151 | // Skip |
@@ -164,10 +164,10 @@ discard block |
||
164 | 164 | * @return string |
165 | 165 | */ |
166 | 166 | private function getCurrentWorkDir($subPath) { |
167 | - if(substr($subPath, 0, 1) === '@') { |
|
168 | - $replace = function ($matches) { |
|
167 | + if (substr($subPath, 0, 1) === '@') { |
|
168 | + $replace = function($matches) { |
|
169 | 169 | $paths = $this->getConfiguration()->getPaths(); |
170 | - if(!array_key_exists($matches[2], $paths)) { |
|
170 | + if (!array_key_exists($matches[2], $paths)) { |
|
171 | 171 | throw new VirtualPathNotRegisteredException("Virtual path not registered: {$matches[1]}{$matches[2]}"); |
172 | 172 | } |
173 | 173 | return $paths[$matches[2]]; |
@@ -24,13 +24,13 @@ discard block |
||
24 | 24 | * @param array $config |
25 | 25 | */ |
26 | 26 | public function __construct(Context $context = null, RecursiveStringPath $recursiveAccessor = null, ObjectProxyFactory $objectProxyFactory = null, array $config = []) { |
27 | - if($context === null) { |
|
27 | + if ($context === null) { |
|
28 | 28 | $context = new HtmlContext(); |
29 | 29 | } |
30 | - if($recursiveAccessor === null) { |
|
30 | + if ($recursiveAccessor === null) { |
|
31 | 31 | $recursiveAccessor = new RecursiveStringPath(); |
32 | 32 | } |
33 | - if($objectProxyFactory === null) { |
|
33 | + if ($objectProxyFactory === null) { |
|
34 | 34 | $objectProxyFactory = new ObjectProxyFactory($context); |
35 | 35 | } |
36 | 36 | $this->context = $context; |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @return array |
65 | 65 | */ |
66 | 66 | public function getPaths() { |
67 | - if(array_key_exists('paths', $this->config)) { |
|
67 | + if (array_key_exists('paths', $this->config)) { |
|
68 | 68 | return $this->config['paths']; |
69 | 69 | } |
70 | 70 | return []; |