Passed
Push — main ( 7f530d...7aae9b )
by Thierry
05:54
created
jaxon-attributes/src/AttributeReader.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -258,8 +258,7 @@
 block discarded – undo
258 258
             }
259 259
 
260 260
             return $this->xMetadata;
261
-        }
262
-        catch(Exception|Error $e)
261
+        } catch(Exception|Error $e)
263 262
         {
264 263
             throw new SetupException($e->getMessage());
265 264
         }
Please login to merge, or discard this patch.
jaxon-core/src/Di/Container.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -199,8 +199,7 @@
 block discarded – undo
199 199
         {
200 200
             return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ?
201 201
                 $this->xAppContainer->get($sClass) : $this->xLibContainer->offsetGet($sClass);
202
-        }
203
-        catch(Exception|Throwable $e)
202
+        } catch(Exception|Throwable $e)
204 203
         {
205 204
             $xLogger = $this->g(LoggerInterface::class);
206 205
             $xTranslator = $this->g(Translator::class);
Please login to merge, or discard this patch.
Switch Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -33,145 +33,145 @@  discard block
 block discarded – undo
33 33
 
34 34
 class Container
35 35
 {
36
-    use Traits\AppTrait;
37
-    use Traits\PsrTrait;
38
-    use Traits\RequestTrait;
39
-    use Traits\ResponseTrait;
40
-    use Traits\PluginTrait;
41
-    use Traits\CallableTrait;
42
-    use Traits\ViewTrait;
43
-    use Traits\UtilTrait;
44
-    use Traits\MetadataTrait;
45
-    use Traits\DiAutoTrait;
36
+use Traits\AppTrait;
37
+use Traits\PsrTrait;
38
+use Traits\RequestTrait;
39
+use Traits\ResponseTrait;
40
+use Traits\PluginTrait;
41
+use Traits\CallableTrait;
42
+use Traits\ViewTrait;
43
+use Traits\UtilTrait;
44
+use Traits\MetadataTrait;
45
+use Traits\DiAutoTrait;
46 46
 
47
-    /**
47
+/**
48 48
      * The library Dependency Injection Container
49 49
      *
50 50
      * @var PimpleContainer
51 51
      */
52
-    private $xLibContainer;
52
+private $xLibContainer;
53 53
 
54
-    /**
54
+/**
55 55
      * The application or framework Dependency Injection Container
56 56
      *
57 57
      * @var ContainerInterface
58 58
      */
59
-    private $xAppContainer = null;
59
+private $xAppContainer = null;
60 60
 
61
-    /**
61
+/**
62 62
      * The class constructor
63 63
      */
64
-    public function __construct()
65
-    {
66
-        $this->xLibContainer = new PimpleContainer();
64
+public function __construct()
65
+{
66
+$this->xLibContainer = new PimpleContainer();
67 67
 
68
-        $this->val(Container::class, $this);
68
+$this->val(Container::class, $this);
69 69
 
70
-        // Register the null logger by default
71
-        $this->setLogger(new NullLogger());
70
+// Register the null logger by default
71
+$this->setLogger(new NullLogger());
72 72
 
73
-        // Template directory
74
-        $sTemplateDir = realpath(__DIR__ . '/../../templates');
75
-        $this->val('jaxon.core.dir.template', $sTemplateDir);
73
+// Template directory
74
+$sTemplateDir = realpath(__DIR__ . '/../../templates');
75
+$this->val('jaxon.core.dir.template', $sTemplateDir);
76 76
 
77
-        // Translation directory
78
-        $sTranslationDir = realpath(__DIR__ . '/../../translations');
79
-        $this->val('jaxon.core.dir.translation', $sTranslationDir);
77
+// Translation directory
78
+$sTranslationDir = realpath(__DIR__ . '/../../translations');
79
+$this->val('jaxon.core.dir.translation', $sTranslationDir);
80 80
 
81
-        $this->registerAll();
82
-        $this->setEventHandlers();
83
-    }
81
+$this->registerAll();
82
+$this->setEventHandlers();
83
+}
84 84
 
85
-    /**
85
+/**
86 86
      * The container for parameters
87 87
      *
88 88
      * @return Container
89 89
      */
90
-    protected function cn(): Container
91
-    {
92
-        return $this;
93
-    }
90
+protected function cn(): Container
91
+{
92
+return $this;
93
+}
94 94
 
95
-    /**
95
+/**
96 96
      * Register the values into the container
97 97
      *
98 98
      * @return void
99 99
      */
100
-    private function registerAll()
101
-    {
102
-        $this->registerApp();
103
-        $this->registerPsr();
104
-        $this->registerRequests();
105
-        $this->registerResponses();
106
-        $this->registerPlugins();
107
-        $this->registerCallables();
108
-        $this->registerViews();
109
-        $this->registerUtils();
110
-        $this->registerMetadataReader();
111
-    }
100
+private function registerAll()
101
+{
102
+$this->registerApp();
103
+$this->registerPsr();
104
+$this->registerRequests();
105
+$this->registerResponses();
106
+$this->registerPlugins();
107
+$this->registerCallables();
108
+$this->registerViews();
109
+$this->registerUtils();
110
+$this->registerMetadataReader();
111
+}
112 112
 
113
-    /**
113
+/**
114 114
      * Set the logger
115 115
      *
116 116
      * @param LoggerInterface|Closure $xLogger
117 117
      *
118 118
      * @return void
119 119
      */
120
-    public function setLogger(LoggerInterface|Closure $xLogger)
121
-    {
122
-        is_a($xLogger, LoggerInterface::class) ?
123
-            $this->val(LoggerInterface::class, $xLogger) :
124
-            $this->set(LoggerInterface::class, $xLogger);
125
-    }
120
+public function setLogger(LoggerInterface|Closure $xLogger)
121
+{
122
+is_a($xLogger, LoggerInterface::class) ?
123
+$this->val(LoggerInterface::class, $xLogger) :
124
+$this->set(LoggerInterface::class, $xLogger);
125
+}
126 126
 
127
-    /**
127
+/**
128 128
      * Get the logger
129 129
      *
130 130
      * @return LoggerInterface
131 131
      */
132
-    public function getLogger(): LoggerInterface
133
-    {
134
-        return $this->get(LoggerInterface::class);
135
-    }
132
+public function getLogger(): LoggerInterface
133
+{
134
+return $this->get(LoggerInterface::class);
135
+}
136 136
 
137
-    /**
137
+/**
138 138
      * Set the container provided by the integrated framework
139 139
      *
140 140
      * @param ContainerInterface $xContainer    The container implementation
141 141
      *
142 142
      * @return void
143 143
      */
144
-    public function setContainer(ContainerInterface $xContainer)
145
-    {
146
-        $this->xAppContainer = $xContainer;
147
-    }
144
+public function setContainer(ContainerInterface $xContainer)
145
+{
146
+$this->xAppContainer = $xContainer;
147
+}
148 148
 
149
-    /**
149
+/**
150 150
      * Check if a class is defined in the container
151 151
      *
152 152
      * @param string $sClass    The full class name
153 153
      *
154 154
      * @return bool
155 155
      */
156
-    public function h(string $sClass): bool
157
-    {
158
-        return $this->xLibContainer->offsetExists($sClass);
159
-    }
156
+public function h(string $sClass): bool
157
+{
158
+return $this->xLibContainer->offsetExists($sClass);
159
+}
160 160
 
161
-    /**
161
+/**
162 162
      * Check if a class is defined in the container
163 163
      *
164 164
      * @param string $sClass    The full class name
165 165
      *
166 166
      * @return bool
167 167
      */
168
-    public function has(string $sClass): bool
169
-    {
170
-        return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ?
171
-            true : $this->xLibContainer->offsetExists($sClass);
172
-    }
168
+public function has(string $sClass): bool
169
+{
170
+return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ?
171
+true : $this->xLibContainer->offsetExists($sClass);
172
+}
173 173
 
174
-    /**
174
+/**
175 175
      * Get a class instance
176 176
      *
177 177
      * @template T
@@ -179,12 +179,12 @@  discard block
 block discarded – undo
179 179
      *
180 180
      * @return T
181 181
      */
182
-    public function g(string $sClass): mixed
183
-    {
184
-        return $this->xLibContainer->offsetGet($sClass);
185
-    }
182
+public function g(string $sClass): mixed
183
+{
184
+return $this->xLibContainer->offsetGet($sClass);
185
+}
186 186
 
187
-    /**
187
+/**
188 188
      * Get a class instance
189 189
      *
190 190
      * @template T
@@ -193,24 +193,24 @@  discard block
 block discarded – undo
193 193
      * @return T
194 194
      * @throws SetupException
195 195
      */
196
-    public function get(string $sClass): mixed
197
-    {
198
-        try
199
-        {
200
-            return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ?
201
-                $this->xAppContainer->get($sClass) : $this->xLibContainer->offsetGet($sClass);
202
-        }
203
-        catch(Exception|Throwable $e)
204
-        {
205
-            $xLogger = $this->g(LoggerInterface::class);
206
-            $xTranslator = $this->g(Translator::class);
207
-            $sMessage = $e->getMessage() . ': ' . $xTranslator->trans('errors.class.container', ['name' => $sClass]);
208
-            $xLogger->error($e->getMessage(), ['message' => $sMessage]);
209
-            throw new SetupException($sMessage);
210
-        }
211
-    }
196
+public function get(string $sClass): mixed
197
+{
198
+try
199
+{
200
+return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ?
201
+    $this->xAppContainer->get($sClass) : $this->xLibContainer->offsetGet($sClass);
202
+}
203
+catch(Exception|Throwable $e)
204
+{
205
+$xLogger = $this->g(LoggerInterface::class);
206
+$xTranslator = $this->g(Translator::class);
207
+$sMessage = $e->getMessage() . ': ' . $xTranslator->trans('errors.class.container', ['name' => $sClass]);
208
+$xLogger->error($e->getMessage(), ['message' => $sMessage]);
209
+throw new SetupException($sMessage);
210
+}
211
+}
212 212
 
213
-    /**
213
+/**
214 214
      * Save a closure in the container
215 215
      *
216 216
      * @param string|class-string $sClass    The full class name
@@ -219,15 +219,15 @@  discard block
 block discarded – undo
219 219
      *
220 220
      * @return void
221 221
      */
222
-    public function set(string $sClass, Closure $xClosure, bool $bIsSingleton = true)
223
-    {
224
-        // Wrap the user closure into a new closure, so it can take this container as a parameter.
225
-        $xClosure = fn() => $xClosure($this);
226
-        $this->xLibContainer->offsetSet($sClass, $bIsSingleton ?
227
-            $xClosure : $this->xLibContainer->factory($xClosure));
228
-    }
222
+public function set(string $sClass, Closure $xClosure, bool $bIsSingleton = true)
223
+{
224
+// Wrap the user closure into a new closure, so it can take this container as a parameter.
225
+$xClosure = fn() => $xClosure($this);
226
+$this->xLibContainer->offsetSet($sClass, $bIsSingleton ?
227
+$xClosure : $this->xLibContainer->factory($xClosure));
228
+}
229 229
 
230
-    /**
230
+/**
231 231
      * Save a value in the container
232 232
      *
233 233
      * @param string|class-string $sKey    The key
@@ -235,12 +235,12 @@  discard block
 block discarded – undo
235 235
      *
236 236
      * @return void
237 237
      */
238
-    public function val(string $sKey, $xValue)
239
-    {
240
-       $this->xLibContainer->offsetSet($sKey, $xValue);
241
-    }
238
+public function val(string $sKey, $xValue)
239
+{
240
+$this->xLibContainer->offsetSet($sKey, $xValue);
241
+}
242 242
 
243
-    /**
243
+/**
244 244
      * Set an alias in the container
245 245
      *
246 246
      * @param string|class-string $sAlias    The alias name
@@ -248,60 +248,60 @@  discard block
 block discarded – undo
248 248
      *
249 249
      * @return void
250 250
      */
251
-    public function alias(string $sAlias, string $sClass)
252
-    {
253
-        $this->set($sAlias, function($di) use ($sClass) {
254
-            return $di->get($sClass);
255
-        });
256
-    }
251
+public function alias(string $sAlias, string $sClass)
252
+{
253
+$this->set($sAlias, function($di) use ($sClass) {
254
+return $di->get($sClass);
255
+});
256
+}
257 257
 
258
-    /**
258
+/**
259 259
      * @param ReflectionClass $xClass
260 260
      * @param ReflectionParameter $xParameter
261 261
      *
262 262
      * @return mixed
263 263
      * @throws SetupException
264 264
      */
265
-    public function getParameter(ReflectionClass $xClass, ReflectionParameter $xParameter)
266
-    {
267
-        $xType = $xParameter->getType();
268
-        // Check the parameter class first.
269
-        if($xType instanceof ReflectionNamedType)
270
-        {
271
-            // Check the class + the name
272
-            if($this->has($xType->getName() . ' $' . $xParameter->getName()))
273
-            {
274
-                return $this->get($xType->getName() . ' $' . $xParameter->getName());
275
-            }
276
-            // Check the class only
277
-            if($this->has($xType->getName()))
278
-            {
279
-                return $this->get($xType->getName());
280
-            }
281
-        }
282
-        // Check the name only
283
-        return $this->get('$' . $xParameter->getName());
284
-    }
265
+public function getParameter(ReflectionClass $xClass, ReflectionParameter $xParameter)
266
+{
267
+$xType = $xParameter->getType();
268
+// Check the parameter class first.
269
+if($xType instanceof ReflectionNamedType)
270
+{
271
+// Check the class + the name
272
+if($this->has($xType->getName() . ' $' . $xParameter->getName()))
273
+{
274
+    return $this->get($xType->getName() . ' $' . $xParameter->getName());
275
+}
276
+// Check the class only
277
+if($this->has($xType->getName()))
278
+{
279
+    return $this->get($xType->getName());
280
+}
281
+}
282
+// Check the name only
283
+return $this->get('$' . $xParameter->getName());
284
+}
285 285
 
286
-    /**
286
+/**
287 287
      * Get the session manager
288 288
      *
289 289
      * @return SessionInterface|null
290 290
      */
291
-    public function getSessionManager(): ?SessionInterface
292
-    {
293
-        return $this->h(SessionInterface::class) ? $this->g(SessionInterface::class) : null;
294
-    }
291
+public function getSessionManager(): ?SessionInterface
292
+{
293
+return $this->h(SessionInterface::class) ? $this->g(SessionInterface::class) : null;
294
+}
295 295
 
296
-    /**
296
+/**
297 297
      * Set the session manager
298 298
      *
299 299
      * @param Closure $xClosure    A closure to create the session manager instance
300 300
      *
301 301
      * @return void
302 302
      */
303
-    public function setSessionManager(Closure $xClosure)
304
-    {
305
-        $this->set(SessionInterface::class, $xClosure);
306
-    }
303
+public function setSessionManager(Closure $xClosure)
304
+{
305
+$this->set(SessionInterface::class, $xClosure);
306
+}
307 307
 }
Please login to merge, or discard this patch.
jaxon-core/src/Response/Manager/ResponseManager.php 1 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/Plugin/Manager/PackageManager.php 1 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.
jaxon-core/src/Plugin/Request/CallableFunction/CallableFunctionPlugin.php 2 patches
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -92,8 +92,7 @@  discard block
 block discarded – undo
92 92
         if(is_string($xOptions))
93 93
         {
94 94
             $xOptions = ['include' => $xOptions];
95
-        }
96
-        elseif(!is_array($xOptions))
95
+        } elseif(!is_array($xOptions))
97 96
         {
98 97
             throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration'));
99 98
         }
