@@ -94,7 +94,7 @@ |
||
94 | 94 | public function redirect(string $sURL, int $nDelay = 0): Response |
95 | 95 | { |
96 | 96 | $sURL = $this->di->getParameterReader()->parseUrl($sURL); |
97 | - if($nDelay <= 0) |
|
97 | + if ($nDelay <= 0) |
|
98 | 98 | { |
99 | 99 | return $this->script("window.location = '$sURL';"); |
100 | 100 | } |
@@ -108,17 +108,17 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function append(ResponseInterface $xResponse) |
110 | 110 | { |
111 | - if($this->xResponse->getCommandCount() === 0) |
|
111 | + if ($this->xResponse->getCommandCount() === 0) |
|
112 | 112 | { |
113 | 113 | $this->xResponse = $xResponse; |
114 | 114 | return; |
115 | 115 | } |
116 | - if(get_class($this->xResponse) !== get_class($xResponse)) |
|
116 | + if (get_class($this->xResponse) !== get_class($xResponse)) |
|
117 | 117 | { |
118 | 118 | throw new RequestException($this->xTranslator->trans('errors.mismatch.types', |
119 | 119 | ['class' => get_class($xResponse)])); |
120 | 120 | } |
121 | - if($this->xResponse !== $xResponse) |
|
121 | + if ($this->xResponse !== $xResponse) |
|
122 | 122 | { |
123 | 123 | $this->xResponse->appendResponse($xResponse); |
124 | 124 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | */ |
160 | 160 | public function printDebug() |
161 | 161 | { |
162 | - foreach($this->aDebugMessages as $sMessage) |
|
162 | + foreach ($this->aDebugMessages as $sMessage) |
|
163 | 163 | { |
164 | 164 | $this->xResponse->debug($sMessage); |
165 | 165 | } |
@@ -173,8 +173,7 @@ discard block |
||
173 | 173 | */ |
174 | 174 | public function getContentType(): string |
175 | 175 | { |
176 | - return empty($this->sCharacterEncoding) ? $this->xResponse->getContentType() : |
|
177 | - $this->xResponse->getContentType() . '; charset="' . $this->sCharacterEncoding . '"'; |
|
176 | + return empty($this->sCharacterEncoding) ? $this->xResponse->getContentType() : $this->xResponse->getContentType() . '; charset="' . $this->sCharacterEncoding . '"'; |
|
178 | 177 | } |
179 | 178 | |
180 | 179 | /** |
@@ -118,15 +118,15 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function checkOptions(string $sCallable, $xOptions): array |
120 | 120 | { |
121 | - if(!$this->xValidator->validateFunction(trim($sCallable))) |
|
121 | + if (!$this->xValidator->validateFunction(trim($sCallable))) |
|
122 | 122 | { |
123 | 123 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
124 | 124 | } |
125 | - if(is_string($xOptions)) |
|
125 | + if (is_string($xOptions)) |
|
126 | 126 | { |
127 | 127 | $xOptions = ['include' => $xOptions]; |
128 | 128 | } |
129 | - elseif(!is_array($xOptions)) |
|
129 | + elseif (!is_array($xOptions)) |
|
130 | 130 | { |
131 | 131 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
132 | 132 | } |
@@ -147,9 +147,9 @@ discard block |
||
147 | 147 | $sPhpFunction = trim($sCallable); |
148 | 148 | $sFunction = $sPhpFunction; |
149 | 149 | // Check if an alias is defined |
150 | - if(isset($aOptions['alias'])) |
|
150 | + if (isset($aOptions['alias'])) |
|
151 | 151 | { |
152 | - $sFunction = (string)$aOptions['alias']; |
|
152 | + $sFunction = (string) $aOptions['alias']; |
|
153 | 153 | unset($aOptions['alias']); |
154 | 154 | } |
155 | 155 | $this->aFunctions[$sFunction] = $sPhpFunction; |
@@ -171,12 +171,12 @@ discard block |
||
171 | 171 | public function getCallable(string $sCallable) |
172 | 172 | { |
173 | 173 | $sFunction = trim($sCallable); |
174 | - if(!isset($this->aFunctions[$sFunction])) |
|
174 | + if (!isset($this->aFunctions[$sFunction])) |
|
175 | 175 | { |
176 | 176 | return null; |
177 | 177 | } |
178 | 178 | $xCallable = new CallableFunction($sFunction, $this->sPrefix . $sFunction, $this->aFunctions[$sFunction]); |
179 | - foreach($this->aOptions[$sFunction] as $sName => $sValue) |
|
179 | + foreach ($this->aOptions[$sFunction] as $sName => $sValue) |
|
180 | 180 | { |
181 | 181 | $xCallable->configure($sName, $sValue); |
182 | 182 | } |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | public function getScript(): string |
206 | 206 | { |
207 | 207 | $code = ''; |
208 | - foreach(array_keys($this->aFunctions) as $sFunction) |
|
208 | + foreach (array_keys($this->aFunctions) as $sFunction) |
|
209 | 209 | { |
210 | 210 | $xFunction = $this->getCallable($sFunction); |
211 | 211 | $code .= $this->getCallableScript($xFunction); |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | public static function canProcessRequest(ServerRequestInterface $xRequest): bool |
220 | 220 | { |
221 | 221 | $aBody = $xRequest->getParsedBody(); |
222 | - if(is_array($aBody)) |
|
222 | + if (is_array($aBody)) |
|
223 | 223 | { |
224 | 224 | return isset($aBody['jxnfun']); |
225 | 225 | } |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | public function setTarget(ServerRequestInterface $xRequest) |
234 | 234 | { |
235 | 235 | $aBody = $xRequest->getParsedBody(); |
236 | - if(is_array($aBody)) |
|
236 | + if (is_array($aBody)) |
|
237 | 237 | { |
238 | 238 | $this->xTarget = Target::makeFunction(trim($aBody['jxnfun'])); |
239 | 239 | return; |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | $sRequestedFunction = $this->xTarget->getFunctionName(); |
252 | 252 | |
253 | 253 | // Security check: make sure the requested function was registered. |
254 | - if(!$this->xValidator->validateFunction($sRequestedFunction) || |
|
254 | + if (!$this->xValidator->validateFunction($sRequestedFunction) || |
|
255 | 255 | !isset($this->aFunctions[$sRequestedFunction])) |
256 | 256 | { |
257 | 257 | // Unable to find the requested function |
@@ -125,8 +125,7 @@ |
||
125 | 125 | if(is_string($xOptions)) |
126 | 126 | { |
127 | 127 | $xOptions = ['include' => $xOptions]; |
128 | - } |
|
129 | - elseif(!is_array($xOptions)) |
|
128 | + } elseif(!is_array($xOptions)) |
|
130 | 129 | { |
131 | 130 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
132 | 131 | } |
@@ -114,15 +114,15 @@ |
||
114 | 114 | { |
115 | 115 | switch($sName) |
116 | 116 | { |
117 | - case 'class': // The user function is a method in the given class |
|
118 | - $this->xPhpFunction = [$sValue, $this->xPhpFunction]; |
|
119 | - break; |
|
120 | - case 'include': |
|
121 | - $this->sInclude = $sValue; |
|
122 | - break; |
|
123 | - default: |
|
124 | - $this->aOptions[$sName] = $sValue; |
|
125 | - break; |
|
117 | + case 'class': // The user function is a method in the given class |
|
118 | + $this->xPhpFunction = [$sValue, $this->xPhpFunction]; |
|
119 | + break; |
|
120 | + case 'include': |
|
121 | + $this->sInclude = $sValue; |
|
122 | + break; |
|
123 | + default: |
|
124 | + $this->aOptions[$sName] = $sValue; |
|
125 | + break; |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function configure(string $sName, string $sValue) |
114 | 114 | { |
115 | - switch($sName) |
|
115 | + switch ($sName) |
|
116 | 116 | { |
117 | 117 | case 'class': // The user function is a method in the given class |
118 | 118 | $this->xPhpFunction = [$sValue, $this->xPhpFunction]; |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function call(array $aArgs = []) |
138 | 138 | { |
139 | - if(($this->sInclude)) |
|
139 | + if (($this->sInclude)) |
|
140 | 140 | { |
141 | 141 | require_once $this->sInclude; |
142 | 142 | } |
143 | 143 | // If the function is an alias for a class method, then instantiate the class |
144 | - if(is_array($this->xPhpFunction) && is_string($this->xPhpFunction[0])) |
|
144 | + if (is_array($this->xPhpFunction) && is_string($this->xPhpFunction[0])) |
|
145 | 145 | { |
146 | 146 | $sClassName = $this->xPhpFunction[0]; |
147 | 147 | $this->xPhpFunction[0] = new $sClassName; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | private function checkDirectory(string $sDirectory): string |
81 | 81 | { |
82 | 82 | $sDirectory = rtrim(trim($sDirectory), '/\\'); |
83 | - if(!is_dir($sDirectory)) |
|
83 | + if (!is_dir($sDirectory)) |
|
84 | 84 | { |
85 | 85 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
86 | 86 | } |
@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function checkOptions(string $sCallable, $xOptions): array |
95 | 95 | { |
96 | - if(is_string($xOptions)) |
|
96 | + if (is_string($xOptions)) |
|
97 | 97 | { |
98 | 98 | $xOptions = ['namespace' => $xOptions]; |
99 | 99 | } |
100 | - if(!is_array($xOptions)) |
|
100 | + if (!is_array($xOptions)) |
|
101 | 101 | { |
102 | 102 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
103 | 103 | } |
@@ -105,14 +105,14 @@ discard block |
||
105 | 105 | $xOptions['directory'] = $this->checkDirectory($sCallable); |
106 | 106 | // Check the namespace |
107 | 107 | $sNamespace = $xOptions['namespace'] ?? ''; |
108 | - if(!($xOptions['namespace'] = trim($sNamespace, ' \\'))) |
|
108 | + if (!($xOptions['namespace'] = trim($sNamespace, ' \\'))) |
|
109 | 109 | { |
110 | 110 | $xOptions['namespace'] = ''; |
111 | 111 | } |
112 | 112 | |
113 | 113 | // Change the keys in $xOptions to have "\" as separator |
114 | 114 | $_aOptions = []; |
115 | - foreach($xOptions as $sName => $aOption) |
|
115 | + foreach ($xOptions as $sName => $aOption) |
|
116 | 116 | { |
117 | 117 | $sName = trim(str_replace('.', '\\', $sName), ' \\'); |
118 | 118 | $_aOptions[$sName] = $aOption; |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function register(string $sType, string $sCallable, array $aOptions): bool |
127 | 127 | { |
128 | - if(($aOptions['namespace'])) |
|
128 | + if (($aOptions['namespace'])) |
|
129 | 129 | { |
130 | 130 | $this->xRegistry->addNamespace($aOptions['namespace'], $aOptions); |
131 | 131 | return true; |
@@ -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 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,12 +256,12 @@ 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 | } |
263 | 263 | // Register the class, if it wasn't already. |
264 | - if(!$this->di->h($sClassName)) |
|
264 | + if (!$this->di->h($sClassName)) |
|
265 | 265 | { |
266 | 266 | $this->di->registerCallableClass($sClassName, $this->xRepository->getClassOptions($sClassName)); |
267 | 267 | } |
@@ -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,14 +181,14 @@ 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 | - if(is_string($aClassOptions['protected'])) |
|
191 | + if (is_string($aClassOptions['protected'])) |
|
192 | 192 | { |
193 | 193 | $aClassOptions['protected'] = [$aClassOptions['protected']]; // Convert to array. |
194 | 194 | } |
@@ -199,21 +199,21 @@ discard block |
||
199 | 199 | $aDirectoryOptions['classes']['*'] ?? [], // Options for all classes |
200 | 200 | $aDirectoryOptions['classes'][$sClassName] ?? [], // Options for this specific class |
201 | 201 | ]; |
202 | - foreach($aOptionGroups as $aOptionGroup) |
|
202 | + foreach ($aOptionGroups as $aOptionGroup) |
|
203 | 203 | { |
204 | - if(isset($aOptionGroup['separator'])) |
|
204 | + if (isset($aOptionGroup['separator'])) |
|
205 | 205 | { |
206 | 206 | $aClassOptions['separator'] = $aOptionGroup['separator']; |
207 | 207 | } |
208 | - if(isset($aOptionGroup['protected'])) |
|
208 | + if (isset($aOptionGroup['protected'])) |
|
209 | 209 | { |
210 | - if(is_string($aOptionGroup['protected'])) |
|
210 | + if (is_string($aOptionGroup['protected'])) |
|
211 | 211 | { |
212 | 212 | $aOptionGroup['protected'] = [$aOptionGroup['protected']]; // Convert to array. |
213 | 213 | } |
214 | 214 | $aClassOptions['protected'] = array_merge($aClassOptions['protected'], $aOptionGroup['protected']); |
215 | 215 | } |
216 | - if(isset($aOptionGroup['functions'])) |
|
216 | + if (isset($aOptionGroup['functions'])) |
|
217 | 217 | { |
218 | 218 | $aClassOptions['functions'] = array_merge($aClassOptions['functions'], $aOptionGroup['functions']); |
219 | 219 | } |
@@ -259,10 +259,10 @@ discard block |
||
259 | 259 | private function getNamespaceClassOptions(string $sClassName) |
260 | 260 | { |
261 | 261 | // Find the corresponding namespace |
262 | - foreach($this->aNamespaceOptions as $sNamespace => $aOptions) |
|
262 | + foreach ($this->aNamespaceOptions as $sNamespace => $aOptions) |
|
263 | 263 | { |
264 | 264 | // Check if the namespace matches the class. |
265 | - if(strncmp($sClassName, $sNamespace . '\\', strlen($sNamespace) + 1) === 0) |
|
265 | + if (strncmp($sClassName, $sNamespace . '\\', strlen($sNamespace) + 1) === 0) |
|
266 | 266 | { |
267 | 267 | // Save the class options |
268 | 268 | $this->aClasses[$sClassName] = $this->makeClassOptions($sClassName, |
@@ -283,17 +283,17 @@ discard block |
||
283 | 283 | public function getClassOptions(string $sClassName): array |
284 | 284 | { |
285 | 285 | // Find options for a class registered with namespace. |
286 | - if(!isset($this->aClasses[$sClassName])) |
|
286 | + if (!isset($this->aClasses[$sClassName])) |
|
287 | 287 | { |
288 | 288 | $this->getNamespaceClassOptions($sClassName); |
289 | - if(!isset($this->aClasses[$sClassName])) |
|
289 | + if (!isset($this->aClasses[$sClassName])) |
|
290 | 290 | { |
291 | 291 | // Find options for a class registered without namespace. |
292 | 292 | // We then need to parse all classes to be able to find one. |
293 | 293 | $this->di->getCallableRegistry()->parseDirectories(); |
294 | 294 | } |
295 | 295 | } |
296 | - if(isset($this->aClasses[$sClassName])) |
|
296 | + if (isset($this->aClasses[$sClassName])) |
|
297 | 297 | { |
298 | 298 | return $this->aClasses[$sClassName]; |
299 | 299 | } |
@@ -322,9 +322,9 @@ discard block |
||
322 | 322 | public function getCallableObjects(): array |
323 | 323 | { |
324 | 324 | $aCallableObjects = []; |
325 | - foreach($this->aClasses as $sClassName => $aOptions) |
|
325 | + foreach ($this->aClasses as $sClassName => $aOptions) |
|
326 | 326 | { |
327 | - if(!$this->di->h($sClassName)) |
|
327 | + if (!$this->di->h($sClassName)) |
|
328 | 328 | { |
329 | 329 | $this->di->registerCallableClass($sClassName, $aOptions); |
330 | 330 | } |
@@ -133,15 +133,15 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function checkOptions(string $sCallable, $xOptions): array |
135 | 135 | { |
136 | - if(!$this->xValidator->validateClass(trim($sCallable))) |
|
136 | + if (!$this->xValidator->validateClass(trim($sCallable))) |
|
137 | 137 | { |
138 | 138 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
139 | 139 | } |
140 | - if(is_string($xOptions)) |
|
140 | + if (is_string($xOptions)) |
|
141 | 141 | { |
142 | 142 | $xOptions = ['include' => $xOptions]; |
143 | 143 | } |
144 | - elseif(!is_array($xOptions)) |
|
144 | + elseif (!is_array($xOptions)) |
|
145 | 145 | { |
146 | 146 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
147 | 147 | } |
@@ -186,16 +186,16 @@ discard block |
||
186 | 186 | $sCode = ''; |
187 | 187 | $aJsClasses = []; |
188 | 188 | $aNamespaces = $this->xRepository->getNamespaces(); |
189 | - foreach($aNamespaces as $sNamespace) |
|
189 | + foreach ($aNamespaces as $sNamespace) |
|
190 | 190 | { |
191 | 191 | $offset = 0; |
192 | 192 | $sJsNamespace = str_replace('\\', '.', $sNamespace); |
193 | 193 | $sJsNamespace .= '.Null'; // This is a sentinel. The last token is not processed in the while loop. |
194 | - while(($dotPosition = strpos($sJsNamespace, '.', $offset)) !== false) |
|
194 | + while (($dotPosition = strpos($sJsNamespace, '.', $offset)) !== false) |
|
195 | 195 | { |
196 | 196 | $sJsClass = substr($sJsNamespace, 0, $dotPosition); |
197 | 197 | // Generate code for this object |
198 | - if(!isset($aJsClasses[$sJsClass])) |
|
198 | + if (!isset($aJsClasses[$sJsClass])) |
|
199 | 199 | { |
200 | 200 | $sCode .= $this->sPrefix . "$sJsClass = {};\n"; |
201 | 201 | $aJsClasses[$sJsClass] = $sJsClass; |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | */ |
217 | 217 | private function getCallableScript(string $sClassName, CallableObject $xCallableObject): string |
218 | 218 | { |
219 | - if($xCallableObject->excluded()) |
|
219 | + if ($xCallableObject->excluded()) |
|
220 | 220 | { |
221 | 221 | return ''; |
222 | 222 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | }); |
245 | 245 | |
246 | 246 | $sCode = $this->getNamespacesScript(); |
247 | - foreach($aCallableObjects as $sClassName => $xCallableObject) |
|
247 | + foreach ($aCallableObjects as $sClassName => $xCallableObject) |
|
248 | 248 | { |
249 | 249 | $sCode .= $this->getCallableScript($sClassName, $xCallableObject); |
250 | 250 | } |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | public static function canProcessRequest(ServerRequestInterface $xRequest): bool |
258 | 258 | { |
259 | 259 | $aBody = $xRequest->getParsedBody(); |
260 | - if(is_array($aBody)) |
|
260 | + if (is_array($aBody)) |
|
261 | 261 | { |
262 | 262 | return isset($aBody['jxncls']) && isset($aBody['jxnmthd']); |
263 | 263 | } |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | public function setTarget(ServerRequestInterface $xRequest) |
272 | 272 | { |
273 | 273 | $aBody = $xRequest->getParsedBody(); |
274 | - if(is_array($aBody)) |
|
274 | + if (is_array($aBody)) |
|
275 | 275 | { |
276 | 276 | $this->xTarget = Target::makeClass(trim($aBody['jxncls']), trim($aBody['jxnmthd'])); |
277 | 277 | return; |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | $sRequestedClass = $this->xTarget->getClassName(); |
290 | 290 | $sRequestedMethod = $this->xTarget->getMethodName(); |
291 | 291 | |
292 | - if(!$this->xValidator->validateClass($sRequestedClass) || |
|
292 | + if (!$this->xValidator->validateClass($sRequestedClass) || |
|
293 | 293 | !$this->xValidator->validateMethod($sRequestedMethod)) |
294 | 294 | { |
295 | 295 | // Unable to find the requested object or method |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | $xCallableObject = $this->xRegistry->getCallableObject($sRequestedClass); |
304 | 304 | return $xCallableObject->call($sRequestedMethod, $this->xParameterReader->args()); |
305 | 305 | } |
306 | - catch(ReflectionException|SetupException $e) |
|
306 | + catch (ReflectionException | SetupException $e) |
|
307 | 307 | { |
308 | 308 | // Unable to find the requested class or method |
309 | 309 | $this->di->getLogger()->error($e->getMessage()); |
@@ -140,8 +140,7 @@ discard block |
||
140 | 140 | if(is_string($xOptions)) |
141 | 141 | { |
142 | 142 | $xOptions = ['include' => $xOptions]; |
143 | - } |
|
144 | - elseif(!is_array($xOptions)) |
|
143 | + } elseif(!is_array($xOptions)) |
|
145 | 144 | { |
146 | 145 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
147 | 146 | } |
@@ -302,8 +301,7 @@ discard block |
||
302 | 301 | { |
303 | 302 | $xCallableObject = $this->xRegistry->getCallableObject($sRequestedClass); |
304 | 303 | return $xCallableObject->call($sRequestedMethod, $this->xParameterReader->args()); |
305 | - } |
|
306 | - catch(ReflectionException|SetupException $e) |
|
304 | + } catch(ReflectionException|SetupException $e) |
|
307 | 305 | { |
308 | 306 | // Unable to find the requested class or method |
309 | 307 | $this->di->getLogger()->error($e->getMessage()); |
@@ -207,36 +207,36 @@ |
||
207 | 207 | switch($sName) |
208 | 208 | { |
209 | 209 | // Set the separator |
210 | - case 'separator': |
|
211 | - if($xValue === '_' || $xValue === '.') |
|
212 | - { |
|
213 | - $this->sSeparator = $xValue; |
|
214 | - } |
|
215 | - break; |
|
216 | - // Set the protected methods |
|
217 | - case 'protected': |
|
218 | - if(is_array($xValue)) |
|
219 | - { |
|
220 | - $this->aProtectedMethods = array_merge($this->aProtectedMethods, $xValue); |
|
221 | - } |
|
222 | - break; |
|
223 | - // Set the methods to call before processing the request |
|
224 | - case '__before': |
|
225 | - $this->setHookMethods($this->aBeforeMethods, $xValue); |
|
226 | - break; |
|
227 | - // Set the methods to call after processing the request |
|
228 | - case '__after': |
|
229 | - $this->setHookMethods($this->aAfterMethods, $xValue); |
|
230 | - break; |
|
231 | - // Set the attributes to inject in the callable object |
|
232 | - case '__di': |
|
233 | - $this->aAttributes = array_merge($this->aAttributes, $xValue); |
|
234 | - break; |
|
235 | - case 'excluded': |
|
236 | - $this->bExcluded = (bool)$xValue; |
|
237 | - break; |
|
238 | - default: |
|
239 | - break; |
|
210 | + case 'separator': |
|
211 | + if($xValue === '_' || $xValue === '.') |
|
212 | + { |
|
213 | + $this->sSeparator = $xValue; |
|
214 | + } |
|
215 | + break; |
|
216 | + // Set the protected methods |
|
217 | + case 'protected': |
|
218 | + if(is_array($xValue)) |
|
219 | + { |
|
220 | + $this->aProtectedMethods = array_merge($this->aProtectedMethods, $xValue); |
|
221 | + } |
|
222 | + break; |
|
223 | + // Set the methods to call before processing the request |
|
224 | + case '__before': |
|
225 | + $this->setHookMethods($this->aBeforeMethods, $xValue); |
|
226 | + break; |
|
227 | + // Set the methods to call after processing the request |
|
228 | + case '__after': |
|
229 | + $this->setHookMethods($this->aAfterMethods, $xValue); |
|
230 | + break; |
|
231 | + // Set the attributes to inject in the callable object |
|
232 | + case '__di': |
|
233 | + $this->aAttributes = array_merge($this->aAttributes, $xValue); |
|
234 | + break; |
|
235 | + case 'excluded': |
|
236 | + $this->bExcluded = (bool)$xValue; |
|
237 | + break; |
|
238 | + default: |
|
239 | + break; |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 |
@@ -181,13 +181,13 @@ discard block |
||
181 | 181 | */ |
182 | 182 | private function setHookMethods(array &$aHookMethods, $xValue) |
183 | 183 | { |
184 | - foreach($xValue as $sCalledMethod => $xMethodToCall) |
|
184 | + foreach ($xValue as $sCalledMethod => $xMethodToCall) |
|
185 | 185 | { |
186 | - if(is_array($xMethodToCall)) |
|
186 | + if (is_array($xMethodToCall)) |
|
187 | 187 | { |
188 | 188 | $aHookMethods[$sCalledMethod] = $xMethodToCall; |
189 | 189 | } |
190 | - elseif(is_string($xMethodToCall)) |
|
190 | + elseif (is_string($xMethodToCall)) |
|
191 | 191 | { |
192 | 192 | $aHookMethods[$sCalledMethod] = [$xMethodToCall]; |
193 | 193 | } |
@@ -204,18 +204,18 @@ discard block |
||
204 | 204 | */ |
205 | 205 | public function configure(string $sName, $xValue) |
206 | 206 | { |
207 | - switch($sName) |
|
207 | + switch ($sName) |
|
208 | 208 | { |
209 | 209 | // Set the separator |
210 | 210 | case 'separator': |
211 | - if($xValue === '_' || $xValue === '.') |
|
211 | + if ($xValue === '_' || $xValue === '.') |
|
212 | 212 | { |
213 | 213 | $this->sSeparator = $xValue; |
214 | 214 | } |
215 | 215 | break; |
216 | 216 | // Set the protected methods |
217 | 217 | case 'protected': |
218 | - if(is_array($xValue)) |
|
218 | + if (is_array($xValue)) |
|
219 | 219 | { |
220 | 220 | $this->aProtectedMethods = array_merge($this->aProtectedMethods, $xValue); |
221 | 221 | } |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | $this->aAttributes = array_merge($this->aAttributes, $xValue); |
234 | 234 | break; |
235 | 235 | case 'excluded': |
236 | - $this->bExcluded = (bool)$xValue; |
|
236 | + $this->bExcluded = (bool) $xValue; |
|
237 | 237 | break; |
238 | 238 | default: |
239 | 239 | break; |
@@ -339,11 +339,11 @@ discard block |
||
339 | 339 | private function callHookMethods(array $aHookMethods, string $sMethod) |
340 | 340 | { |
341 | 341 | $aMethods = $aHookMethods[$sMethod] ?? $aHookMethods['*'] ?? []; |
342 | - foreach($aMethods as $xKey => $xValue) |
|
342 | + foreach ($aMethods as $xKey => $xValue) |
|
343 | 343 | { |
344 | 344 | $sMethodName = $xValue; |
345 | 345 | $aMethodArgs = []; |
346 | - if(is_string($xKey)) |
|
346 | + if (is_string($xKey)) |
|
347 | 347 | { |
348 | 348 | $sMethodName = $xKey; |
349 | 349 | $aMethodArgs = is_array($xValue) ? $xValue : [$xValue]; |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | |
369 | 369 | // Set attributes from the DI container |
370 | 370 | $aAttributes = $this->aAttributes[$sMethod] ?? $this->aAttributes['*'] ?? []; |
371 | - foreach($aAttributes as $sName => $sClass) |
|
371 | + foreach ($aAttributes as $sName => $sClass) |
|
372 | 372 | { |
373 | 373 | // Warning: dynamic properties will be deprecated in PHP8.2. |
374 | 374 | $this->xRegisteredObject->$sName = $this->di->get($sClass); |
@@ -186,8 +186,7 @@ |
||
186 | 186 | if(is_array($xMethodToCall)) |
187 | 187 | { |
188 | 188 | $aHookMethods[$sCalledMethod] = $xMethodToCall; |
189 | - } |
|
190 | - elseif(is_string($xMethodToCall)) |
|
189 | + } elseif(is_string($xMethodToCall)) |
|
191 | 190 | { |
192 | 191 | $aHookMethods[$sCalledMethod] = [$xMethodToCall]; |
193 | 192 | } |