@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | 'workingDirectory' => $this->workingDirectory, |
| 71 | 71 | ] |
| 72 | 72 | ]; |
| 73 | - if($this->containersToMerge !== NULL){ |
|
| 73 | + if ($this->containersToMerge !== NULL) { |
|
| 74 | 74 | foreach ($this->containersToMerge as $containerToMerge) { |
| 75 | 75 | foreach ($containerToMerge->getParameters() as $k => $v) { |
| 76 | 76 | $config['parameters'][$k] = $v; |
@@ -86,34 +86,34 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | // BC break check |
| 88 | 88 | $mainSections = ['includes', 'class', 'parameters', 'services']; |
| 89 | - foreach($config as $key => $val){ |
|
| 90 | - if(!in_array($key, $mainSections)) { |
|
| 89 | + foreach ($config as $key => $val) { |
|
| 90 | + if (!in_array($key, $mainSections)) { |
|
| 91 | 91 | throw new \RuntimeException("Since version 2.0 are supported main only these sections: " . implode(", ", $mainSections) . ". Section '$key' found. Move your variables into parameters section."); |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | $container = new Container(); |
| 96 | 96 | $container->setClass($config['class']); |
| 97 | - if(isset($config['parameters'])){ |
|
| 97 | + if (isset($config['parameters'])) { |
|
| 98 | 98 | $container->setParameters($config['parameters']); |
| 99 | 99 | } |
| 100 | - if(isset($config['services'])){ |
|
| 101 | - foreach($config['services'] as $name => $config){ |
|
| 102 | - if(!is_array($config)){ |
|
| 100 | + if (isset($config['services'])) { |
|
| 101 | + foreach ($config['services'] as $name => $config) { |
|
| 102 | + if (!is_array($config)) { |
|
| 103 | 103 | $container->addService($name, $config); // is directly service object from merged container |
| 104 | 104 | continue; |
| 105 | 105 | } |
| 106 | 106 | $class = $config['class']; |
| 107 | 107 | $arguments = []; |
| 108 | - if($config['class'] instanceof \Nette\Neon\Entity){ |
|
| 108 | + if ($config['class'] instanceof \Nette\Neon\Entity) { |
|
| 109 | 109 | $class = $config['class']->value; |
| 110 | 110 | $arguments = $config['class']->attributes; |
| 111 | 111 | } |
| 112 | 112 | $reflectionClass = new \ReflectionClass($class); |
| 113 | 113 | $service = $reflectionClass->newInstanceArgs($arguments); |
| 114 | - if(isset($config['setup'])){ |
|
| 115 | - foreach($config['setup'] as $neonEntity){ |
|
| 116 | - if(!method_exists($service, $neonEntity->value)){ |
|
| 114 | + if (isset($config['setup'])) { |
|
| 115 | + foreach ($config['setup'] as $neonEntity) { |
|
| 116 | + if (!method_exists($service, $neonEntity->value)) { |
|
| 117 | 117 | throw new \RuntimeException("Class $class does not have method $neonEntity->value()."); |
| 118 | 118 | } |
| 119 | 119 | call_user_func_array(array($service, $neonEntity->value), $neonEntity->attributes); |
@@ -132,9 +132,9 @@ discard block |
||
| 132 | 132 | $return = []; |
| 133 | 133 | foreach ($files as $file) { |
| 134 | 134 | $array = $this->readFile($file); |
| 135 | - if($array !== NULL){ |
|
| 136 | - if(isset($array['includes'])){ |
|
| 137 | - foreach($array['includes'] as $include){ |
|
| 135 | + if ($array !== NULL) { |
|
| 136 | + if (isset($array['includes'])) { |
|
| 137 | + foreach ($array['includes'] as $include) { |
|
| 138 | 138 | $return[] = dirname($file) . DIRECTORY_SEPARATOR . $include; |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | { |
| 150 | 150 | foreach ($files as $file) { |
| 151 | 151 | $array = $this->readFile($file); |
| 152 | - if($array !== NULL) { |
|
| 152 | + if ($array !== NULL) { |
|
| 153 | 153 | $config = array_replace_recursive($config, $array); |
| 154 | 154 | } |
| 155 | 155 | } |
@@ -174,18 +174,18 @@ discard block |
||
| 174 | 174 | { |
| 175 | 175 | $config = $this->resolveUnmergables($config); |
| 176 | 176 | foreach ($config as $key => $value) { |
| 177 | - if($value instanceof \Nette\Neon\Entity){ |
|
| 177 | + if ($value instanceof \Nette\Neon\Entity) { |
|
| 178 | 178 | $value->value = $this->parseValue($value->value, $allConfig); |
| 179 | - foreach($value->attributes as $k => $v){ |
|
| 180 | - if(is_array($v)){ |
|
| 179 | + foreach ($value->attributes as $k => $v) { |
|
| 180 | + if (is_array($v)) { |
|
| 181 | 181 | $value->attributes[$k] = $this->parseValues($v, $allConfig, array_merge($keysPath, [$key])); |
| 182 | - }else{ |
|
| 182 | + } else { |
|
| 183 | 183 | $value->attributes[$k] = $this->parseValue($v, $allConfig); |
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | }elseif (is_array($value)) { |
| 187 | 187 | $value = $this->parseValues($value, $allConfig, array_merge($keysPath, [$key])); |
| 188 | - } elseif(!is_object($value)) { |
|
| 188 | + } elseif (!is_object($value)) { |
|
| 189 | 189 | $value = $this->parseValue($value, $allConfig); |
| 190 | 190 | } |
| 191 | 191 | |
@@ -195,11 +195,11 @@ discard block |
||
| 195 | 195 | $config[$newKey] = $value; |
| 196 | 196 | |
| 197 | 197 | // write to global config |
| 198 | - $v =& $allConfig; |
|
| 198 | + $v = & $allConfig; |
|
| 199 | 199 | foreach ($keysPath as $kp) { |
| 200 | - $v =& $v[$kp]; |
|
| 200 | + $v = & $v[$kp]; |
|
| 201 | 201 | } |
| 202 | - if(!($value instanceof \Nette\Neon\Entity)) { |
|
| 202 | + if (!($value instanceof \Nette\Neon\Entity)) { |
|
| 203 | 203 | $v[$newKey] = $value; |
| 204 | 204 | } |
| 205 | 205 | } |
@@ -212,14 +212,14 @@ discard block |
||
| 212 | 212 | if (preg_match_all('#%([^%]+)%#', $value, $matches)) { |
| 213 | 213 | foreach ($matches[1] as $match) { |
| 214 | 214 | $parameter = $config['parameters']; |
| 215 | - foreach(explode(".", $match) as $m){ |
|
| 215 | + foreach (explode(".", $match) as $m) { |
|
| 216 | 216 | if (!array_key_exists($m, $parameter)) { |
| 217 | 217 | throw new \RuntimeException("Cannot find variable '$match', part '$m'."); |
| 218 | 218 | } |
| 219 | 219 | $parameter = $parameter[$m]; |
| 220 | 220 | } |
| 221 | - if(is_array($parameter)){ |
|
| 222 | - if("%$match%" !== $value){ // if is variable value an array, must not be part of a string |
|
| 221 | + if (is_array($parameter)) { |
|
| 222 | + if ("%$match%" !== $value) { // if is variable value an array, must not be part of a string |
|
| 223 | 223 | throw new \RuntimeException("Array value cannot be part of a string."); |
| 224 | 224 | } |
| 225 | 225 | return $parameter; |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | private function resolveUnmergables($config) |
| 235 | 235 | { |
| 236 | 236 | foreach ($config as $key => $value) { |
| 237 | - if(preg_match('#!$#', $key)){ |
|
| 237 | + if (preg_match('#!$#', $key)) { |
|
| 238 | 238 | $newKey = substr($key, 0, strlen($key) - 1); |
| 239 | 239 | $config[$newKey] = $value; |
| 240 | 240 | unset($config[$key]); |