@@ -32,9 +32,9 @@ |
||
| 32 | 32 | * @return $this |
| 33 | 33 | */ |
| 34 | 34 | public function addAll(array $map) { |
| 35 | - foreach($map as $key => $value) { |
|
| 36 | - if(is_numeric($key) || !is_string($key)) { |
|
| 37 | - throw new \Exception("Invalid key type: ".gettype($key)); |
|
| 35 | + foreach ($map as $key => $value) { |
|
| 36 | + if (is_numeric($key) || !is_string($key)) { |
|
| 37 | + throw new \Exception("Invalid key type: " . gettype($key)); |
|
| 38 | 38 | } |
| 39 | 39 | $this->add($key, $value); |
| 40 | 40 | } |
@@ -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. |
@@ -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,7 +22,7 @@ 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) { |
|
| 25 | + if ($basePath && $filename) { |
|
| 26 | 26 | return rtrim($basePath, '/') . '/' . ltrim($filename, '/'); |
| 27 | 27 | } |
| 28 | 28 | return $basePath . $filename; |
@@ -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; |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @param WorkerConfiguration $configuration |
| 19 | 19 | */ |
| 20 | 20 | public function __construct($basePath, $fileExt = '.phtml', array $vars = array(), WorkerConfiguration $configuration = null) { |
| 21 | - if($configuration === null) { |
|
| 21 | + if ($configuration === null) { |
|
| 22 | 22 | $configuration = new FileWorkerConfiguration(); |
| 23 | 23 | } |
| 24 | 24 | parent::__construct($vars, [], $configuration); |
@@ -56,13 +56,13 @@ discard block |
||
| 56 | 56 | $this->setRegions($regions); |
| 57 | 57 | |
| 58 | 58 | try { |
| 59 | - $content = $this->obRecord(function () use ($filename) { |
|
| 59 | + $content = $this->obRecord(function() use ($filename) { |
|
| 60 | 60 | $templateFilename = Directories::concat($this->currentWorkDir, $filename); |
| 61 | 61 | $templatePath = stream_resolve_include_path($templateFilename . $this->fileExt); |
| 62 | - if($templatePath !== false) { |
|
| 62 | + if ($templatePath !== false) { |
|
| 63 | 63 | $templateFilename = $templatePath; |
| 64 | 64 | } |
| 65 | - $fn = function () use ($templateFilename) { |
|
| 65 | + $fn = function() use ($templateFilename) { |
|
| 66 | 66 | /** @noinspection PhpIncludeInspection */ |
| 67 | 67 | require $templateFilename; |
| 68 | 68 | }; |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * @throws \Exception |
| 83 | 83 | */ |
| 84 | 84 | private function generateLayoutContent($content) { |
| 85 | - if($this->getLayout() !== null) { |
|
| 85 | + if ($this->getLayout() !== null) { |
|
| 86 | 86 | $regions = $this->getRegions(); |
| 87 | 87 | $regions['content'] = $content; |
| 88 | 88 | $layoutResource = $this->getLayout(); |
@@ -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 | } |