Passed
Push — main ( c6b105...31af8b )
by Thierry
07:02
created
jaxon-core/src/Di/Traits/PluginTrait.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
     public function registerPackage(string $sClassName, array $aUserOptions): void
194 194
     {
195 195
         // Register the user class, but only if the user didn't already.
196
-        if(!$this->h($sClassName))
196
+        if (!$this->h($sClassName))
197 197
         {
198 198
             $this->set($sClassName, fn() => $this->make($sClassName));
199 199
         }
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
         $this->set($sConfigKey, function($di) use($aUserOptions) {
204 204
             $xOptionsProvider = $aUserOptions['provider'] ?? null;
205 205
             // The user can provide a callable that returns the package options.
206
-            if(is_callable($xOptionsProvider))
206
+            if (is_callable($xOptionsProvider))
207 207
             {
208 208
                 $aUserOptions = $xOptionsProvider($aUserOptions);
209 209
             }
Please login to merge, or discard this patch.
jaxon-core/src/Di/ComponentContainer.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      */
132 132
     public function set(string $sClass, Closure $xClosure)
133 133
     {
134
-       $this->xContainer->offsetSet($sClass, function() use($xClosure) {
134
+        $this->xContainer->offsetSet($sClass, function() use($xClosure) {
135 135
             return $xClosure($this);
136 136
         });
137 137
     }
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
      */
147 147
     public function val(string $sKey, $xValue)
148 148
     {
149
-       $this->xContainer->offsetSet($sKey, $xValue);
149
+        $this->xContainer->offsetSet($sKey, $xValue);
150 150
     }
151 151
 
152 152
     /**
Please login to merge, or discard this patch.
Spacing   +16 added lines, -17 removed lines patch added patch discarded remove patch
@@ -194,13 +194,13 @@  discard block
 block discarded – undo
194 194
         try
195 195
         {
196 196
             // Make sure the registered class exists
197
-            if(isset($aOptions['include']))
197
+            if (isset($aOptions['include']))
198 198
             {
199 199
                 require_once $aOptions['include'];
200 200
             }
201 201
             $xReflectionClass = new ReflectionClass($sClassName);
202 202
             // Check if the class is registrable
203
-            if(!$xReflectionClass->isInstantiable())
203
+            if (!$xReflectionClass->isInstantiable())
204 204
             {
205 205
                 return;
206 206
             }
@@ -208,14 +208,14 @@  discard block
 block discarded – undo
208 208
             $this->aComponents[$sClassName] = $aOptions;
209 209
             $this->val($this->getReflectionClassKey($sClassName), $xReflectionClass);
210 210
             // Register the user class, but only if the user didn't already.
211
-            if(!$this->has($sClassName))
211
+            if (!$this->has($sClassName))
212 212
             {
213 213
                 $this->set($sClassName, function() use($sClassName) {
214 214
                     return $this->make($this->get($this->getReflectionClassKey($sClassName)));
215 215
                 });
216 216
             }
217 217
         }
218
-        catch(ReflectionException $e)
218
+        catch (ReflectionException $e)
219 219
         {
220 220
             throw new SetupException($this->di->g(Translator::class)
221 221
                 ->trans('errors.class.invalid', ['name' => $sClassName]));
@@ -232,12 +232,12 @@  discard block
 block discarded – undo
232 232
      */
233 233
     private function discoverComponent(string $sClassName)
234 234
     {
235
-        if(!isset($this->aComponents[$sClassName]))
235
+        if (!isset($this->aComponents[$sClassName]))
236 236
         {
237 237
             $xRegistry = $this->di->g(ComponentRegistry::class);
238 238
             $xRegistry->updateHash(false); // Disable hash calculation.
239 239
             $aOptions = $xRegistry->getNamespaceComponentOptions($sClassName);
240
-            if($aOptions !== null)
240
+            if ($aOptions !== null)
241 241
             {
242 242
                 $this->registerComponent($sClassName, $aOptions);
243 243
             }
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
                 $xRegistry->registerComponentsInDirectories();
249 249
             }
250 250
         }
251
-        if(!isset($this->aComponents[$sClassName]))
251
+        if (!isset($this->aComponents[$sClassName]))
252 252
         {
253 253
             throw new SetupException($this->di->g(Translator::class)
254 254
                 ->trans('errors.class.invalid', ['name' => $sClassName]));
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
     public function getCallableObjects(): array
265 265
     {
266 266
         $aCallableObjects = [];
267
-        foreach($this->aComponents as $sClassName => $_)
267
+        foreach ($this->aComponents as $sClassName => $_)
268 268
         {
269 269
             $aCallableObjects[$sClassName] = $this->makeCallableObject($sClassName);
270 270
         }
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
     {
284 284
         $sComponentObject = $this->getCallableObjectKey($sClassName);
285 285
         // Prevent duplication. It's important not to use the class name here.
286
-        if($this->has($sComponentObject))
286
+        if ($this->has($sComponentObject))
287 287
         {
288 288
             return;
289 289
         }
@@ -308,14 +308,14 @@  discard block
 block discarded – undo
308 308
 
309 309
         // Initialize the user class instance
310 310
         $this->xContainer->extend($sClassName, function($xClassInstance) use($sClassName) {
311
-            if($xClassInstance instanceof AbstractComponent)
311
+            if ($xClassInstance instanceof AbstractComponent)
312 312
             {
313 313
                 $xHelper = $this->get($this->getCallableHelperKey($sClassName));
314 314
                 $xHelper->xTarget = $this->xTarget;
315 315
 
316 316
                 // Call the protected "initComponent()" method of the Component class.
317 317
                 $cSetter = function($di, $xHelper) {
318
-                    $this->initComponent($di, $xHelper);  // "$this" here refers to the Component class.
318
+                    $this->initComponent($di, $xHelper); // "$this" here refers to the Component class.
319 319
                 };
320 320
                 $cSetter = $cSetter->bindTo($xClassInstance, $xClassInstance);
321 321
                 call_user_func($cSetter, $this->di, $xHelper);
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
             /** @var CallableObject */
331 331
             $xCallableObject = $this->get($this->getCallableObjectKey($sClassName));
332 332
             $xCallableObject->setDiClassAttributes($xClassInstance);
333
-            if($this->xTarget !== null)
333
+            if ($this->xTarget !== null)
334 334
             {
335 335
                 $sMethodName = $this->xTarget->getMethodName();
336 336
                 $xCallableObject->setDiMethodAttributes($xClassInstance, $sMethodName);
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
     private function registerRequestFactory(string $sClassName, string $sFactoryKey)
407 407
     {
408 408
         $this->xContainer->offsetSet($sFactoryKey, function() use($sClassName) {
409
-            if(!($xCallable = $this->makeCallableObject($sClassName)))
409
+            if (!($xCallable = $this->makeCallableObject($sClassName)))
410 410
             {
411 411
                 return null;
412 412
             }
@@ -436,13 +436,13 @@  discard block
 block discarded – undo
436 436
     private function getComponentRequestFactory(string $sClassName): ?JxnCall
437 437
     {
438 438
         $sClassName = trim($sClassName, " \t");
439
-        if($sClassName === '')
439
+        if ($sClassName === '')
440 440
         {
441 441
             return null;
442 442
         }
443 443
 
444 444
         $sFactoryKey = $this->getRequestFactoryKey($sClassName);
445
-        if(!$this->has($sFactoryKey))
445
+        if (!$this->has($sFactoryKey))
446 446
         {
447 447
             $this->registerRequestFactory($sClassName, $sFactoryKey);
448 448
         }
@@ -458,7 +458,6 @@  discard block
 block discarded – undo
458 458
      */
459 459
     public function getRequestFactory(string $sClassName = ''): JxnCall
460 460
     {
461
-        return $sClassName === '' ? $this->getFunctionRequestFactory() :
462
-            $this->getComponentRequestFactory($sClassName);
461
+        return $sClassName === '' ? $this->getFunctionRequestFactory() : $this->getComponentRequestFactory($sClassName);
463 462
     }
464 463
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -214,8 +214,7 @@  discard block
 block discarded – undo
214 214
                     return $this->make($this->get($this->getReflectionClassKey($sClassName)));
215 215
                 });
216 216
             }
217
-        }
218
-        catch(ReflectionException $e)
217
+        } catch(ReflectionException $e)
219 218
         {
220 219
             throw new SetupException($this->di->g(Translator::class)
221 220
                 ->trans('errors.class.invalid', ['name' => $sClassName]));
@@ -240,8 +239,7 @@  discard block
 block discarded – undo
240 239
             if($aOptions !== null)
241 240
             {
242 241
                 $this->registerComponent($sClassName, $aOptions);
243
-            }
244
-            else // if(!isset($this->aComponents[$sClassName]))
242
+            } else // if(!isset($this->aComponents[$sClassName]))
245 243
             {
246 244
                 // The component was not found in a registered namespace. We need to parse all
247 245
                 // the directories to be able to find a component registered without a namespace.
Please login to merge, or discard this patch.
jaxon-core/src/Response/Manager/ResponseManager.php 2 patches
Spacing   +6 added lines, -7 removed lines patch added patch discarded remove patch
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
      */
187 187
     private function getCommandArgs(array|JsonSerializable $aArgs, bool $bRemoveEmpty = false): array
188 188
     {
189
-        if(!$bRemoveEmpty)
189
+        if (!$bRemoveEmpty)
190 190
         {
191 191
             return $aArgs;
192 192
         }
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
             'name' => $this->str($sName),
212 212
             'args' => $this->getCommandArgs($aArgs, $bRemoveEmpty),
213 213
         ]);
214
-        if($this->bOnConfirm)
214
+        if ($this->bOnConfirm)
215 215
         {
216 216
             $this->aConfirmCommands[] = $xCommand;
217 217
         }
@@ -240,14 +240,14 @@  discard block
 block discarded – undo
240 240
     public function addConfirmCommand(string $sName, Closure $fConfirm,
241 241
         string $sQuestion, array $aArgs = []): self
242 242
     {
243
-        if($this->bOnConfirm)
243
+        if ($this->bOnConfirm)
244 244
         {
245 245
             throw new AppException($this->xTranslator->trans('errors.app.confirm.nested'));
246 246
         }
247 247
         $this->bOnConfirm = true;
248 248
         $fConfirm();
249 249
         $this->bOnConfirm = false;
250
-        if(($nCommandCount = count($this->aConfirmCommands)) > 0)
250
+        if (($nCommandCount = count($this->aConfirmCommands)) > 0)
251 251
         {
252 252
             $aCommand = $this->di->getDialogCommand()->confirm($this->str($sQuestion), $aArgs);
253 253
             $aCommand['count'] = $nCommandCount;
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
      */
355 355
     public function printDebug()
356 356
     {
357
-        foreach($this->aDebugMessages as $sMessage)
357
+        foreach ($this->aDebugMessages as $sMessage)
358 358
         {
359 359
             $this->addCommand('script.debug', ['message' => $this->str($sMessage)]);
360 360
         }
@@ -368,8 +368,7 @@  discard block
 block discarded – undo
368 368
      */
369 369
     public function getContentType(): string
370 370
     {
371
-        return empty($this->sCharacterEncoding) ? $this->getResponse()->getContentType() :
372
-            $this->getResponse()->getContentType() . '; charset="' . $this->sCharacterEncoding . '"';
371
+        return empty($this->sCharacterEncoding) ? $this->getResponse()->getContentType() : $this->getResponse()->getContentType() . '; charset="' . $this->sCharacterEncoding . '"';
373 372
     }
374 373
 
375 374
     /**
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -214,8 +214,7 @@
 block discarded – undo
214 214
         if($this->bOnConfirm)
215 215
         {
216 216
             $this->aConfirmCommands[] = $xCommand;
217
-        }
218
-        else
217
+        } else
219 218
         {
220 219
             $this->aCommands[] = $xCommand;
221 220
         }
Please login to merge, or discard this patch.
jaxon-core/src/Response/Manager/Command.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@
 block discarded – undo
66 66
      */
67 67
     public function setOption(string $sName, string|array|JsonSerializable $xValue): Command
68 68
     {
69
-        if(isset($this->aCommand['options']))
69
+        if (isset($this->aCommand['options']))
70 70
         {
71 71
             $this->aCommand['options'][$this->str($sName)] = $xValue;
72 72
             return $this;
Please login to merge, or discard this patch.
jaxon-core/src/Response/AbstractResponse.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -91,15 +91,15 @@
 block discarded – undo
91 91
         return $this->xManager->getErrorMessage();
92 92
     }
93 93
 
94
-     /**
95
-     * Add a response command to the array of commands
96
-     *
97
-     * @param string $sName    The command name
98
-     * @param array|JsonSerializable $aArgs    The command arguments
99
-     * @param bool $bRemoveEmpty
100
-     *
101
-     * @return Command
102
-     */
94
+        /**
95
+         * Add a response command to the array of commands
96
+         *
97
+         * @param string $sName    The command name
98
+         * @param array|JsonSerializable $aArgs    The command arguments
99
+         * @param bool $bRemoveEmpty
100
+         *
101
+         * @return Command
102
+         */
103 103
     public function addCommand(string $sName, array|JsonSerializable $aArgs = [],
104 104
         bool $bRemoveEmpty = false): Command
105 105
     {
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Manager/PackageManager.php 3 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -63,25 +63,25 @@  discard block
 block discarded – undo
63 63
     private function updateContainer(Config $xConfig): void
64 64
     {
65 65
         $aOptions = $xConfig->getOption('container.set', []);
66
-        foreach($aOptions as $xKey => $xValue)
66
+        foreach ($aOptions as $xKey => $xValue)
67 67
         {
68 68
             // The key is the class name. It must be a string.
69 69
             $this->di->set((string)$xKey, $xValue);
70 70
         }
71 71
         $aOptions = $xConfig->getOption('container.val', []);
72
-        foreach($aOptions as $xKey => $xValue)
72
+        foreach ($aOptions as $xKey => $xValue)
73 73
         {
74 74
             // The key is the class name. It must be a string.
75 75
             $this->di->val((string)$xKey, $xValue);
76 76
         }
77 77
         $aOptions = $xConfig->getOption('container.auto', []);
78
-        foreach($aOptions as $xValue)
78
+        foreach ($aOptions as $xValue)
79 79
         {
80 80
             // The key is the class name. It must be a string.
81 81
             $this->di->auto((string)$xValue);
82 82
         }
83 83
         $aOptions = $xConfig->getOption('container.alias', []);
84
-        foreach($aOptions as $xKey => $xValue)
84
+        foreach ($aOptions as $xKey => $xValue)
85 85
         {
86 86
             // The key is the class name. It must be a string.
87 87
             $this->di->alias((string)$xKey, (string)$xValue);
@@ -99,15 +99,15 @@  discard block
 block discarded – undo
99 99
      */
100 100
     private function registerCallables(array $aOptions, string $sCallableType): void
101 101
     {
102
-        foreach($aOptions as $xKey => $xValue)
102
+        foreach ($aOptions as $xKey => $xValue)
103 103
         {
104
-            if(is_integer($xKey) && is_string($xValue))
104
+            if (is_integer($xKey) && is_string($xValue))
105 105
             {
106 106
                 // Register a function without options
107 107
                 $this->xPluginManager->registerCallable($sCallableType, $xValue);
108 108
                 continue;
109 109
             }
110
-            if(is_string($xKey) && (is_array($xValue) || is_string($xValue)))
110
+            if (is_string($xKey) && (is_array($xValue) || is_string($xValue)))
111 111
             {
112 112
                 // Register a function with options
113 113
                 $this->xPluginManager->registerCallable($sCallableType, $xKey, $xValue);
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      */
125 125
     private function registerExceptionHandlers(Config $xConfig): void
126 126
     {
127
-        foreach($xConfig->getOption('exceptions', []) as $sExClass => $xExHandler)
127
+        foreach ($xConfig->getOption('exceptions', []) as $sExClass => $xExHandler)
128 128
         {
129 129
             $this->xCallbackManager->error($xExHandler, is_string($sExClass) ? $sExClass : '');
130 130
         }
@@ -147,19 +147,19 @@  discard block
 block discarded – undo
147 147
         // key of the array item, a string as the value of an entry without a key,
148 148
         // or set with the key $sOptionKey in an array entry without a key.
149 149
         $aCallables = [];
150
-        foreach($xConfig->getOption($sOptionName, []) as $xKey => $xValue)
150
+        foreach ($xConfig->getOption($sOptionName, []) as $xKey => $xValue)
151 151
         {
152
-            if(is_string($xKey))
152
+            if (is_string($xKey))
153 153
             {
154 154
                 $aCallables[$xKey] = $xValue;
155 155
                 continue;
156 156
             }
157
-            if(is_string($xValue))
157
+            if (is_string($xValue))
158 158
             {
159 159
                 $aCallables[] = $xValue;
160 160
                 continue;
161 161
             }
162
-            if(is_array($xValue) && isset($xValue[$sOptionKey]))
162
+            if (is_array($xValue) && isset($xValue[$sOptionKey]))
163 163
             {
164 164
                 $aCallables[$xValue[$sOptionKey]] = $xValue;
165 165
             }
@@ -214,12 +214,12 @@  discard block
 block discarded – undo
214 214
     {
215 215
         // $this->aPackages contains packages config file paths.
216 216
         $aLibOptions = $sClassName::config();
217
-        if(is_string($aLibOptions))
217
+        if (is_string($aLibOptions))
218 218
         {
219 219
             // A string is supposed to be the path to a config file.
220 220
             $aLibOptions = $this->xConfigManager->read($aLibOptions);
221 221
         }
222
-        elseif(!is_array($aLibOptions))
222
+        elseif (!is_array($aLibOptions))
223 223
         {
224 224
             // Otherwise, anything else than an array is not accepted.
225 225
             $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]);
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
     public function registerPackage(string $sClassName, array $aUserOptions = []): void
243 243
     {
244 244
         $sClassName = trim($sClassName, '\\ ');
245
-        if(!is_subclass_of($sClassName, AbstractPackage::class))
245
+        if (!is_subclass_of($sClassName, AbstractPackage::class))
246 246
         {
247 247
             $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]);
248 248
             throw new SetupException($sMessage);
@@ -286,16 +286,16 @@  discard block
 block discarded – undo
286 286
 
287 287
         // Register packages
288 288
         $aPackageConfig = $xAppConfig->getOption('packages', []);
289
-        foreach($aPackageConfig as $xKey => $xValue)
289
+        foreach ($aPackageConfig as $xKey => $xValue)
290 290
         {
291
-            if(is_integer($xKey) && is_string($xValue))
291
+            if (is_integer($xKey) && is_string($xValue))
292 292
             {
293 293
                 // Register a package without options
294 294
                 $sClassName = $xValue;
295 295
                 $this->registerPackage($sClassName);
296 296
                 continue;
297 297
             }
298
-            if(is_string($xKey) && is_array($xValue))
298
+            if (is_string($xKey) && is_array($xValue))
299 299
             {
300 300
                 // Register a package with options
301 301
                 $sClassName = $xKey;
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -218,8 +218,7 @@
 block discarded – undo
218 218
         {
219 219
             // A string is supposed to be the path to a config file.
220 220
             $aLibOptions = $this->xConfigManager->read($aLibOptions);
221
-        }
222
-        elseif(!is_array($aLibOptions))
221
+        } elseif(!is_array($aLibOptions))
223 222
         {
224 223
             // Otherwise, anything else than an array is not accepted.
225 224
             $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]);
Please login to merge, or discard this patch.
Switch Indentation   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
 class PackageManager
37 37
 {
38
-    /**
38
+/**
39 39
      * The constructor
40 40
      *
41 41
      * @param Container $di
@@ -47,48 +47,48 @@  discard block
 block discarded – undo
47 47
      * @param CallbackManager $xCallbackManager
48 48
      * @param ComponentRegistry $xRegistry
49 49
      */
50
-    public function __construct(private Container $di, private Translator $xTranslator,
51
-        private PluginManager $xPluginManager, private ConfigManager $xConfigManager,
52
-        private CodeGenerator $xCodeGenerator, private ViewRenderer $xViewRenderer,
53
-        private CallbackManager $xCallbackManager, private ComponentRegistry $xRegistry)
54
-    {}
50
+public function __construct(private Container $di, private Translator $xTranslator,
51
+private PluginManager $xPluginManager, private ConfigManager $xConfigManager,
52
+private CodeGenerator $xCodeGenerator, private ViewRenderer $xViewRenderer,
53
+private CallbackManager $xCallbackManager, private ComponentRegistry $xRegistry)
54
+{}
55 55
 
56
-    /**
56
+/**
57 57
      * Save items in the DI container
58 58
      *
59 59
      * @param Config $xConfig
60 60
      *
61 61
      * @return void
62 62
      */
63
-    private function updateContainer(Config $xConfig): void
64
-    {
65
-        $aOptions = $xConfig->getOption('container.set', []);
66
-        foreach($aOptions as $xKey => $xValue)
67
-        {
68
-            // The key is the class name. It must be a string.
69
-            $this->di->set((string)$xKey, $xValue);
70
-        }
71
-        $aOptions = $xConfig->getOption('container.val', []);
72
-        foreach($aOptions as $xKey => $xValue)
73
-        {
74
-            // The key is the class name. It must be a string.
75
-            $this->di->val((string)$xKey, $xValue);
76
-        }
77
-        $aOptions = $xConfig->getOption('container.auto', []);
78
-        foreach($aOptions as $xValue)
79
-        {
80
-            // The key is the class name. It must be a string.
81
-            $this->di->auto((string)$xValue);
82
-        }
83
-        $aOptions = $xConfig->getOption('container.alias', []);
84
-        foreach($aOptions as $xKey => $xValue)
85
-        {
86
-            // The key is the class name. It must be a string.
87
-            $this->di->alias((string)$xKey, (string)$xValue);
88
-        }
89
-    }
63
+private function updateContainer(Config $xConfig): void
64
+{
65
+$aOptions = $xConfig->getOption('container.set', []);
66
+foreach($aOptions as $xKey => $xValue)
67
+{
68
+// The key is the class name. It must be a string.
69
+$this->di->set((string)$xKey, $xValue);
70
+}
71
+$aOptions = $xConfig->getOption('container.val', []);
72
+foreach($aOptions as $xKey => $xValue)
73
+{
74
+// The key is the class name. It must be a string.
75
+$this->di->val((string)$xKey, $xValue);
76
+}
77
+$aOptions = $xConfig->getOption('container.auto', []);
78
+foreach($aOptions as $xValue)
79
+{
80
+// The key is the class name. It must be a string.
81
+$this->di->auto((string)$xValue);
82
+}
83
+$aOptions = $xConfig->getOption('container.alias', []);
84
+foreach($aOptions as $xKey => $xValue)
85
+{
86
+// The key is the class name. It must be a string.
87
+$this->di->alias((string)$xKey, (string)$xValue);
88
+}
89
+}
90 90
 
91
-    /**
91
+/**
92 92
      * Register callables from a section of the config
93 93
      *
94 94
      * @param array $aOptions    The content of the config section
@@ -97,40 +97,40 @@  discard block
 block discarded – undo
97 97
      * @return void
98 98
      * @throws SetupException
99 99
      */
100
-    private function registerCallables(array $aOptions, string $sCallableType): void
101
-    {
102
-        foreach($aOptions as $xKey => $xValue)
103
-        {
104
-            if(is_integer($xKey) && is_string($xValue))
105
-            {
106
-                // Register a function without options
107
-                $this->xPluginManager->registerCallable($sCallableType, $xValue);
108
-                continue;
109
-            }
110
-            if(is_string($xKey) && (is_array($xValue) || is_string($xValue)))
111
-            {
112
-                // Register a function with options
113
-                $this->xPluginManager->registerCallable($sCallableType, $xKey, $xValue);
114
-            }
115
-        }
116
-    }
100
+private function registerCallables(array $aOptions, string $sCallableType): void
101
+{
102
+foreach($aOptions as $xKey => $xValue)
103
+{
104
+if(is_integer($xKey) && is_string($xValue))
105
+{
106
+    // Register a function without options
107
+    $this->xPluginManager->registerCallable($sCallableType, $xValue);
108
+    continue;
109
+}
110
+if(is_string($xKey) && (is_array($xValue) || is_string($xValue)))
111
+{
112
+    // Register a function with options
113
+    $this->xPluginManager->registerCallable($sCallableType, $xKey, $xValue);
114
+}
115
+}
116
+}
117 117
 
118
-    /**
118
+/**
119 119
      * Register exceptions handlers
120 120
      *
121 121
      * @param Config $xConfig
122 122
      *
123 123
      * @return void
124 124
      */
125
-    private function registerExceptionHandlers(Config $xConfig): void
126
-    {
127
-        foreach($xConfig->getOption('exceptions', []) as $sExClass => $xExHandler)
128
-        {
129
-            $this->xCallbackManager->error($xExHandler, is_string($sExClass) ? $sExClass : '');
130
-        }
131
-    }
125
+private function registerExceptionHandlers(Config $xConfig): void
126
+{
127
+foreach($xConfig->getOption('exceptions', []) as $sExClass => $xExHandler)
128
+{
129
+$this->xCallbackManager->error($xExHandler, is_string($sExClass) ? $sExClass : '');
130
+}
131
+}
132 132
 
133
-    /**
133
+/**
134 134
      * Get a callable list from config
135 135
      *
136 136
      * @param Config $xConfig
@@ -140,35 +140,35 @@  discard block
 block discarded – undo
140 140
      *
141 141
      * @return void
142 142
      */
143
-    private function registerCallablesFromConfig(Config $xConfig,
144
-        string $sOptionName, string $sOptionKey, string $sCallableType): void
145
-    {
146
-        // The callable (directory path, class or function name) can be used as the
147
-        // key of the array item, a string as the value of an entry without a key,
148
-        // or set with the key $sOptionKey in an array entry without a key.
149
-        $aCallables = [];
150
-        foreach($xConfig->getOption($sOptionName, []) as $xKey => $xValue)
151
-        {
152
-            if(is_string($xKey))
153
-            {
154
-                $aCallables[$xKey] = $xValue;
155
-                continue;
156
-            }
157
-            if(is_string($xValue))
158
-            {
159
-                $aCallables[] = $xValue;
160
-                continue;
161
-            }
162
-            if(is_array($xValue) && isset($xValue[$sOptionKey]))
163
-            {
164
-                $aCallables[$xValue[$sOptionKey]] = $xValue;
165
-            }
166
-            // Invalid values are ignored.
167
-        }
168
-        $this->registerCallables($aCallables, $sCallableType);
169
-    }
143
+private function registerCallablesFromConfig(Config $xConfig,
144
+string $sOptionName, string $sOptionKey, string $sCallableType): void
145
+{
146
+// The callable (directory path, class or function name) can be used as the
147
+// key of the array item, a string as the value of an entry without a key,
148
+// or set with the key $sOptionKey in an array entry without a key.
149
+$aCallables = [];
150
+foreach($xConfig->getOption($sOptionName, []) as $xKey => $xValue)
151
+{
152
+if(is_string($xKey))
153
+{
154
+    $aCallables[$xKey] = $xValue;
155
+    continue;
156
+}
157
+if(is_string($xValue))
158
+{
159
+    $aCallables[] = $xValue;
160
+    continue;
161
+}
162
+if(is_array($xValue) && isset($xValue[$sOptionKey]))
163
+{
164
+    $aCallables[$xValue[$sOptionKey]] = $xValue;
165
+}
166
+// Invalid values are ignored.
167
+}
168
+$this->registerCallables($aCallables, $sCallableType);
169
+}
170 170
 
171
-    /**
171
+/**
172 172
      * Read and set Jaxon options from a JSON config file
173 173
      *
174 174
      * @param Config $xConfig The config options
@@ -176,33 +176,33 @@  discard block
 block discarded – undo
176 176
      * @return void
177 177
      * @throws SetupException
178 178
      */
179
-    private function registerItemsFromConfig(Config $xConfig): void
180
-    {
181
-        // Set the config for the registered callables.
182
-        $this->xRegistry->setPackageConfig($xConfig);
179
+private function registerItemsFromConfig(Config $xConfig): void
180
+{
181
+// Set the config for the registered callables.
182
+$this->xRegistry->setPackageConfig($xConfig);
183 183
 
184
-        // Register functions, classes and directories
185
-        $this->registerCallablesFromConfig($xConfig,
186
-            'functions', 'name', Jaxon::CALLABLE_FUNCTION);
187
-        $this->registerCallablesFromConfig($xConfig,
188
-            'classes', 'name', Jaxon::CALLABLE_CLASS);
189
-        $this->registerCallablesFromConfig($xConfig,
190
-            'directories', 'path', Jaxon::CALLABLE_DIR);
184
+// Register functions, classes and directories
185
+$this->registerCallablesFromConfig($xConfig,
186
+'functions', 'name', Jaxon::CALLABLE_FUNCTION);
187
+$this->registerCallablesFromConfig($xConfig,
188
+'classes', 'name', Jaxon::CALLABLE_CLASS);
189
+$this->registerCallablesFromConfig($xConfig,
190
+'directories', 'path', Jaxon::CALLABLE_DIR);
191 191
 
192
-        // Unset the current config.
193
-        $this->xRegistry->unsetPackageConfig();
192
+// Unset the current config.
193
+$this->xRegistry->unsetPackageConfig();
194 194
 
195
-        // Register the view namespaces
196
-        // Note: the $xUserConfig can provide a "template" option, which is used to customize
197
-        // the user defined view namespaces. That's why it is needed here.
198
-        $this->xViewRenderer->addNamespaces($xConfig);
199
-        // Save items in the DI container
200
-        $this->updateContainer($xConfig);
201
-        // Register the exception handlers
202
-        $this->registerExceptionHandlers($xConfig);
203
-    }
195
+// Register the view namespaces
196
+// Note: the $xUserConfig can provide a "template" option, which is used to customize
197
+// the user defined view namespaces. That's why it is needed here.
198
+$this->xViewRenderer->addNamespaces($xConfig);
199
+// Save items in the DI container
200
+$this->updateContainer($xConfig);
201
+// Register the exception handlers
202
+$this->registerExceptionHandlers($xConfig);
203
+}
204 204
 
205
-    /**
205
+/**
206 206
      * Get the options provided by the package library
207 207
      *
208 208
      * @param class-string $sClassName    The package class
@@ -210,27 +210,27 @@  discard block
 block discarded – undo
210 210
      * @return Config
211 211
      * @throws SetupException
212 212
      */
213
-    private function getPackageLibConfig(string $sClassName): Config
214
-    {
215
-        // $this->aPackages contains packages config file paths.
216
-        $aLibOptions = $sClassName::config();
217
-        if(is_string($aLibOptions))
218
-        {
219
-            // A string is supposed to be the path to a config file.
220
-            $aLibOptions = $this->xConfigManager->read($aLibOptions);
221
-        }
222
-        elseif(!is_array($aLibOptions))
223
-        {
224
-            // Otherwise, anything else than an array is not accepted.
225
-            $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]);
226
-            throw new SetupException($sMessage);
227
-        }
228
-        // Add the package name to the config
229
-        $aLibOptions['package'] = $sClassName;
230
-        return $this->xConfigManager->newConfig($aLibOptions);
231
-    }
213
+private function getPackageLibConfig(string $sClassName): Config
214
+{
215
+// $this->aPackages contains packages config file paths.
216
+$aLibOptions = $sClassName::config();
217
+if(is_string($aLibOptions))
218
+{
219
+// A string is supposed to be the path to a config file.
220
+$aLibOptions = $this->xConfigManager->read($aLibOptions);
221
+}
222
+elseif(!is_array($aLibOptions))
223
+{
224
+// Otherwise, anything else than an array is not accepted.
225
+$sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]);
226
+throw new SetupException($sMessage);
227
+}
228
+// Add the package name to the config
229
+$aLibOptions['package'] = $sClassName;
230
+return $this->xConfigManager->newConfig($aLibOptions);
231
+}
232 232
 
233
-    /**
233
+/**
234 234
      * Register a package
235 235
      *
236 236
      * @param class-string $sClassName    The package class
@@ -239,27 +239,27 @@  discard block
 block discarded – undo
239 239
      * @return void
240 240
      * @throws SetupException
241 241
      */
242
-    public function registerPackage(string $sClassName, array $aUserOptions = []): void
243
-    {
244
-        $sClassName = trim($sClassName, '\\ ');
245
-        if(!is_subclass_of($sClassName, AbstractPackage::class))
246
-        {
247
-            $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]);
248
-            throw new SetupException($sMessage);
249
-        }
242
+public function registerPackage(string $sClassName, array $aUserOptions = []): void
243
+{
244
+$sClassName = trim($sClassName, '\\ ');
245
+if(!is_subclass_of($sClassName, AbstractPackage::class))
246
+{
247
+$sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]);
248
+throw new SetupException($sMessage);
249
+}
250 250
 
251
-        // Register the declarations in the package config.
252
-        $xAppConfig = $this->getPackageLibConfig($sClassName);
253
-        $this->registerItemsFromConfig($xAppConfig);
251
+// Register the declarations in the package config.
252
+$xAppConfig = $this->getPackageLibConfig($sClassName);
253
+$this->registerItemsFromConfig($xAppConfig);
254 254
 
255
-        // Register the package and its options in the DI
256
-        $this->di->registerPackage($sClassName, $aUserOptions);
255
+// Register the package and its options in the DI
256
+$this->di->registerPackage($sClassName, $aUserOptions);
257 257
 
258
-        // Register the package as a code generator.
259
-        $this->xCodeGenerator->addCodeGenerator($sClassName, 500);
260
-    }
258
+// Register the package as a code generator.
259
+$this->xCodeGenerator->addCodeGenerator($sClassName, 500);
260
+}
261 261
 
262
-    /**
262
+/**
263 263
      * Get a package instance
264 264
      *
265 265
      * @template T of AbstractPackage
@@ -267,41 +267,41 @@  discard block
 block discarded – undo
267 267
      *
268 268
      * @return T|null
269 269
      */
270
-    public function getPackage(string $sClassName): ?AbstractPackage
271
-    {
272
-        $sClassName = trim($sClassName, '\\ ');
273
-        return $this->di->h($sClassName) ? $this->di->g($sClassName) : null;
274
-    }
270
+public function getPackage(string $sClassName): ?AbstractPackage
271
+{
272
+$sClassName = trim($sClassName, '\\ ');
273
+return $this->di->h($sClassName) ? $this->di->g($sClassName) : null;
274
+}
275 275
 
276
-    /**
276
+/**
277 277
      * Read and set Jaxon options from the config
278 278
      *
279 279
      * @return void
280 280
      * @throws SetupException
281 281
      */
282
-    public function registerFromConfig(): void
283
-    {
284
-        $xAppConfig = $this->xConfigManager->getAppConfig();
285
-        $this->registerItemsFromConfig($xAppConfig);
282
+public function registerFromConfig(): void
283
+{
284
+$xAppConfig = $this->xConfigManager->getAppConfig();
285
+$this->registerItemsFromConfig($xAppConfig);
286 286
 
287
-        // Register packages
288
-        $aPackageConfig = $xAppConfig->getOption('packages', []);
289
-        foreach($aPackageConfig as $xKey => $xValue)
290
-        {
291
-            if(is_integer($xKey) && is_string($xValue))
292
-            {
293
-                // Register a package without options
294
-                $sClassName = $xValue;
295
-                $this->registerPackage($sClassName);
296
-                continue;
297
-            }
298
-            if(is_string($xKey) && is_array($xValue))
299
-            {
300
-                // Register a package with options
301
-                $sClassName = $xKey;
302
-                $aPkgOptions = $xValue;
303
-                $this->registerPackage($sClassName, $aPkgOptions);
304
-            }
305
-        }
306
-    }
287
+// Register packages
288
+$aPackageConfig = $xAppConfig->getOption('packages', []);
289
+foreach($aPackageConfig as $xKey => $xValue)
290
+{
291
+if(is_integer($xKey) && is_string($xValue))
292
+{
293
+    // Register a package without options
294
+    $sClassName = $xValue;
295
+    $this->registerPackage($sClassName);
296
+    continue;
297
+}
298
+if(is_string($xKey) && is_array($xValue))
299
+{
300
+    // Register a package with options
301
+    $sClassName = $xKey;
302
+    $aPkgOptions = $xValue;
303
+    $this->registerPackage($sClassName, $aPkgOptions);
304
+}
305
+}
306
+}
307 307
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Manager/PluginManager.php 2 patches
Spacing   +9 added lines, -10 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
     private function _registerPlugin(string $sClassName, string $sPluginName, array $aInterfaces): int
101 101
     {
102 102
         // Any plugin must implement the PluginInterface interface.
103
-        if(!in_array(PluginInterface::class, $aInterfaces))
103
+        if (!in_array(PluginInterface::class, $aInterfaces))
104 104
         {
105 105
             $sMessage = $this->xTranslator->trans('errors.register.invalid', [
106 106
                 'name' => $sClassName,
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
         }
110 110
 
111 111
         // Response plugin.
112
-        if(in_array(ResponsePluginInterface::class, $aInterfaces))
112
+        if (in_array(ResponsePluginInterface::class, $aInterfaces))
113 113
         {
114 114
             $this->aResponsePlugins[$sPluginName] = $sClassName;
115 115
             return 1;
@@ -117,12 +117,12 @@  discard block
 block discarded – undo
117 117
 
118 118
         // Request plugin.
119 119
         $nCount = 0;
120
-        if(in_array(CallableRegistryInterface::class, $aInterfaces))
120
+        if (in_array(CallableRegistryInterface::class, $aInterfaces))
121 121
         {
122 122
             $this->aRegistryPlugins[$sPluginName] = $sClassName;
123 123
             $nCount++;
124 124
         }
125
-        if(in_array(RequestHandlerInterface::class, $aInterfaces))
125
+        if (in_array(RequestHandlerInterface::class, $aInterfaces))
126 126
         {
127 127
             $this->aRequestHandlers[$sPluginName] = $sClassName;
128 128
             $nCount++;
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
         $nCount = $this->_registerPlugin($sClassName, $sPluginName, $aInterfaces);
152 152
 
153 153
         // Any plugin can implement the CodeGeneratorInterface interface.
154
-        if(in_array(CodeGeneratorInterface::class, $aInterfaces))
154
+        if (in_array(CodeGeneratorInterface::class, $aInterfaces))
155 155
         {
156 156
             $this->xCodeGenerator->addCodeGenerator($sClassName, $nPriority);
157 157
             $nCount++;
158 158
         }
159 159
         // The class is not a valid plugin.
160
-        if($nCount === 0)
160
+        if ($nCount === 0)
161 161
         {
162 162
             $sMessage = $this->xTranslator->trans('errors.register.invalid', [
163 163
                 'name' => $sClassName,
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
         }
167 167
 
168 168
         // Register the plugin in the DI container, if necessary
169
-        if(!$this->di->has($sClassName))
169
+        if (!$this->di->has($sClassName))
170 170
         {
171 171
             $this->di->auto($sClassName);
172 172
         }
@@ -182,8 +182,7 @@  discard block
 block discarded – undo
182 182
      */
183 183
     public function getResponsePlugin(string $sName): ?ResponsePluginInterface
184 184
     {
185
-        return $this->di->h($sName) ? $this->di->g($sName) :
186
-            (!isset($this->aResponsePlugins[$sName]) ? null :
185
+        return $this->di->h($sName) ? $this->di->g($sName) : (!isset($this->aResponsePlugins[$sName]) ? null :
187 186
             $this->di->g($this->aResponsePlugins[$sName]));
188 187
     }
189 188
 
@@ -201,7 +200,7 @@  discard block
 block discarded – undo
201 200
      */
202 201
     public function registerCallable(string $sType, string $sCallable, $xOptions = []): void
203 202
     {
204
-        if(isset($this->aRegistryPlugins[$sType]) &&
203
+        if (isset($this->aRegistryPlugins[$sType]) &&
205 204
             ($xPlugin = $this->di->g($this->aRegistryPlugins[$sType])))
206 205
         {
207 206
             $xPlugin->register($sType, $sCallable, $xPlugin->checkOptions($sCallable, $xOptions));
Please login to merge, or discard this patch.
Switch Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -45,49 +45,49 @@  discard block
 block discarded – undo
45 45
 
46 46
 class PluginManager
47 47
 {
48
-    /**
48
+/**
49 49
      * Request plugins, indexed by name
50 50
      *
51 51
      * @var array<string>
52 52
      */
53
-    private $aRegistryPlugins = [];
53
+private $aRegistryPlugins = [];
54 54
 
55
-    /**
55
+/**
56 56
      * Request handlers, indexed by name
57 57
      *
58 58
      * @var array<string>
59 59
      */
60
-    private $aRequestHandlers = [];
60
+private $aRequestHandlers = [];
61 61
 
62
-    /**
62
+/**
63 63
      * Response plugins, indexed by name
64 64
      *
65 65
      * @var array<string>
66 66
      */
67
-    private $aResponsePlugins = [];
67
+private $aResponsePlugins = [];
68 68
 
69
-    /**
69
+/**
70 70
      * The constructor
71 71
      *
72 72
      * @param Container $di
73 73
      * @param CodeGenerator $xCodeGenerator
74 74
      * @param Translator $xTranslator
75 75
      */
76
-    public function __construct(private Container $di,
77
-        private CodeGenerator $xCodeGenerator, private Translator $xTranslator)
78
-    {}
76
+public function __construct(private Container $di,
77
+private CodeGenerator $xCodeGenerator, private Translator $xTranslator)
78
+{}
79 79
 
80
-    /**
80
+/**
81 81
      * Get the request plugins
82 82
      *
83 83
      * @return array<class-string>
84 84
      */
85
-    public function getRequestHandlers(): array
86
-    {
87
-        return $this->aRequestHandlers;
88
-    }
85
+public function getRequestHandlers(): array
86
+{
87
+return $this->aRequestHandlers;
88
+}
89 89
 
90
-    /**
90
+/**
91 91
      * Register a plugin
92 92
      *
93 93
      * @param class-string $sClassName    The plugin class
@@ -97,40 +97,40 @@  discard block
 block discarded – undo
97 97
      * @return int
98 98
      * @throws SetupException
99 99
      */
100
-    private function _registerPlugin(string $sClassName, string $sPluginName, array $aInterfaces): int
101
-    {
102
-        // Any plugin must implement the PluginInterface interface.
103
-        if(!in_array(PluginInterface::class, $aInterfaces))
104
-        {
105
-            $sMessage = $this->xTranslator->trans('errors.register.invalid', [
106
-                'name' => $sClassName,
107
-            ]);
108
-            throw new SetupException($sMessage);
109
-        }
110
-
111
-        // Response plugin.
112
-        if(in_array(ResponsePluginInterface::class, $aInterfaces))
113
-        {
114
-            $this->aResponsePlugins[$sPluginName] = $sClassName;
115
-            return 1;
116
-        }
117
-
118
-        // Request plugin.
119
-        $nCount = 0;
120
-        if(in_array(CallableRegistryInterface::class, $aInterfaces))
121
-        {
122
-            $this->aRegistryPlugins[$sPluginName] = $sClassName;
123
-            $nCount++;
124
-        }
125
-        if(in_array(RequestHandlerInterface::class, $aInterfaces))
126
-        {
127
-            $this->aRequestHandlers[$sPluginName] = $sClassName;
128
-            $nCount++;
129
-        }
130
-        return $nCount;
131
-    }
132
-
133
-    /**
100
+private function _registerPlugin(string $sClassName, string $sPluginName, array $aInterfaces): int
101
+{
102
+// Any plugin must implement the PluginInterface interface.
103
+if(!in_array(PluginInterface::class, $aInterfaces))
104
+{
105
+$sMessage = $this->xTranslator->trans('errors.register.invalid', [
106
+    'name' => $sClassName,
107
+]);
108
+throw new SetupException($sMessage);
109
+}
110
+
111
+// Response plugin.
112
+if(in_array(ResponsePluginInterface::class, $aInterfaces))
113
+{
114
+$this->aResponsePlugins[$sPluginName] = $sClassName;
115
+return 1;
116
+}
117
+
118
+// Request plugin.
119
+$nCount = 0;
120
+if(in_array(CallableRegistryInterface::class, $aInterfaces))
121
+{
122
+$this->aRegistryPlugins[$sPluginName] = $sClassName;
123
+$nCount++;
124
+}
125
+if(in_array(RequestHandlerInterface::class, $aInterfaces))
126
+{
127
+$this->aRequestHandlers[$sPluginName] = $sClassName;
128
+$nCount++;
129
+}
130
+return $nCount;
131
+}
132
+
133
+/**
134 134
      * Register a plugin
135 135
      *
136 136
      * Below is a table for priorities and their description:
@@ -145,34 +145,34 @@  discard block
 block discarded – undo
145 145
      * @return void
146 146
      * @throws SetupException
147 147
      */
148
-    public function registerPlugin(string $sClassName, string $sPluginName, int $nPriority = 1000): void
149
-    {
150
-        $aInterfaces = class_implements($sClassName);
151
-        $nCount = $this->_registerPlugin($sClassName, $sPluginName, $aInterfaces);
152
-
153
-        // Any plugin can implement the CodeGeneratorInterface interface.
154
-        if(in_array(CodeGeneratorInterface::class, $aInterfaces))
155
-        {
156
-            $this->xCodeGenerator->addCodeGenerator($sClassName, $nPriority);
157
-            $nCount++;
158
-        }
159
-        // The class is not a valid plugin.
160
-        if($nCount === 0)
161
-        {
162
-            $sMessage = $this->xTranslator->trans('errors.register.invalid', [
163
-                'name' => $sClassName,
164
-            ]);
165
-            throw new SetupException($sMessage);
166
-        }
167
-
168
-        // Register the plugin in the DI container, if necessary
169
-        if(!$this->di->has($sClassName))
170
-        {
171
-            $this->di->auto($sClassName);
172
-        }
173
-    }
174
-
175
-    /**
148
+public function registerPlugin(string $sClassName, string $sPluginName, int $nPriority = 1000): void
149
+{
150
+$aInterfaces = class_implements($sClassName);
151
+$nCount = $this->_registerPlugin($sClassName, $sPluginName, $aInterfaces);
152
+
153
+// Any plugin can implement the CodeGeneratorInterface interface.
154
+if(in_array(CodeGeneratorInterface::class, $aInterfaces))
155
+{
156
+$this->xCodeGenerator->addCodeGenerator($sClassName, $nPriority);
157
+$nCount++;
158
+}
159
+// The class is not a valid plugin.
160
+if($nCount === 0)
161
+{
162
+$sMessage = $this->xTranslator->trans('errors.register.invalid', [
163
+    'name' => $sClassName,
164
+]);
165
+throw new SetupException($sMessage);
166
+}
167
+
168
+// Register the plugin in the DI container, if necessary
169
+if(!$this->di->has($sClassName))
170
+{
171
+$this->di->auto($sClassName);
172
+}
173
+}
174
+
175
+/**
176 176
      * Find the specified response plugin by name or class name
177 177
      *
178 178
      * @template R of ResponsePluginInterface
@@ -180,14 +180,14 @@  discard block
 block discarded – undo
180 180
      *
181 181
      * @return ($sName is class-string ? R : ResponsePluginInterface)|null
182 182
      */
183
-    public function getResponsePlugin(string $sName): ?ResponsePluginInterface
184
-    {
185
-        return $this->di->h($sName) ? $this->di->g($sName) :
186
-            (!isset($this->aResponsePlugins[$sName]) ? null :
187
-            $this->di->g($this->aResponsePlugins[$sName]));
188
-    }
189
-
190
-    /**
183
+public function getResponsePlugin(string $sName): ?ResponsePluginInterface
184
+{
185
+return $this->di->h($sName) ? $this->di->g($sName) :
186
+(!isset($this->aResponsePlugins[$sName]) ? null :
187
+$this->di->g($this->aResponsePlugins[$sName]));
188
+}
189
+
190
+/**
191 191
      * Register a callable function or class
192 192
      *
193 193
      * Call the request plugin with the $sType defined as name.
@@ -199,46 +199,46 @@  discard block
 block discarded – undo
199 199
      * @return void
200 200
      * @throws SetupException
201 201
      */
202
-    public function registerCallable(string $sType, string $sCallable, $xOptions = []): void
203
-    {
204
-        if(isset($this->aRegistryPlugins[$sType]) &&
205
-            ($xPlugin = $this->di->g($this->aRegistryPlugins[$sType])))
206
-        {
207
-            $xPlugin->register($sType, $sCallable, $xPlugin->checkOptions($sCallable, $xOptions));
208
-            return;
209
-        }
210
-        throw new SetupException($this->xTranslator->trans('errors.register.plugin',
211
-            ['name' => $sType, 'callable' => $sCallable]));
212
-    }
213
-
214
-    /**
202
+public function registerCallable(string $sType, string $sCallable, $xOptions = []): void
203
+{
204
+if(isset($this->aRegistryPlugins[$sType]) &&
205
+($xPlugin = $this->di->g($this->aRegistryPlugins[$sType])))
206
+{
207
+$xPlugin->register($sType, $sCallable, $xPlugin->checkOptions($sCallable, $xOptions));
208
+return;
209
+}
210
+throw new SetupException($this->xTranslator->trans('errors.register.plugin',
211
+['name' => $sType, 'callable' => $sCallable]));
212
+}
213
+
214
+/**
215 215
      * Register the Jaxon request plugins
216 216
      *
217 217
      * @return void
218 218
      * @throws SetupException
219 219
      */
220
-    public function registerPlugins(): void
221
-    {
222
-        // Request plugins
223
-        $this->registerPlugin(CallableClassPlugin::class, Jaxon::CALLABLE_CLASS, 101);
224
-        $this->registerPlugin(CallableFunctionPlugin::class, Jaxon::CALLABLE_FUNCTION, 102);
225
-        $this->registerPlugin(CallableDirPlugin::class, Jaxon::CALLABLE_DIR, 103);
226
-
227
-        // Response plugins
228
-        $this->registerPlugin(ScriptPlugin::class, ScriptPlugin::NAME, 700);
229
-        $this->registerPlugin(DataBagPlugin::class, DataBagPlugin::NAME, 700);
230
-        $this->registerPlugin(DialogPlugin::class, DialogPlugin::NAME, 750);
231
-        $this->registerPlugin(PaginatorPlugin::class, PaginatorPlugin::NAME, 800);
232
-        $this->registerPlugin(PsrPlugin::class, PsrPlugin::NAME, 850);
233
-    }
234
-
235
-    /**
220
+public function registerPlugins(): void
221
+{
222
+// Request plugins
223
+$this->registerPlugin(CallableClassPlugin::class, Jaxon::CALLABLE_CLASS, 101);
224
+$this->registerPlugin(CallableFunctionPlugin::class, Jaxon::CALLABLE_FUNCTION, 102);
225
+$this->registerPlugin(CallableDirPlugin::class, Jaxon::CALLABLE_DIR, 103);
226
+
227
+// Response plugins
228
+$this->registerPlugin(ScriptPlugin::class, ScriptPlugin::NAME, 700);
229
+$this->registerPlugin(DataBagPlugin::class, DataBagPlugin::NAME, 700);
230
+$this->registerPlugin(DialogPlugin::class, DialogPlugin::NAME, 750);
231
+$this->registerPlugin(PaginatorPlugin::class, PaginatorPlugin::NAME, 800);
232
+$this->registerPlugin(PsrPlugin::class, PsrPlugin::NAME, 850);
233
+}
234
+
235
+/**
236 236
      * Get the parameter reader
237 237
      *
238 238
      * @return ParameterReader
239 239
      */
240
-    public function getParameterReader(): ParameterReader
241
-    {
242
-        return $this->di->g(ParameterReader::class);
243
-    }
240
+public function getParameterReader(): ParameterReader
241
+{
242
+return $this->di->g(ParameterReader::class);
243
+}
244 244
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Response/Psr/PsrPlugin.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@
 block discarded – undo
63 63
     public function ajaxResponse(): ResponseInterface
64 64
     {
65 65
         $xPsrResponse = $this->xPsr17Factory->createResponse(200);
66
-        if($this->xRequest->getMethod() === 'GET')
66
+        if ($this->xRequest->getMethod() === 'GET')
67 67
         {
68 68
             $xPsrResponse = $xPsrResponse
69 69
                 ->withHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT')
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Response/DataBag/DataBagPlugin.php 1 patch
Spacing   +4 added lines, -6 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
      */
35 35
     private function initDataBag(): void
36 36
     {
37
-        if($this->xDataBag !== null)
37
+        if ($this->xDataBag !== null)
38 38
         {
39 39
             return;
40 40
         }
@@ -44,8 +44,7 @@  discard block
 block discarded – undo
44 44
         $aBody = $xRequest->getParsedBody();
45 45
         $aParams = $xRequest->getQueryParams();
46 46
         $aData = is_array($aBody) ?
47
-            $this->readData($aBody['jxnbags'] ?? []) :
48
-            $this->readData($aParams['jxnbags'] ?? []);
47
+            $this->readData($aBody['jxnbags'] ?? []) : $this->readData($aParams['jxnbags'] ?? []);
49 48
         $this->xDataBag = new DataBag($this, $aData);
50 49
     }
51 50
 
@@ -67,8 +66,7 @@  discard block
 block discarded – undo
67 66
         // Todo: clean input data.
68 67
         // Todo: verify the checksums.
69 68
         return is_string($xData) ?
70
-            (json_decode($xData, true) ?: []) :
71
-            (is_array($xData) ? $xData : []);
69
+            (json_decode($xData, true) ?: []) : (is_array($xData) ? $xData : []);
72 70
     }
73 71
 
74 72
     /**
@@ -86,7 +84,7 @@  discard block
 block discarded – undo
86 84
     public function writeCommand(): void
87 85
     {
88 86
         $this->initDataBag();
89
-        if($this->xDataBag->touched())
87
+        if ($this->xDataBag->touched())
90 88
         {
91 89
             // Todo: calculate the checksums.
92 90
             $this->addCommand('databag.set', ['values' => $this->xDataBag]);
Please login to merge, or discard this patch.