@@ -236,8 +235,7 @@  discard block
 block discarded – undo
236 235
         {
237 236
             /** @var CallableFunction */
238 237
             $xFunction = $this->getCallable($sRequestedFunction);
239
-        }
240
-        catch(Exception $e)
238
+        } catch(Exception $e)
241 239
         {
242 240
             // Unable to find the requested function
243 241
             $this->throwException($e, $this->xTranslator->trans('errors.functions.invalid',
@@ -246,8 +244,7 @@  discard block
 block discarded – undo
246 244
         try
247 245
         {
248 246
             $xFunction->call($this->xTarget->args());
249
-        }
250
-        catch(Exception $e)
247
+        } catch(Exception $e)
251 248
         {
252 249
             // Unable to execute the requested function
253 250
             $this->throwException($e, $this->xTranslator->trans('errors.functions.call',
Please login to merge, or discard this patch.
Switch Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -42,21 +42,21 @@  discard block
 block discarded – undo
42 42
 
43 43
 class CallableFunctionPlugin extends AbstractRequestPlugin
44 44
 {
45
-    /**
45
+/**
46 46
      * The registered functions names
47 47
      *
48 48
      * @var array
49 49
      */
50
-    protected $aFunctions = [];
50
+protected $aFunctions = [];
51 51
 
52
-    /**
52
+/**
53 53
      * The registered functions options
54 54
      *
55 55
      * @var array
56 56
      */
57
-    protected $aOptions = [];
57
+protected $aOptions = [];
58 58
 
59
-    /**
59
+/**
60 60
      * The constructor
61 61
      *
62 62
      * @param string $sPrefix
@@ -66,41 +66,41 @@  discard block
 block discarded – undo
66 66
      * @param Translator $xTranslator
67 67
      * @param Validator $xValidator
68 68
      */
69
-    public function __construct(private string $sPrefix, private bool $bDebug,
70
-        private Container $di, private TemplateEngine $xTemplateEngine,
71
-        private Translator $xTranslator, private Validator $xValidator)
72
-    {}
69
+public function __construct(private string $sPrefix, private bool $bDebug,
70
+private Container $di, private TemplateEngine $xTemplateEngine,
71
+private Translator $xTranslator, private Validator $xValidator)
72
+{}
73 73
 
74
-    /**
74
+/**
75 75
      * @inheritDoc
76 76
      */
77
-    public function getName(): string
78
-    {
79
-        return Jaxon::CALLABLE_FUNCTION;
80
-    }
77
+public function getName(): string
78
+{
79
+return Jaxon::CALLABLE_FUNCTION;
80
+}
81 81
 
82
-    /**
82
+/**
83 83
      * @inheritDoc
84 84
      * @throws SetupException
85 85
      */
86
-    public function checkOptions(string $sCallable, $xOptions): array
87
-    {
88
-        if(!$this->xValidator->validateFunction(trim($sCallable)))
89
-        {
90
-            throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration'));
91
-        }
92
-        if(is_string($xOptions))
93
-        {
94
-            $xOptions = ['include' => $xOptions];
95
-        }
96
-        elseif(!is_array($xOptions))
97
-        {
98
-            throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration'));
99
-        }
100
-        return $xOptions;
101
-    }
86
+public function checkOptions(string $sCallable, $xOptions): array
87
+{
88
+if(!$this->xValidator->validateFunction(trim($sCallable)))
89
+{
90
+throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration'));
91
+}
92
+if(is_string($xOptions))
93
+{
94
+$xOptions = ['include' => $xOptions];
95
+}
96
+elseif(!is_array($xOptions))
97
+{
98
+throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration'));
99
+}
100
+return $xOptions;
101
+}
102 102
 
103
-    /**
103
+/**
104 104
      * Register a user defined function
105 105
      *
106 106
      * @param string $sType    The type of request handler being registered
@@ -109,149 +109,149 @@  discard block
 block discarded – undo
109 109
      *
110 110
      * @return bool
111 111
      */
112
-    public function register(string $sType, string $sCallable, array $aOptions): bool
113
-    {
114
-        $sPhpFunction = trim($sCallable);
115
-        $sFunction = $sPhpFunction;
116
-        // Check if an alias is defined
117
-        if(isset($aOptions['alias']))
118
-        {
119
-            $sFunction = (string)$aOptions['alias'];
120
-            unset($aOptions['alias']);
121
-        }
122
-        $this->aFunctions[$sFunction] = $sPhpFunction;
123
-        $this->aOptions[$sFunction] = $aOptions;
124
-        return true;
125
-    }
112
+public function register(string $sType, string $sCallable, array $aOptions): bool
113
+{
114
+$sPhpFunction = trim($sCallable);
115
+$sFunction = $sPhpFunction;
116
+// Check if an alias is defined
117
+if(isset($aOptions['alias']))
118
+{
119
+$sFunction = (string)$aOptions['alias'];
120
+unset($aOptions['alias']);
121
+}
122
+$this->aFunctions[$sFunction] = $sPhpFunction;
123
+$this->aOptions[$sFunction] = $aOptions;
124
+return true;
125
+}
126 126
 
127
-    /**
127
+/**
128 128
      * @inheritDoc
129 129
      */
130
-    public function getHash(): string
131
-    {
132
-        return md5(implode('', array_keys($this->aFunctions)));
133
-    }
130
+public function getHash(): string
131
+{
132
+return md5(implode('', array_keys($this->aFunctions)));
133
+}
134 134
 
135
-    /**
135
+/**
136 136
      * @inheritDoc
137 137
      */
138
-    public function getCallable(string $sCallable): CallableFunction|null
139
-    {
140
-        $sFunction = trim($sCallable);
141
-        if(!isset($this->aFunctions[$sFunction]))
142
-        {
143
-            return null;
144
-        }
145
-        $xCallable = new CallableFunction($this->di, $sFunction,
146
-            $this->sPrefix . $sFunction, $this->aFunctions[$sFunction]);
147
-        foreach($this->aOptions[$sFunction] as $sName => $sValue)
148
-        {
149
-            $xCallable->configure($sName, $sValue);
150
-        }
151
-        return $xCallable;
152
-    }
138
+public function getCallable(string $sCallable): CallableFunction|null
139
+{
140
+$sFunction = trim($sCallable);
141
+if(!isset($this->aFunctions[$sFunction]))
142
+{
143
+return null;
144
+}
145
+$xCallable = new CallableFunction($this->di, $sFunction,
146
+$this->sPrefix . $sFunction, $this->aFunctions[$sFunction]);
147
+foreach($this->aOptions[$sFunction] as $sName => $sValue)
148
+{
149
+$xCallable->configure($sName, $sValue);
150
+}
151
+return $xCallable;
152
+}
153 153
 
154
-    /**
154
+/**
155 155
      * Generate the javascript function stub that is sent to the browser on initial page load
156 156
      *
157 157
      * @param CallableFunction $xFunction
158 158
      *
159 159
      * @return string
160 160
      */
161
-    private function getCallableScript(CallableFunction $xFunction): string
162
-    {
163
-        return $this->xTemplateEngine->render('jaxon::callables/function.js', [
164
-            'sName' => $xFunction->getName(),
165
-            'sJsName' => $xFunction->getJsName(),
166
-            'aOptions' => $xFunction->getOptions(),
167
-        ]);
168
-    }
161
+private function getCallableScript(CallableFunction $xFunction): string
162
+{
163
+return $this->xTemplateEngine->render('jaxon::callables/function.js', [
164
+'sName' => $xFunction->getName(),
165
+'sJsName' => $xFunction->getJsName(),
166
+'aOptions' => $xFunction->getOptions(),
167
+]);
168
+}
169 169
 
170
-    /**
170
+/**
171 171
      * @inheritDoc
172 172
      */
173
-    public function getScript(): string
174
-    {
175
-        $code = '';
176
-        foreach(array_keys($this->aFunctions) as $sFunction)
177
-        {
178
-            $xFunction = $this->getCallable($sFunction);
179
-            $code .= $this->getCallableScript($xFunction);
180
-        }
181
-        return $code;
182
-    }
173
+public function getScript(): string
174
+{
175
+$code = '';
176
+foreach(array_keys($this->aFunctions) as $sFunction)
177
+{
178
+$xFunction = $this->getCallable($sFunction);
179
+$code .= $this->getCallableScript($xFunction);
180
+}
181
+return $code;
182
+}
183 183
 
184
-    /**
184
+/**
185 185
      * @inheritDoc
186 186
      */
187
-    public static function canProcessRequest(ServerRequestInterface $xRequest): bool
188
-    {
189
-        $aCall = $xRequest->getAttribute('jxncall');
190
-        // throw new \Exception(json_encode(['call' => $aCall]));
191
-        return $aCall !== null && ($aCall['type'] ?? '') === 'func' && isset($aCall['name']);
192
-    }
187
+public static function canProcessRequest(ServerRequestInterface $xRequest): bool
188
+{
189
+$aCall = $xRequest->getAttribute('jxncall');
190
+// throw new \Exception(json_encode(['call' => $aCall]));
191
+return $aCall !== null && ($aCall['type'] ?? '') === 'func' && isset($aCall['name']);
192
+}
193 193
 
194
-    /**
194
+/**
195 195
      * @inheritDoc
196 196
      */
197
-    public function setTarget(ServerRequestInterface $xRequest): Target
198
-    {
199
-        $aCall = $xRequest->getAttribute('jxncall');
200
-        $this->xTarget = Target::makeFunction(trim($aCall['name']));
201
-        return $this->xTarget;
202
-    }
197
+public function setTarget(ServerRequestInterface $xRequest): Target
198
+{
199
+$aCall = $xRequest->getAttribute('jxncall');
200
+$this->xTarget = Target::makeFunction(trim($aCall['name']));
201
+return $this->xTarget;
202
+}
203 203
 
204
-    /**
204
+/**
205 205
      * @param Exception $xException
206 206
      * @param string $sErrorMessage
207 207
      *
208 208
      * @throws RequestException
209 209
      * @return void
210 210
      */
211
-    private function throwException(Exception $xException, string $sErrorMessage): void
212
-    {
213
-        $this->di->getLogger()->error($xException->getMessage());
214
-        throw new RequestException($sErrorMessage . (!$this->bDebug ? '' :
215
-            "\n" . $xException->getMessage()));
216
-    }
211
+private function throwException(Exception $xException, string $sErrorMessage): void
212
+{
213
+$this->di->getLogger()->error($xException->getMessage());
214
+throw new RequestException($sErrorMessage . (!$this->bDebug ? '' :
215
+"\n" . $xException->getMessage()));
216
+}
217 217
 
218
-    /**
218
+/**
219 219
      * @inheritDoc
220 220
      * @throws RequestException
221 221
      */
222
-    public function processRequest(): void
223
-    {
224
-        $sRequestedFunction = $this->xTarget->getFunctionName();
222
+public function processRequest(): void
223
+{
224
+$sRequestedFunction = $this->xTarget->getFunctionName();
225 225
 
226
-        // Security check: make sure the requested function was registered.
227
-        if(!$this->xValidator->validateFunction($sRequestedFunction) ||
228
-            !isset($this->aFunctions[$sRequestedFunction]))
229
-        {
230
-            // Unable to find the requested function
231
-            throw new RequestException($this->xTranslator->trans('errors.functions.invalid',
232
-                ['name' => $sRequestedFunction]));
233
-        }
226
+// Security check: make sure the requested function was registered.
227
+if(!$this->xValidator->validateFunction($sRequestedFunction) ||
228
+!isset($this->aFunctions[$sRequestedFunction]))
229
+{
230
+// Unable to find the requested function
231
+throw new RequestException($this->xTranslator->trans('errors.functions.invalid',
232
+    ['name' => $sRequestedFunction]));
233
+}
234 234
 
235
-        try
236
-        {
237
-            /** @var CallableFunction */
238
-            $xFunction = $this->getCallable($sRequestedFunction);
239
-        }
240
-        catch(Exception $e)
241
-        {
242
-            // Unable to find the requested function
243
-            $this->throwException($e, $this->xTranslator->trans('errors.functions.invalid',
244
-                ['name' => $sRequestedFunction]));
245
-        }
246
-        try
247
-        {
248
-            $xFunction->call($this->xTarget->args());
249
-        }
250
-        catch(Exception $e)
251
-        {
252
-            // Unable to execute the requested function
253
-            $this->throwException($e, $this->xTranslator->trans('errors.functions.call',
254
-                ['name' => $sRequestedFunction]));
255
-        }
256
-    }
235
+try
236
+{
237
+/** @var CallableFunction */
238
+$xFunction = $this->getCallable($sRequestedFunction);
239
+}
240
+catch(Exception $e)
241
+{
242
+// Unable to find the requested function
243
+$this->throwException($e, $this->xTranslator->trans('errors.functions.invalid',
244
+    ['name' => $sRequestedFunction]));
245
+}
246
+try
247
+{
248
+$xFunction->call($this->xTarget->args());
249
+}
250
+catch(Exception $e)
251
+{
252
+// Unable to execute the requested function
253
+$this->throwException($e, $this->xTranslator->trans('errors.functions.call',
254
+    ['name' => $sRequestedFunction]));
255
+}
256
+}
257 257
 }
Please login to merge, or discard this patch.
jaxon-core/src/App/Config/ConfigManager.php 2 patches
Braces   +8 added lines, -16 removed lines patch added patch discarded remove patch
@@ -69,23 +69,19 @@  discard block
 block discarded – undo
69 69
         try
70 70
         {
71 71
             return $this->xConfigReader->read($sConfigFile);
72
-        }
73
-        catch(YamlExtension $e)
72
+        } catch(YamlExtension $e)
74 73
         {
75 74
             $sMessage = $this->xTranslator->trans('errors.yaml.install');
76 75
             throw new SetupException($sMessage);
77
-        }
78
-        catch(FileExtension $e)
76
+        } catch(FileExtension $e)
79 77
         {
80 78
             $sMessage = $this->xTranslator->trans('errors.file.extension', ['path' => $sConfigFile]);
81 79
             throw new SetupException($sMessage);
82
-        }
83
-        catch(FileAccess $e)
80
+        } catch(FileAccess $e)
84 81
         {
85 82
             $sMessage = $this->xTranslator->trans('errors.file.access', ['path' => $sConfigFile]);
86 83
             throw new SetupException($sMessage);
87
-        }
88
-        catch(FileContent $e)
84
+        } catch(FileContent $e)
89 85
         {
90 86
             $sMessage = $this->xTranslator->trans('errors.file.content', ['path' => $sConfigFile]);
91 87
             throw new SetupException($sMessage);
@@ -110,8 +106,7 @@  discard block
 block discarded – undo
110 106
                 ->setOptions($this->xLibConfig, $this->read($sConfigFile), $sConfigSection);
111 107
             // Call the config change listeners.
112 108
             $this->xEventManager->libConfigChanged($this->xLibConfig, '');
113
-        }
114
-        catch(DataDepth $e)
109
+        } catch(DataDepth $e)
115 110
         {
116 111
             $sMessage = $this->xTranslator->trans('errors.data.depth', [
117 112
                 'key' => $e->sPrefix,
@@ -139,8 +134,7 @@  discard block
 block discarded – undo
139 134
             // Call the config change listeners.
140 135
             $this->xEventManager->libConfigChanged($this->xLibConfig, '');
141 136
             return $this->xLibConfig->changed();
142
-        }
143
-        catch(DataDepth $e)
137
+        } catch(DataDepth $e)
144 138
         {
145 139
             $sMessage = $this->xTranslator->trans('errors.data.depth', [
146 140
                 'key' => $e->sPrefix,
@@ -246,8 +240,7 @@  discard block
 block discarded – undo
246 240
             // Call the config change listeners.
247 241
             $this->xEventManager->appConfigChanged($this->xAppConfig, '');
248 242
             return $this->xAppConfig->changed();
249
-        }
250
-        catch(DataDepth $e)
243
+        } catch(DataDepth $e)
251 244
         {
252 245
             $sMessage = $this->xTranslator->trans('errors.data.depth', [
253 246
                 'key' => $e->sPrefix,
@@ -296,8 +289,7 @@  discard block
 block discarded – undo
296 289
         try
297 290
         {
298 291
             return $this->xConfigSetter->newConfig($aOptions, $sNamePrefix);
299
-        }
300
-        catch(DataDepth $e)
292
+        } catch(DataDepth $e)
301 293
         {
302 294
             $sMessage = $this->xTranslator->trans('errors.data.depth', [
303 295
                 'key' => $e->sPrefix,
Please login to merge, or discard this patch.
Switch Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -29,17 +29,17 @@  discard block
 block discarded – undo
29 29
 
30 30
 class ConfigManager
31 31
 {
32
-    /**
32
+/**
33 33
      * @var Config
34 34
      */
35
-    protected $xLibConfig;
35
+protected $xLibConfig;
36 36
 
37
-    /**
37
+/**
38 38
      * @var Config
39 39
      */
40
-    protected $xAppConfig;
40
+protected $xAppConfig;
41 41
 
42
-    /**
42
+/**
43 43
      * The constructor
44 44
      *
45 45
      * @param array $aDefaultOptions
@@ -48,15 +48,15 @@  discard block
 block discarded – undo
48 48
      * @param ConfigSetter $xConfigSetter
49 49
      * @param ConfigEventManager $xEventManager
50 50
      */
51
-    public function __construct(array $aDefaultOptions, private Translator $xTranslator,
52
-        private ConfigReader $xConfigReader, private ConfigSetter $xConfigSetter,
53
-        private ConfigEventManager $xEventManager)
54
-    {
55
-        $this->xLibConfig = $xConfigSetter->newConfig($aDefaultOptions);
56
-        $this->xAppConfig = $xConfigSetter->newConfig();
57
-    }
51
+public function __construct(array $aDefaultOptions, private Translator $xTranslator,
52
+private ConfigReader $xConfigReader, private ConfigSetter $xConfigSetter,
53
+private ConfigEventManager $xEventManager)
54
+{
55
+$this->xLibConfig = $xConfigSetter->newConfig($aDefaultOptions);
56
+$this->xAppConfig = $xConfigSetter->newConfig();
57
+}
58 58
 
59
-    /**
59
+/**
60 60
      * Read a config file
61 61
      *
62 62
      * @param string $sConfigFile
@@ -64,35 +64,35 @@  discard block
 block discarded – undo
64 64
      * @return array
65 65
      * @throws SetupException
66 66
      */
67
-    public function read(string $sConfigFile): array
68
-    {
69
-        try
70
-        {
71
-            return $this->xConfigReader->read($sConfigFile);
72
-        }
73
-        catch(YamlExtension $e)
74
-        {
75
-            $sMessage = $this->xTranslator->trans('errors.yaml.install');
76
-            throw new SetupException($sMessage);
77
-        }
78
-        catch(FileExtension $e)
79
-        {
80
-            $sMessage = $this->xTranslator->trans('errors.file.extension', ['path' => $sConfigFile]);
81
-            throw new SetupException($sMessage);
82
-        }
83
-        catch(FileAccess $e)
84
-        {
85
-            $sMessage = $this->xTranslator->trans('errors.file.access', ['path' => $sConfigFile]);
86
-            throw new SetupException($sMessage);
87
-        }
88
-        catch(FileContent $e)
89
-        {
90
-            $sMessage = $this->xTranslator->trans('errors.file.content', ['path' => $sConfigFile]);
91
-            throw new SetupException($sMessage);
92
-        }
93
-    }
67
+public function read(string $sConfigFile): array
68
+{
69
+try
70
+{
71
+return $this->xConfigReader->read($sConfigFile);
72
+}
73
+catch(YamlExtension $e)
74
+{
75
+$sMessage = $this->xTranslator->trans('errors.yaml.install');
76
+throw new SetupException($sMessage);
77
+}
78
+catch(FileExtension $e)
79
+{
80
+$sMessage = $this->xTranslator->trans('errors.file.extension', ['path' => $sConfigFile]);
81
+throw new SetupException($sMessage);
82
+}
83
+catch(FileAccess $e)
84
+{
85
+$sMessage = $this->xTranslator->trans('errors.file.access', ['path' => $sConfigFile]);
86
+throw new SetupException($sMessage);
87
+}
88
+catch(FileContent $e)
89
+{
90
+$sMessage = $this->xTranslator->trans('errors.file.content', ['path' => $sConfigFile]);
91
+throw new SetupException($sMessage);
92
+}
93
+}
94 94
 
95
-    /**
95
+/**
96 96
      * Read options from a config file and set the library config
97 97
      *
98 98
      * @param string $sConfigFile The full path to the config file
@@ -101,27 +101,27 @@  discard block
 block discarded – undo
101 101
      * @return void
102 102
      * @throws SetupException
103 103
      */
104
-    public function load(string $sConfigFile, string $sConfigSection = ''): void
105
-    {
106
-        try
107
-        {
108
-            // Read the options and save in the config.
109
-            $this->xLibConfig = $this->xConfigSetter
110
-                ->setOptions($this->xLibConfig, $this->read($sConfigFile), $sConfigSection);
111
-            // Call the config change listeners.
112
-            $this->xEventManager->libConfigChanged($this->xLibConfig, '');
113
-        }
114
-        catch(DataDepth $e)
115
-        {
116
-            $sMessage = $this->xTranslator->trans('errors.data.depth', [
117
-                'key' => $e->sPrefix,
118
-                'depth' => $e->nDepth,
119
-            ]);
120
-            throw new SetupException($sMessage);
121
-        }
122
-    }
104
+public function load(string $sConfigFile, string $sConfigSection = ''): void
105
+{
106
+try
107
+{
108
+// Read the options and save in the config.
109
+$this->xLibConfig = $this->xConfigSetter
110
+    ->setOptions($this->xLibConfig, $this->read($sConfigFile), $sConfigSection);
111
+// Call the config change listeners.
112
+$this->xEventManager->libConfigChanged($this->xLibConfig, '');
113
+}
114
+catch(DataDepth $e)
115
+{
116
+$sMessage = $this->xTranslator->trans('errors.data.depth', [
117
+    'key' => $e->sPrefix,
118
+    'depth' => $e->nDepth,
119
+]);
120
+throw new SetupException($sMessage);
121
+}
122
+}
123 123
 
124
-    /**
124
+/**
125 125
      * Set the config options of the library
126 126
      *
127 127
      * @param array $aOptions
@@ -130,27 +130,27 @@  discard block
 block discarded – undo
130 130
      * @return bool
131 131
      * @throws SetupException
132 132
      */
133
-    public function setOptions(array $aOptions, string $sNamePrefix = ''): bool
134
-    {
135
-        try
136
-        {
137
-            $this->xLibConfig = $this->xConfigSetter
138
-                ->setOptions($this->xLibConfig, $aOptions, $sNamePrefix);
139
-            // Call the config change listeners.
140
-            $this->xEventManager->libConfigChanged($this->xLibConfig, '');
141
-            return $this->xLibConfig->changed();
142
-        }
143
-        catch(DataDepth $e)
144
-        {
145
-            $sMessage = $this->xTranslator->trans('errors.data.depth', [
146
-                'key' => $e->sPrefix,
147
-                'depth' => $e->nDepth,
148
-            ]);
149
-            throw new SetupException($sMessage);
150
-        }
151
-    }
133
+public function setOptions(array $aOptions, string $sNamePrefix = ''): bool
134
+{
135
+try
136
+{
137
+$this->xLibConfig = $this->xConfigSetter
138
+    ->setOptions($this->xLibConfig, $aOptions, $sNamePrefix);
139
+// Call the config change listeners.
140
+$this->xEventManager->libConfigChanged($this->xLibConfig, '');
141
+return $this->xLibConfig->changed();
142
+}
143
+catch(DataDepth $e)
144
+{
145
+$sMessage = $this->xTranslator->trans('errors.data.depth', [
146
+    'key' => $e->sPrefix,
147
+    'depth' => $e->nDepth,
148
+]);
149
+throw new SetupException($sMessage);
150
+}
151
+}
152 152
 
153
-    /**
153
+/**
154 154
      * Set the value of a config option
155 155
      *
156 156
      * @param string $sName The option name
@@ -158,15 +158,15 @@  discard block
 block discarded – undo
158 158
      *
159 159
      * @return void
160 160
      */
161
-    public function setOption(string $sName, $xValue): void
162
-    {
163
-        $this->xLibConfig = $this->xConfigSetter
164
-            ->setOption($this->xLibConfig, $sName, $xValue);
165
-        // Call the config change listeners.
166
-        $this->xEventManager->libConfigChanged($this->xLibConfig, $sName);
167
-    }
161
+public function setOption(string $sName, $xValue): void
162
+{
163
+$this->xLibConfig = $this->xConfigSetter
164
+->setOption($this->xLibConfig, $sName, $xValue);
165
+// Call the config change listeners.
166
+$this->xEventManager->libConfigChanged($this->xLibConfig, $sName);
167
+}
168 168
 
169
-    /**
169
+/**
170 170
      * Get the value of a config option
171 171
      *
172 172
      * @param string $sName The option name
@@ -174,36 +174,36 @@  discard block
 block discarded – undo
174 174
      *
175 175
      * @return mixed
176 176
      */
177
-    public function getOption(string $sName, $xDefault = null): mixed
178
-    {
179
-        return $this->xLibConfig->getOption($sName, $xDefault);
180
-    }
177
+public function getOption(string $sName, $xDefault = null): mixed
178
+{
179
+return $this->xLibConfig->getOption($sName, $xDefault);
180
+}
181 181
 
182
-    /**
182
+/**
183 183
      * Check the presence of a config option
184 184
      *
185 185
      * @param string $sName The option name
186 186
      *
187 187
      * @return bool
188 188
      */
189
-    public function hasOption(string $sName): bool
190
-    {
191
-        return $this->xLibConfig->hasOption($sName);
192
-    }
189
+public function hasOption(string $sName): bool
190
+{
191
+return $this->xLibConfig->hasOption($sName);
192
+}
193 193
 
194
-    /**
194
+/**
195 195
      * Get the names of the options matching a given prefix
196 196
      *
197 197
      * @param string $sPrefix The prefix to match
198 198
      *
199 199
      * @return array
200 200
      */
201
-    public function getOptionNames(string $sPrefix): array
202
-    {
203
-        return $this->xLibConfig->getOptionNames($sPrefix);
204
-    }
201
+public function getOptionNames(string $sPrefix): array
202
+{
203
+return $this->xLibConfig->getOptionNames($sPrefix);
204
+}
205 205
 
206
-    /**
206
+/**
207 207
      * Set the value of a config option
208 208
      *
209 209
      * @param string $sName The option name
@@ -211,25 +211,25 @@  discard block
 block discarded – undo
211 211
      *
212 212
      * @return void
213 213
      */
214
-    public function setAppOption(string $sName, $xValue): void
215
-    {
216
-        $this->xAppConfig = $this->xConfigSetter
217
-            ->setOption($this->xAppConfig, $sName, $xValue);
218
-        // Call the config change listeners.
219
-        $this->xEventManager->appConfigChanged($this->xAppConfig, $sName);
220
-    }
214
+public function setAppOption(string $sName, $xValue): void
215
+{
216
+$this->xAppConfig = $this->xConfigSetter
217
+->setOption($this->xAppConfig, $sName, $xValue);
218
+// Call the config change listeners.
219
+$this->xEventManager->appConfigChanged($this->xAppConfig, $sName);
220
+}
221 221
 
222
-    /**
222
+/**
223 223
      * Get the application config
224 224
      *
225 225
      * @return Config
226 226
      */
227
-    public function getAppConfig(): Config
228
-    {
229
-        return $this->xAppConfig;
230
-    }
227
+public function getAppConfig(): Config
228
+{
229
+return $this->xAppConfig;
230
+}
231 231
 
232
-    /**
232
+/**
233 233
      * Set the application config options
234 234
      *
235 235
      * @param array $aAppOptions
@@ -237,27 +237,27 @@  discard block
 block discarded – undo
237 237
      *
238 238
      * @return bool
239 239
      */
240
-    public function setAppOptions(array $aAppOptions, string $sNamePrefix = ''): bool
241
-    {
242
-        try
243
-        {
244
-            $this->xAppConfig = $this->xConfigSetter
245
-                ->setOptions($this->xAppConfig, $aAppOptions, $sNamePrefix);
246
-            // Call the config change listeners.
247
-            $this->xEventManager->appConfigChanged($this->xAppConfig, '');
248
-            return $this->xAppConfig->changed();
249
-        }
250
-        catch(DataDepth $e)
251
-        {
252
-            $sMessage = $this->xTranslator->trans('errors.data.depth', [
253
-                'key' => $e->sPrefix,
254
-                'depth' => $e->nDepth,
255
-            ]);
256
-            throw new SetupException($sMessage);
257
-        }
258
-    }
240
+public function setAppOptions(array $aAppOptions, string $sNamePrefix = ''): bool
241
+{
242
+try
243
+{
244
+$this->xAppConfig = $this->xConfigSetter
245
+    ->setOptions($this->xAppConfig, $aAppOptions, $sNamePrefix);
246
+// Call the config change listeners.
247
+$this->xEventManager->appConfigChanged($this->xAppConfig, '');
248
+return $this->xAppConfig->changed();
249
+}
250
+catch(DataDepth $e)
251
+{
252
+$sMessage = $this->xTranslator->trans('errors.data.depth', [
253
+    'key' => $e->sPrefix,
254
+    'depth' => $e->nDepth,
255
+]);
256
+throw new SetupException($sMessage);
257
+}
258
+}
259 259
 
260
-    /**
260
+/**
261 261
      * Get the value of an application config option
262 262
      *
263 263
      * @param string $sName The option name
@@ -265,24 +265,24 @@  discard block
 block discarded – undo
265 265
      *
266 266
      * @return mixed
267 267
      */
268
-    public function getAppOption(string $sName, $xDefault = null): mixed
269
-    {
270
-        return $this->xAppConfig->getOption($sName, $xDefault);
271
-    }
268
+public function getAppOption(string $sName, $xDefault = null): mixed
269
+{
270
+return $this->xAppConfig->getOption($sName, $xDefault);
271
+}
272 272
 
273
-    /**
273
+/**
274 274
      * Check the presence of an application config option
275 275
      *
276 276
      * @param string $sName The option name
277 277
      *
278 278
      * @return bool
279 279
      */
280
-    public function hasAppOption(string $sName): bool
281
-    {
282
-        return $this->xAppConfig->hasOption($sName);
283
-    }
280
+public function hasAppOption(string $sName): bool
281
+{
282
+return $this->xAppConfig->hasOption($sName);
283
+}
284 284
 
285
-    /**
285
+/**
286 286
      * Create a new the config object
287 287
      *
288 288
      * @param array $aOptions     The options array
@@ -291,54 +291,54 @@  discard block
 block discarded – undo
291 291
      * @return Config
292 292
      * @throws SetupException
293 293
      */
294
-    public function newConfig(array $aOptions = [], string $sNamePrefix = ''): Config
295
-    {
296
-        try
297
-        {
298
-            return $this->xConfigSetter->newConfig($aOptions, $sNamePrefix);
299
-        }
300
-        catch(DataDepth $e)
301
-        {
302
-            $sMessage = $this->xTranslator->trans('errors.data.depth', [
303
-                'key' => $e->sPrefix,
304
-                'depth' => $e->nDepth,
305
-            ]);
306
-            throw new SetupException($sMessage);
307
-        }
308
-    }
294
+public function newConfig(array $aOptions = [], string $sNamePrefix = ''): Config
295
+{
296
+try
297
+{
298
+return $this->xConfigSetter->newConfig($aOptions, $sNamePrefix);
299
+}
300
+catch(DataDepth $e)
301
+{
302
+$sMessage = $this->xTranslator->trans('errors.data.depth', [
303
+    'key' => $e->sPrefix,
304
+    'depth' => $e->nDepth,
305
+]);
306
+throw new SetupException($sMessage);
307
+}
308
+}
309 309
 
310
-    /**
310
+/**
311 311
      * @param string $sClassName
312 312
      *
313 313
      * @return void
314 314
      */
315
-    public function addLibEventListener(string $sClassName): void
316
-    {
317
-        $this->xEventManager->addLibConfigListener($sClassName);
318
-    }
315
+public function addLibEventListener(string $sClassName): void
316
+{
317
+$this->xEventManager->addLibConfigListener($sClassName);
318
+}
319 319
 
320
-    /**
320
+/**
321 321
      * @param string $sClassName
322 322
      *
323 323
      * @return void
324 324
      */
325
-    public function addAppEventListener(string $sClassName): void
326
-    {
327
-        $this->xEventManager->addAppConfigListener($sClassName);
328
-    }
325
+public function addAppEventListener(string $sClassName): void
326
+{
327
+$this->xEventManager->addAppConfigListener($sClassName);
328
+}
329 329
 
330
-    /**
330
+/**
331 331
      * Make the helpers functions available in the global namespace.
332 332
      *
333 333
      * @param bool $bForce
334 334
      *
335 335
      * @return void
336 336
      */
337
-    public function globals(bool $bForce = false): void
338
-    {
339
-        if($bForce || $this->getAppOption('helpers.global', true))
340
-        {
341
-            require_once dirname(__DIR__, 2) . '/globals.php';
342
-        }
343
-    }
337
+public function globals(bool $bForce = false): void
338
+{
339
+if($bForce || $this->getAppOption('helpers.global', true))
340
+{
341
+require_once dirname(__DIR__, 2) . '/globals.php';
342
+}
343
+}
344 344
 }
Please login to merge, or discard this patch.
jaxon-core/src/App/View/Store.php 1 patch
Switch Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -9,35 +9,35 @@  discard block
 block discarded – undo
9 9
 
10 10
 class Store implements JsonSerializable, Stringable
11 11
 {
12
-    /**
12
+/**
13 13
      * The view renderer
14 14
      *
15 15
      * @var ViewInterface
16 16
      */
17
-    protected $xRenderer;
17
+protected $xRenderer;
18 18
 
19
-    /**
19
+/**
20 20
      * The view namespace
21 21
      *
22 22
      * @var string
23 23
      */
24
-    protected $sNamespace;
24
+protected $sNamespace;
25 25
 
26
-    /**
26
+/**
27 27
      * The view name
28 28
      *
29 29
      * @var string
30 30
      */
31
-    protected $sViewName;
31
+protected $sViewName;
32 32
 
33
-    /**
33
+/**
34 34
      * The view data
35 35
      *
36 36
      * @var array
37 37
      */
38
-    protected $aViewData = [];
38
+protected $aViewData = [];
39 39
 
40
-    /**
40
+/**
41 41
      * Make a piece of data available for the rendered view
42 42
      *
43 43
      * @param string $sName    The data name
@@ -45,26 +45,26 @@  discard block
 block discarded – undo
45 45
      *
46 46
      * @return Store
47 47
      */
48
-    public function with(string $sName, $xValue): Store
49
-    {
50
-        $this->aViewData[$sName] = $xValue;
51
-        return $this;
52
-    }
48
+public function with(string $sName, $xValue): Store
49
+{
50
+$this->aViewData[$sName] = $xValue;
51
+return $this;
52
+}
53 53
 
54
-    /**
54
+/**
55 55
      * Set the data to be rendered
56 56
      *
57 57
      * @param array $aViewData    The view data
58 58
      *
59 59
      * @return Store
60 60
      */
61
-    public function setData(array $aViewData): Store
62
-    {
63
-        $this->aViewData = array_merge($this->aViewData, $aViewData);
64
-        return $this;
65
-    }
61
+public function setData(array $aViewData): Store
62
+{
63
+$this->aViewData = array_merge($this->aViewData, $aViewData);
64
+return $this;
65
+}
66 66
 
67
-    /**
67
+/**
68 68
      * Set the view to be rendered, with optional data
69 69
      *
70 70
      * @param ViewInterface $xRenderer    The view renderer
@@ -74,65 +74,65 @@  discard block
 block discarded – undo
74 74
      *
75 75
      * @return Store
76 76
      */
77
-    public function setView(ViewInterface $xRenderer,
78
-        string $sNamespace, string $sViewName, array $aViewData = []): Store
79
-    {
80
-        $this->xRenderer = $xRenderer;
81
-        $this->sNamespace = trim($sNamespace);
82
-        $this->sViewName = trim($sViewName);
83
-        $this->aViewData = array_merge($this->aViewData, $aViewData);
84
-        return $this;
85
-    }
77
+public function setView(ViewInterface $xRenderer,
78
+string $sNamespace, string $sViewName, array $aViewData = []): Store
79
+{
80
+$this->xRenderer = $xRenderer;
81
+$this->sNamespace = trim($sNamespace);
82
+$this->sViewName = trim($sViewName);
83
+$this->aViewData = array_merge($this->aViewData, $aViewData);
84
+return $this;
85
+}
86 86
 
87
-    /**
87
+/**
88 88
      * Get the view namespace
89 89
      *
90 90
      * @return string        The view namespace
91 91
      */
92
-    public function getNamespace(): string
93
-    {
94
-        return $this->sNamespace;
95
-    }
92
+public function getNamespace(): string
93
+{
94
+return $this->sNamespace;
95
+}
96 96
 
97
-    /**
97
+/**
98 98
      * Get the view name
99 99
      *
100 100
      * @return string        The view name
101 101
      */
102
-    public function getViewName(): string
103
-    {
104
-        return $this->sViewName;
105
-    }
102
+public function getViewName(): string
103
+{
104
+return $this->sViewName;
105
+}
106 106
 
107
-    /**
107
+/**
108 108
      * Get the view data
109 109
      *
110 110
      * @return array         The view data
111 111
      */
112
-    public function getViewData(): array
113
-    {
114
-        return $this->aViewData;
115
-    }
112
+public function getViewData(): array
113
+{
114
+return $this->aViewData;
115
+}
116 116
 
117
-    /**
117
+/**
118 118
      * Render a view using third party view system
119 119
      *
120 120
      * @return string        The string representation of the view
121 121
      */
122
-    public function __toString(): string
123
-    {
124
-        return !$this->xRenderer ? '' : $this->xRenderer->render($this);
125
-    }
122
+public function __toString(): string
123
+{
124
+return !$this->xRenderer ? '' : $this->xRenderer->render($this);
125
+}
126 126
 
127
-    /**
127
+/**
128 128
      * Convert this object to string for json.
129 129
      *
130 130
      * This is a method of the JsonSerializable interface.
131 131
      *
132 132
      * @return string
133 133
      */
134
-    public function jsonSerialize(): string
135
-    {
136
-        return $this->__toString();
137
-    }
134
+public function jsonSerialize(): string
135
+{
136
+return $this->__toString();
137
+}
138 138
 }
Please login to merge, or discard this patch.
jaxon-core/src/App/View/ViewRenderer.php 1 patch
Switch Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -16,58 +16,58 @@  discard block
 block discarded – undo
16 16
 
17 17
 class ViewRenderer
18 18
 {
19
-    /**
19
+/**
20 20
      * @var Container
21 21
      */
22
-    protected $di;
22
+protected $di;
23 23
 
24
-    /**
24
+/**
25 25
      * The view data store
26 26
      *
27 27
      * @var Store
28 28
      */
29
-    protected $xStore = null;
29
+protected $xStore = null;
30 30
 
31
-    /**
31
+/**
32 32
      * The view data store
33 33
      *
34 34
      * @var Store
35 35
      */
36
-    protected $xEmptyStore = null;
36
+protected $xEmptyStore = null;
37 37
 
38
-    /**
38
+/**
39 39
      * The view namespaces
40 40
      *
41 41
      * @var array
42 42
      */
43
-    protected $aNamespaces = [];
43
+protected $aNamespaces = [];
44 44
 
45
-    /**
45
+/**
46 46
      * The default namespace
47 47
      *
48 48
      * @var string
49 49
      */
50
-    protected $sDefaultNamespace = 'jaxon';
50
+protected $sDefaultNamespace = 'jaxon';
51 51
 
52
-    /**
52
+/**
53 53
      * The view global data
54 54
      *
55 55
      * @var array
56 56
      */
57
-    protected $aViewData = [];
57
+protected $aViewData = [];
58 58
 
59
-    /**
59
+/**
60 60
      * The class constructor
61 61
      *
62 62
      * @param Container $di
63 63
      */
64
-    public function __construct(Container $di)
65
-    {
66
-        $this->di = $di;
67
-        $this->xEmptyStore = new Store();
68
-    }
64
+public function __construct(Container $di)
65
+{
66
+$this->di = $di;
67
+$this->xEmptyStore = new Store();
68
+}
69 69
 
70
-    /**
70
+/**
71 71
      * Add a view namespace, and set the corresponding renderer.
72 72
      *
73 73
      * @param string $sNamespace    The namespace name
@@ -77,59 +77,59 @@  discard block
 block discarded – undo
77 77
      *
78 78
      * @return void
79 79
      */
80
-    public function addNamespace(string $sNamespace, string $sDirectory,
81
-        string $sExtension, string $sRenderer): void
82
-    {
83
-        $aNamespace = [
84
-            'directory' => $sDirectory,
85
-            'extension' => $sExtension,
86
-            'renderer' => $sRenderer,
87
-        ];
88
-        $this->aNamespaces[$sNamespace] = $aNamespace;
89
-    }
80
+public function addNamespace(string $sNamespace, string $sDirectory,
81
+string $sExtension, string $sRenderer): void
82
+{
83
+$aNamespace = [
84
+'directory' => $sDirectory,
85
+'extension' => $sExtension,
86
+'renderer' => $sRenderer,
87
+];
88
+$this->aNamespaces[$sNamespace] = $aNamespace;
89
+}
90 90
 
91
-    /**
91
+/**
92 92
      * Set the view namespaces.
93 93
      *
94 94
      * @param Config $xAppConfig    The config options provided in the library
95 95
      *
96 96
      * @return void
97 97
      */
98
-    public function addNamespaces(Config $xAppConfig): void
99
-    {
100
-        if(empty($aNamespaces = $xAppConfig->getOptionNames('views')))
101
-        {
102
-            return;
103
-        }
98
+public function addNamespaces(Config $xAppConfig): void
99
+{
100
+if(empty($aNamespaces = $xAppConfig->getOptionNames('views')))
101
+{
102
+return;
103
+}
104 104
 
105
-        $sPackage = $xAppConfig->getOption('package', '');
106
-        foreach($aNamespaces as $sNamespace => $sOption)
107
-        {
108
-            // Save the namespace
109
-            $aNamespace = $xAppConfig->getOption($sOption);
110
-            $aNamespace['package'] = $sPackage;
111
-            if(!isset($aNamespace['renderer']))
112
-            {
113
-                $aNamespace['renderer'] = 'jaxon'; // 'jaxon' is the default renderer.
114
-            }
115
-            $this->aNamespaces[$sNamespace] = $aNamespace;
116
-        }
117
-    }
105
+$sPackage = $xAppConfig->getOption('package', '');
106
+foreach($aNamespaces as $sNamespace => $sOption)
107
+{
108
+// Save the namespace
109
+$aNamespace = $xAppConfig->getOption($sOption);
110
+$aNamespace['package'] = $sPackage;
111
+if(!isset($aNamespace['renderer']))
112
+{
113
+    $aNamespace['renderer'] = 'jaxon'; // 'jaxon' is the default renderer.
114
+}
115
+$this->aNamespaces[$sNamespace] = $aNamespace;
116
+}
117
+}
118 118
 
119
-    /**
119
+/**
120 120
      * Get the view renderer
121 121
      *
122 122
      * @param string $sId    The unique identifier of the view renderer
123 123
      *
124 124
      * @return ViewInterface
125 125
      */
126
-    public function getRenderer(string $sId): ViewInterface
127
-    {
128
-        // Return the view renderer with the given id
129
-        return $this->di->g("jaxon.app.view.$sId");
130
-    }
126
+public function getRenderer(string $sId): ViewInterface
127
+{
128
+// Return the view renderer with the given id
129
+return $this->di->g("jaxon.app.view.$sId");
130
+}
131 131
 
132
-    /**
132
+/**
133 133
      * Add a view renderer with an id
134 134
      *
135 135
      * @param string $sId    The unique identifier of the view renderer
@@ -137,25 +137,25 @@  discard block
 block discarded – undo
137 137
      *
138 138
      * @return void
139 139
      */
140
-    public function addRenderer(string $sId, Closure $xClosure): void
141
-    {
142
-        // Return the initialized view renderer
143
-        $this->di->set("jaxon.app.view.$sId", function($di) use($sId, $xClosure) {
144
-            // Get the defined renderer
145
-            $xRenderer = $xClosure($di);
146
-            // Init the renderer with the template namespaces
147
-            $aNamespaces = array_filter($this->aNamespaces, function($aOptions) use($sId) {
148
-                return $aOptions['renderer'] === $sId;
149
-            });
150
-            foreach($aNamespaces as $sName => $aOptions)
151
-            {
152
-                $xRenderer->addNamespace($sName, $aOptions['directory'], $aOptions['extension']);
153
-            }
154
-            return $xRenderer;
155
-        });
156
-    }
140
+public function addRenderer(string $sId, Closure $xClosure): void
141
+{
142
+// Return the initialized view renderer
143
+$this->di->set("jaxon.app.view.$sId", function($di) use($sId, $xClosure) {
144
+// Get the defined renderer
145
+$xRenderer = $xClosure($di);
146
+// Init the renderer with the template namespaces
147
+$aNamespaces = array_filter($this->aNamespaces, function($aOptions) use($sId) {
148
+    return $aOptions['renderer'] === $sId;
149
+});
150
+foreach($aNamespaces as $sName => $aOptions)
151
+{
152
+    $xRenderer->addNamespace($sName, $aOptions['directory'], $aOptions['extension']);
153
+}
154
+return $xRenderer;
155
+});
156
+}
157 157
 
158
-    /**
158
+/**
159 159
      * Add a view renderer with an id
160 160
      *
161 161
      * @param string $sId    The unique identifier of the view renderer
@@ -164,55 +164,55 @@  discard block
 block discarded – undo
164 164
      *
165 165
      * @return void
166 166
      */
167
-    public function setDefaultRenderer(string $sId, string $sExtension, Closure $xClosure): void
168
-    {
169
-        $this->setDefaultNamespace($sId);
170
-        $this->addNamespace($sId, '', $sExtension, $sId);
171
-        $this->addRenderer($sId, $xClosure);
172
-    }
167
+public function setDefaultRenderer(string $sId, string $sExtension, Closure $xClosure): void
168
+{
169
+$this->setDefaultNamespace($sId);
170
+$this->addNamespace($sId, '', $sExtension, $sId);
171
+$this->addRenderer($sId, $xClosure);
172
+}
173 173
 
174
-    /**
174
+/**
175 175
      * Get the view renderer for a given namespace
176 176
      *
177 177
      * @param string $sNamespace    The namespace name
178 178
      *
179 179
      * @return ViewInterface|null
180 180
      */
181
-    public function getNamespaceRenderer(string $sNamespace): ?ViewInterface
182
-    {
183
-        if(!isset($this->aNamespaces[$sNamespace]))
184
-        {
185
-            return null;
186
-        }
187
-        // Return the view renderer with the configured id
188
-        return $this->getRenderer($this->aNamespaces[$sNamespace]['renderer']);
189
-    }
181
+public function getNamespaceRenderer(string $sNamespace): ?ViewInterface
182
+{
183
+if(!isset($this->aNamespaces[$sNamespace]))
184
+{
185
+return null;
186
+}
187
+// Return the view renderer with the configured id
188
+return $this->getRenderer($this->aNamespaces[$sNamespace]['renderer']);
189
+}
190 190
 
191
-    /**
191
+/**
192 192
      * Set the default namespace
193 193
      *
194 194
      * @param string $sDefaultNamespace
195 195
      */
196
-    public function setDefaultNamespace(string $sDefaultNamespace): void
197
-    {
198
-        $this->sDefaultNamespace = $sDefaultNamespace;
199
-    }
196
+public function setDefaultNamespace(string $sDefaultNamespace): void
197
+{
198
+$this->sDefaultNamespace = $sDefaultNamespace;
199
+}
200 200
 
201
-    /**
201
+/**
202 202
      * Get the current store or create a new store
203 203
      *
204 204
      * @return Store
205 205
      */
206
-    protected function store(): Store
207
-    {
208
-        if(!$this->xStore)
209
-        {
210
-            $this->xStore = new Store();
211
-        }
212
-        return $this->xStore;
213
-    }
206
+protected function store(): Store
207
+{
208
+if(!$this->xStore)
209
+{
210
+$this->xStore = new Store();
211
+}
212
+return $this->xStore;
213
+}
214 214
 
215
-    /**
215
+/**
216 216
      * Make a piece of data available for the rendered view
217 217
      *
218 218
      * @param string $sName    The data name
@@ -220,13 +220,13 @@  discard block
 block discarded – undo
220 220
      *
221 221
      * @return ViewRenderer
222 222
      */
223
-    public function set(string $sName, $xValue): ViewRenderer
224
-    {
225
-        $this->store()->with($sName, $xValue);
226
-        return $this;
227
-    }
223
+public function set(string $sName, $xValue): ViewRenderer
224
+{
225
+$this->store()->with($sName, $xValue);
226
+return $this;
227
+}
228 228
 
229
-    /**
229
+/**
230 230
      * Make a piece of data available for all views
231 231
      *
232 232
      * @param string $sName    The data name
@@ -234,29 +234,29 @@  discard block
 block discarded – undo
234 234
      *
235 235
      * @return ViewRenderer
236 236
      */
237
-    public function share(string $sName, $xValue): ViewRenderer
238
-    {
239
-        $this->aViewData[$sName] = $xValue;
240
-        return $this;
241
-    }
237
+public function share(string $sName, $xValue): ViewRenderer
238
+{
239
+$this->aViewData[$sName] = $xValue;
240
+return $this;
241
+}
242 242
 
243
-    /**
243
+/**
244 244
      * Make an array of data available for all views
245 245
      *
246 246
      * @param array $aValues    The data values
247 247
      *
248 248
      * @return ViewRenderer
249 249
      */
250
-    public function shareValues(array $aValues): ViewRenderer
251
-    {
252
-        foreach($aValues as $sName => $xValue)
253
-        {
254
-            $this->share($sName, $xValue);
255
-        }
256
-        return $this;
257
-    }
250
+public function shareValues(array $aValues): ViewRenderer
251
+{
252
+foreach($aValues as $sName => $xValue)
253
+{
254
+$this->share($sName, $xValue);
255
+}
256
+return $this;
257
+}
258 258
 
259
-    /**
259
+/**
260 260
      * Render a view using a store
261 261
      *
262 262
      * The store returned by this function will later be used with the make() method to render the view.
@@ -266,32 +266,32 @@  discard block
 block discarded – undo
266 266
      *
267 267
      * @return Store   A store populated with the view data
268 268
      */
269
-    public function render(string $sViewName, array $aViewData = []): Store
270
-    {
271
-        $xStore = $this->store();
272
-        // Get the default view namespace
273
-        $sNamespace = $this->sDefaultNamespace;
274
-        // Get the namespace from the view name
275
-        $nSeparatorPosition = strrpos($sViewName, '::');
276
-        if($nSeparatorPosition !== false)
277
-        {
278
-            $sNamespace = substr($sViewName, 0, $nSeparatorPosition);
279
-            $sViewName = substr($sViewName, $nSeparatorPosition + 2);
280
-        }
269
+public function render(string $sViewName, array $aViewData = []): Store
270
+{
271
+$xStore = $this->store();
272
+// Get the default view namespace
273
+$sNamespace = $this->sDefaultNamespace;
274
+// Get the namespace from the view name
275
+$nSeparatorPosition = strrpos($sViewName, '::');
276
+if($nSeparatorPosition !== false)
277
+{
278
+$sNamespace = substr($sViewName, 0, $nSeparatorPosition);
279
+$sViewName = substr($sViewName, $nSeparatorPosition + 2);
280
+}
281 281
 
282
-        $xRenderer = $this->getNamespaceRenderer($sNamespace);
283
-        if(!$xRenderer)
284
-        {
285
-            // Cannot render a view if there's no renderer corresponding to the namespace.
286
-            return $this->xEmptyStore;
287
-        }
282
+$xRenderer = $this->getNamespaceRenderer($sNamespace);
283
+if(!$xRenderer)
284
+{
285
+// Cannot render a view if there's no renderer corresponding to the namespace.
286
+return $this->xEmptyStore;
287
+}
288 288
 
289
-        $xStore->setData(array_merge($this->aViewData, $aViewData))
290
-            ->setView($xRenderer, $sNamespace, $sViewName);
289
+$xStore->setData(array_merge($this->aViewData, $aViewData))
290
+->setView($xRenderer, $sNamespace, $sViewName);
291 291
 
292
-        // Set the store to null so a new store will be created for the next view.
293
-        $this->xStore = null;
294
-        // Return the store
295
-        return $xStore;
296
-    }
292
+// Set the store to null so a new store will be created for the next view.
293
+$this->xStore = null;
294
+// Return the store
295
+return $xStore;
296
+}
297 297
 }
Please login to merge, or discard this patch.
jaxon-core/src/App/PageComponent.php 1 patch
Switch Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -6,53 +6,53 @@
 block discarded – undo
6 6
 
7 7
 abstract class PageComponent extends NodeComponent
8 8
 {
9
-    /**
9
+/**
10 10
      * The current page number.
11 11
      *
12 12
      * @var int
13 13
      */
14
-    private int $currentPage = 1;
14
+private int $currentPage = 1;
15 15
 
16
-    /**
16
+/**
17 17
      * Get the total number of items to paginate.
18 18
      *
19 19
      * @return int
20 20
      */
21
-    abstract protected function count(): int;
21
+abstract protected function count(): int;
22 22
 
23
-    /**
23
+/**
24 24
      * Get the max number of items per page.
25 25
      *
26 26
      * @return int
27 27
      */
28
-    abstract protected function limit(): int;
28
+abstract protected function limit(): int;
29 29
 
30
-    /**
30
+/**
31 31
      * Get the paginator for the component.
32 32
      *
33 33
      * @param int $pageNumber
34 34
      *
35 35
      * @return Paginator
36 36
      */
37
-    protected function paginator(int $pageNumber): Paginator
38
-    {
39
-        return $this->cl(Component\Pagination::class)
40
-            // Use the js class name as component item identifier.
41
-            ->item($this->rq()->_class())
42
-            ->paginator($pageNumber > 0 ? $pageNumber : 1, $this->limit(), $this->count())
43
-            // This callback will receive the final value of the current page number.
44
-            ->page(function(int $currentPage) {
45
-                $this->currentPage = $currentPage;
46
-            });
47
-    }
37
+protected function paginator(int $pageNumber): Paginator
38
+{
39
+return $this->cl(Component\Pagination::class)
40
+// Use the js class name as component item identifier.
41
+->item($this->rq()->_class())
42
+->paginator($pageNumber > 0 ? $pageNumber : 1, $this->limit(), $this->count())
43
+// This callback will receive the final value of the current page number.
44
+->page(function(int $currentPage) {
45
+    $this->currentPage = $currentPage;
46
+});
47
+}
48 48
 
49
-    /**
49
+/**
50 50
      * Get the current page number
51 51
      *
52 52
      * @return int
53 53
      */
54
-    protected function currentPage(): int
55
-    {
56
-        return $this->currentPage;
57
-    }
54
+protected function currentPage(): int
55
+{
56
+return $this->currentPage;
57
+}
58 58
 }
Please login to merge, or discard this patch.