@@ -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); |
@@ -68,22 +68,22 @@ discard block |
||
| 68 | 68 | $this->setRegions($regions); |
| 69 | 69 | |
| 70 | 70 | try { |
| 71 | - $content = $this->obRecord(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 | require $templateFilename; |
| 82 | 82 | }; |
| 83 | 83 | $fn->bindTo(new \stdClass()); |
| 84 | 84 | call_user_func($fn); |
| 85 | 85 | } else { |
| 86 | - if($this->parent !== null) { |
|
| 86 | + if ($this->parent !== null) { |
|
| 87 | 87 | echo $this->parent->render($resource, $vars); |
| 88 | 88 | } else { |
| 89 | 89 | throw new ResourceNotFoundException("Resource not found: {$resource}"); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * @throws \Exception |
| 104 | 104 | */ |
| 105 | 105 | private function generateLayoutContent($content) { |
| 106 | - if($this->getLayout() !== null) { |
|
| 106 | + if ($this->getLayout() !== null) { |
|
| 107 | 107 | $regions = $this->getRegions(); |
| 108 | 108 | $regions['content'] = $content; |
| 109 | 109 | $layoutResource = $this->getLayout(); |
@@ -134,16 +134,16 @@ discard block |
||
| 134 | 134 | * @return string |
| 135 | 135 | */ |
| 136 | 136 | private function normalize($templateFilename) { |
| 137 | - if(strpos($templateFilename, '..')) { |
|
| 137 | + if (strpos($templateFilename, '..')) { |
|
| 138 | 138 | $templateFilename = strtr($templateFilename, [DIRECTORY_SEPARATOR => '/']); |
| 139 | 139 | $templateFilename = preg_replace('/\\/+/', '/', $templateFilename); |
| 140 | 140 | $parts = explode('/', $templateFilename); |
| 141 | 141 | $correctedParts = []; |
| 142 | - foreach($parts as $part) { |
|
| 143 | - if($part === '.') { |
|
| 142 | + foreach ($parts as $part) { |
|
| 143 | + if ($part === '.') { |
|
| 144 | 144 | // Skip |
| 145 | - } elseif($part === '..') { |
|
| 146 | - if(count($correctedParts)) { |
|
| 145 | + } elseif ($part === '..') { |
|
| 146 | + if (count($correctedParts)) { |
|
| 147 | 147 | array_pop($correctedParts); |
| 148 | 148 | } else { |
| 149 | 149 | // Skip |
@@ -162,10 +162,10 @@ discard block |
||
| 162 | 162 | * @return string |
| 163 | 163 | */ |
| 164 | 164 | private function getCurrentWorkDir($subPath) { |
| 165 | - if(substr($subPath, 0, 1) === '@') { |
|
| 166 | - $replace = function ($matches) { |
|
| 165 | + if (substr($subPath, 0, 1) === '@') { |
|
| 166 | + $replace = function($matches) { |
|
| 167 | 167 | $paths = $this->getConfiguration()->getPaths(); |
| 168 | - if(!array_key_exists($matches[2], $paths)) { |
|
| 168 | + if (!array_key_exists($matches[2], $paths)) { |
|
| 169 | 169 | throw new VirtualPathNotRegisteredException("Virtual path not registered: {$matches[1]}{$matches[2]}"); |
| 170 | 170 | } |
| 171 | 171 | return $paths[$matches[2]]; |