@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | public function shallIncludeAssets(Plugin $xPlugin): bool |
72 | 72 | { |
73 | 73 | $sPluginOptionName = 'assets.include.' . $xPlugin->getName(); |
74 | - if($this->xConfigManager->hasOption($sPluginOptionName)) |
|
74 | + if ($this->xConfigManager->hasOption($sPluginOptionName)) |
|
75 | 75 | { |
76 | 76 | return $this->xConfigManager->getOption($sPluginOptionName); |
77 | 77 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $sJsLibUri = rtrim($this->xConfigManager->getOption('js.lib.uri', self::JS_LIB_URL), '/') . '/'; |
91 | 91 | // Add component files to the javascript file array; |
92 | 92 | $aJsFiles = [$sJsLibUri . 'jaxon.core' . $sJsExtension]; |
93 | - if($this->xConfigManager->getOption('core.debug.on')) |
|
93 | + if ($this->xConfigManager->getOption('core.debug.on')) |
|
94 | 94 | { |
95 | 95 | $sLanguage = $this->xConfigManager->getOption('core.language'); |
96 | 96 | $aJsFiles[] = $sJsLibUri . 'jaxon.debug' . $sJsExtension; |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function getOptionVars(): array |
109 | 109 | { |
110 | - if(!$this->xConfigManager->hasOption('core.request.uri')) |
|
110 | + if (!$this->xConfigManager->hasOption('core.request.uri')) |
|
111 | 111 | { |
112 | 112 | $this->xConfigManager->setOption('core.request.uri', $this->xParameterReader->uri()); |
113 | 113 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | // Check config options |
141 | 141 | // - The js.app.export option must be set to true |
142 | 142 | // - The js.app.uri and js.app.dir options must be set to non null values |
143 | - if(!$this->xConfigManager->getOption('js.app.export', false) || |
|
143 | + if (!$this->xConfigManager->getOption('js.app.export', false) || |
|
144 | 144 | !$this->xConfigManager->getOption('js.app.uri') || |
145 | 145 | !$this->xConfigManager->getOption('js.app.dir')) |
146 | 146 | { |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function createJsFiles(CodeGenerator $xCodeGenerator): string |
160 | 160 | { |
161 | - if(!$this->shallCreateJsFiles()) |
|
161 | + if (!$this->shallCreateJsFiles()) |
|
162 | 162 | { |
163 | 163 | return ''; |
164 | 164 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | $sJsFileName = $this->xConfigManager->getOption('js.app.file') ?: $xCodeGenerator->getHash(); |
168 | 168 | $sJsDirectory = rtrim($this->xConfigManager->getOption('js.app.dir'), '\/') . DIRECTORY_SEPARATOR; |
169 | 169 | // - The js.app.dir must be writable |
170 | - if(!$sJsFileName || !is_dir($sJsDirectory) || !is_writable($sJsDirectory)) |
|
170 | + if (!$sJsFileName || !is_dir($sJsDirectory) || !is_writable($sJsDirectory)) |
|
171 | 171 | { |
172 | 172 | return ''; |
173 | 173 | } |
@@ -175,15 +175,15 @@ discard block |
||
175 | 175 | $sJsFilePath = $sJsDirectory . $sJsFileName . '.js'; |
176 | 176 | $sJsMinFilePath = $sJsDirectory . $sJsFileName . '.min.js'; |
177 | 177 | $sJsFileUri = rtrim($this->xConfigManager->getOption('js.app.uri'), '/') . "/$sJsFileName"; |
178 | - if(!is_file($sJsFilePath) && !@file_put_contents($sJsFilePath, $xCodeGenerator->getJsScript())) |
|
178 | + if (!is_file($sJsFilePath) && !@file_put_contents($sJsFilePath, $xCodeGenerator->getJsScript())) |
|
179 | 179 | { |
180 | 180 | return ''; |
181 | 181 | } |
182 | - if(!$this->xConfigManager->getOption('js.app.minify', false)) |
|
182 | + if (!$this->xConfigManager->getOption('js.app.minify', false)) |
|
183 | 183 | { |
184 | 184 | return $sJsFileUri . '.js'; |
185 | 185 | } |
186 | - if(!is_file($sJsMinFilePath) && !$this->xMinifier->minify($sJsFilePath, $sJsMinFilePath)) |
|
186 | + if (!is_file($sJsMinFilePath) && !$this->xMinifier->minify($sJsFilePath, $sJsMinFilePath)) |
|
187 | 187 | { |
188 | 188 | // If the file cannot be minified, return the plain js file. |
189 | 189 | return $sJsFileUri . '.js'; |
@@ -136,18 +136,18 @@ discard block |
||
136 | 136 | $aOptions = $this->getOptionNames($sKeyPrefix); |
137 | 137 | $sSpaces = str_repeat(' ', $nSpaces); |
138 | 138 | $sScript = ''; |
139 | - foreach($aOptions as $sShortName => $sFullName) |
|
139 | + foreach ($aOptions as $sShortName => $sFullName) |
|
140 | 140 | { |
141 | 141 | $value = $this->xConfigManager->getOption($sFullName); |
142 | - if(is_string($value)) |
|
142 | + if (is_string($value)) |
|
143 | 143 | { |
144 | 144 | $value = "'$value'"; |
145 | 145 | } |
146 | - elseif(is_bool($value)) |
|
146 | + elseif (is_bool($value)) |
|
147 | 147 | { |
148 | 148 | $value = ($value ? 'true' : 'false'); |
149 | 149 | } |
150 | - elseif(!is_numeric($value)) |
|
150 | + elseif (!is_numeric($value)) |
|
151 | 151 | { |
152 | 152 | $value = json_encode($value); |
153 | 153 | } |
@@ -175,10 +175,10 @@ discard block |
||
175 | 175 | */ |
176 | 176 | public function getJsCode(string $sFile): string |
177 | 177 | { |
178 | - if($this->hasOption('assets.js')) |
|
178 | + if ($this->hasOption('assets.js')) |
|
179 | 179 | { |
180 | 180 | // If this expression evaluates to false, then the asset is not displayed. |
181 | - if(!($sUri = $this->getOption('assets.js'))) |
|
181 | + if (!($sUri = $this->getOption('assets.js'))) |
|
182 | 182 | { |
183 | 183 | return ''; |
184 | 184 | } |
@@ -200,10 +200,10 @@ discard block |
||
200 | 200 | */ |
201 | 201 | public function getCssCode(string $sFile): string |
202 | 202 | { |
203 | - if($this->hasOption('assets.css')) |
|
203 | + if ($this->hasOption('assets.css')) |
|
204 | 204 | { |
205 | 205 | // If this expression evaluates to false, then the asset is not displayed. |
206 | - if(!($sUri = $this->getOption('assets.css'))) |
|
206 | + if (!($sUri = $this->getOption('assets.css'))) |
|
207 | 207 | { |
208 | 208 | return ''; |
209 | 209 | } |
@@ -142,12 +142,10 @@ discard block |
||
142 | 142 | if(is_string($value)) |
143 | 143 | { |
144 | 144 | $value = "'$value'"; |
145 | - } |
|
146 | - elseif(is_bool($value)) |
|
145 | + } elseif(is_bool($value)) |
|
147 | 146 | { |
148 | 147 | $value = ($value ? 'true' : 'false'); |
149 | - } |
|
150 | - elseif(!is_numeric($value)) |
|
148 | + } elseif(!is_numeric($value)) |
|
151 | 149 | { |
152 | 150 | $value = json_encode($value); |
153 | 151 | } |
@@ -182,8 +180,7 @@ discard block |
||
182 | 180 | { |
183 | 181 | return ''; |
184 | 182 | } |
185 | - } |
|
186 | - else |
|
183 | + } else |
|
187 | 184 | { |
188 | 185 | $sUri = $this->sUri . '/' . ($this->sSubDir ? $this->sSubDir . '/' : '') . |
189 | 186 | ($this->sVersion ? $this->sVersion . '/' : '') . $sFile; |
@@ -207,8 +204,7 @@ discard block |
||
207 | 204 | { |
208 | 205 | return ''; |
209 | 206 | } |
210 | - } |
|
211 | - else |
|
207 | + } else |
|
212 | 208 | { |
213 | 209 | $sUri = $this->sUri . '/' . ($this->sSubDir ? $this->sSubDir . '/' : '') . |
214 | 210 | ($this->sVersion ? $this->sVersion . '/' : '') . $sFile; |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $this->xRepository = $xRepository; |
90 | 90 | |
91 | 91 | // Set the composer autoloader |
92 | - if(file_exists(($sAutoloadFile = __DIR__ . '/../../../../../../autoload.php')) || |
|
92 | + if (file_exists(($sAutoloadFile = __DIR__ . '/../../../../../../autoload.php')) || |
|
93 | 93 | file_exists(($sAutoloadFile = __DIR__ . '/../../../../vendor/autoload.php'))) |
94 | 94 | { |
95 | 95 | $this->xAutoloader = require($sAutoloadFile); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | public function addDirectory(string $sDirectory, array $aOptions) |
107 | 107 | { |
108 | 108 | // Set the autoload option default value |
109 | - if(!isset($aOptions['autoload'])) |
|
109 | + if (!isset($aOptions['autoload'])) |
|
110 | 110 | { |
111 | 111 | $aOptions['autoload'] = true; |
112 | 112 | } |
@@ -123,26 +123,26 @@ discard block |
||
123 | 123 | public function addNamespace(string $sNamespace, array $aOptions) |
124 | 124 | { |
125 | 125 | // Separator default value |
126 | - if(!isset($aOptions['separator'])) |
|
126 | + if (!isset($aOptions['separator'])) |
|
127 | 127 | { |
128 | 128 | $aOptions['separator'] = '.'; |
129 | 129 | } |
130 | 130 | $aOptions['separator'] = trim($aOptions['separator']); |
131 | - if(!in_array($aOptions['separator'], ['.', '_'])) |
|
131 | + if (!in_array($aOptions['separator'], ['.', '_'])) |
|
132 | 132 | { |
133 | 133 | $aOptions['separator'] = '.'; |
134 | 134 | } |
135 | - if($aOptions['separator'] === '_') |
|
135 | + if ($aOptions['separator'] === '_') |
|
136 | 136 | { |
137 | 137 | $this->bUsingUnderscore = true; |
138 | 138 | } |
139 | 139 | // Set the autoload option default value |
140 | - if(!isset($aOptions['autoload'])) |
|
140 | + if (!isset($aOptions['autoload'])) |
|
141 | 141 | { |
142 | 142 | $aOptions['autoload'] = true; |
143 | 143 | } |
144 | 144 | // Register the dir with PSR4 autoloading |
145 | - if(($aOptions['autoload']) && $this->xAutoloader != null) |
|
145 | + if (($aOptions['autoload']) && $this->xAutoloader != null) |
|
146 | 146 | { |
147 | 147 | $this->xAutoloader->setPsr4($sNamespace . '\\', $aOptions['directory']); |
148 | 148 | } |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | public function parseDirectories() |
158 | 158 | { |
159 | 159 | // This is to be done only once. |
160 | - if($this->bDirectoriesParsed) |
|
160 | + if ($this->bDirectoriesParsed) |
|
161 | 161 | { |
162 | 162 | return; |
163 | 163 | } |
@@ -165,14 +165,14 @@ discard block |
||
165 | 165 | |
166 | 166 | // Browse directories without namespaces and read all the files. |
167 | 167 | $aClassMap = []; |
168 | - foreach($this->xRepository->getDirectoryOptions() as $sDirectory => $aOptions) |
|
168 | + foreach ($this->xRepository->getDirectoryOptions() as $sDirectory => $aOptions) |
|
169 | 169 | { |
170 | 170 | $itFile = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($sDirectory)); |
171 | 171 | // Iterate on dir content |
172 | - foreach($itFile as $xFile) |
|
172 | + foreach ($itFile as $xFile) |
|
173 | 173 | { |
174 | 174 | // Skip everything except PHP files |
175 | - if(!$xFile->isFile() || $xFile->getExtension() != 'php') |
|
175 | + if (!$xFile->isFile() || $xFile->getExtension() != 'php') |
|
176 | 176 | { |
177 | 177 | continue; |
178 | 178 | } |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | $sClassName = $xFile->getBasename('.php'); |
181 | 181 | $aClassOptions = ['timestamp' => $xFile->getMTime()]; |
182 | 182 | // No more custom classmap autoloading. The file will be included when needed. |
183 | - if(($aOptions['autoload'])) |
|
183 | + if (($aOptions['autoload'])) |
|
184 | 184 | { |
185 | 185 | $aClassMap[$sClassName] = $xFile->getPathname(); |
186 | 186 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | } |
189 | 189 | } |
190 | 190 | // Set classmap autoloading |
191 | - if(($aClassMap) && $this->xAutoloader !== null) |
|
191 | + if (($aClassMap) && $this->xAutoloader !== null) |
|
192 | 192 | { |
193 | 193 | $this->xAutoloader->addClassMap($aClassMap); |
194 | 194 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | public function parseNamespaces() |
203 | 203 | { |
204 | 204 | // This is to be done only once. |
205 | - if($this->bNamespacesParsed) |
|
205 | + if ($this->bNamespacesParsed) |
|
206 | 206 | { |
207 | 207 | return; |
208 | 208 | } |
@@ -210,17 +210,17 @@ discard block |
||
210 | 210 | |
211 | 211 | // Browse directories with namespaces and read all the files. |
212 | 212 | $sDS = DIRECTORY_SEPARATOR; |
213 | - foreach($this->xRepository->getNamespaceOptions() as $sNamespace => $aOptions) |
|
213 | + foreach ($this->xRepository->getNamespaceOptions() as $sNamespace => $aOptions) |
|
214 | 214 | { |
215 | 215 | $this->xRepository->addNamespace($sNamespace, ['separator' => $aOptions['separator']]); |
216 | 216 | |
217 | 217 | // Iterate on dir content |
218 | 218 | $sDirectory = $aOptions['directory']; |
219 | 219 | $itFile = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($sDirectory)); |
220 | - foreach($itFile as $xFile) |
|
220 | + foreach ($itFile as $xFile) |
|
221 | 221 | { |
222 | 222 | // skip everything except PHP files |
223 | - if(!$xFile->isFile() || $xFile->getExtension() != 'php') |
|
223 | + if (!$xFile->isFile() || $xFile->getExtension() != 'php') |
|
224 | 224 | { |
225 | 225 | continue; |
226 | 226 | } |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | $sClassPath = $sNamespace; |
230 | 230 | $sRelativePath = substr($xFile->getPath(), strlen($sDirectory)); |
231 | 231 | $sRelativePath = trim(str_replace($sDS, '\\', $sRelativePath), '\\'); |
232 | - if($sRelativePath !== '') |
|
232 | + if ($sRelativePath !== '') |
|
233 | 233 | { |
234 | 234 | $sClassPath .= '\\' . $sRelativePath; |
235 | 235 | } |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | // Replace all separators ('.' and '_') with antislashes, and remove the antislashes |
257 | 257 | // at the beginning and the end of the class name. |
258 | 258 | $sClassName = trim(str_replace('.', '\\', $sClassName), '\\'); |
259 | - if($this->bUsingUnderscore) |
|
259 | + if ($this->bUsingUnderscore) |
|
260 | 260 | { |
261 | 261 | $sClassName = trim(str_replace('_', '\\', $sClassName), '\\'); |
262 | 262 | } |
@@ -111,10 +111,12 @@ discard block |
||
111 | 111 | $sReflectionClass = $sClassName . '_ReflectionClass'; |
112 | 112 | |
113 | 113 | // Prevent duplication |
114 | - if($this->h($sReflectionClass)) // It's important not to use the class name here. |
|
114 | + if($this->h($sReflectionClass)) { |
|
115 | + // It's important not to use the class name here. |
|
115 | 116 | { |
116 | 117 | return; |
117 | 118 | } |
119 | + } |
|
118 | 120 | |
119 | 121 | // Make sure the registered class exists |
120 | 122 | if(isset($aOptions['include'])) |
@@ -125,8 +127,7 @@ discard block |
||
125 | 127 | try |
126 | 128 | { |
127 | 129 | $this->val($sReflectionClass, new ReflectionClass($sClassName)); |
128 | - } |
|
129 | - catch(ReflectionException $e) |
|
130 | + } catch(ReflectionException $e) |
|
130 | 131 | { |
131 | 132 | $xTranslator = $this->g(Translator::class); |
132 | 133 | $sMessage = $xTranslator->trans('errors.class.invalid', ['name' => $sClassName]); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | */ |
34 | 34 | private function setDiAttributes($xRegisteredObject, array $aDiOptions) |
35 | 35 | { |
36 | - foreach($aDiOptions as $sName => $sClass) |
|
36 | + foreach ($aDiOptions as $sName => $sClass) |
|
37 | 37 | { |
38 | 38 | // Set the protected attributes of the object |
39 | 39 | $cSetter = function($xInjectedObject) use($sName) { |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $this->setDiAttributes($xRegisteredObject, $aDiOptions); |
64 | 64 | |
65 | 65 | // Set the Jaxon request target in the helper |
66 | - if($xRegisteredObject instanceof CallableClass) |
|
66 | + if ($xRegisteredObject instanceof CallableClass) |
|
67 | 67 | { |
68 | 68 | // Set the protected attributes of the object |
69 | 69 | $cSetter = function() use($xTarget) { |
@@ -91,13 +91,13 @@ discard block |
||
91 | 91 | $sReflectionClass = $sClassName . '_ReflectionClass'; |
92 | 92 | |
93 | 93 | // Prevent duplication |
94 | - if($this->h($sReflectionClass)) // It's important not to use the class name here. |
|
94 | + if ($this->h($sReflectionClass)) // It's important not to use the class name here. |
|
95 | 95 | { |
96 | 96 | return; |
97 | 97 | } |
98 | 98 | |
99 | 99 | // Make sure the registered class exists |
100 | - if(isset($aOptions['include'])) |
|
100 | + if (isset($aOptions['include'])) |
|
101 | 101 | { |
102 | 102 | require_once($aOptions['include']); |
103 | 103 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | { |
107 | 107 | $this->val($sReflectionClass, new ReflectionClass($sClassName)); |
108 | 108 | } |
109 | - catch(ReflectionException $e) |
|
109 | + catch (ReflectionException $e) |
|
110 | 110 | { |
111 | 111 | $xTranslator = $this->g(Translator::class); |
112 | 112 | $sMessage = $xTranslator->trans('errors.class.invalid', ['name' => $sClassName]); |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | }); |
131 | 131 | |
132 | 132 | // Register the user class, but only if the user didn't already. |
133 | - if(!$this->h($sClassName)) |
|
133 | + if (!$this->h($sClassName)) |
|
134 | 134 | { |
135 | 135 | $this->set($sClassName, function($di) use($sReflectionClass) { |
136 | 136 | return $this->make($di->g($sReflectionClass)); |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | // Initialize the user class instance |
140 | 140 | $this->xLibContainer->extend($sClassName, function($xRegisteredObject) |
141 | 141 | use($sCallableObject, $sClassName) { |
142 | - if($xRegisteredObject instanceof CallableClass) |
|
142 | + if ($xRegisteredObject instanceof CallableClass) |
|
143 | 143 | { |
144 | 144 | $cSetter = function($di) use($sClassName) { |
145 | 145 | // Set the protected attributes of the object |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $sPkgConfigKey = $this->getPackageConfigKey($sClassName); |
213 | 213 | $this->val($sPkgConfigKey, $xPkgConfig); |
214 | 214 | // Register the user class, but only if the user didn't already. |
215 | - if(!$this->h($sClassName)) |
|
215 | + if (!$this->h($sClassName)) |
|
216 | 216 | { |
217 | 217 | $this->set($sClassName, function() use($sClassName) { |
218 | 218 | return $this->make($sClassName); |
@@ -124,28 +124,28 @@ discard block |
||
124 | 124 | { |
125 | 125 | $bIsUsed = false; |
126 | 126 | $aInterfaces = class_implements($sClassName); |
127 | - if(in_array(CodeGeneratorInterface::class, $aInterfaces)) |
|
127 | + if (in_array(CodeGeneratorInterface::class, $aInterfaces)) |
|
128 | 128 | { |
129 | 129 | $this->xCodeGenerator->addCodeGenerator($sClassName, $nPriority); |
130 | 130 | $bIsUsed = true; |
131 | 131 | } |
132 | - if(in_array(CallableRegistryInterface::class, $aInterfaces)) |
|
132 | + if (in_array(CallableRegistryInterface::class, $aInterfaces)) |
|
133 | 133 | { |
134 | 134 | $this->aRegistryPlugins[$sPluginName] = $sClassName; |
135 | 135 | $bIsUsed = true; |
136 | 136 | } |
137 | - if(in_array(RequestHandlerInterface::class, $aInterfaces)) |
|
137 | + if (in_array(RequestHandlerInterface::class, $aInterfaces)) |
|
138 | 138 | { |
139 | 139 | $this->aRequestHandlers[$sPluginName] = $sClassName; |
140 | 140 | $bIsUsed = true; |
141 | 141 | } |
142 | - if(in_array(ResponsePluginInterface::class, $aInterfaces)) |
|
142 | + if (in_array(ResponsePluginInterface::class, $aInterfaces)) |
|
143 | 143 | { |
144 | 144 | $this->aResponsePlugins[$sPluginName] = $sClassName; |
145 | 145 | $bIsUsed = true; |
146 | 146 | } |
147 | 147 | |
148 | - if(!$bIsUsed) |
|
148 | + if (!$bIsUsed) |
|
149 | 149 | { |
150 | 150 | // The class is invalid. |
151 | 151 | $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | } |
154 | 154 | |
155 | 155 | // Register the plugin in the DI container, if necessary |
156 | - if(!$this->di->has($sClassName)) |
|
156 | + if (!$this->di->has($sClassName)) |
|
157 | 157 | { |
158 | 158 | $this->di->auto($sClassName); |
159 | 159 | } |
@@ -169,12 +169,12 @@ discard block |
||
169 | 169 | */ |
170 | 170 | public function getResponsePlugin(string $sName, ?ResponseInterface $xResponse = null): ?ResponsePlugin |
171 | 171 | { |
172 | - if(!isset($this->aResponsePlugins[$sName])) |
|
172 | + if (!isset($this->aResponsePlugins[$sName])) |
|
173 | 173 | { |
174 | 174 | return null; |
175 | 175 | } |
176 | 176 | $xPlugin = $this->di->g($this->aResponsePlugins[$sName]); |
177 | - if(($xResponse)) |
|
177 | + if (($xResponse)) |
|
178 | 178 | { |
179 | 179 | $xPlugin->setResponse($xResponse); |
180 | 180 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function registerCallable(string $sType, string $sCallable, $xOptions = []) |
197 | 197 | { |
198 | - if(isset($this->aRegistryPlugins[$sType]) && |
|
198 | + if (isset($this->aRegistryPlugins[$sType]) && |
|
199 | 199 | ($xPlugin = $this->di->g($this->aRegistryPlugins[$sType]))) |
200 | 200 | { |
201 | 201 | $xPlugin->register($sType, $sCallable, $xPlugin->checkOptions($sCallable, $xOptions)); |
@@ -298,11 +298,11 @@ |
||
298 | 298 | $sMethod = $this->xTarget->getMethodName(); |
299 | 299 | // The hooks defined at method level are merged with those defined at class level. |
300 | 300 | $aMethods = array_merge($aHookMethods['*'] ?? [], $aHookMethods[$sMethod] ?? []); |
301 | - foreach($aMethods as $xKey => $xValue) |
|
301 | + foreach ($aMethods as $xKey => $xValue) |
|
302 | 302 | { |
303 | 303 | $sHookName = $xValue; |
304 | 304 | $aHookArgs = []; |
305 | - if(is_string($xKey)) |
|
305 | + if (is_string($xKey)) |
|
306 | 306 | { |
307 | 307 | $sHookName = $xKey; |
308 | 308 | $aHookArgs = is_array($xValue) ? $xValue : [$xValue]; |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | |
111 | 111 | // The methods of the CallableClass class must not be exported |
112 | 112 | $xCallableClass = new ReflectionClass(CallableClass::class); |
113 | - foreach($xCallableClass->getMethods(ReflectionMethod::IS_PUBLIC) as $xMethod) |
|
113 | + foreach ($xCallableClass->getMethods(ReflectionMethod::IS_PUBLIC) as $xMethod) |
|
114 | 114 | { |
115 | 115 | $this->aProtectedMethods[] = $xMethod->getName(); |
116 | 116 | } |
@@ -181,15 +181,15 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function makeClassOptions(string $sClassName, array $aClassOptions, array $aDirectoryOptions): array |
183 | 183 | { |
184 | - foreach($this->aDefaultClassOptions as $sOption => $xValue) |
|
184 | + foreach ($this->aDefaultClassOptions as $sOption => $xValue) |
|
185 | 185 | { |
186 | - if(!isset($aClassOptions[$sOption])) |
|
186 | + if (!isset($aClassOptions[$sOption])) |
|
187 | 187 | { |
188 | 188 | $aClassOptions[$sOption] = $xValue; |
189 | 189 | } |
190 | 190 | } |
191 | - $aClassOptions['excluded'] = (bool)($aClassOptions['excluded'] ?? false); // Convert to bool. |
|
192 | - if(is_string($aClassOptions['protected'])) |
|
191 | + $aClassOptions['excluded'] = (bool) ($aClassOptions['excluded'] ?? false); // Convert to bool. |
|
192 | + if (is_string($aClassOptions['protected'])) |
|
193 | 193 | { |
194 | 194 | $aClassOptions['protected'] = [$aClassOptions['protected']]; // Convert to array. |
195 | 195 | } |
@@ -200,25 +200,25 @@ discard block |
||
200 | 200 | $aDirectoryOptions['classes']['*'] ?? [], // Options for all classes |
201 | 201 | $aDirectoryOptions['classes'][$sClassName] ?? [], // Options for this specific class |
202 | 202 | ]; |
203 | - foreach($aOptionGroups as $aOptionGroup) |
|
203 | + foreach ($aOptionGroups as $aOptionGroup) |
|
204 | 204 | { |
205 | - if(isset($aOptionGroup['separator'])) |
|
205 | + if (isset($aOptionGroup['separator'])) |
|
206 | 206 | { |
207 | - $aClassOptions['separator'] = (string)$aOptionGroup['separator']; |
|
207 | + $aClassOptions['separator'] = (string) $aOptionGroup['separator']; |
|
208 | 208 | } |
209 | - if(isset($aOptionGroup['excluded'])) |
|
209 | + if (isset($aOptionGroup['excluded'])) |
|
210 | 210 | { |
211 | - $aClassOptions['excluded'] = (bool)$aOptionGroup['excluded']; |
|
211 | + $aClassOptions['excluded'] = (bool) $aOptionGroup['excluded']; |
|
212 | 212 | } |
213 | - if(isset($aOptionGroup['protected'])) |
|
213 | + if (isset($aOptionGroup['protected'])) |
|
214 | 214 | { |
215 | - if(is_string($aOptionGroup['protected'])) |
|
215 | + if (is_string($aOptionGroup['protected'])) |
|
216 | 216 | { |
217 | 217 | $aOptionGroup['protected'] = [$aOptionGroup['protected']]; // Convert to array. |
218 | 218 | } |
219 | 219 | $aClassOptions['protected'] = array_merge($aClassOptions['protected'], $aOptionGroup['protected']); |
220 | 220 | } |
221 | - if(isset($aOptionGroup['functions'])) |
|
221 | + if (isset($aOptionGroup['functions'])) |
|
222 | 222 | { |
223 | 223 | $aClassOptions['functions'] = array_merge($aClassOptions['functions'], $aOptionGroup['functions']); |
224 | 224 | } |
@@ -264,10 +264,10 @@ discard block |
||
264 | 264 | private function getNamespaceClassOptions(string $sClassName) |
265 | 265 | { |
266 | 266 | // Find the corresponding namespace |
267 | - foreach($this->aNamespaceOptions as $sNamespace => $aOptions) |
|
267 | + foreach ($this->aNamespaceOptions as $sNamespace => $aOptions) |
|
268 | 268 | { |
269 | 269 | // Check if the namespace matches the class. |
270 | - if(strncmp($sClassName, $sNamespace . '\\', strlen($sNamespace) + 1) === 0) |
|
270 | + if (strncmp($sClassName, $sNamespace . '\\', strlen($sNamespace) + 1) === 0) |
|
271 | 271 | { |
272 | 272 | // Save the class options |
273 | 273 | $this->aClasses[$sClassName] = $this->makeClassOptions($sClassName, |
@@ -288,17 +288,17 @@ discard block |
||
288 | 288 | public function getClassOptions(string $sClassName): array |
289 | 289 | { |
290 | 290 | // Find options for a class registered with namespace. |
291 | - if(!isset($this->aClasses[$sClassName])) |
|
291 | + if (!isset($this->aClasses[$sClassName])) |
|
292 | 292 | { |
293 | 293 | $this->getNamespaceClassOptions($sClassName); |
294 | - if(!isset($this->aClasses[$sClassName])) |
|
294 | + if (!isset($this->aClasses[$sClassName])) |
|
295 | 295 | { |
296 | 296 | // Find options for a class registered without namespace. |
297 | 297 | // We then need to parse all classes to be able to find one. |
298 | 298 | $this->di->getCallableRegistry()->parseDirectories(); |
299 | 299 | } |
300 | 300 | } |
301 | - if(isset($this->aClasses[$sClassName])) |
|
301 | + if (isset($this->aClasses[$sClassName])) |
|
302 | 302 | { |
303 | 303 | return $this->aClasses[$sClassName]; |
304 | 304 | } |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | public function getCallableObjects(): array |
328 | 328 | { |
329 | 329 | $aCallableObjects = []; |
330 | - foreach($this->aClasses as $sClassName => $aOptions) |
|
330 | + foreach ($this->aClasses as $sClassName => $aOptions) |
|
331 | 331 | { |
332 | 332 | $this->di->registerCallableClass($sClassName, $aOptions); |
333 | 333 | $aCallableObjects[$sClassName] = $this->di->getCallableObject($sClassName); |
@@ -231,19 +231,19 @@ discard block |
||
231 | 231 | switch($sName) |
232 | 232 | { |
233 | 233 | // Set the methods to call before processing the request |
234 | - case '__before': |
|
235 | - $this->setHookMethods($this->aBeforeMethods, $xValue); |
|
236 | - break; |
|
237 | - // Set the methods to call after processing the request |
|
238 | - case '__after': |
|
239 | - $this->setHookMethods($this->aAfterMethods, $xValue); |
|
240 | - break; |
|
241 | - // Set the attributes to inject in the callable object |
|
242 | - case '__di': |
|
243 | - $this->addDiOption($xValue); |
|
244 | - break; |
|
245 | - default: |
|
246 | - break; |
|
234 | + case '__before': |
|
235 | + $this->setHookMethods($this->aBeforeMethods, $xValue); |
|
236 | + break; |
|
237 | + // Set the methods to call after processing the request |
|
238 | + case '__after': |
|
239 | + $this->setHookMethods($this->aAfterMethods, $xValue); |
|
240 | + break; |
|
241 | + // Set the attributes to inject in the callable object |
|
242 | + case '__di': |
|
243 | + $this->addDiOption($xValue); |
|
244 | + break; |
|
245 | + default: |
|
246 | + break; |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | |
@@ -291,20 +291,20 @@ discard block |
||
291 | 291 | { |
292 | 292 | switch($sOptionName) |
293 | 293 | { |
294 | - case 'excluded': |
|
295 | - if((bool)$xOptionValue) |
|
296 | - { |
|
297 | - $this->addProtectedMethods($sFunctionName); |
|
298 | - } |
|
299 | - break; |
|
300 | - // For databags, all the value are merged in a single array. |
|
301 | - case 'bags': |
|
302 | - $this->_addJsArrayOption($sFunctionName, $sOptionName, $xOptionValue); |
|
303 | - return; |
|
304 | - // For all the other options, including callback, only the last value is kept. |
|
305 | - case 'callback': |
|
306 | - default: |
|
307 | - $this->_setJsOption($sFunctionName, $sOptionName, $xOptionValue); |
|
294 | + case 'excluded': |
|
295 | + if((bool)$xOptionValue) |
|
296 | + { |
|
297 | + $this->addProtectedMethods($sFunctionName); |
|
298 | + } |
|
299 | + break; |
|
300 | + // For databags, all the value are merged in a single array. |
|
301 | + case 'bags': |
|
302 | + $this->_addJsArrayOption($sFunctionName, $sOptionName, $xOptionValue); |
|
303 | + return; |
|
304 | + // For all the other options, including callback, only the last value is kept. |
|
305 | + case 'callback': |
|
306 | + default: |
|
307 | + $this->_setJsOption($sFunctionName, $sOptionName, $xOptionValue); |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 |
@@ -81,29 +81,29 @@ discard block |
||
81 | 81 | public function __construct(array $aOptions, array $aAnnotations) |
82 | 82 | { |
83 | 83 | [$bExcluded, $aAnnotationOptions, $aAnnotationProtected] = $aAnnotations; |
84 | - $this->bExcluded = $bExcluded || (bool)($aOptions['excluded'] ?? false); |
|
85 | - if($this->bExcluded) |
|
84 | + $this->bExcluded = $bExcluded || (bool) ($aOptions['excluded'] ?? false); |
|
85 | + if ($this->bExcluded) |
|
86 | 86 | { |
87 | 87 | return; |
88 | 88 | } |
89 | 89 | |
90 | 90 | $sSeparator = $aOptions['separator']; |
91 | - if($sSeparator === '_' || $sSeparator === '.') |
|
91 | + if ($sSeparator === '_' || $sSeparator === '.') |
|
92 | 92 | { |
93 | 93 | $this->sSeparator = $sSeparator; |
94 | 94 | } |
95 | 95 | $this->addProtectedMethods($aOptions['protected']); |
96 | 96 | $this->addProtectedMethods($aAnnotationProtected); |
97 | 97 | |
98 | - foreach($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
98 | + foreach ($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
99 | 99 | { |
100 | 100 | $aFunctionNames = explode(',', $sNames); // Names are in comma-separated list. |
101 | - foreach($aFunctionNames as $sFunctionName) |
|
101 | + foreach ($aFunctionNames as $sFunctionName) |
|
102 | 102 | { |
103 | 103 | $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
104 | 104 | } |
105 | 105 | } |
106 | - foreach($aAnnotationOptions as $sFunctionName => $aFunctionOptions) |
|
106 | + foreach ($aAnnotationOptions as $sFunctionName => $aFunctionOptions) |
|
107 | 107 | { |
108 | 108 | $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
109 | 109 | } |
@@ -116,14 +116,14 @@ discard block |
||
116 | 116 | */ |
117 | 117 | private function addProtectedMethods($xMethods) |
118 | 118 | { |
119 | - if(!is_array($xMethods)) |
|
119 | + if (!is_array($xMethods)) |
|
120 | 120 | { |
121 | - $this->aProtectedMethods[trim((string)$xMethods)] = true; |
|
121 | + $this->aProtectedMethods[trim((string) $xMethods)] = true; |
|
122 | 122 | return; |
123 | 123 | } |
124 | - foreach($xMethods as $sMethod) |
|
124 | + foreach ($xMethods as $sMethod) |
|
125 | 125 | { |
126 | - $this->aProtectedMethods[trim((string)$sMethod)] = true; |
|
126 | + $this->aProtectedMethods[trim((string) $sMethod)] = true; |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 | |
@@ -197,17 +197,17 @@ discard block |
||
197 | 197 | */ |
198 | 198 | private function setHookMethods(array &$aHookMethods, $xValue) |
199 | 199 | { |
200 | - foreach($xValue as $sCalledMethod => $xMethodToCall) |
|
200 | + foreach ($xValue as $sCalledMethod => $xMethodToCall) |
|
201 | 201 | { |
202 | - if(!isset($aHookMethods[$sCalledMethod])) |
|
202 | + if (!isset($aHookMethods[$sCalledMethod])) |
|
203 | 203 | { |
204 | 204 | $aHookMethods[$sCalledMethod] = []; |
205 | 205 | } |
206 | - if(is_array($xMethodToCall)) |
|
206 | + if (is_array($xMethodToCall)) |
|
207 | 207 | { |
208 | 208 | $aHookMethods[$sCalledMethod] = array_merge($aHookMethods[$sCalledMethod], $xMethodToCall); |
209 | 209 | } |
210 | - elseif(is_string($xMethodToCall)) |
|
210 | + elseif (is_string($xMethodToCall)) |
|
211 | 211 | { |
212 | 212 | $aHookMethods[$sCalledMethod][] = $xMethodToCall; |
213 | 213 | } |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | */ |
233 | 233 | private function addOption(string $sName, $xValue) |
234 | 234 | { |
235 | - switch($sName) |
|
235 | + switch ($sName) |
|
236 | 236 | { |
237 | 237 | // Set the methods to call before processing the request |
238 | 238 | case '__before': |
@@ -260,11 +260,11 @@ discard block |
||
260 | 260 | */ |
261 | 261 | private function _addJsArrayOption(string $sFunctionName, string $sOptionName, $xOptionValue) |
262 | 262 | { |
263 | - if(is_string($xOptionValue)) |
|
263 | + if (is_string($xOptionValue)) |
|
264 | 264 | { |
265 | 265 | $xOptionValue = [$xOptionValue]; |
266 | 266 | } |
267 | - if(!is_array($xOptionValue)) |
|
267 | + if (!is_array($xOptionValue)) |
|
268 | 268 | { |
269 | 269 | return; // Do not save. |
270 | 270 | } |
@@ -293,10 +293,10 @@ discard block |
||
293 | 293 | */ |
294 | 294 | private function addJsOption(string $sFunctionName, string $sOptionName, $xOptionValue) |
295 | 295 | { |
296 | - switch($sOptionName) |
|
296 | + switch ($sOptionName) |
|
297 | 297 | { |
298 | 298 | case 'excluded': |
299 | - if((bool)$xOptionValue) |
|
299 | + if ((bool) $xOptionValue) |
|
300 | 300 | { |
301 | 301 | $this->addProtectedMethods($sFunctionName); |
302 | 302 | } |
@@ -320,12 +320,11 @@ discard block |
||
320 | 320 | */ |
321 | 321 | private function addFunctionOptions(string $sFunctionName, array $aFunctionOptions) |
322 | 322 | { |
323 | - foreach($aFunctionOptions as $sOptionName => $xOptionValue) |
|
323 | + foreach ($aFunctionOptions as $sOptionName => $xOptionValue) |
|
324 | 324 | { |
325 | 325 | substr($sOptionName, 0, 2) === '__' ? |
326 | 326 | // Options for PHP classes. They start with "__". |
327 | - $this->addOption($sOptionName, [$sFunctionName => $xOptionValue]) : |
|
328 | - // Options for javascript code. |
|
327 | + $this->addOption($sOptionName, [$sFunctionName => $xOptionValue]) : // Options for javascript code. |
|
329 | 328 | $this->addJsOption($sFunctionName, $sOptionName, $xOptionValue); |
330 | 329 | } |
331 | 330 | } |
@@ -341,12 +340,11 @@ discard block |
||
341 | 340 | $aOptions = array_merge($this->aJsOptions['*'] ?? []); // Clone the array |
342 | 341 | // Then add the method options. |
343 | 342 | $aMethodOptions = $this->aJsOptions[$sMethodName] ?? []; |
344 | - foreach($aMethodOptions as $sOptionName => $xOptionValue) |
|
343 | + foreach ($aMethodOptions as $sOptionName => $xOptionValue) |
|
345 | 344 | { |
346 | 345 | // For databags, merge the values in a single array. |
347 | 346 | // For all the other options, including callback, keep the last value. |
348 | - $aOptions[$sOptionName] = $sOptionName !== 'bags' ? $xOptionValue : |
|
349 | - array_unique(array_merge($aOptions[$sOptionName] ?? [], $xOptionValue)); |
|
347 | + $aOptions[$sOptionName] = $sOptionName !== 'bags' ? $xOptionValue : array_unique(array_merge($aOptions[$sOptionName] ?? [], $xOptionValue)); |
|
350 | 348 | } |
351 | 349 | return $aOptions; |
352 | 350 | } |
@@ -206,8 +206,7 @@ |
||
206 | 206 | if(is_array($xMethodToCall)) |
207 | 207 | { |
208 | 208 | $aHookMethods[$sCalledMethod] = array_merge($aHookMethods[$sCalledMethod], $xMethodToCall); |
209 | - } |
|
210 | - elseif(is_string($xMethodToCall)) |
|
209 | + } elseif(is_string($xMethodToCall)) |
|
211 | 210 | { |
212 | 211 | $aHookMethods[$sCalledMethod][] = $xMethodToCall; |
213 | 212 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | */ |
215 | 215 | public function set(string $sClass, Closure $xClosure) |
216 | 216 | { |
217 | - $this->xLibContainer->offsetSet($sClass, function() use($xClosure) { |
|
217 | + $this->xLibContainer->offsetSet($sClass, function() use($xClosure) { |
|
218 | 218 | return $xClosure($this); |
219 | 219 | }); |
220 | 220 | } |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | */ |
230 | 230 | public function val(string $sKey, $xValue) |
231 | 231 | { |
232 | - $this->xLibContainer->offsetSet($sKey, $xValue); |
|
232 | + $this->xLibContainer->offsetSet($sKey, $xValue); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | */ |
158 | 158 | public function has(string $sClass): bool |
159 | 159 | { |
160 | - if($this->xAppContainer != null && $this->xAppContainer->has($sClass)) |
|
160 | + if ($this->xAppContainer != null && $this->xAppContainer->has($sClass)) |
|
161 | 161 | { |
162 | 162 | return true; |
163 | 163 | } |
@@ -188,13 +188,13 @@ discard block |
||
188 | 188 | { |
189 | 189 | try |
190 | 190 | { |
191 | - if($this->xAppContainer != null && $this->xAppContainer->has($sClass)) |
|
191 | + if ($this->xAppContainer != null && $this->xAppContainer->has($sClass)) |
|
192 | 192 | { |
193 | 193 | return $this->xAppContainer->get($sClass); |
194 | 194 | } |
195 | 195 | return $this->xLibContainer->offsetGet($sClass); |
196 | 196 | } |
197 | - catch(Exception|Throwable $e) |
|
197 | + catch (Exception | Throwable $e) |
|
198 | 198 | { |
199 | 199 | $xLogger = $this->g(LoggerInterface::class); |
200 | 200 | $xTranslator = $this->g(Translator::class); |
@@ -258,15 +258,15 @@ discard block |
||
258 | 258 | { |
259 | 259 | $xType = $xParameter->getType(); |
260 | 260 | // Check the parameter class first. |
261 | - if($xType instanceof ReflectionNamedType) |
|
261 | + if ($xType instanceof ReflectionNamedType) |
|
262 | 262 | { |
263 | 263 | // Check the class + the name |
264 | - if($this->has($xType->getName() . ' $' . $xParameter->getName())) |
|
264 | + if ($this->has($xType->getName() . ' $' . $xParameter->getName())) |
|
265 | 265 | { |
266 | 266 | return $this->get($xType->getName() . ' $' . $xParameter->getName()); |
267 | 267 | } |
268 | 268 | // Check the class only |
269 | - if($this->get($xType->getName())) |
|
269 | + if ($this->get($xType->getName())) |
|
270 | 270 | { |
271 | 271 | return $this->get($xType->getName()); |
272 | 272 | } |
@@ -286,16 +286,16 @@ discard block |
||
286 | 286 | */ |
287 | 287 | public function make($xClass) |
288 | 288 | { |
289 | - if(is_string($xClass)) |
|
289 | + if (is_string($xClass)) |
|
290 | 290 | { |
291 | 291 | $xClass = new ReflectionClass($xClass); // Create the reflection class instance |
292 | 292 | } |
293 | - if(!($xClass instanceof ReflectionClass)) |
|
293 | + if (!($xClass instanceof ReflectionClass)) |
|
294 | 294 | { |
295 | 295 | return null; |
296 | 296 | } |
297 | 297 | // Use the Reflection class to get the parameters of the constructor |
298 | - if(($constructor = $xClass->getConstructor()) === null) |
|
298 | + if (($constructor = $xClass->getConstructor()) === null) |
|
299 | 299 | { |
300 | 300 | return $xClass->newInstance(); |
301 | 301 | } |
@@ -193,8 +193,7 @@ |
||
193 | 193 | return $this->xAppContainer->get($sClass); |
194 | 194 | } |
195 | 195 | return $this->xLibContainer->offsetGet($sClass); |
196 | - } |
|
197 | - catch(Exception|Throwable $e) |
|
196 | + } catch(Exception|Throwable $e) |
|
198 | 197 | { |
199 | 198 | $xLogger = $this->g(LoggerInterface::class); |
200 | 199 | $xTranslator = $this->g(Translator::class); |