Passed
Push — main ( 273db0...683317 )
by Thierry
03:54
created
jaxon-core/src/Di/ComponentContainer.php 1 patch
Switch Indentation   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -40,85 +40,85 @@  discard block
 block discarded – undo
40 40
 
41 41
 class ComponentContainer
42 42
 {
43
-    use Traits\DiAutoTrait;
44
-    use Traits\ComponentTrait;
43
+use Traits\DiAutoTrait;
44
+use Traits\ComponentTrait;
45 45
 
46
-    /**
46
+/**
47 47
      * The Dependency Injection Container for registered classes
48 48
      *
49 49
      * @var PimpleContainer
50 50
      */
51
-    private $xContainer;
51
+private $xContainer;
52 52
 
53
-    /**
53
+/**
54 54
      * This will be set only when getting the object targetted by the ajax request.
55 55
      *
56 56
      * @var Target|null
57 57
      */
58
-    private $xTarget = null;
58
+private $xTarget = null;
59 59
 
60
-    /**
60
+/**
61 61
      * The class constructor
62 62
      *
63 63
      * @param Container $di
64 64
      */
65
-    public function __construct(private Container $di)
66
-    {
67
-        $this->xContainer = new PimpleContainer();
68
-        $this->val(ComponentContainer::class, $this);
69
-
70
-        // Register the call factory for registered functions
71
-        $this->set($this->getRequestFactoryKey(JxnCall::class), fn() =>
72
-            new JxnCall($this->di->g(ConfigManager::class)
73
-                ->getOption('core.prefix.function', '')));
74
-
75
-        // Register the pagination component, but do not export to js.
76
-        $this->saveComponent(Pagination::class, [
77
-            'excluded' => true,
78
-            'separator' => '.',
79
-            // The namespace has the same name as the Component class.
80
-            'namespace' => Component::class,
81
-        ]);
82
-
83
-        // Register the logger component, and export to js.
84
-        $this->di->callback()->boot(function() {
85
-            if($this->di->config()->loggingEnabled())
86
-            {
87
-                $this->saveComponent(LoggerComponent::class, [
88
-                    'separator' => '.',
89
-                    // The namespace has the same name as the Component class.
90
-                    'namespace' => Component::class,
91
-                ]);
92
-            }
93
-        });
94
-
95
-        $this->setComponentPublicMethods('node', NodeComponent::class, ['item', 'html']);
96
-        $this->setComponentPublicMethods('func', FuncComponent::class, ['paginator']);
97
-    }
65
+public function __construct(private Container $di)
66
+{
67
+$this->xContainer = new PimpleContainer();
68
+$this->val(ComponentContainer::class, $this);
69
+
70
+// Register the call factory for registered functions
71
+$this->set($this->getRequestFactoryKey(JxnCall::class), fn() =>
72
+new JxnCall($this->di->g(ConfigManager::class)
73
+    ->getOption('core.prefix.function', '')));
74
+
75
+// Register the pagination component, but do not export to js.
76
+$this->saveComponent(Pagination::class, [
77
+'excluded' => true,
78
+'separator' => '.',
79
+// The namespace has the same name as the Component class.
80
+'namespace' => Component::class,
81
+]);
82
+
83
+// Register the logger component, and export to js.
84
+$this->di->callback()->boot(function() {
85
+if($this->di->config()->loggingEnabled())
86
+{
87
+    $this->saveComponent(LoggerComponent::class, [
88
+        'separator' => '.',
89
+        // The namespace has the same name as the Component class.
90
+        'namespace' => Component::class,
91
+    ]);
92
+}
93
+});
94
+
95
+$this->setComponentPublicMethods('node', NodeComponent::class, ['item', 'html']);
96
+$this->setComponentPublicMethods('func', FuncComponent::class, ['paginator']);
97
+}
98 98
 
99
-    /**
99
+/**
100 100
      * The container for parameters
101 101
      *
102 102
      * @return Container
103 103
      */
104
-    protected function cn(): Container
105
-    {
106
-        return $this->di;
107
-    }
104
+protected function cn(): Container
105
+{
106
+return $this->di;
107
+}
108 108
 
109
-    /**
109
+/**
110 110
      * Check if a class is defined in the container
111 111
      *
112 112
      * @param class-string $sClass    The full class name
113 113
      *
114 114
      * @return bool
115 115
      */
116
-    public function has(string $sClass): bool
117
-    {
118
-        return $this->xContainer->offsetExists($sClass);
119
-    }
116
+public function has(string $sClass): bool
117
+{
118
+return $this->xContainer->offsetExists($sClass);
119
+}
120 120
 
121
-    /**
121
+/**
122 122
      * Save a closure in the container
123 123
      *
124 124
      * @param class-string $sClass    The full class name
@@ -126,12 +126,12 @@  discard block
 block discarded – undo
126 126
      *
127 127
      * @return void
128 128
      */
129
-    public function set(string $sClass, Closure $xClosure): void
130
-    {
131
-        $this->xContainer->offsetSet($sClass, fn() => $xClosure($this));
132
-    }
129
+public function set(string $sClass, Closure $xClosure): void
130
+{
131
+$this->xContainer->offsetSet($sClass, fn() => $xClosure($this));
132
+}
133 133
 
134
-    /**
134
+/**
135 135
      * Save a value in the container
136 136
      *
137 137
      * @param string|class-string $sKey    The key
@@ -139,12 +139,12 @@  discard block
 block discarded – undo
139 139
      *
140 140
      * @return void
141 141
      */
142
-    public function val(string $sKey, $xValue): void
143
-    {
144
-       $this->xContainer->offsetSet($sKey, $xValue);
145
-    }
142
+public function val(string $sKey, $xValue): void
143
+{
144
+$this->xContainer->offsetSet($sKey, $xValue);
145
+}
146 146
 
147
-    /**
147
+/**
148 148
      * Get a class instance
149 149
      *
150 150
      * @template T
@@ -152,12 +152,12 @@  discard block
 block discarded – undo
152 152
      *
153 153
      * @return T
154 154
      */
155
-    public function get(string $sClass): mixed
156
-    {
157
-        return $this->xContainer->offsetGet($sClass);
158
-    }
155
+public function get(string $sClass): mixed
156
+{
157
+return $this->xContainer->offsetGet($sClass);
158
+}
159 159
 
160
-    /**
160
+/**
161 161
      * Get a component when one of its method needs to be called
162 162
      *
163 163
      * @template T
@@ -166,17 +166,17 @@  discard block
 block discarded – undo
166 166
      *
167 167
      * @return T|null
168 168
      */
169
-    public function getTargetComponent(string $sClassName, Target $xTarget): mixed
170
-    {
171
-        // Set the target only when getting the object targetted by the ajax request.
172
-        $this->xTarget = $xTarget;
173
-        $xComponent = $this->get($sClassName);
174
-        $this->xTarget = null;
169
+public function getTargetComponent(string $sClassName, Target $xTarget): mixed
170
+{
171
+// Set the target only when getting the object targetted by the ajax request.
172
+$this->xTarget = $xTarget;
173
+$xComponent = $this->get($sClassName);
174
+$this->xTarget = null;
175 175
 
176
-        return $xComponent;
177
-    }
176
+return $xComponent;
177
+}
178 178
 
179
-    /**
179
+/**
180 180
      * Register a component and its options
181 181
      *
182 182
      * @param class-string $sClassName    The class name
@@ -184,40 +184,40 @@  discard block
 block discarded – undo
184 184
      *
185 185
      * @return void
186 186
      */
187
-    public function saveComponent(string $sClassName, array $aOptions): void
188
-    {
189
-        try
190
-        {
191
-            // Make sure the registered class exists
192
-            if(isset($aOptions['include']))
193
-            {
194
-                require_once $aOptions['include'];
195
-            }
196
-            $xReflectionClass = new ReflectionClass($sClassName);
197
-            // Check if the class is registrable
198
-            if(!$xReflectionClass->isInstantiable())
199
-            {
200
-                return;
201
-            }
202
-
203
-            $this->_saveClassOptions($sClassName, $aOptions);
204
-
205
-            $sClassKey = $this->getReflectionClassKey($sClassName);
206
-            $this->val($sClassKey, $xReflectionClass);
207
-            // Register the user class, but only if the user didn't already.
208
-            if(!$this->has($sClassName))
209
-            {
210
-                $this->set($sClassName, fn() => $this->make($this->get($sClassKey)));
211
-            }
212
-        }
213
-        catch(ReflectionException $e)
214
-        {
215
-            throw new SetupException($this->cn()->g(Translator::class)
216
-                ->trans('errors.class.invalid', ['name' => $sClassName]));
217
-        }
218
-    }
187
+public function saveComponent(string $sClassName, array $aOptions): void
188
+{
189
+try
190
+{
191
+// Make sure the registered class exists
192
+if(isset($aOptions['include']))
193
+{
194
+    require_once $aOptions['include'];
195
+}
196
+$xReflectionClass = new ReflectionClass($sClassName);
197
+// Check if the class is registrable
198
+if(!$xReflectionClass->isInstantiable())
199
+{
200
+    return;
201
+}
219 202
 
220
-    /**
203
+$this->_saveClassOptions($sClassName, $aOptions);
204
+
205
+$sClassKey = $this->getReflectionClassKey($sClassName);
206
+$this->val($sClassKey, $xReflectionClass);
207
+// Register the user class, but only if the user didn't already.
208
+if(!$this->has($sClassName))
209
+{
210
+    $this->set($sClassName, fn() => $this->make($this->get($sClassKey)));
211
+}
212
+}
213
+catch(ReflectionException $e)
214
+{
215
+throw new SetupException($this->cn()->g(Translator::class)
216
+    ->trans('errors.class.invalid', ['name' => $sClassName]));
217
+}
218
+}
219
+
220
+/**
221 221
      * Register a component
222 222
      *
223 223
      * @param string $sComponentId The component name
@@ -225,74 +225,74 @@  discard block
 block discarded – undo
225 225
      * @return string
226 226
      * @throws SetupException
227 227
      */
228
-    private function _registerComponent(string $sComponentId): string
229
-    {
230
-        // Replace all separators ('.' or '_') with antislashes, and trim the class name.
231
-        $sClassName = trim(str_replace(['.', '_'], '\\', $sComponentId), '\\');
232
-
233
-        $sComponentObject = $this->getCallableObjectKey($sClassName);
234
-        // Prevent duplication. It's important not to use the class name here.
235
-        if($this->has($sComponentObject))
236
-        {
237
-            return $sClassName;
238
-        }
239
-
240
-        // Register the helper class
241
-        $this->set($this->getCallableHelperKey($sClassName), function() use($sClassName) {
242
-            $xFactory = $this->di->getCallFactory();
243
-            return new ComponentHelper($this, $xFactory->rq($sClassName),
244
-                $xFactory, $this->di->getViewRenderer(),
245
-                $this->di->getLogger(), $this->di->getSessionManager(),
246
-                $this->di->getStash(), $this->di->getUploadHandler());
247
-        });
248
-
249
-        $this->discoverComponent($sClassName);
250
-
251
-        // Register the callable object
252
-        $this->set($sComponentObject, function() use($sComponentId, $sClassName) {
253
-            $aOptions = $this->_getClassOptions($sComponentId);
254
-            $xReflectionClass = $this->get($this->getReflectionClassKey($sClassName));
255
-            $xOptions = $this->getComponentOptions($xReflectionClass, $aOptions);
256
-            return new CallableObject($this, $this->di, $xReflectionClass, $xOptions);
257
-        });
258
-
259
-        // Initialize the user class instance
260
-        $this->xContainer->extend($sClassName, function($xClassInstance) use($sClassName) {
261
-            if($xClassInstance instanceof AbstractComponent)
262
-            {
263
-                $xHelper = $this->get($this->getCallableHelperKey($sClassName));
264
-                $xHelper->xTarget = $this->xTarget;
265
-
266
-                // Call the protected "initComponent()" method of the Component class.
267
-                $cSetter = function($di, $xHelper) {
268
-                    $this->initComponent($di, $xHelper);  // "$this" here refers to the Component class.
269
-                };
270
-                $cSetter = $cSetter->bindTo($xClassInstance, $xClassInstance);
271
-                call_user_func($cSetter, $this->di, $xHelper);
272
-            }
273
-
274
-            // Run the callbacks for class initialisation
275
-            $this->di->g(CallbackManager::class)->onInit($xClassInstance);
276
-
277
-            // Set attributes from the DI container.
278
-            // The class level DI options are set on any component.
279
-            // The method level DI options are set only on the targetted component.
280
-            /** @var CallableObject */
281
-            $xCallableObject = $this->get($this->getCallableObjectKey($sClassName));
282
-            $xCallableObject->setDiClassAttributes($xClassInstance);
283
-            if($this->xTarget !== null)
284
-            {
285
-                $sMethodName = $this->xTarget->getMethodName();
286
-                $xCallableObject->setDiMethodAttributes($xClassInstance, $sMethodName);
287
-            }
288
-
289
-            return $xClassInstance;
290
-        });
291
-
292
-        return $sClassName;
293
-    }
228
+private function _registerComponent(string $sComponentId): string
229
+{
230
+// Replace all separators ('.' or '_') with antislashes, and trim the class name.
231
+$sClassName = trim(str_replace(['.', '_'], '\\', $sComponentId), '\\');
232
+
233
+$sComponentObject = $this->getCallableObjectKey($sClassName);
234
+// Prevent duplication. It's important not to use the class name here.
235
+if($this->has($sComponentObject))
236
+{
237
+return $sClassName;
238
+}
239
+
240
+// Register the helper class
241
+$this->set($this->getCallableHelperKey($sClassName), function() use($sClassName) {
242
+$xFactory = $this->di->getCallFactory();
243
+return new ComponentHelper($this, $xFactory->rq($sClassName),
244
+    $xFactory, $this->di->getViewRenderer(),
245
+    $this->di->getLogger(), $this->di->getSessionManager(),
246
+    $this->di->getStash(), $this->di->getUploadHandler());
247
+});
248
+
249
+$this->discoverComponent($sClassName);
250
+
251
+// Register the callable object
252
+$this->set($sComponentObject, function() use($sComponentId, $sClassName) {
253
+$aOptions = $this->_getClassOptions($sComponentId);
254
+$xReflectionClass = $this->get($this->getReflectionClassKey($sClassName));
255
+$xOptions = $this->getComponentOptions($xReflectionClass, $aOptions);
256
+return new CallableObject($this, $this->di, $xReflectionClass, $xOptions);
257
+});
258
+
259
+// Initialize the user class instance
260
+$this->xContainer->extend($sClassName, function($xClassInstance) use($sClassName) {
261
+if($xClassInstance instanceof AbstractComponent)
262
+{
263
+    $xHelper = $this->get($this->getCallableHelperKey($sClassName));
264
+    $xHelper->xTarget = $this->xTarget;
265
+
266
+    // Call the protected "initComponent()" method of the Component class.
267
+    $cSetter = function($di, $xHelper) {
268
+        $this->initComponent($di, $xHelper);  // "$this" here refers to the Component class.
269
+    };
270
+    $cSetter = $cSetter->bindTo($xClassInstance, $xClassInstance);
271
+    call_user_func($cSetter, $this->di, $xHelper);
272
+}
273
+
274
+// Run the callbacks for class initialisation
275
+$this->di->g(CallbackManager::class)->onInit($xClassInstance);
276
+
277
+// Set attributes from the DI container.
278
+// The class level DI options are set on any component.
279
+// The method level DI options are set only on the targetted component.
280
+/** @var CallableObject */
281
+$xCallableObject = $this->get($this->getCallableObjectKey($sClassName));
282
+$xCallableObject->setDiClassAttributes($xClassInstance);
283
+if($this->xTarget !== null)
284
+{
285
+    $sMethodName = $this->xTarget->getMethodName();
286
+    $xCallableObject->setDiMethodAttributes($xClassInstance, $sMethodName);
287
+}
288
+
289
+return $xClassInstance;
290
+});
291
+
292
+return $sClassName;
293
+}
294 294
 
295
-    /**
295
+/**
296 296
      * Get the callable object for a given class
297 297
      * The callable object is registered if it is not already in the DI.
298 298
      *
@@ -301,13 +301,13 @@  discard block
 block discarded – undo
301 301
      * @return CallableObject|null
302 302
      * @throws SetupException
303 303
      */
304
-    public function makeCallableObject(string $sComponentId): ?CallableObject
305
-    {
306
-        $sClassName = $this->_registerComponent($sComponentId);
307
-        return $this->get($this->getCallableObjectKey($sClassName));
308
-    }
304
+public function makeCallableObject(string $sComponentId): ?CallableObject
305
+{
306
+$sClassName = $this->_registerComponent($sComponentId);
307
+return $this->get($this->getCallableObjectKey($sClassName));
308
+}
309 309
 
310
-    /**
310
+/**
311 311
      * Get an instance of a component by name
312 312
      *
313 313
      * @template T
@@ -316,53 +316,53 @@  discard block
 block discarded – undo
316 316
      * @return T|null
317 317
      * @throws SetupException
318 318
      */
319
-    public function makeComponent(string $sClassName): mixed
320
-    {
321
-        $sComponentId = str_replace('\\', '.', $sClassName);
322
-        $sClassName = $this->_registerComponent($sComponentId);
323
-        return $this->get($sClassName);
324
-    }
319
+public function makeComponent(string $sClassName): mixed
320
+{
321
+$sComponentId = str_replace('\\', '.', $sClassName);
322
+$sClassName = $this->_registerComponent($sComponentId);
323
+return $this->get($sClassName);
324
+}
325 325
 
326
-    /**
326
+/**
327 327
      * Get a factory for a call to a registered function.
328 328
      *
329 329
      * @return JxnCall
330 330
      */
331
-    public function getFunctionRequestFactory(): JxnCall
332
-    {
333
-        return $this->get($this->getRequestFactoryKey(JxnCall::class));
334
-    }
331
+public function getFunctionRequestFactory(): JxnCall
332
+{
333
+return $this->get($this->getRequestFactoryKey(JxnCall::class));
334
+}
335 335
 
336
-    /**
336
+/**
337 337
      * Get a factory for a call to a registered component.
338 338
      *
339 339
      * @param class-string $sClassName
340 340
      *
341 341
      * @return JxnCall|null
342 342
      */
343
-    public function getComponentRequestFactory(string $sClassName): ?JxnCall
343
+public function getComponentRequestFactory(string $sClassName): ?JxnCall
344
+{
345
+$sClassName = trim($sClassName, " \t");
346
+if($sClassName === '')
347
+{
348
+return null;
349
+}
350
+
351
+$sFactoryKey = $this->getRequestFactoryKey($sClassName);
352
+if(!$this->has($sFactoryKey))
353
+{
354
+$this->xContainer->offsetSet($sFactoryKey, function() use($sClassName) {
355
+    $sComponentId = str_replace('\\', '.', $sClassName);
356
+    if(!($xCallable = $this->makeCallableObject($sComponentId)))
344 357
     {
345
-        $sClassName = trim($sClassName, " \t");
346
-        if($sClassName === '')
347
-        {
348
-            return null;
349
-        }
350
-
351
-        $sFactoryKey = $this->getRequestFactoryKey($sClassName);
352
-        if(!$this->has($sFactoryKey))
353
-        {
354
-            $this->xContainer->offsetSet($sFactoryKey, function() use($sClassName) {
355
-                $sComponentId = str_replace('\\', '.', $sClassName);
356
-                if(!($xCallable = $this->makeCallableObject($sComponentId)))
357
-                {
358
-                    return null;
359
-                }
360
-
361
-                $xConfigManager = $this->di->g(ConfigManager::class);
362
-                $sPrefix = $xConfigManager->getOption('core.prefix.class', '');
363
-                return new JxnClassCall($sPrefix . $xCallable->getJsName());
364
-            });
365
-        }
366
-        return $this->get($sFactoryKey);
358
+        return null;
367 359
     }
360
+
361
+    $xConfigManager = $this->di->g(ConfigManager::class);
362
+    $sPrefix = $xConfigManager->getOption('core.prefix.class', '');
363
+    return new JxnClassCall($sPrefix . $xCallable->getJsName());
364
+});
365
+}
366
+return $this->get($sFactoryKey);
367
+}
368 368
 }
Please login to merge, or discard this patch.
jaxon-core/src/Request/Handler/RequestHandler.php 1 patch
Switch Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -30,14 +30,14 @@  discard block
 block discarded – undo
30 30
 
31 31
 class RequestHandler
32 32
 {
33
-    /**
33
+/**
34 34
      * The request plugin that is able to process the current request
35 35
      *
36 36
      * @var RequestHandlerInterface
37 37
      */
38
-    private $xRequestPlugin = null;
38
+private $xRequestPlugin = null;
39 39
 
40
-    /**
40
+/**
41 41
      * The constructor
42 42
      *
43 43
      * @param Container $di
@@ -46,113 +46,113 @@  discard block
 block discarded – undo
46 46
      * @param CallbackManager $xCallbackManager
47 47
      * @param DatabagPlugin $xDatabagPlugin
48 48
      */
49
-    public function __construct(private Container $di, private PluginManager $xPluginManager,
50
-        private ResponseManager $xResponseManager, private CallbackManager $xCallbackManager,
51
-        private DatabagPlugin $xDatabagPlugin)
52
-    {}
49
+public function __construct(private Container $di, private PluginManager $xPluginManager,
50
+private ResponseManager $xResponseManager, private CallbackManager $xCallbackManager,
51
+private DatabagPlugin $xDatabagPlugin)
52
+{}
53 53
 
54
-    /**
54
+/**
55 55
      * Check if the current request can be processed
56 56
      *
57 57
      * Calls each of the request plugins and determines if the current request can be processed by one of them.
58 58
      *
59 59
      * @return bool
60 60
      */
61
-    public function canProcessRequest(): bool
62
-    {
63
-        // Return true if the request plugin was already found
64
-        if($this->xRequestPlugin !== null)
65
-        {
66
-            return true;
67
-        }
61
+public function canProcessRequest(): bool
62
+{
63
+// Return true if the request plugin was already found
64
+if($this->xRequestPlugin !== null)
65
+{
66
+return true;
67
+}
68 68
 
69
-        // The HTTP request
70
-        $xRequest = $this->di->getRequest();
69
+// The HTTP request
70
+$xRequest = $this->di->getRequest();
71 71
 
72
-        // Find a plugin to process the request
73
-        foreach($this->xPluginManager->getRequestHandlers() as $sClassName)
74
-        {
75
-            if($sClassName::canProcessRequest($xRequest))
76
-            {
77
-                $this->xRequestPlugin = $this->di->g($sClassName);
78
-                $xTarget = $this->xRequestPlugin->setTarget($xRequest);
79
-                $xTarget->setMethodArgs($this->di->getRequestArguments());
80
-                return true;
81
-            }
82
-        }
83
-        return false;
84
-    }
72
+// Find a plugin to process the request
73
+foreach($this->xPluginManager->getRequestHandlers() as $sClassName)
74
+{
75
+if($sClassName::canProcessRequest($xRequest))
76
+{
77
+    $this->xRequestPlugin = $this->di->g($sClassName);
78
+    $xTarget = $this->xRequestPlugin->setTarget($xRequest);
79
+    $xTarget->setMethodArgs($this->di->getRequestArguments());
80
+    return true;
81
+}
82
+}
83
+return false;
84
+}
85 85
 
86
-    /**
86
+/**
87 87
      * Process the current request and handle errors and exceptions.
88 88
      *
89 89
      * @return void
90 90
      * @throws RequestException
91 91
      */
92
-    private function _processRequest(): void
93
-    {
94
-        // Process the request
95
-        if($this->xRequestPlugin !== null)
96
-        {
97
-            $this->xRequestPlugin->processRequest();
98
-            // Process the databag
99
-            $this->xDatabagPlugin->writeCommand();
100
-        }
101
-    }
92
+private function _processRequest(): void
93
+{
94
+// Process the request
95
+if($this->xRequestPlugin !== null)
96
+{
97
+$this->xRequestPlugin->processRequest();
98
+// Process the databag
99
+$this->xDatabagPlugin->writeCommand();
100
+}
101
+}
102 102
 
103
-    /**
103
+/**
104 104
      * Process the current request.
105 105
      *
106 106
      * @return void
107 107
      * @throws RequestException
108 108
      */
109
-    public function processRequest(): void
110
-    {
111
-        // We need the library to have been bootstrapped.
112
-        $this->di->getBootstrap()->onBoot();
109
+public function processRequest(): void
110
+{
111
+// We need the library to have been bootstrapped.
112
+$this->di->getBootstrap()->onBoot();
113 113
 
114
-        // Check if there is a plugin to process this request
115
-        if(!$this->canProcessRequest())
116
-        {
117
-            return;
118
-        }
114
+// Check if there is a plugin to process this request
115
+if(!$this->canProcessRequest())
116
+{
117
+return;
118
+}
119 119
 
120
-        try
121
-        {
122
-            $bEndRequest = false;
123
-            // Handle before processing event
124
-            if($this->xRequestPlugin !== null)
125
-            {
126
-                $this->xCallbackManager->onBefore($this->xRequestPlugin->getTarget(), $bEndRequest);
127
-            }
128
-            if($bEndRequest)
129
-            {
130
-                return;
131
-            }
120
+try
121
+{
122
+$bEndRequest = false;
123
+// Handle before processing event
124
+if($this->xRequestPlugin !== null)
125
+{
126
+    $this->xCallbackManager->onBefore($this->xRequestPlugin->getTarget(), $bEndRequest);
127
+}
128
+if($bEndRequest)
129
+{
130
+    return;
131
+}
132 132
 
133
-            $this->_processRequest();
133
+$this->_processRequest();
134 134
 
135
-            // Handle after processing event
136
-            if($this->xRequestPlugin !== null)
137
-            {
138
-                $this->xCallbackManager->onAfter($this->xRequestPlugin->getTarget(), $bEndRequest);
139
-            }
140
-        }
141
-        // An exception was thrown while processing the request.
142
-        // The request missed the corresponding handler function,
143
-        // or an error occurred while attempting to execute the handler.
144
-        catch(RequestException $e)
145
-        {
146
-            $this->xResponseManager->error($e->getMessage());
147
-            $this->xCallbackManager->onInvalid($e);
148
-        }
149
-        catch(Exception $e)
150
-        {
151
-            $this->xResponseManager->error($e->getMessage());
152
-            $this->xCallbackManager->onError($e);
153
-        }
135
+// Handle after processing event
136
+if($this->xRequestPlugin !== null)
137
+{
138
+    $this->xCallbackManager->onAfter($this->xRequestPlugin->getTarget(), $bEndRequest);
139
+}
140
+}
141
+// An exception was thrown while processing the request.
142
+// The request missed the corresponding handler function,
143
+// or an error occurred while attempting to execute the handler.
144
+catch(RequestException $e)
145
+{
146
+$this->xResponseManager->error($e->getMessage());
147
+$this->xCallbackManager->onInvalid($e);
148
+}
149
+catch(Exception $e)
150
+{
151
+$this->xResponseManager->error($e->getMessage());
152
+$this->xCallbackManager->onError($e);
153
+}
154 154
 
155
-        // Print the debug messages
156
-        $this->xResponseManager->printDebug();
157
-    }
155
+// Print the debug messages
156
+$this->xResponseManager->printDebug();
157
+}
158 158
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Code/ConfigScriptGenerator.php 1 patch
Switch Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -22,53 +22,53 @@
 block discarded – undo
22 22
 
23 23
 class ConfigScriptGenerator extends AbstractCodeGenerator
24 24
 {
25
-    /**
25
+/**
26 26
      * The constructor
27 27
      *
28 28
      * @param ParameterReader $xParameterReader
29 29
      * @param TemplateEngine $xTemplateEngine
30 30
      * @param ConfigManager $xConfigManager
31 31
      */
32
-    public function __construct(private ParameterReader $xParameterReader,
33
-        private TemplateEngine $xTemplateEngine, private ConfigManager $xConfigManager)
34
-    {}
32
+public function __construct(private ParameterReader $xParameterReader,
33
+private TemplateEngine $xTemplateEngine, private ConfigManager $xConfigManager)
34
+{}
35 35
 
36
-    /**
36
+/**
37 37
      * Get the value of a config option
38 38
      *
39 39
      * @param string $sName The option name
40 40
      *
41 41
      * @return mixed
42 42
      */
43
-    private function option(string $sName): mixed
44
-    {
45
-        return $this->xConfigManager->getOption($sName);
46
-    }
43
+private function option(string $sName): mixed
44
+{
45
+return $this->xConfigManager->getOption($sName);
46
+}
47 47
 
48
-    /**
48
+/**
49 49
      * @inheritDoc
50 50
      * @throws UriException
51 51
      */
52
-    public function getScript(): string
53
-    {
54
-        // It is important to call $this->xParameterReader->uri() only if necessary.
55
-        $sUri = $this->option('core.request.uri') ?: $this->xParameterReader->uri();
56
-        $aOptions = [
57
-            'sResponseType'      => 'JSON',
58
-            'sVersion'           => $this->option('core.version'),
59
-            'sLanguage'          => $this->option('core.language'),
60
-            'sRequestURI'        => $sUri,
61
-            'sDefaultMode'       => $this->option('core.request.mode'),
62
-            'sDefaultMethod'     => $this->option('core.request.method'),
63
-            'sCsrfMetaName'      => $this->option('core.request.csrf_meta'),
64
-            'bLoggingEnabled'    => $this->xConfigManager->loggingEnabled(),
65
-            'bDebug'             => $this->option('core.debug.on'),
66
-            'bVerboseDebug'      => $this->option('core.debug.verbose'),
67
-            'sDebugOutputID'     => $this->option('core.debug.output_id'),
68
-            'nResponseQueueSize' => $this->option('js.lib.queue_size'),
69
-            'sStatusMessages'    => $this->option('js.lib.show_status') ? 'true' : 'false',
70
-            'sWaitCursor'        => $this->option('js.lib.show_cursor') ? 'true' : 'false',
71
-        ];
72
-        return $this->xTemplateEngine->render('jaxon::plugins/config.js', $aOptions);
73
-    }
52
+public function getScript(): string
53
+{
54
+// It is important to call $this->xParameterReader->uri() only if necessary.
55
+$sUri = $this->option('core.request.uri') ?: $this->xParameterReader->uri();
56
+$aOptions = [
57
+'sResponseType'      => 'JSON',
58
+'sVersion'           => $this->option('core.version'),
59
+'sLanguage'          => $this->option('core.language'),
60
+'sRequestURI'        => $sUri,
61
+'sDefaultMode'       => $this->option('core.request.mode'),
62
+'sDefaultMethod'     => $this->option('core.request.method'),
63
+'sCsrfMetaName'      => $this->option('core.request.csrf_meta'),
64
+'bLoggingEnabled'    => $this->xConfigManager->loggingEnabled(),
65
+'bDebug'             => $this->option('core.debug.on'),
66
+'bVerboseDebug'      => $this->option('core.debug.verbose'),
67
+'sDebugOutputID'     => $this->option('core.debug.output_id'),
68
+'nResponseQueueSize' => $this->option('js.lib.queue_size'),
69
+'sStatusMessages'    => $this->option('js.lib.show_status') ? 'true' : 'false',
70
+'sWaitCursor'        => $this->option('js.lib.show_cursor') ? 'true' : 'false',
71
+];
72
+return $this->xTemplateEngine->render('jaxon::plugins/config.js', $aOptions);
73
+}
74 74
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Code/AssetManager.php 1 patch
Switch Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -26,142 +26,142 @@
 block discarded – undo
26 26
 
27 27
 class AssetManager
28 28
 {
29
-    use ConfigTrait;
29
+use ConfigTrait;
30 30
 
31
-    /**
31
+/**
32 32
      * Default library URL
33 33
      *
34 34
      * @var string
35 35
      */
36
-    const JS_LIB_URL = 'https://cdn.jsdelivr.net/gh/jaxon-php/[email protected]/dist';
36
+const JS_LIB_URL = 'https://cdn.jsdelivr.net/gh/jaxon-php/[email protected]/dist';
37 37
 
38
-    /**
38
+/**
39 39
      * The constructor
40 40
      *
41 41
      * @param ConfigManager $xConfigManager
42 42
      * @param MinifierInterface $xMinifier
43 43
      */
44
-    public function __construct(private ConfigManager $xConfigManager,
45
-        private MinifierInterface $xMinifier)
46
-    {}
44
+public function __construct(private ConfigManager $xConfigManager,
45
+private MinifierInterface $xMinifier)
46
+{}
47 47
 
48
-    /**
48
+/**
49 49
      * @return ConfigManager
50 50
      */
51
-    protected function config(): ConfigManager
52
-    {
53
-        return $this->xConfigManager;
54
-    }
51
+protected function config(): ConfigManager
52
+{
53
+return $this->xConfigManager;
54
+}
55 55
 
56
-    /**
56
+/**
57 57
      * Get app js options
58 58
      *
59 59
      * @return string
60 60
      */
61
-    public function getJsOptions(): string
62
-    {
63
-        return $this->getLibOption('js.app.options', '');
64
-    }
61
+public function getJsOptions(): string
62
+{
63
+return $this->getLibOption('js.app.options', '');
64
+}
65 65
 
66
-    /**
66
+/**
67 67
      * Check if the assets of this plugin shall be included in Jaxon generated code.
68 68
      *
69 69
      * @param AbstractPlugin $xPlugin
70 70
      *
71 71
      * @return bool
72 72
      */
73
-    public function shallIncludeAssets(AbstractPlugin $xPlugin): bool
74
-    {
75
-        $sPluginOptionName = 'assets.include.' . $xPlugin->getName();
76
-        if($this->hasLibOption($sPluginOptionName))
77
-        {
78
-            return $this->getLibOption($sPluginOptionName);
79
-        }
80
-        return $this->getLibOption('assets.include.all', true);
81
-    }
82
-
83
-    /**
73
+public function shallIncludeAssets(AbstractPlugin $xPlugin): bool
74
+{
75
+$sPluginOptionName = 'assets.include.' . $xPlugin->getName();
76
+if($this->hasLibOption($sPluginOptionName))
77
+{
78
+return $this->getLibOption($sPluginOptionName);
79
+}
80
+return $this->getLibOption('assets.include.all', true);
81
+}
82
+
83
+/**
84 84
      * Get the HTML tags to include Jaxon javascript files into the page
85 85
      *
86 86
      * @return array
87 87
      */
88
-    public function getJsLibFiles(): array
89
-    {
90
-        $sJsExtension = $this->getLibOption('js.app.minify') ? '.min.js' : '.js';
91
-        // The URI for the javascript library files
92
-        $sJsLibUri = $this->getLibOption('js.lib.uri', self::JS_LIB_URL);
93
-        $sJsLibUri = rtrim($sJsLibUri, '/');
94
-
95
-        // Add component files to the javascript file array;
96
-        $aJsFiles = [
97
-            $this->getLibOption('js.lib.jq', "$sJsLibUri/libs/chibi/chibi$sJsExtension"),
98
-            "$sJsLibUri/jaxon.core$sJsExtension",
99
-        ];
100
-        if($this->getLibOption('core.debug.on'))
101
-        {
102
-            $sLanguage = $this->getLibOption('core.language');
103
-            $aJsFiles[] = "$sJsLibUri/jaxon.debug$sJsExtension";
104
-            $aJsFiles[] = "$sJsLibUri/lang/jaxon.$sLanguage$sJsExtension";
105
-        }
106
-
107
-        return $aJsFiles;
108
-    }
109
-
110
-    /**
88
+public function getJsLibFiles(): array
89
+{
90
+$sJsExtension = $this->getLibOption('js.app.minify') ? '.min.js' : '.js';
91
+// The URI for the javascript library files
92
+$sJsLibUri = $this->getLibOption('js.lib.uri', self::JS_LIB_URL);
93
+$sJsLibUri = rtrim($sJsLibUri, '/');
94
+
95
+// Add component files to the javascript file array;
96
+$aJsFiles = [
97
+$this->getLibOption('js.lib.jq', "$sJsLibUri/libs/chibi/chibi$sJsExtension"),
98
+"$sJsLibUri/jaxon.core$sJsExtension",
99
+];
100
+if($this->getLibOption('core.debug.on'))
101
+{
102
+$sLanguage = $this->getLibOption('core.language');
103
+$aJsFiles[] = "$sJsLibUri/jaxon.debug$sJsExtension";
104
+$aJsFiles[] = "$sJsLibUri/lang/jaxon.$sLanguage$sJsExtension";
105
+}
106
+
107
+return $aJsFiles;
108
+}
109
+
110
+/**
111 111
      * Get the javascript file name
112 112
      *
113 113
      * @return bool
114 114
      */
115
-    public function shallCreateJsFiles(): bool
116
-    {
117
-        // Check config options
118
-        // - The js.app.export option must be set to true
119
-        // - The js.app.uri and js.app.dir options must be set to non null values
120
-        if(!$this->getLibOption('js.app.export', false) ||
121
-            !$this->getLibOption('js.app.uri') || !$this->getLibOption('js.app.dir'))
122
-        {
123
-            return false;
124
-        }
125
-        return true;
126
-    }
127
-
128
-    /**
115
+public function shallCreateJsFiles(): bool
116
+{
117
+// Check config options
118
+// - The js.app.export option must be set to true
119
+// - The js.app.uri and js.app.dir options must be set to non null values
120
+if(!$this->getLibOption('js.app.export', false) ||
121
+!$this->getLibOption('js.app.uri') || !$this->getLibOption('js.app.dir'))
122
+{
123
+return false;
124
+}
125
+return true;
126
+}
127
+
128
+/**
129 129
      * Write javascript files and return the corresponding URI
130 130
      *
131 131
      * @param CodeGenerator $xCodeGenerator
132 132
      *
133 133
      * @return string
134 134
      */
135
-    public function createJsFiles(CodeGenerator $xCodeGenerator): string
136
-    {
137
-        // Check dir access
138
-        $sJsFileName = $this->getLibOption('js.app.file') ?: $xCodeGenerator->getHash();
139
-        $sJsDirectory = rtrim($this->getLibOption('js.app.dir'), '\/') . DIRECTORY_SEPARATOR;
140
-        // - The js.app.dir must be writable
141
-        if(!$sJsFileName || !is_dir($sJsDirectory) || !is_writable($sJsDirectory))
142
-        {
143
-            return '';
144
-        }
145
-
146
-        $sJsFilePath = $sJsDirectory . $sJsFileName . '.js';
147
-        $sJsMinFilePath = $sJsDirectory . $sJsFileName . '.min.js';
148
-        $sJsFileUri = rtrim($this->getLibOption('js.app.uri'), '/') . "/$sJsFileName";
149
-
150
-        if(!is_file($sJsFilePath) &&
151
-            !@file_put_contents($sJsFilePath, $xCodeGenerator->getJsScript()))
152
-        {
153
-            return '';
154
-        }
155
-        if(!$this->getLibOption('js.app.minify', false))
156
-        {
157
-            return $sJsFileUri . '.js';
158
-        }
159
-        if(!is_file($sJsMinFilePath) &&
160
-            !$this->xMinifier->minify($sJsFilePath, $sJsMinFilePath))
161
-        {
162
-            // If the file cannot be minified, return the plain js file.
163
-            return $sJsFileUri . '.js';
164
-        }
165
-        return $sJsFileUri . '.min.js';
166
-    }
135
+public function createJsFiles(CodeGenerator $xCodeGenerator): string
136
+{
137
+// Check dir access
138
+$sJsFileName = $this->getLibOption('js.app.file') ?: $xCodeGenerator->getHash();
139
+$sJsDirectory = rtrim($this->getLibOption('js.app.dir'), '\/') . DIRECTORY_SEPARATOR;
140
+// - The js.app.dir must be writable
141
+if(!$sJsFileName || !is_dir($sJsDirectory) || !is_writable($sJsDirectory))
142
+{
143
+return '';
144
+}
145
+
146
+$sJsFilePath = $sJsDirectory . $sJsFileName . '.js';
147
+$sJsMinFilePath = $sJsDirectory . $sJsFileName . '.min.js';
148
+$sJsFileUri = rtrim($this->getLibOption('js.app.uri'), '/') . "/$sJsFileName";
149
+
150
+if(!is_file($sJsFilePath) &&
151
+!@file_put_contents($sJsFilePath, $xCodeGenerator->getJsScript()))
152
+{
153
+return '';
154
+}
155
+if(!$this->getLibOption('js.app.minify', false))
156
+{
157
+return $sJsFileUri . '.js';
158
+}
159
+if(!is_file($sJsMinFilePath) &&
160
+!$this->xMinifier->minify($sJsFilePath, $sJsMinFilePath))
161
+{
162
+// If the file cannot be minified, return the plain js file.
163
+return $sJsFileUri . '.js';
164
+}
165
+return $sJsFileUri . '.min.js';
166
+}
167 167
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Code/CodeGenerator.php 1 patch
Switch Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -31,75 +31,75 @@  discard block
 block discarded – undo
31 31
 
32 32
 class CodeGenerator
33 33
 {
34
-    /**
34
+/**
35 35
      * @var AssetManager
36 36
      */
37
-    private $xAssetManager;
37
+private $xAssetManager;
38 38
 
39
-    /**
39
+/**
40 40
      * The classes that generate code
41 41
      *
42 42
      * @var array<string>
43 43
      */
44
-    protected $aCodeGenerators = [];
44
+protected $aCodeGenerators = [];
45 45
 
46
-    /**
46
+/**
47 47
      * @var string
48 48
      */
49
-    protected $sJsOptions;
49
+protected $sJsOptions;
50 50
 
51
-    /**
51
+/**
52 52
      * @var array
53 53
      */
54
-    protected $aCss = [];
54
+protected $aCss = [];
55 55
 
56
-    /**
56
+/**
57 57
      * @var array
58 58
      */
59
-    protected $aJs = [];
59
+protected $aJs = [];
60 60
 
61
-    /**
61
+/**
62 62
      * @var array
63 63
      */
64
-    protected $aCodeJs = [];
64
+protected $aCodeJs = [];
65 65
 
66
-    /**
66
+/**
67 67
      * @var array
68 68
      */
69
-    protected $aCodeJsBefore = [];
69
+protected $aCodeJsBefore = [];
70 70
 
71
-    /**
71
+/**
72 72
      * @var array
73 73
      */
74
-    protected $aCodeJsAfter = [];
74
+protected $aCodeJsAfter = [];
75 75
 
76
-    /**
76
+/**
77 77
      * @var array
78 78
      */
79
-    protected $aCodeJsFiles = [];
79
+protected $aCodeJsFiles = [];
80 80
 
81
-    /**
81
+/**
82 82
      * @var bool
83 83
      */
84
-    protected $bGenerated = false;
84
+protected $bGenerated = false;
85 85
 
86
-    /**
86
+/**
87 87
      * The constructor
88 88
      *
89 89
      * @param string $sVersion
90 90
      * @param Container $di
91 91
      * @param TemplateEngine $xTemplateEngine
92 92
      */
93
-    public function __construct(private string $sVersion, private Container $di,
94
-        private TemplateEngine $xTemplateEngine)
95
-    {
96
-        // The Jaxon library config is on top.
97
-        $this->addCodeGenerator(ConfigScriptGenerator::class, 0);
98
-        // The ready script comes after.
99
-        $this->addCodeGenerator(ReadyScriptGenerator::class, 200);
100
-    }
101
-
102
-    /**
93
+public function __construct(private string $sVersion, private Container $di,
94
+private TemplateEngine $xTemplateEngine)
95
+{
96
+// The Jaxon library config is on top.
97
+$this->addCodeGenerator(ConfigScriptGenerator::class, 0);
98
+// The ready script comes after.
99
+$this->addCodeGenerator(ReadyScriptGenerator::class, 200);
100
+}
101
+
102
+/**
103 103
      * Add a code generator to the list
104 104
      *
105 105
      * @param string $sClassName    The code generator class
@@ -107,39 +107,39 @@  discard block
 block discarded – undo
107 107
      *
108 108
      * @return void
109 109
      */
110
-    public function addCodeGenerator(string $sClassName, int $nPriority): void
111
-    {
112
-        while(isset($this->aCodeGenerators[$nPriority]))
113
-        {
114
-            $nPriority++;
115
-        }
116
-        $this->aCodeGenerators[$nPriority] = $sClassName;
117
-    }
118
-
119
-    /**
110
+public function addCodeGenerator(string $sClassName, int $nPriority): void
111
+{
112
+while(isset($this->aCodeGenerators[$nPriority]))
113
+{
114
+$nPriority++;
115
+}
116
+$this->aCodeGenerators[$nPriority] = $sClassName;
117
+}
118
+
119
+/**
120 120
      * @param string $sClassName
121 121
      *
122 122
      * @return CodeGeneratorInterface
123 123
      */
124
-    private function getCodeGenerator(string $sClassName): CodeGeneratorInterface
125
-    {
126
-        return $this->di->g($sClassName);
127
-    }
124
+private function getCodeGenerator(string $sClassName): CodeGeneratorInterface
125
+{
126
+return $this->di->g($sClassName);
127
+}
128 128
 
129
-    /**
129
+/**
130 130
      * Generate a hash for all the javascript code generated by the library
131 131
      *
132 132
      * @return string
133 133
      */
134
-    public function getHash(): string
135
-    {
136
-        $aHashes = array_map(fn($sClassName) =>
137
-            $this->getCodeGenerator($sClassName)->getHash(), $this->aCodeGenerators);
138
-        $aHashes[] = $this->sVersion;
139
-        return md5(implode('', $aHashes));
140
-    }
141
-
142
-    /**
134
+public function getHash(): string
135
+{
136
+$aHashes = array_map(fn($sClassName) =>
137
+$this->getCodeGenerator($sClassName)->getHash(), $this->aCodeGenerators);
138
+$aHashes[] = $this->sVersion;
139
+return md5(implode('', $aHashes));
140
+}
141
+
142
+/**
143 143
      * Render a template in the 'plugins' subdir
144 144
      *
145 145
      * @param string $sTemplate    The template filename
@@ -147,185 +147,185 @@  discard block
 block discarded – undo
147 147
      *
148 148
      * @return string
149 149
      */
150
-    private function render(string $sTemplate, array $aVars = []): string
151
-    {
152
-        $aVars['sJsOptions'] = $this->sJsOptions;
153
-        return $this->xTemplateEngine->render("jaxon::plugins/$sTemplate", $aVars);
154
-    }
150
+private function render(string $sTemplate, array $aVars = []): string
151
+{
152
+$aVars['sJsOptions'] = $this->sJsOptions;
153
+return $this->xTemplateEngine->render("jaxon::plugins/$sTemplate", $aVars);
154
+}
155 155
 
156
-    /**
156
+/**
157 157
      * Generate the Jaxon CSS and js codes for a given plugin
158 158
      *
159 159
      * @param CodeGeneratorInterface $xGenerator
160 160
      *
161 161
      * @return void
162 162
      */
163
-    private function generatePluginCodes(CodeGeneratorInterface $xGenerator): void
164
-    {
165
-        if(!is_subclass_of($xGenerator, AbstractPlugin::class) ||
166
-            $this->xAssetManager->shallIncludeAssets($xGenerator))
167
-        {
168
-            // HTML tags for CSS
169
-            if(($sCss = trim($xGenerator->getCss(), " \n")) !== '')
170
-            {
171
-                $this->aCss[] = $sCss;
172
-            }
173
-            // HTML tags for js
174
-            if(($sJs = trim($xGenerator->getJs(), " \n")) !== '')
175
-            {
176
-                $this->aJs[] = $sJs;
177
-            }
178
-        }
179
-
180
-        // Additional js codes
181
-        if(($xJsCode = $xGenerator->getJsCode()) !== null)
182
-        {
183
-            if(($sJs = trim($xJsCode->sJs, " \n")) !== '')
184
-            {
185
-                $this->aCodeJs[] = $sJs;
186
-            }
187
-            if(($sJsBefore = trim($xJsCode->sJsBefore, " \n")) !== '')
188
-            {
189
-                $this->aCodeJsBefore[] = $sJsBefore;
190
-            }
191
-            if(($sJsAfter = trim($xJsCode->sJsAfter, " \n")) !== '')
192
-            {
193
-                $this->aCodeJsAfter[] = $sJsAfter;
194
-            }
195
-            $this->aCodeJsFiles = array_merge($this->aCodeJsFiles, $xJsCode->aFiles);
196
-        }
197
-    }
198
-
199
-    /**
163
+private function generatePluginCodes(CodeGeneratorInterface $xGenerator): void
164
+{
165
+if(!is_subclass_of($xGenerator, AbstractPlugin::class) ||
166
+$this->xAssetManager->shallIncludeAssets($xGenerator))
167
+{
168
+// HTML tags for CSS
169
+if(($sCss = trim($xGenerator->getCss(), " \n")) !== '')
170
+{
171
+    $this->aCss[] = $sCss;
172
+}
173
+// HTML tags for js
174
+if(($sJs = trim($xGenerator->getJs(), " \n")) !== '')
175
+{
176
+    $this->aJs[] = $sJs;
177
+}
178
+}
179
+
180
+// Additional js codes
181
+if(($xJsCode = $xGenerator->getJsCode()) !== null)
182
+{
183
+if(($sJs = trim($xJsCode->sJs, " \n")) !== '')
184
+{
185
+    $this->aCodeJs[] = $sJs;
186
+}
187
+if(($sJsBefore = trim($xJsCode->sJsBefore, " \n")) !== '')
188
+{
189
+    $this->aCodeJsBefore[] = $sJsBefore;
190
+}
191
+if(($sJsAfter = trim($xJsCode->sJsAfter, " \n")) !== '')
192
+{
193
+    $this->aCodeJsAfter[] = $sJsAfter;
194
+}
195
+$this->aCodeJsFiles = array_merge($this->aCodeJsFiles, $xJsCode->aFiles);
196
+}
197
+}
198
+
199
+/**
200 200
      * Generate the Jaxon CSS ans js codes
201 201
      *
202 202
      * @return void
203 203
      * @throws UriException
204 204
      */
205
-    private function generateCodes(): void
206
-    {
207
-        if($this->bGenerated)
208
-        {
209
-            return;
210
-        }
211
-
212
-        // We need the library to have been bootstrapped.
213
-        $this->di->getBootstrap()->onBoot();
214
-
215
-        // Sort the code generators by ascending priority
216
-        ksort($this->aCodeGenerators);
217
-
218
-        // Cannot be injected because of dependency loop.
219
-        $this->xAssetManager = $this->di->getAssetManager();
220
-
221
-        $this->sJsOptions = $this->xAssetManager->getJsOptions();
222
-        foreach($this->aCodeGenerators as $sClassName)
223
-        {
224
-            $this->generatePluginCodes($this->getCodeGenerator($sClassName));
225
-        }
226
-
227
-        // Load the Jaxon lib js files, after the other libs js files.
228
-        $this->aJs[] = trim($this->render('includes.js', [
229
-            'aUrls' => $this->xAssetManager->getJsLibFiles(),
230
-        ]));
231
-
232
-        // The codes are already generated.
233
-        $this->bGenerated = true;
234
-    }
235
-
236
-    /**
205
+private function generateCodes(): void
206
+{
207
+if($this->bGenerated)
208
+{
209
+return;
210
+}
211
+
212
+// We need the library to have been bootstrapped.
213
+$this->di->getBootstrap()->onBoot();
214
+
215
+// Sort the code generators by ascending priority
216
+ksort($this->aCodeGenerators);
217
+
218
+// Cannot be injected because of dependency loop.
219
+$this->xAssetManager = $this->di->getAssetManager();
220
+
221
+$this->sJsOptions = $this->xAssetManager->getJsOptions();
222
+foreach($this->aCodeGenerators as $sClassName)
223
+{
224
+$this->generatePluginCodes($this->getCodeGenerator($sClassName));
225
+}
226
+
227
+// Load the Jaxon lib js files, after the other libs js files.
228
+$this->aJs[] = trim($this->render('includes.js', [
229
+'aUrls' => $this->xAssetManager->getJsLibFiles(),
230
+]));
231
+
232
+// The codes are already generated.
233
+$this->bGenerated = true;
234
+}
235
+
236
+/**
237 237
      * Get the HTML tags to include Jaxon CSS code and files into the page
238 238
      *
239 239
      * @return string
240 240
      * @throws UriException
241 241
      */
242
-    public function getCss(): string
243
-    {
244
-        $this->generateCodes();
245
-        return implode("\n\n", $this->aCss);
246
-    }
242
+public function getCss(): string
243
+{
244
+$this->generateCodes();
245
+return implode("\n\n", $this->aCss);
246
+}
247 247
 
248
-    /**
248
+/**
249 249
      * Get the HTML tags to include Jaxon javascript files into the page
250 250
      *
251 251
      * @return string
252 252
      * @throws UriException
253 253
      */
254
-    public function getJs(): string
255
-    {
256
-        $this->generateCodes();
257
-        return implode("\n\n", $this->aJs);
258
-    }
254
+public function getJs(): string
255
+{
256
+$this->generateCodes();
257
+return implode("\n\n", $this->aJs);
258
+}
259 259
 
260
-    /**
260
+/**
261 261
      * Get the Javascript code
262 262
      *
263 263
      * @return string
264 264
      */
265
-    public function getJsScript(): string
266
-    {
267
-        $aJsScripts = [];
268
-        foreach($this->aCodeGenerators as $sClassName)
269
-        {
270
-            $xGenerator = $this->getCodeGenerator($sClassName);
271
-            // Javascript code
272
-            if(($sJsScript = trim($xGenerator->getScript(), " \n")) !== '')
273
-            {
274
-                $aJsScripts[] = $sJsScript;
275
-            }
276
-        }
277
-        return implode("\n\n", $aJsScripts);
278
-    }
279
-
280
-    /**
265
+public function getJsScript(): string
266
+{
267
+$aJsScripts = [];
268
+foreach($this->aCodeGenerators as $sClassName)
269
+{
270
+$xGenerator = $this->getCodeGenerator($sClassName);
271
+// Javascript code
272
+if(($sJsScript = trim($xGenerator->getScript(), " \n")) !== '')
273
+{
274
+    $aJsScripts[] = $sJsScript;
275
+}
276
+}
277
+return implode("\n\n", $aJsScripts);
278
+}
279
+
280
+/**
281 281
      * @param bool $bIncludeJs Also get the JS files
282 282
      * @param bool $bIncludeCss Also get the CSS files
283 283
      *
284 284
      * @return array<string>
285 285
      */
286
-    private function renderCodes(bool $bIncludeJs, bool $bIncludeCss): array
287
-    {
288
-        $aCodes = [];
289
-        if($bIncludeCss)
290
-        {
291
-            $aCodes[] = $this->getCss();
292
-        }
293
-        if($bIncludeJs)
294
-        {
295
-            $aCodes[] = $this->getJs();
296
-        }
297
-
298
-        $sUrl = !$this->xAssetManager->shallCreateJsFiles() ? '' :
299
-            $this->xAssetManager->createJsFiles($this);
300
-        // Wrap the js code into the corresponding HTML tag.
301
-        $aCodes[] = $sUrl !== '' ?
302
-            $this->render('include.js', ['sUrl' => $sUrl]) :
303
-            $this->render('wrapper.js', ['sScript' => $this->getJsScript()]);
304
-
305
-        // Wrap the js codes into HTML tags.
306
-        if(count($this->aCodeJsBefore) > 0)
307
-        {
308
-            $sScript = implode("\n\n", $this->aCodeJsBefore);
309
-            $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]);
310
-        }
311
-        if(count($this->aCodeJs) > 0)
312
-        {
313
-            $sScript = implode("\n\n", $this->aCodeJs);
314
-            $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]);
315
-        }
316
-        if(count($this->aCodeJsFiles) > 0)
317
-        {
318
-            $aCodes[] = $this->render('includes.js', ['aUrls' => $this->aCodeJsFiles]);
319
-        }
320
-        if(count($this->aCodeJsAfter) > 0)
321
-        {
322
-            $sScript = implode("\n\n", $this->aCodeJsAfter);
323
-            $aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]);
324
-        }
325
-        return $aCodes;
326
-    }
327
-
328
-    /**
286
+private function renderCodes(bool $bIncludeJs, bool $bIncludeCss): array
287
+{
288
+$aCodes = [];
289
+if($bIncludeCss)
290
+{
291
+$aCodes[] = $this->getCss();
292
+}
293
+if($bIncludeJs)
294
+{
295
+$aCodes[] = $this->getJs();
296
+}
297
+
298
+$sUrl = !$this->xAssetManager->shallCreateJsFiles() ? '' :
299
+$this->xAssetManager->createJsFiles($this);
300
+// Wrap the js code into the corresponding HTML tag.
301
+$aCodes[] = $sUrl !== '' ?
302
+$this->render('include.js', ['sUrl' => $sUrl]) :
303
+$this->render('wrapper.js', ['sScript' => $this->getJsScript()]);
304
+
305
+// Wrap the js codes into HTML tags.
306
+if(count($this->aCodeJsBefore) > 0)
307
+{
308
+$sScript = implode("\n\n", $this->aCodeJsBefore);
309
+$aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]);
310
+}
311
+if(count($this->aCodeJs) > 0)
312
+{
313
+$sScript = implode("\n\n", $this->aCodeJs);
314
+$aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]);
315
+}
316
+if(count($this->aCodeJsFiles) > 0)
317
+{
318
+$aCodes[] = $this->render('includes.js', ['aUrls' => $this->aCodeJsFiles]);
319
+}
320
+if(count($this->aCodeJsAfter) > 0)
321
+{
322
+$sScript = implode("\n\n", $this->aCodeJsAfter);
323
+$aCodes[] = $this->render('wrapper.js', ['sScript' => $sScript]);
324
+}
325
+return $aCodes;
326
+}
327
+
328
+/**
329 329
      * Get the javascript code to be sent to the browser
330 330
      *
331 331
      * @param bool $bIncludeJs Also get the JS files
@@ -334,10 +334,10 @@  discard block
 block discarded – undo
334 334
      * @return string
335 335
      * @throws UriException
336 336
      */
337
-    public function getScript(bool $bIncludeJs, bool $bIncludeCss): string
338
-    {
339
-        $this->generateCodes();
340
-        $aCodes = $this->renderCodes($bIncludeJs, $bIncludeCss);
341
-        return implode("\n\n", $aCodes);
342
-    }
337
+public function getScript(bool $bIncludeJs, bool $bIncludeCss): string
338
+{
339
+$this->generateCodes();
340
+$aCodes = $this->renderCodes($bIncludeJs, $bIncludeCss);
341
+return implode("\n\n", $aCodes);
342
+}
343 343
 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Request/CallableClass/CallableClassPlugin.php 1 patch
Switch Indentation   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -46,17 +46,17 @@  discard block
 block discarded – undo
46 46
 
47 47
 class CallableClassPlugin extends AbstractRequestPlugin
48 48
 {
49
-    /**
49
+/**
50 50
      * @var array<CallableObject>
51 51
      */
52
-    private array $aCallableObjects = [];
52
+private array $aCallableObjects = [];
53 53
 
54
-    /**
54
+/**
55 55
      * @var array<string>
56 56
      */
57
-    private array $aCallableNames = [];
57
+private array $aCallableNames = [];
58 58
 
59
-    /**
59
+/**
60 60
      * The class constructor
61 61
      *
62 62
      * @param string $sPrefix
@@ -67,150 +67,150 @@  discard block
 block discarded – undo
67 67
      * @param TemplateEngine $xTemplateEngine
68 68
      * @param Validator $xValidator
69 69
      */
70
-    public function __construct(private string $sPrefix,
71
-        private LoggerInterface $xLogger, private ComponentContainer $cdi,
72
-        private ComponentRegistry $xRegistry, private Translator $xTranslator,
73
-        private TemplateEngine $xTemplateEngine, private Validator $xValidator)
74
-    {}
70
+public function __construct(private string $sPrefix,
71
+private LoggerInterface $xLogger, private ComponentContainer $cdi,
72
+private ComponentRegistry $xRegistry, private Translator $xTranslator,
73
+private TemplateEngine $xTemplateEngine, private Validator $xValidator)
74
+{}
75 75
 
76
-    /**
76
+/**
77 77
      * @inheritDoc
78 78
      */
79
-    public function getName(): string
80
-    {
81
-        return Jaxon::CALLABLE_CLASS;
82
-    }
79
+public function getName(): string
80
+{
81
+return Jaxon::CALLABLE_CLASS;
82
+}
83 83
 
84
-    /**
84
+/**
85 85
      * @inheritDoc
86 86
      * @throws SetupException
87 87
      */
88
-    public function checkOptions(string $sCallable, $xOptions): array
89
-    {
90
-        if(!$this->xValidator->validateClass(trim($sCallable)))
91
-        {
92
-            throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration'));
93
-        }
94
-        if(is_string($xOptions))
95
-        {
96
-            $xOptions = ['include' => $xOptions];
97
-        }
98
-        elseif(!is_array($xOptions))
99
-        {
100
-            throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration'));
101
-        }
102
-        return $xOptions;
103
-    }
104
-
105
-    /**
88
+public function checkOptions(string $sCallable, $xOptions): array
89
+{
90
+if(!$this->xValidator->validateClass(trim($sCallable)))
91
+{
92
+throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration'));
93
+}
94
+if(is_string($xOptions))
95
+{
96
+$xOptions = ['include' => $xOptions];
97
+}
98
+elseif(!is_array($xOptions))
99
+{
100
+throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration'));
101
+}
102
+return $xOptions;
103
+}
104
+
105
+/**
106 106
      * @inheritDoc
107 107
      */
108
-    public function register(string $sType, string $sCallable, array $aOptions): bool
109
-    {
110
-        $sClassName = trim($sCallable);
111
-        $this->xRegistry->registerComponent($sClassName, $aOptions);
112
-        return true;
113
-    }
114
-
115
-    /**
108
+public function register(string $sType, string $sCallable, array $aOptions): bool
109
+{
110
+$sClassName = trim($sCallable);
111
+$this->xRegistry->registerComponent($sClassName, $aOptions);
112
+return true;
113
+}
114
+
115
+/**
116 116
      * @inheritDoc
117 117
      * @throws SetupException
118 118
      */
119
-    public function getCallable(string $sCallable): CallableObject|null
120
-    {
121
-        return $this->cdi->makeCallableObject($sCallable);
122
-    }
119
+public function getCallable(string $sCallable): CallableObject|null
120
+{
121
+return $this->cdi->makeCallableObject($sCallable);
122
+}
123 123
 
124
-    /**
124
+/**
125 125
      * @inheritDoc
126 126
      */
127
-    public function getHash(): string
128
-    {
129
-        $this->xRegistry->registerAllComponents();
130
-        return md5($this->xRegistry->getHash());
131
-    }
127
+public function getHash(): string
128
+{
129
+$this->xRegistry->registerAllComponents();
130
+return md5($this->xRegistry->getHash());
131
+}
132 132
 
133
-    /**
133
+/**
134 134
      * Add a callable object to the script generator
135 135
      *
136 136
      * @param CallableObject $xCallableObject
137 137
      *
138 138
      * @return void
139 139
      */
140
-    private function addCallable(CallableObject $xCallableObject): void
141
-    {
142
-        $aCallableMethods = $xCallableObject->getCallableMethods();
143
-        if($xCallableObject->excluded() || count($aCallableMethods) === 0)
144
-        {
145
-            return;
146
-        }
147
-
148
-        $aCallableObject = &$this->aCallableObjects;
149
-        $sJsName = $xCallableObject->getJsName();
150
-        foreach(explode('.', $sJsName) as $sName)
151
-        {
152
-            if(!isset($aCallableObject['children'][$sName]))
153
-            {
154
-                $aCallableObject['children'][$sName] = [];
155
-            }
156
-            $aCallableObject = &$aCallableObject['children'][$sName];
157
-        }
158
-
159
-        $aCallableObject['methods'] = $aCallableMethods;
160
-        $aCallableObject['index'] = count($this->aCallableNames);
161
-        $this->aCallableNames[] = $sJsName;
162
-    }
163
-
164
-    /**
140
+private function addCallable(CallableObject $xCallableObject): void
141
+{
142
+$aCallableMethods = $xCallableObject->getCallableMethods();
143
+if($xCallableObject->excluded() || count($aCallableMethods) === 0)
144
+{
145
+return;
146
+}
147
+
148
+$aCallableObject = &$this->aCallableObjects;
149
+$sJsName = $xCallableObject->getJsName();
150
+foreach(explode('.', $sJsName) as $sName)
151
+{
152
+if(!isset($aCallableObject['children'][$sName]))
153
+{
154
+    $aCallableObject['children'][$sName] = [];
155
+}
156
+$aCallableObject = &$aCallableObject['children'][$sName];
157
+}
158
+
159
+$aCallableObject['methods'] = $aCallableMethods;
160
+$aCallableObject['index'] = count($this->aCallableNames);
161
+$this->aCallableNames[] = $sJsName;
162
+}
163
+
164
+/**
165 165
      * @param string $sIndent
166 166
      * @param array $aTemplateVars
167 167
      *
168 168
      * @return string
169 169
      */
170
-    private function renderMethod(string $sIndent, array $aTemplateVars): string
171
-    {
172
-        $aOptions = [];
173
-        foreach($aTemplateVars['aMethod']['options'] as $sKey => $sValue)
174
-        {
175
-            $aOptions[] = "$sKey: $sValue";
176
-        }
177
-        $aTemplateVars['sArguments'] = count($aOptions) === 0 ? 'args' :
178
-            'args, { ' . implode(', ', $aOptions) . ' }';
179
-
180
-        return $sIndent . trim($this->xTemplateEngine
181
-            ->render('jaxon::callables/method.js', $aTemplateVars));
182
-    }
183
-
184
-    /**
170
+private function renderMethod(string $sIndent, array $aTemplateVars): string
171
+{
172
+$aOptions = [];
173
+foreach($aTemplateVars['aMethod']['options'] as $sKey => $sValue)
174
+{
175
+$aOptions[] = "$sKey: $sValue";
176
+}
177
+$aTemplateVars['sArguments'] = count($aOptions) === 0 ? 'args' :
178
+'args, { ' . implode(', ', $aOptions) . ' }';
179
+
180
+return $sIndent . trim($this->xTemplateEngine
181
+->render('jaxon::callables/method.js', $aTemplateVars));
182
+}
183
+
184
+/**
185 185
      * @param string $sJsClass
186 186
      * @param array $aCallable
187 187
      * @param int $nIndent
188 188
      *
189 189
      * @return string
190 190
      */
191
-    private function renderCallable(string $sJsClass, array $aCallable, int $nIndent): string
192
-    {
193
-        $nIndent += 2; // Indentation.
194
-        $sIndent = str_repeat(' ', $nIndent);
195
-
196
-        $fMethodCallback = fn($aMethod) => $this->renderMethod($sIndent, [
197
-            'aMethod' => $aMethod,
198
-            'nIndex' => $aCallable['index'] ?? 0,
199
-        ]);
200
-        $aMethods = !isset($aCallable['methods']) ? [] :
201
-            array_map($fMethodCallback, $aCallable['methods']);
202
-
203
-        $aChildren = [];
204
-        foreach($aCallable['children'] ?? [] as $sName => $aChild)
205
-        {
206
-            $aChildren[] = $this->renderChild("$sName:", "$sJsClass.$sName",
207
-                $aChild, $nIndent) . ',';
208
-        }
209
-
210
-        return implode("\n", array_merge($aMethods, $aChildren));
211
-    }
212
-
213
-    /**
191
+private function renderCallable(string $sJsClass, array $aCallable, int $nIndent): string
192
+{
193
+$nIndent += 2; // Indentation.
194
+$sIndent = str_repeat(' ', $nIndent);
195
+
196
+$fMethodCallback = fn($aMethod) => $this->renderMethod($sIndent, [
197
+'aMethod' => $aMethod,
198
+'nIndex' => $aCallable['index'] ?? 0,
199
+]);
200
+$aMethods = !isset($aCallable['methods']) ? [] :
201
+array_map($fMethodCallback, $aCallable['methods']);
202
+
203
+$aChildren = [];
204
+foreach($aCallable['children'] ?? [] as $sName => $aChild)
205
+{
206
+$aChildren[] = $this->renderChild("$sName:", "$sJsClass.$sName",
207
+    $aChild, $nIndent) . ',';
208
+}
209
+
210
+return implode("\n", array_merge($aMethods, $aChildren));
211
+}
212
+
213
+/**
214 214
      * @param string $sJsVar
215 215
      * @param string $sJsClass
216 216
      * @param array $aCallable
@@ -218,70 +218,70 @@  discard block
 block discarded – undo
218 218
      *
219 219
      * @return string
220 220
      */
221
-    private function renderChild(string $sJsVar, string $sJsClass,
222
-        array $aCallable, int $nIndent = 0): string
223
-    {
224
-        $sIndent = str_repeat(' ', $nIndent);
225
-        $sScript = $this->renderCallable($sJsClass, $aCallable, $nIndent);
221
+private function renderChild(string $sJsVar, string $sJsClass,
222
+array $aCallable, int $nIndent = 0): string
223
+{
224
+$sIndent = str_repeat(' ', $nIndent);
225
+$sScript = $this->renderCallable($sJsClass, $aCallable, $nIndent);
226 226
 
227
-        return <<<CODE
227
+return <<<CODE
228 228
 $sIndent$sJsVar {
229 229
 $sScript
230 230
 $sIndent}
231 231
 CODE;
232
-    }
232
+}
233 233
 
234
-    /**
234
+/**
235 235
      * Generate client side javascript code for the registered callable objects
236 236
      *
237 237
      * @return string
238 238
      * @throws SetupException
239 239
      */
240
-    public function getScript(): string
241
-    {
242
-        $this->xRegistry->registerAllComponents();
243
-
244
-        $this->aCallableNames = [];
245
-        $this->aCallableObjects = ['children' => []];
246
-        foreach($this->cdi->getCallableObjects() as $xCallableObject)
247
-        {
248
-            $this->addCallable($xCallableObject);
249
-        }
250
-
251
-        $aScripts = [
252
-            $this->xTemplateEngine ->render('jaxon::callables/objects.js', [
253
-                'aCallableNames' => $this->aCallableNames,
254
-            ])
255
-        ];
256
-        foreach($this->aCallableObjects['children'] as $sJsClass => $aCallable)
257
-        {
258
-            $aScripts[] = $this->renderChild("{$this->sPrefix}$sJsClass =",
259
-                $sJsClass, $aCallable) . ';';
260
-        }
261
-        return implode("\n", $aScripts) . "\n";
262
-    }
263
-
264
-    /**
240
+public function getScript(): string
241
+{
242
+$this->xRegistry->registerAllComponents();
243
+
244
+$this->aCallableNames = [];
245
+$this->aCallableObjects = ['children' => []];
246
+foreach($this->cdi->getCallableObjects() as $xCallableObject)
247
+{
248
+$this->addCallable($xCallableObject);
249
+}
250
+
251
+$aScripts = [
252
+$this->xTemplateEngine ->render('jaxon::callables/objects.js', [
253
+    'aCallableNames' => $this->aCallableNames,
254
+])
255
+];
256
+foreach($this->aCallableObjects['children'] as $sJsClass => $aCallable)
257
+{
258
+$aScripts[] = $this->renderChild("{$this->sPrefix}$sJsClass =",
259
+    $sJsClass, $aCallable) . ';';
260
+}
261
+return implode("\n", $aScripts) . "\n";
262
+}
263
+
264
+/**
265 265
      * @inheritDoc
266 266
      */
267
-    public static function canProcessRequest(ServerRequestInterface $xRequest): bool
268
-    {
269
-        $aCall = $xRequest->getAttribute('jxncall');
270
-        return $aCall !== null && ($aCall['type'] ?? '') === 'class' &&
271
-            isset($aCall['name']) && isset($aCall['method']) &&
272
-            is_string($aCall['name']) && is_string($aCall['method']);
273
-    }
274
-
275
-    /**
267
+public static function canProcessRequest(ServerRequestInterface $xRequest): bool
268
+{
269
+$aCall = $xRequest->getAttribute('jxncall');
270
+return $aCall !== null && ($aCall['type'] ?? '') === 'class' &&
271
+isset($aCall['name']) && isset($aCall['method']) &&
272
+is_string($aCall['name']) && is_string($aCall['method']);
273
+}
274
+
275
+/**
276 276
      * @inheritDoc
277 277
      */
278
-    public function setTarget(ServerRequestInterface $xRequest): Target
279
-    {
280
-        $this->xTarget = Target::makeClass($xRequest->getAttribute('jxncall'));
281
-        return $this->xTarget;
282
-    }
278
+public function setTarget(ServerRequestInterface $xRequest): Target
279
+{
280
+$this->xTarget = Target::makeClass($xRequest->getAttribute('jxncall'));
281
+return $this->xTarget;
282
+}
283 283
 
284
-    /**
284
+/**
285 285
      * @param string $sExceptionMessage
286 286
      * @param string $sErrorCode
287 287
      * @param array $aErrorParams
@@ -289,53 +289,53 @@  discard block
 block discarded – undo
289 289
      * @throws RequestException
290 290
      * @return void
291 291
      */
292
-    private function throwException(string $sExceptionMessage,
293
-        string $sErrorCode, array $aErrorParams = []): void
294
-    {
295
-        $sMessage = $this->xTranslator->trans($sErrorCode, $aErrorParams) .
296
-            (!$sExceptionMessage ? '' : "\n$sExceptionMessage");
297
-        $this->xLogger->error($sMessage);
298
-        throw new RequestException($sMessage);
299
-    }
300
-
301
-    /**
292
+private function throwException(string $sExceptionMessage,
293
+string $sErrorCode, array $aErrorParams = []): void
294
+{
295
+$sMessage = $this->xTranslator->trans($sErrorCode, $aErrorParams) .
296
+(!$sExceptionMessage ? '' : "\n$sExceptionMessage");
297
+$this->xLogger->error($sMessage);
298
+throw new RequestException($sMessage);
299
+}
300
+
301
+/**
302 302
      * @inheritDoc
303 303
      * @throws RequestException
304 304
      */
305
-    public function processRequest(): void
306
-    {
307
-        $sClassName = $this->xTarget->getClassName();
308
-        $sMethodName = $this->xTarget->getMethodName();
309
-        // Will be used to print a translated error message.
310
-        $aErrorParams = ['class' => $sClassName, 'method' => $sMethodName];
311
-
312
-        if(!$this->xValidator->validateJsObject($sClassName) ||
313
-            !$this->xValidator->validateMethod($sMethodName))
314
-        {
315
-            // Unable to find the requested object or method
316
-            $this->throwException('', 'errors.objects.invalid', $aErrorParams);
317
-        }
318
-
319
-        // Call the requested method
320
-        try
321
-        {
322
-            $sError = 'errors.objects.find';
323
-            /** @var CallableObject */
324
-            $xCallableObject = $this->getCallable($sClassName);
325
-
326
-            if($xCallableObject->excluded($sMethodName))
327
-            {
328
-                // Unable to find the requested class or method
329
-                $this->throwException('', 'errors.objects.excluded', $aErrorParams);
330
-            }
331
-
332
-            $sError = 'errors.objects.call';
333
-            $xCallableObject->call($this->xTarget);
334
-        }
335
-        catch(ReflectionException|SetupException $e)
336
-        {
337
-            // Unable to execute the requested class or method
338
-            $this->throwException($e->getMessage(), $sError, $aErrorParams);
339
-        }
340
-    }
305
+public function processRequest(): void
306
+{
307
+$sClassName = $this->xTarget->getClassName();
308
+$sMethodName = $this->xTarget->getMethodName();
309
+// Will be used to print a translated error message.
310
+$aErrorParams = ['class' => $sClassName, 'method' => $sMethodName];
311
+
312
+if(!$this->xValidator->validateJsObject($sClassName) ||
313
+!$this->xValidator->validateMethod($sMethodName))
314
+{
315
+// Unable to find the requested object or method
316
+$this->throwException('', 'errors.objects.invalid', $aErrorParams);
317
+}
318
+
319
+// Call the requested method
320
+try
321
+{
322
+$sError = 'errors.objects.find';
323
+/** @var CallableObject */
324
+$xCallableObject = $this->getCallable($sClassName);
325
+
326
+if($xCallableObject->excluded($sMethodName))
327
+{
328
+    // Unable to find the requested class or method
329
+    $this->throwException('', 'errors.objects.excluded', $aErrorParams);
330
+}
331
+
332
+$sError = 'errors.objects.call';
333
+$xCallableObject->call($this->xTarget);
334
+}
335
+catch(ReflectionException|SetupException $e)
336
+{
337
+// Unable to execute the requested class or method
338
+$this->throwException($e->getMessage(), $sError, $aErrorParams);
339
+}
340
+}
341 341
 }
Please login to merge, or discard this patch.
jaxon-upload/tests/TestUpload/UploadHandlerTest.php 1 patch
Switch Indentation   +551 added lines, -551 removed lines patch added patch discarded remove patch
@@ -21,605 +21,605 @@
 block discarded – undo
21 21
 
22 22
 class UploadHandlerTest extends TestCase
23 23
 {
24
-    /**
24
+/**
25 25
      * @var string
26 26
      */
27
-    protected $sNameWhite;
27
+protected $sNameWhite;
28 28
 
29
-    /**
29
+/**
30 30
      * @var string
31 31
      */
32
-    protected $sPathWhite;
32
+protected $sPathWhite;
33 33
 
34
-    /**
34
+/**
35 35
      * @var int
36 36
      */
37
-    protected $sSizeWhite;
37
+protected $sSizeWhite;
38 38
 
39
-    /**
39
+/**
40 40
      * @var string
41 41
      */
42
-    protected $sNameBlue;
42
+protected $sNameBlue;
43 43
 
44
-    /**
44
+/**
45 45
      * @var string
46 46
      */
47
-    protected $sPathBlue;
47
+protected $sPathBlue;
48 48
 
49
-    /**
49
+/**
50 50
      * @var int
51 51
      */
52
-    protected $sSizeBlue;
52
+protected $sSizeBlue;
53 53
 
54
-    /**
54
+/**
55 55
      * @throws SetupException
56 56
      */
57
-    public function setUp(): void
58
-    {
59
-        jaxon()->di()->getPluginManager()->registerPlugins();
60
-        _register();
61
-        jaxon()->setOption('core.upload.enabled', true);
62
-        jaxon()->setOption('core.response.send', false);
63
-
64
-        $tmpDir = __DIR__ . '/../upload/tmp';
65
-        @mkdir($tmpDir);
66
-
67
-        $sSrcWhite = __DIR__ . '/../upload/src/white.png';
68
-        $this->sNameWhite = 'white.png';
69
-        $this->sPathWhite = "$tmpDir/{$this->sNameWhite}";
70
-        $this->sSizeWhite = filesize($sSrcWhite);
71
-        // Copy the file to the temp dir.
72
-        @copy($sSrcWhite, $this->sPathWhite);
73
-
74
-        $sSrcBlue = __DIR__ . '/../upload/src/blue.png';
75
-        $this->sNameBlue = 'blue.png';
76
-        $this->sPathBlue = "$tmpDir/{$this->sNameBlue}";
77
-        $this->sSizeBlue = filesize($sSrcBlue);
78
-        // Copy the file to the temp dir.
79
-        @copy($sSrcBlue, $this->sPathBlue);
80
-
81
-        jaxon()->register(Jaxon::CALLABLE_CLASS, 'SampleUpload', __DIR__ . '/../src/sample.php');
82
-        jaxon()->di()->getBootstrap()->onBoot();
83
-    }
84
-
85
-    /**
57
+public function setUp(): void
58
+{
59
+jaxon()->di()->getPluginManager()->registerPlugins();
60
+_register();
61
+jaxon()->setOption('core.upload.enabled', true);
62
+jaxon()->setOption('core.response.send', false);
63
+
64
+$tmpDir = __DIR__ . '/../upload/tmp';
65
+@mkdir($tmpDir);
66
+
67
+$sSrcWhite = __DIR__ . '/../upload/src/white.png';
68
+$this->sNameWhite = 'white.png';
69
+$this->sPathWhite = "$tmpDir/{$this->sNameWhite}";
70
+$this->sSizeWhite = filesize($sSrcWhite);
71
+// Copy the file to the temp dir.
72
+@copy($sSrcWhite, $this->sPathWhite);
73
+
74
+$sSrcBlue = __DIR__ . '/../upload/src/blue.png';
75
+$this->sNameBlue = 'blue.png';
76
+$this->sPathBlue = "$tmpDir/{$this->sNameBlue}";
77
+$this->sSizeBlue = filesize($sSrcBlue);
78
+// Copy the file to the temp dir.
79
+@copy($sSrcBlue, $this->sPathBlue);
80
+
81
+jaxon()->register(Jaxon::CALLABLE_CLASS, 'SampleUpload', __DIR__ . '/../src/sample.php');
82
+jaxon()->di()->getBootstrap()->onBoot();
83
+}
84
+
85
+/**
86 86
      * @throws SetupException
87 87
      */
88
-    public function tearDown(): void
89
-    {
90
-        jaxon()->reset();
91
-        parent::tearDown();
92
-    }
88
+public function tearDown(): void
89
+{
90
+jaxon()->reset();
91
+parent::tearDown();
92
+}
93 93
 
94
-    /**
94
+/**
95 95
      * @throws RequestException
96 96
      */
97
-    public function testAjaxUpload()
98
-    {
99
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
100
-        // Send a request to the registered class
101
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
102
-            return $c->g(ServerRequestCreator::class)
103
-                ->fromGlobals()
104
-                ->withParsedBody([
105
-                    'jxncall' => json_encode([
106
-                        'type' => 'class',
107
-                        'name' => 'SampleUpload',
108
-                        'method' => 'myMethod',
109
-                        'args' => [],
110
-                    ]),
111
-                ])
112
-                ->withUploadedFiles([
113
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
114
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
115
-                ])
116
-                ->withMethod('POST');
117
-        });
118
-
119
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
120
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
121
-        jaxon()->processRequest();
122
-
123
-        // Uploaded files
124
-        $aFiles = jaxon()->upload()->files();
125
-        $this->assertCount(1, $aFiles);
126
-        $this->assertCount(1, $aFiles['image']);
127
-        $xFile = $aFiles['image'][0];
128
-        $this->assertEquals('white', $xFile->name());
129
-        $this->assertEquals($this->sNameWhite, $xFile->filename());
130
-        $this->assertEquals('png', $xFile->type());
131
-        $this->assertEquals('png', $xFile->extension());
132
-    }
133
-
134
-    /**
97
+public function testAjaxUpload()
98
+{
99
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
100
+// Send a request to the registered class
101
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
102
+return $c->g(ServerRequestCreator::class)
103
+    ->fromGlobals()
104
+    ->withParsedBody([
105
+        'jxncall' => json_encode([
106
+            'type' => 'class',
107
+            'name' => 'SampleUpload',
108
+            'method' => 'myMethod',
109
+            'args' => [],
110
+        ]),
111
+    ])
112
+    ->withUploadedFiles([
113
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
114
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
115
+    ])
116
+    ->withMethod('POST');
117
+});
118
+
119
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
120
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
121
+jaxon()->processRequest();
122
+
123
+// Uploaded files
124
+$aFiles = jaxon()->upload()->files();
125
+$this->assertCount(1, $aFiles);
126
+$this->assertCount(1, $aFiles['image']);
127
+$xFile = $aFiles['image'][0];
128
+$this->assertEquals('white', $xFile->name());
129
+$this->assertEquals($this->sNameWhite, $xFile->filename());
130
+$this->assertEquals('png', $xFile->type());
131
+$this->assertEquals('png', $xFile->extension());
132
+}
133
+
134
+/**
135 135
      * @throws RequestException
136 136
      */
137
-    public function testAjaxUploadMultipleFiles()
138
-    {
139
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
140
-        // Send a request to the registered class
141
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
142
-            return $c->g(ServerRequestCreator::class)
143
-                ->fromGlobals()
144
-                ->withParsedBody([
145
-                    'jxncall' => json_encode([
146
-                        'type' => 'class',
147
-                        'name' => 'SampleUpload',
148
-                        'method' => 'myMethod',
149
-                        'args' => [],
150
-                    ]),
151
-                ])
152
-                ->withUploadedFiles([
153
-                    'image' => [
154
-                        new UploadedFile($this->sPathWhite, $this->sSizeWhite,
155
-                            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
156
-                        new UploadedFile($this->sPathBlue, $this->sSizeBlue,
157
-                            UPLOAD_ERR_OK, $this->sNameBlue, 'png'),
158
-                    ],
159
-                ])
160
-                ->withMethod('POST');
161
-        });
162
-
163
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
164
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
165
-        jaxon()->processRequest();
166
-
167
-        // Uploaded files
168
-        $aFiles = jaxon()->upload()->files();
169
-        $this->assertCount(1, $aFiles);
170
-        $this->assertCount(2, $aFiles['image']);
171
-        $xFile = $aFiles['image'][0];
172
-        $this->assertEquals('white', $xFile->name());
173
-        $this->assertEquals($this->sNameWhite, $xFile->filename());
174
-        $this->assertEquals('png', $xFile->type());
175
-        $this->assertEquals('png', $xFile->extension());
176
-        $xFile = $aFiles['image'][1];
177
-        $this->assertEquals('blue', $xFile->name());
178
-        $this->assertEquals($this->sNameBlue, $xFile->filename());
179
-        $this->assertEquals('png', $xFile->type());
180
-        $this->assertEquals('png', $xFile->extension());
181
-    }
182
-
183
-    /**
137
+public function testAjaxUploadMultipleFiles()
138
+{
139
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
140
+// Send a request to the registered class
141
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
142
+return $c->g(ServerRequestCreator::class)
143
+    ->fromGlobals()
144
+    ->withParsedBody([
145
+        'jxncall' => json_encode([
146
+            'type' => 'class',
147
+            'name' => 'SampleUpload',
148
+            'method' => 'myMethod',
149
+            'args' => [],
150
+        ]),
151
+    ])
152
+    ->withUploadedFiles([
153
+        'image' => [
154
+            new UploadedFile($this->sPathWhite, $this->sSizeWhite,
155
+                UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
156
+            new UploadedFile($this->sPathBlue, $this->sSizeBlue,
157
+                UPLOAD_ERR_OK, $this->sNameBlue, 'png'),
158
+        ],
159
+    ])
160
+    ->withMethod('POST');
161
+});
162
+
163
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
164
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
165
+jaxon()->processRequest();
166
+
167
+// Uploaded files
168
+$aFiles = jaxon()->upload()->files();
169
+$this->assertCount(1, $aFiles);
170
+$this->assertCount(2, $aFiles['image']);
171
+$xFile = $aFiles['image'][0];
172
+$this->assertEquals('white', $xFile->name());
173
+$this->assertEquals($this->sNameWhite, $xFile->filename());
174
+$this->assertEquals('png', $xFile->type());
175
+$this->assertEquals('png', $xFile->extension());
176
+$xFile = $aFiles['image'][1];
177
+$this->assertEquals('blue', $xFile->name());
178
+$this->assertEquals($this->sNameBlue, $xFile->filename());
179
+$this->assertEquals('png', $xFile->type());
180
+$this->assertEquals('png', $xFile->extension());
181
+}
182
+
183
+/**
184 184
      * @throws RequestException
185 185
      */
186
-    public function testAjaxUploadMultipleNames()
187
-    {
188
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
189
-        // Send a request to the registered class
190
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
191
-            return $c->g(ServerRequestCreator::class)
192
-                ->fromGlobals()
193
-                ->withParsedBody([
194
-                    'jxncall' => json_encode([
195
-                        'type' => 'class',
196
-                        'name' => 'SampleUpload',
197
-                        'method' => 'myMethod',
198
-                        'args' => [],
199
-                    ]),
200
-                ])
201
-                ->withUploadedFiles([
202
-                    'white' => [
203
-                        new UploadedFile($this->sPathWhite, $this->sSizeWhite,
204
-                            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
205
-                    ],
206
-                    'blue' => [
207
-                        new UploadedFile($this->sPathBlue, $this->sSizeBlue,
208
-                            UPLOAD_ERR_OK, $this->sNameBlue, 'png'),
209
-                    ],
210
-                ])
211
-                ->withMethod('POST');
212
-        });
213
-
214
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
215
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
216
-        jaxon()->processRequest();
217
-
218
-        // Uploaded files
219
-        $aFiles = jaxon()->upload()->files();
220
-        $this->assertCount(2, $aFiles);
221
-        $this->assertCount(1, $aFiles['white']);
222
-        $this->assertCount(1, $aFiles['blue']);
223
-        $xFile = $aFiles['white'][0];
224
-        $this->assertEquals('white', $xFile->name());
225
-        $this->assertEquals($this->sNameWhite, $xFile->filename());
226
-        $this->assertEquals('png', $xFile->type());
227
-        $this->assertEquals('png', $xFile->extension());
228
-        $xFile = $aFiles['blue'][0];
229
-        $this->assertEquals('blue', $xFile->name());
230
-        $this->assertEquals($this->sNameBlue, $xFile->filename());
231
-        $this->assertEquals('png', $xFile->type());
232
-        $this->assertEquals('png', $xFile->extension());
233
-    }
234
-
235
-    /**
186
+public function testAjaxUploadMultipleNames()
187
+{
188
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
189
+// Send a request to the registered class
190
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
191
+return $c->g(ServerRequestCreator::class)
192
+    ->fromGlobals()
193
+    ->withParsedBody([
194
+        'jxncall' => json_encode([
195
+            'type' => 'class',
196
+            'name' => 'SampleUpload',
197
+            'method' => 'myMethod',
198
+            'args' => [],
199
+        ]),
200
+    ])
201
+    ->withUploadedFiles([
202
+        'white' => [
203
+            new UploadedFile($this->sPathWhite, $this->sSizeWhite,
204
+                UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
205
+        ],
206
+        'blue' => [
207
+            new UploadedFile($this->sPathBlue, $this->sSizeBlue,
208
+                UPLOAD_ERR_OK, $this->sNameBlue, 'png'),
209
+        ],
210
+    ])
211
+    ->withMethod('POST');
212
+});
213
+
214
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
215
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
216
+jaxon()->processRequest();
217
+
218
+// Uploaded files
219
+$aFiles = jaxon()->upload()->files();
220
+$this->assertCount(2, $aFiles);
221
+$this->assertCount(1, $aFiles['white']);
222
+$this->assertCount(1, $aFiles['blue']);
223
+$xFile = $aFiles['white'][0];
224
+$this->assertEquals('white', $xFile->name());
225
+$this->assertEquals($this->sNameWhite, $xFile->filename());
226
+$this->assertEquals('png', $xFile->type());
227
+$this->assertEquals('png', $xFile->extension());
228
+$xFile = $aFiles['blue'][0];
229
+$this->assertEquals('blue', $xFile->name());
230
+$this->assertEquals($this->sNameBlue, $xFile->filename());
231
+$this->assertEquals('png', $xFile->type());
232
+$this->assertEquals('png', $xFile->extension());
233
+}
234
+
235
+/**
236 236
      * @throws RequestException
237 237
      */
238
-    public function testAjaxUploadNameSanitizer()
239
-    {
240
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
241
-        jaxon()->upload()->sanitizer(function($sFilename, $sVarName) {
242
-            return $sVarName === 'image' ? 'img_' . $sFilename : $sFilename;
243
-        });
244
-        // Send a request to the registered class
245
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
246
-            return $c->g(ServerRequestCreator::class)
247
-                ->fromGlobals()
248
-                ->withParsedBody([
249
-                    'jxncall' => json_encode([
250
-                        'type' => 'class',
251
-                        'name' => 'SampleUpload',
252
-                        'method' => 'myMethod',
253
-                        'args' => [],
254
-                    ]),
255
-                ])
256
-                ->withUploadedFiles([
257
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
258
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
259
-                ])
260
-                ->withMethod('POST');
261
-        });
262
-
263
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
264
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
265
-        jaxon()->processRequest();
266
-
267
-        // Uploaded files
268
-        $aFiles = jaxon()->upload()->files();
269
-        $this->assertCount(1, $aFiles);
270
-        $this->assertCount(1, $aFiles['image']);
271
-        $xFile = $aFiles['image'][0];
272
-        $this->assertEquals('img_white', $xFile->name());
273
-        $this->assertEquals('png', $xFile->type());
274
-        $this->assertEquals('png', $xFile->extension());
275
-        $this->assertEquals($this->sNameWhite, $xFile->filename());
276
-    }
277
-
278
-    /**
238
+public function testAjaxUploadNameSanitizer()
239
+{
240
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
241
+jaxon()->upload()->sanitizer(function($sFilename, $sVarName) {
242
+return $sVarName === 'image' ? 'img_' . $sFilename : $sFilename;
243
+});
244
+// Send a request to the registered class
245
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
246
+return $c->g(ServerRequestCreator::class)
247
+    ->fromGlobals()
248
+    ->withParsedBody([
249
+        'jxncall' => json_encode([
250
+            'type' => 'class',
251
+            'name' => 'SampleUpload',
252
+            'method' => 'myMethod',
253
+            'args' => [],
254
+        ]),
255
+    ])
256
+    ->withUploadedFiles([
257
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
258
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
259
+    ])
260
+    ->withMethod('POST');
261
+});
262
+
263
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
264
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
265
+jaxon()->processRequest();
266
+
267
+// Uploaded files
268
+$aFiles = jaxon()->upload()->files();
269
+$this->assertCount(1, $aFiles);
270
+$this->assertCount(1, $aFiles['image']);
271
+$xFile = $aFiles['image'][0];
272
+$this->assertEquals('img_white', $xFile->name());
273
+$this->assertEquals('png', $xFile->type());
274
+$this->assertEquals('png', $xFile->extension());
275
+$this->assertEquals($this->sNameWhite, $xFile->filename());
276
+}
277
+
278
+/**
279 279
      * @throws RequestException
280 280
      */
281
-    public function testUploadFileTypeValidationOk()
282
-    {
283
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
284
-        jaxon()->setOption('upload.default.types', ['png']);
285
-        // Send a request to the registered class
286
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
287
-            return $c->g(ServerRequestCreator::class)
288
-                ->fromGlobals()
289
-                ->withParsedBody([
290
-                    'jxncall' => json_encode([
291
-                        'type' => 'class',
292
-                        'name' => 'SampleUpload',
293
-                        'method' => 'myMethod',
294
-                        'args' => [],
295
-                    ]),
296
-                ])
297
-                ->withUploadedFiles([
298
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
299
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
300
-                ])
301
-                ->withMethod('POST');
302
-        });
303
-
304
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
305
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
306
-        jaxon()->processRequest();
307
-
308
-        // Return the file name for the next test
309
-        $aFiles = jaxon()->upload()->files();
310
-        $this->assertCount(1, $aFiles);
311
-        $this->assertCount(1, $aFiles['image']);
312
-        $xFile = $aFiles['image'][0];
313
-        $this->assertEquals('white', $xFile->name());
314
-        $this->assertEquals($this->sNameWhite, $xFile->filename());
315
-    }
316
-
317
-    /**
281
+public function testUploadFileTypeValidationOk()
282
+{
283
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
284
+jaxon()->setOption('upload.default.types', ['png']);
285
+// Send a request to the registered class
286
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
287
+return $c->g(ServerRequestCreator::class)
288
+    ->fromGlobals()
289
+    ->withParsedBody([
290
+        'jxncall' => json_encode([
291
+            'type' => 'class',
292
+            'name' => 'SampleUpload',
293
+            'method' => 'myMethod',
294
+            'args' => [],
295
+        ]),
296
+    ])
297
+    ->withUploadedFiles([
298
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
299
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
300
+    ])
301
+    ->withMethod('POST');
302
+});
303
+
304
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
305
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
306
+jaxon()->processRequest();
307
+
308
+// Return the file name for the next test
309
+$aFiles = jaxon()->upload()->files();
310
+$this->assertCount(1, $aFiles);
311
+$this->assertCount(1, $aFiles['image']);
312
+$xFile = $aFiles['image'][0];
313
+$this->assertEquals('white', $xFile->name());
314
+$this->assertEquals($this->sNameWhite, $xFile->filename());
315
+}
316
+
317
+/**
318 318
      * @throws RequestException
319 319
      */
320
-    public function testUploadFileTypeValidationError()
321
-    {
322
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
323
-        jaxon()->setOption('upload.default.types', ['jpg']);
324
-        // Send a request to the registered class
325
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
326
-            return $c->g(ServerRequestCreator::class)
327
-                ->fromGlobals()
328
-                ->withParsedBody([
329
-                    'jxncall' => json_encode([
330
-                        'type' => 'class',
331
-                        'name' => 'SampleUpload',
332
-                        'method' => 'myMethod',
333
-                        'args' => [],
334
-                    ]),
335
-                ])
336
-                ->withUploadedFiles([
337
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
338
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
339
-                ])
340
-                ->withMethod('POST');
341
-        });
342
-
343
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
344
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
345
-        $this->expectException(RequestException::class);
346
-        jaxon()->processRequest();
347
-    }
348
-
349
-    /**
320
+public function testUploadFileTypeValidationError()
321
+{
322
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
323
+jaxon()->setOption('upload.default.types', ['jpg']);
324
+// Send a request to the registered class
325
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
326
+return $c->g(ServerRequestCreator::class)
327
+    ->fromGlobals()
328
+    ->withParsedBody([
329
+        'jxncall' => json_encode([
330
+            'type' => 'class',
331
+            'name' => 'SampleUpload',
332
+            'method' => 'myMethod',
333
+            'args' => [],
334
+        ]),
335
+    ])
336
+    ->withUploadedFiles([
337
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
338
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
339
+    ])
340
+    ->withMethod('POST');
341
+});
342
+
343
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
344
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
345
+$this->expectException(RequestException::class);
346
+jaxon()->processRequest();
347
+}
348
+
349
+/**
350 350
      * @throws RequestException
351 351
      */
352
-    public function testUploadFileExtensionValidationOk()
353
-    {
354
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
355
-        jaxon()->setOption('upload.default.extensions', ['png']);
356
-        // Send a request to the registered class
357
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
358
-            return $c->g(ServerRequestCreator::class)
359
-                ->fromGlobals()
360
-                ->withParsedBody([
361
-                    'jxncall' => json_encode([
362
-                        'type' => 'class',
363
-                        'name' => 'SampleUpload',
364
-                        'method' => 'myMethod',
365
-                        'args' => [],
366
-                    ]),
367
-                ])
368
-                ->withUploadedFiles([
369
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
370
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
371
-                ])
372
-                ->withMethod('POST');
373
-        });
374
-
375
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
376
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
377
-        jaxon()->processRequest();
378
-
379
-        // Return the file name for the next test
380
-        $aFiles = jaxon()->upload()->files();
381
-        $this->assertCount(1, $aFiles);
382
-        $this->assertCount(1, $aFiles['image']);
383
-        $xFile = $aFiles['image'][0];
384
-        $this->assertEquals('white', $xFile->name());
385
-        $this->assertEquals($this->sNameWhite, $xFile->filename());
386
-    }
387
-
388
-    /**
352
+public function testUploadFileExtensionValidationOk()
353
+{
354
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
355
+jaxon()->setOption('upload.default.extensions', ['png']);
356
+// Send a request to the registered class
357
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
358
+return $c->g(ServerRequestCreator::class)
359
+    ->fromGlobals()
360
+    ->withParsedBody([
361
+        'jxncall' => json_encode([
362
+            'type' => 'class',
363
+            'name' => 'SampleUpload',
364
+            'method' => 'myMethod',
365
+            'args' => [],
366
+        ]),
367
+    ])
368
+    ->withUploadedFiles([
369
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
370
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
371
+    ])
372
+    ->withMethod('POST');
373
+});
374
+
375
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
376
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
377
+jaxon()->processRequest();
378
+
379
+// Return the file name for the next test
380
+$aFiles = jaxon()->upload()->files();
381
+$this->assertCount(1, $aFiles);
382
+$this->assertCount(1, $aFiles['image']);
383
+$xFile = $aFiles['image'][0];
384
+$this->assertEquals('white', $xFile->name());
385
+$this->assertEquals($this->sNameWhite, $xFile->filename());
386
+}
387
+
388
+/**
389 389
      * @throws RequestException
390 390
      */
391
-    public function testUploadFileExtensionValidationError()
392
-    {
393
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
394
-        jaxon()->setOption('upload.default.extensions', ['jpg']);
395
-        // Send a request to the registered class
396
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
397
-            return $c->g(ServerRequestCreator::class)
398
-                ->fromGlobals()
399
-                ->withParsedBody([
400
-                    'jxncall' => json_encode([
401
-                        'type' => 'class',
402
-                        'name' => 'SampleUpload',
403
-                        'method' => 'myMethod',
404
-                        'args' => [],
405
-                    ]),
406
-                ])
407
-                ->withUploadedFiles([
408
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
409
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
410
-                ])
411
-                ->withMethod('POST');
412
-        });
413
-
414
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
415
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
416
-        $this->expectException(RequestException::class);
417
-        jaxon()->processRequest();
418
-    }
419
-
420
-    /**
391
+public function testUploadFileExtensionValidationError()
392
+{
393
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
394
+jaxon()->setOption('upload.default.extensions', ['jpg']);
395
+// Send a request to the registered class
396
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
397
+return $c->g(ServerRequestCreator::class)
398
+    ->fromGlobals()
399
+    ->withParsedBody([
400
+        'jxncall' => json_encode([
401
+            'type' => 'class',
402
+            'name' => 'SampleUpload',
403
+            'method' => 'myMethod',
404
+            'args' => [],
405
+        ]),
406
+    ])
407
+    ->withUploadedFiles([
408
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
409
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
410
+    ])
411
+    ->withMethod('POST');
412
+});
413
+
414
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
415
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
416
+$this->expectException(RequestException::class);
417
+jaxon()->processRequest();
418
+}
419
+
420
+/**
421 421
      * @throws RequestException
422 422
      */
423
-    public function testUploadFileMaxSizeValidationOk()
424
-    {
425
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
426
-        jaxon()->setOption('upload.default.max-size', 30000);
427
-        // Send a request to the registered class
428
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
429
-            return $c->g(ServerRequestCreator::class)
430
-                ->fromGlobals()
431
-                ->withParsedBody([
432
-                    'jxncall' => json_encode([
433
-                        'type' => 'class',
434
-                        'name' => 'SampleUpload',
435
-                        'method' => 'myMethod',
436
-                        'args' => [],
437
-                    ]),
438
-                ])
439
-                ->withUploadedFiles([
440
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
441
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
442
-                ])
443
-                ->withMethod('POST');
444
-        });
445
-
446
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
447
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
448
-        jaxon()->processRequest();
449
-
450
-        // Return the file name for the next test
451
-        $aFiles = jaxon()->upload()->files();
452
-        $this->assertCount(1, $aFiles);
453
-        $this->assertCount(1, $aFiles['image']);
454
-        $xFile = $aFiles['image'][0];
455
-        $this->assertEquals('white', $xFile->name());
456
-        $this->assertEquals($this->sNameWhite, $xFile->filename());
457
-    }
458
-
459
-    /**
423
+public function testUploadFileMaxSizeValidationOk()
424
+{
425
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
426
+jaxon()->setOption('upload.default.max-size', 30000);
427
+// Send a request to the registered class
428
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
429
+return $c->g(ServerRequestCreator::class)
430
+    ->fromGlobals()
431
+    ->withParsedBody([
432
+        'jxncall' => json_encode([
433
+            'type' => 'class',
434
+            'name' => 'SampleUpload',
435
+            'method' => 'myMethod',
436
+            'args' => [],
437
+        ]),
438
+    ])
439
+    ->withUploadedFiles([
440
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
441
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
442
+    ])
443
+    ->withMethod('POST');
444
+});
445
+
446
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
447
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
448
+jaxon()->processRequest();
449
+
450
+// Return the file name for the next test
451
+$aFiles = jaxon()->upload()->files();
452
+$this->assertCount(1, $aFiles);
453
+$this->assertCount(1, $aFiles['image']);
454
+$xFile = $aFiles['image'][0];
455
+$this->assertEquals('white', $xFile->name());
456
+$this->assertEquals($this->sNameWhite, $xFile->filename());
457
+}
458
+
459
+/**
460 460
      * @throws RequestException
461 461
      */
462
-    public function testUploadFileMaxSizeValidationError()
463
-    {
464
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
465
-        jaxon()->setOption('upload.default.max-size', 25000);
466
-        // Send a request to the registered class
467
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
468
-            return $c->g(ServerRequestCreator::class)
469
-                ->fromGlobals()
470
-                ->withParsedBody([
471
-                    'jxncall' => json_encode([
472
-                        'type' => 'class',
473
-                        'name' => 'SampleUpload',
474
-                        'method' => 'myMethod',
475
-                        'args' => [],
476
-                    ]),
477
-                ])
478
-                ->withUploadedFiles([
479
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
480
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
481
-                ])
482
-                ->withMethod('POST');
483
-        });
484
-
485
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
486
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
487
-        $this->expectException(RequestException::class);
488
-        jaxon()->processRequest();
489
-    }
490
-
491
-    /**
462
+public function testUploadFileMaxSizeValidationError()
463
+{
464
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
465
+jaxon()->setOption('upload.default.max-size', 25000);
466
+// Send a request to the registered class
467
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
468
+return $c->g(ServerRequestCreator::class)
469
+    ->fromGlobals()
470
+    ->withParsedBody([
471
+        'jxncall' => json_encode([
472
+            'type' => 'class',
473
+            'name' => 'SampleUpload',
474
+            'method' => 'myMethod',
475
+            'args' => [],
476
+        ]),
477
+    ])
478
+    ->withUploadedFiles([
479
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
480
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
481
+    ])
482
+    ->withMethod('POST');
483
+});
484
+
485
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
486
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
487
+$this->expectException(RequestException::class);
488
+jaxon()->processRequest();
489
+}
490
+
491
+/**
492 492
      * @throws RequestException
493 493
      */
494
-    public function testUploadFileMinSizeValidationOk()
495
-    {
496
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
497
-        jaxon()->setOption('upload.default.min-size', 25000);
498
-        // Send a request to the registered class
499
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
500
-            return $c->g(ServerRequestCreator::class)
501
-                ->fromGlobals()
502
-                ->withParsedBody([
503
-                    'jxncall' => json_encode([
504
-                        'type' => 'class',
505
-                        'name' => 'SampleUpload',
506
-                        'method' => 'myMethod',
507
-                        'args' => [],
508
-                    ]),
509
-                ])
510
-                ->withUploadedFiles([
511
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
512
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
513
-                ])
514
-                ->withMethod('POST');
515
-        });
516
-
517
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
518
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
519
-        jaxon()->processRequest();
520
-
521
-        // Return the file name for the next test
522
-        $aFiles = jaxon()->upload()->files();
523
-        $this->assertCount(1, $aFiles);
524
-        $this->assertCount(1, $aFiles['image']);
525
-        $xFile = $aFiles['image'][0];
526
-        $this->assertEquals('white', $xFile->name());
527
-        $this->assertEquals($this->sNameWhite, $xFile->filename());
528
-    }
529
-
530
-    /**
494
+public function testUploadFileMinSizeValidationOk()
495
+{
496
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
497
+jaxon()->setOption('upload.default.min-size', 25000);
498
+// Send a request to the registered class
499
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
500
+return $c->g(ServerRequestCreator::class)
501
+    ->fromGlobals()
502
+    ->withParsedBody([
503
+        'jxncall' => json_encode([
504
+            'type' => 'class',
505
+            'name' => 'SampleUpload',
506
+            'method' => 'myMethod',
507
+            'args' => [],
508
+        ]),
509
+    ])
510
+    ->withUploadedFiles([
511
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
512
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
513
+    ])
514
+    ->withMethod('POST');
515
+});
516
+
517
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
518
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
519
+jaxon()->processRequest();
520
+
521
+// Return the file name for the next test
522
+$aFiles = jaxon()->upload()->files();
523
+$this->assertCount(1, $aFiles);
524
+$this->assertCount(1, $aFiles['image']);
525
+$xFile = $aFiles['image'][0];
526
+$this->assertEquals('white', $xFile->name());
527
+$this->assertEquals($this->sNameWhite, $xFile->filename());
528
+}
529
+
530
+/**
531 531
      * @throws RequestException
532 532
      */
533
-    public function testUploadFileMinSizeValidationError()
534
-    {
535
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
536
-        jaxon()->setOption('upload.default.min-size', 30000);
537
-        // Send a request to the registered class
538
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
539
-            return $c->g(ServerRequestCreator::class)
540
-                ->fromGlobals()
541
-                ->withParsedBody([
542
-                    'jxncall' => json_encode([
543
-                        'type' => 'class',
544
-                        'name' => 'SampleUpload',
545
-                        'method' => 'myMethod',
546
-                        'args' => [],
547
-                    ]),
548
-                ])
549
-                ->withUploadedFiles([
550
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
551
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
552
-                ])
553
-                ->withMethod('POST');
554
-        });
555
-
556
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
557
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
558
-        $this->expectException(RequestException::class);
559
-        jaxon()->processRequest();
560
-    }
561
-
562
-    /**
533
+public function testUploadFileMinSizeValidationError()
534
+{
535
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
536
+jaxon()->setOption('upload.default.min-size', 30000);
537
+// Send a request to the registered class
538
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
539
+return $c->g(ServerRequestCreator::class)
540
+    ->fromGlobals()
541
+    ->withParsedBody([
542
+        'jxncall' => json_encode([
543
+            'type' => 'class',
544
+            'name' => 'SampleUpload',
545
+            'method' => 'myMethod',
546
+            'args' => [],
547
+        ]),
548
+    ])
549
+    ->withUploadedFiles([
550
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
551
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
552
+    ])
553
+    ->withMethod('POST');
554
+});
555
+
556
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
557
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
558
+$this->expectException(RequestException::class);
559
+jaxon()->processRequest();
560
+}
561
+
562
+/**
563 563
      * @throws RequestException
564 564
      * @throws SetupException
565 565
      */
566
-    public function testPsrAjaxUpload()
567
-    {
568
-        _register();
569
-        jaxon()->setOption('core.upload.enabled', true);
570
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
571
-        // Send a request to the registered class
572
-        $xRequest = jaxon()->di()->g(ServerRequestCreator::class)
573
-            ->fromGlobals()
574
-            ->withParsedBody([
575
-                'jxncall' => json_encode([
576
-                    'type' => 'class',
577
-                    'name' => 'SampleUpload',
578
-                    'method' => 'myMethod',
579
-                    'args' => [],
580
-                ]),
581
-            ])
582
-            ->withUploadedFiles([
583
-                'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
584
-                    UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
585
-            ])
586
-            ->withMethod('POST');
587
-
588
-        $xPsrConfigMiddleware = jaxon()->psr()->config(__DIR__ . '/../config/psr.php');
589
-        $xPsrAjaxMiddleware = jaxon()->psr()->ajax();
590
-        // PSR request handler that does nothing, useful to call the config middleware.
591
-        $xEmptyRequestHandler = new class implements RequestHandlerInterface
592
-        {
593
-            private $xPsr17Factory;
594
-
595
-            public function __construct()
596
-            {
597
-                $this->xPsr17Factory = new Psr17Factory();
598
-            }
599
-
600
-            public function handle(ServerRequestInterface $request): ResponseInterface
601
-            {
602
-                return $this->xPsr17Factory->createResponse();
603
-            }
604
-        };
605
-        // Call the config middleware
606
-        $xPsrConfigMiddleware->process($xRequest, $xEmptyRequestHandler);
607
-        // Call the ajax middleware
608
-        $xPsrResponse = $xPsrAjaxMiddleware->process($xRequest, $xEmptyRequestHandler);
609
-
610
-        // Both responses must have the same content and content type
611
-        $xJaxonResponse = jaxon()->getResponse();
612
-        $this->assertEquals($xPsrResponse->getBody()->__toString(), $xJaxonResponse->getOutput());
613
-        $this->assertEquals($xPsrResponse->getHeader('content-type')[0], $xJaxonResponse->getContentType());
614
-
615
-        // Uploaded files
616
-        $aFiles = jaxon()->upload()->files();
617
-        $this->assertCount(1, $aFiles);
618
-        $this->assertCount(1, $aFiles['image']);
619
-        $xFile = $aFiles['image'][0];
620
-        $this->assertEquals('white', $xFile->name());
621
-        $this->assertEquals($this->sNameWhite, $xFile->filename());
622
-        $this->assertEquals('png', $xFile->type());
623
-        $this->assertEquals('png', $xFile->extension());
624
-    }
566
+public function testPsrAjaxUpload()
567
+{
568
+_register();
569
+jaxon()->setOption('core.upload.enabled', true);
570
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
571
+// Send a request to the registered class
572
+$xRequest = jaxon()->di()->g(ServerRequestCreator::class)
573
+->fromGlobals()
574
+->withParsedBody([
575
+    'jxncall' => json_encode([
576
+        'type' => 'class',
577
+        'name' => 'SampleUpload',
578
+        'method' => 'myMethod',
579
+        'args' => [],
580
+    ]),
581
+])
582
+->withUploadedFiles([
583
+    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
584
+        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
585
+])
586
+->withMethod('POST');
587
+
588
+$xPsrConfigMiddleware = jaxon()->psr()->config(__DIR__ . '/../config/psr.php');
589
+$xPsrAjaxMiddleware = jaxon()->psr()->ajax();
590
+// PSR request handler that does nothing, useful to call the config middleware.
591
+$xEmptyRequestHandler = new class implements RequestHandlerInterface
592
+{
593
+private $xPsr17Factory;
594
+
595
+public function __construct()
596
+{
597
+    $this->xPsr17Factory = new Psr17Factory();
598
+}
599
+
600
+public function handle(ServerRequestInterface $request): ResponseInterface
601
+{
602
+    return $this->xPsr17Factory->createResponse();
603
+}
604
+};
605
+// Call the config middleware
606
+$xPsrConfigMiddleware->process($xRequest, $xEmptyRequestHandler);
607
+// Call the ajax middleware
608
+$xPsrResponse = $xPsrAjaxMiddleware->process($xRequest, $xEmptyRequestHandler);
609
+
610
+// Both responses must have the same content and content type
611
+$xJaxonResponse = jaxon()->getResponse();
612
+$this->assertEquals($xPsrResponse->getBody()->__toString(), $xJaxonResponse->getOutput());
613
+$this->assertEquals($xPsrResponse->getHeader('content-type')[0], $xJaxonResponse->getContentType());
614
+
615
+// Uploaded files
616
+$aFiles = jaxon()->upload()->files();
617
+$this->assertCount(1, $aFiles);
618
+$this->assertCount(1, $aFiles['image']);
619
+$xFile = $aFiles['image'][0];
620
+$this->assertEquals('white', $xFile->name());
621
+$this->assertEquals($this->sNameWhite, $xFile->filename());
622
+$this->assertEquals('png', $xFile->type());
623
+$this->assertEquals('png', $xFile->extension());
624
+}
625 625
 }
Please login to merge, or discard this patch.
jaxon-upload/tests/TestUpload/UploadFsLocalTest.php 1 patch
Switch Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -19,166 +19,166 @@
 block discarded – undo
19 19
 
20 20
 class UploadFsLocalTest extends TestCase
21 21
 {
22
-    /**
22
+/**
23 23
      * @var string
24 24
      */
25
-    protected $sNameWhite;
25
+protected $sNameWhite;
26 26
 
27
-    /**
27
+/**
28 28
      * @var string
29 29
      */
30
-    protected $sPathWhite;
30
+protected $sPathWhite;
31 31
 
32
-    /**
32
+/**
33 33
      * @var int
34 34
      */
35
-    protected $sSizeWhite;
35
+protected $sSizeWhite;
36 36
 
37
-    /**
37
+/**
38 38
      * @var string
39 39
      */
40
-    protected $sNameBlue;
40
+protected $sNameBlue;
41 41
 
42
-    /**
42
+/**
43 43
      * @var string
44 44
      */
45
-    protected $sPathBlue;
45
+protected $sPathBlue;
46 46
 
47
-    /**
47
+/**
48 48
      * @var int
49 49
      */
50
-    protected $sSizeBlue;
50
+protected $sSizeBlue;
51 51
 
52
-    /**
52
+/**
53 53
      * @throws SetupException
54 54
      */
55
-    public function setUp(): void
56
-    {
57
-        jaxon()->di()->getPluginManager()->registerPlugins();
58
-        jaxon()->setOption('core.response.send', false);
59
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
60
-        _register();
61
-
62
-        $tmpDir = __DIR__ . '/../upload/tmp';
63
-        @mkdir($tmpDir);
64
-
65
-        $sSrcWhite = __DIR__ . '/../upload/src/white.png';
66
-        $this->sNameWhite = 'white.png';
67
-        $this->sPathWhite = "$tmpDir/{$this->sNameWhite}";
68
-        $this->sSizeWhite = filesize($sSrcWhite);
69
-        // Copy the file to the temp dir.
70
-        @copy($sSrcWhite, $this->sPathWhite);
71
-
72
-        $sSrcBlue = __DIR__ . '/../upload/src/blue.png';
73
-        $this->sNameBlue = 'blue.png';
74
-        $this->sPathBlue = "$tmpDir/{$this->sNameBlue}";
75
-        $this->sSizeBlue = filesize($sSrcBlue);
76
-        // Copy the file to the temp dir.
77
-        @copy($sSrcBlue, $this->sPathBlue);
78
-    }
79
-
80
-    /**
55
+public function setUp(): void
56
+{
57
+jaxon()->di()->getPluginManager()->registerPlugins();
58
+jaxon()->setOption('core.response.send', false);
59
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
60
+_register();
61
+
62
+$tmpDir = __DIR__ . '/../upload/tmp';
63
+@mkdir($tmpDir);
64
+
65
+$sSrcWhite = __DIR__ . '/../upload/src/white.png';
66
+$this->sNameWhite = 'white.png';
67
+$this->sPathWhite = "$tmpDir/{$this->sNameWhite}";
68
+$this->sSizeWhite = filesize($sSrcWhite);
69
+// Copy the file to the temp dir.
70
+@copy($sSrcWhite, $this->sPathWhite);
71
+
72
+$sSrcBlue = __DIR__ . '/../upload/src/blue.png';
73
+$this->sNameBlue = 'blue.png';
74
+$this->sPathBlue = "$tmpDir/{$this->sNameBlue}";
75
+$this->sSizeBlue = filesize($sSrcBlue);
76
+// Copy the file to the temp dir.
77
+@copy($sSrcBlue, $this->sPathBlue);
78
+}
79
+
80
+/**
81 81
      * @throws SetupException
82 82
      */
83
-    public function tearDown(): void
84
-    {
85
-        jaxon()->reset();
86
-        parent::tearDown();
87
-    }
83
+public function tearDown(): void
84
+{
85
+jaxon()->reset();
86
+parent::tearDown();
87
+}
88 88
 
89
-    /**
89
+/**
90 90
      * @throws RequestException
91 91
      */
92
-    public function testHttpUploadDisabled()
93
-    {
94
-        jaxon()->setOption('core.upload.enabled', false);
95
-        jaxon()->register(Jaxon::CALLABLE_CLASS, 'SampleUpload', __DIR__ . '/../src/sample.php');
96
-        jaxon()->di()->getBootstrap()->onBoot();
97
-
98
-        // Send a request to the registered class
99
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
100
-            return $c->g(ServerRequestCreator::class)
101
-                ->fromGlobals()
102
-                ->withUploadedFiles([
103
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
104
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
105
-                ])
106
-                ->withMethod('POST');
107
-        });
108
-
109
-        $this->assertFalse(jaxon()->di()->getRequestHandler()->canProcessRequest());
110
-    }
111
-
112
-    /**
92
+public function testHttpUploadDisabled()
93
+{
94
+jaxon()->setOption('core.upload.enabled', false);
95
+jaxon()->register(Jaxon::CALLABLE_CLASS, 'SampleUpload', __DIR__ . '/../src/sample.php');
96
+jaxon()->di()->getBootstrap()->onBoot();
97
+
98
+// Send a request to the registered class
99
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
100
+return $c->g(ServerRequestCreator::class)
101
+    ->fromGlobals()
102
+    ->withUploadedFiles([
103
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
104
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
105
+    ])
106
+    ->withMethod('POST');
107
+});
108
+
109
+$this->assertFalse(jaxon()->di()->getRequestHandler()->canProcessRequest());
110
+}
111
+
112
+/**
113 113
      * @throws RequestException
114 114
      */
115
-    public function testRequestWithNoPluginNoUpload()
116
-    {
117
-        jaxon()->setOption('core.upload.enabled', false);
118
-        jaxon()->register(Jaxon::CALLABLE_CLASS, 'SampleUpload', __DIR__ . '/../src/sample.php');
119
-        jaxon()->di()->getBootstrap()->onBoot();
120
-
121
-        // Send a request to the registered class
122
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
123
-            return $c->g(ServerRequestCreator::class)
124
-                ->fromGlobals()
125
-                ->withParsedBody([
126
-                    'jxncall' => json_encode([
127
-                        'who' => 'Nobody',
128
-                        'args' => [],
129
-                    ]),
130
-                ])
131
-                ->withMethod('POST');
132
-        });
133
-
134
-        $this->assertFalse(jaxon()->di()->getRequestHandler()->canProcessRequest());
135
-    }
136
-
137
-    /**
115
+public function testRequestWithNoPluginNoUpload()
116
+{
117
+jaxon()->setOption('core.upload.enabled', false);
118
+jaxon()->register(Jaxon::CALLABLE_CLASS, 'SampleUpload', __DIR__ . '/../src/sample.php');
119
+jaxon()->di()->getBootstrap()->onBoot();
120
+
121
+// Send a request to the registered class
122
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
123
+return $c->g(ServerRequestCreator::class)
124
+    ->fromGlobals()
125
+    ->withParsedBody([
126
+        'jxncall' => json_encode([
127
+            'who' => 'Nobody',
128
+            'args' => [],
129
+        ]),
130
+    ])
131
+    ->withMethod('POST');
132
+});
133
+
134
+$this->assertFalse(jaxon()->di()->getRequestHandler()->canProcessRequest());
135
+}
136
+
137
+/**
138 138
      * @throws RequestException
139 139
      */
140
-    public function testUploadInMemoryStorage()
141
-    {
142
-        jaxon()->setOption('core.upload.enabled', true);
143
-        jaxon()->setOption('upload.default.storage', 'memory');
144
-        jaxon()->register(Jaxon::CALLABLE_CLASS, 'SampleUpload', __DIR__ . '/../src/sample.php');
145
-        jaxon()->di()->getBootstrap()->onBoot();
146
-
147
-        // In memory file system adapter
148
-        jaxon()->upload()->registerStorageAdapter('memory',
149
-            fn() => new InMemoryFilesystemAdapter());
150
-
151
-        // Send a request to the registered class
152
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
153
-            return $c->g(ServerRequestCreator::class)
154
-                ->fromGlobals()
155
-                ->withParsedBody([
156
-                    'jxncall' => json_encode([
157
-                        'type' => 'class',
158
-                        'name' => 'SampleUpload',
159
-                        'method' => 'myMethod',
160
-                        'args' => [],
161
-                    ]),
162
-                ])
163
-                ->withUploadedFiles([
164
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
165
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
166
-                ])
167
-                ->withMethod('POST');
168
-        });
169
-
170
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
171
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
172
-        jaxon()->processRequest();
173
-
174
-        // Uploaded files
175
-        $aFiles = jaxon()->upload()->files();
176
-        $this->assertCount(1, $aFiles);
177
-        $this->assertCount(1, $aFiles['image']);
178
-        $xFile = $aFiles['image'][0];
179
-        $this->assertEquals('white', $xFile->name());
180
-        $this->assertEquals($this->sNameWhite, $xFile->filename());
181
-        $this->assertEquals('png', $xFile->type());
182
-        $this->assertEquals('png', $xFile->extension());
183
-    }
140
+public function testUploadInMemoryStorage()
141
+{
142
+jaxon()->setOption('core.upload.enabled', true);
143
+jaxon()->setOption('upload.default.storage', 'memory');
144
+jaxon()->register(Jaxon::CALLABLE_CLASS, 'SampleUpload', __DIR__ . '/../src/sample.php');
145
+jaxon()->di()->getBootstrap()->onBoot();
146
+
147
+// In memory file system adapter
148
+jaxon()->upload()->registerStorageAdapter('memory',
149
+fn() => new InMemoryFilesystemAdapter());
150
+
151
+// Send a request to the registered class
152
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
153
+return $c->g(ServerRequestCreator::class)
154
+    ->fromGlobals()
155
+    ->withParsedBody([
156
+        'jxncall' => json_encode([
157
+            'type' => 'class',
158
+            'name' => 'SampleUpload',
159
+            'method' => 'myMethod',
160
+            'args' => [],
161
+        ]),
162
+    ])
163
+    ->withUploadedFiles([
164
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
165
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
166
+    ])
167
+    ->withMethod('POST');
168
+});
169
+
170
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
171
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
172
+jaxon()->processRequest();
173
+
174
+// Uploaded files
175
+$aFiles = jaxon()->upload()->files();
176
+$this->assertCount(1, $aFiles);
177
+$this->assertCount(1, $aFiles['image']);
178
+$xFile = $aFiles['image'][0];
179
+$this->assertEquals('white', $xFile->name());
180
+$this->assertEquals($this->sNameWhite, $xFile->filename());
181
+$this->assertEquals('png', $xFile->type());
182
+$this->assertEquals('png', $xFile->extension());
183
+}
184 184
 }
Please login to merge, or discard this patch.
jaxon-upload/tests/TestUpload/UploadTest.php 1 patch
Switch Indentation   +508 added lines, -508 removed lines patch added patch discarded remove patch
@@ -16,561 +16,561 @@
 block discarded – undo
16 16
 
17 17
 class UploadTest extends TestCase
18 18
 {
19
-    /**
19
+/**
20 20
      * @var string
21 21
      */
22
-    protected $sNameWhite;
22
+protected $sNameWhite;
23 23
 
24
-    /**
24
+/**
25 25
      * @var string
26 26
      */
27
-    protected $sPathWhite;
27
+protected $sPathWhite;
28 28
 
29
-    /**
29
+/**
30 30
      * @var int
31 31
      */
32
-    protected $sSizeWhite;
32
+protected $sSizeWhite;
33 33
 
34
-    /**
34
+/**
35 35
      * @var string
36 36
      */
37
-    protected $sNameBlue;
37
+protected $sNameBlue;
38 38
 
39
-    /**
39
+/**
40 40
      * @var string
41 41
      */
42
-    protected $sPathBlue;
42
+protected $sPathBlue;
43 43
 
44
-    /**
44
+/**
45 45
      * @var int
46 46
      */
47
-    protected $sSizeBlue;
47
+protected $sSizeBlue;
48 48
 
49
-    /**
49
+/**
50 50
      * @throws SetupException
51 51
      */
52
-    public function setUp(): void
53
-    {
54
-        _register();
55
-        jaxon()->setOption('core.upload.enabled', true);
56
-
57
-        jaxon()->setOption('core.response.send', false);
58
-        $tmpDir = __DIR__ . '/../upload/tmp';
59
-        @mkdir($tmpDir);
60
-
61
-        $sSrcWhite = __DIR__ . '/../upload/src/white.png';
62
-        $this->sNameWhite = 'white.png';
63
-        $this->sPathWhite = "$tmpDir/{$this->sNameWhite}";
64
-        $this->sSizeWhite = filesize($sSrcWhite);
65
-        // Copy the file to the temp dir.
66
-        @copy($sSrcWhite, $this->sPathWhite);
67
-
68
-        $sSrcBlue = __DIR__ . '/../upload/src/blue.png';
69
-        $this->sNameBlue = 'blue.png';
70
-        $this->sPathBlue = "$tmpDir/{$this->sNameBlue}";
71
-        $this->sSizeBlue = filesize($sSrcBlue);
72
-        // Copy the file to the temp dir.
73
-        @copy($sSrcBlue, $this->sPathBlue);
74
-
75
-        jaxon()->register(Jaxon::CALLABLE_CLASS, 'SampleUpload', __DIR__ . '/../src/sample.php');
76
-        jaxon()->di()->getBootstrap()->onBoot();
77
-    }
78
-
79
-    /**
52
+public function setUp(): void
53
+{
54
+_register();
55
+jaxon()->setOption('core.upload.enabled', true);
56
+
57
+jaxon()->setOption('core.response.send', false);
58
+$tmpDir = __DIR__ . '/../upload/tmp';
59
+@mkdir($tmpDir);
60
+
61
+$sSrcWhite = __DIR__ . '/../upload/src/white.png';
62
+$this->sNameWhite = 'white.png';
63
+$this->sPathWhite = "$tmpDir/{$this->sNameWhite}";
64
+$this->sSizeWhite = filesize($sSrcWhite);
65
+// Copy the file to the temp dir.
66
+@copy($sSrcWhite, $this->sPathWhite);
67
+
68
+$sSrcBlue = __DIR__ . '/../upload/src/blue.png';
69
+$this->sNameBlue = 'blue.png';
70
+$this->sPathBlue = "$tmpDir/{$this->sNameBlue}";
71
+$this->sSizeBlue = filesize($sSrcBlue);
72
+// Copy the file to the temp dir.
73
+@copy($sSrcBlue, $this->sPathBlue);
74
+
75
+jaxon()->register(Jaxon::CALLABLE_CLASS, 'SampleUpload', __DIR__ . '/../src/sample.php');
76
+jaxon()->di()->getBootstrap()->onBoot();
77
+}
78
+
79
+/**
80 80
      * @throws SetupException
81 81
      */
82
-    public function tearDown(): void
83
-    {
84
-        jaxon()->reset();
85
-        parent::tearDown();
86
-    }
82
+public function tearDown(): void
83
+{
84
+jaxon()->reset();
85
+parent::tearDown();
86
+}
87 87
 
88
-    /**
88
+/**
89 89
      * @throws RequestException
90 90
      */
91
-    public function testAjaxUpload()
92
-    {
93
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
94
-        // Send a request to the registered class
95
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
96
-            return $c->g(ServerRequestCreator::class)
97
-                ->fromGlobals()
98
-                ->withParsedBody([
99
-                    'jxncall' => json_encode([
100
-                        'type' => 'class',
101
-                        'name' => 'SampleUpload',
102
-                        'method' => 'myMethod',
103
-                        'args' => [],
104
-                    ]),
105
-                ])
106
-                ->withUploadedFiles([
107
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
108
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
109
-                ])
110
-                ->withMethod('POST');
111
-        });
112
-
113
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
114
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
115
-        jaxon()->processRequest();
116
-
117
-        // Uploaded files
118
-        $aFiles = jaxon()->upload()->files();
119
-        $this->assertCount(1, $aFiles);
120
-        $this->assertCount(1, $aFiles['image']);
121
-        $xFile = $aFiles['image'][0];
122
-        $this->assertEquals('white', $xFile->name());
123
-        $this->assertEquals($this->sNameWhite, $xFile->filename());
124
-        $this->assertEquals('png', $xFile->type());
125
-        $this->assertEquals('png', $xFile->extension());
126
-    }
127
-
128
-    /**
91
+public function testAjaxUpload()
92
+{
93
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
94
+// Send a request to the registered class
95
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
96
+return $c->g(ServerRequestCreator::class)
97
+    ->fromGlobals()
98
+    ->withParsedBody([
99
+        'jxncall' => json_encode([
100
+            'type' => 'class',
101
+            'name' => 'SampleUpload',
102
+            'method' => 'myMethod',
103
+            'args' => [],
104
+        ]),
105
+    ])
106
+    ->withUploadedFiles([
107
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
108
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
109
+    ])
110
+    ->withMethod('POST');
111
+});
112
+
113
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
114
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
115
+jaxon()->processRequest();
116
+
117
+// Uploaded files
118
+$aFiles = jaxon()->upload()->files();
119
+$this->assertCount(1, $aFiles);
120
+$this->assertCount(1, $aFiles['image']);
121
+$xFile = $aFiles['image'][0];
122
+$this->assertEquals('white', $xFile->name());
123
+$this->assertEquals($this->sNameWhite, $xFile->filename());
124
+$this->assertEquals('png', $xFile->type());
125
+$this->assertEquals('png', $xFile->extension());
126
+}
127
+
128
+/**
129 129
      * @throws RequestException
130 130
      */
131
-    public function testAjaxUploadMultipleFiles()
132
-    {
133
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
134
-        // Send a request to the registered class
135
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
136
-            return $c->g(ServerRequestCreator::class)
137
-                ->fromGlobals()
138
-                ->withParsedBody([
139
-                    'jxncall' => json_encode([
140
-                        'type' => 'class',
141
-                        'name' => 'SampleUpload',
142
-                        'method' => 'myMethod',
143
-                        'args' => [],
144
-                    ]),
145
-                ])
146
-                ->withUploadedFiles([
147
-                    'image' => [
148
-                        new UploadedFile($this->sPathWhite, $this->sSizeWhite,
149
-                            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
150
-                        new UploadedFile($this->sPathBlue, $this->sSizeBlue,
151
-                            UPLOAD_ERR_OK, $this->sNameBlue, 'png'),
152
-                    ],
153
-                ])
154
-                ->withMethod('POST');
155
-        });
156
-
157
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
158
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
159
-        jaxon()->processRequest();
160
-
161
-        // Uploaded files
162
-        $aFiles = jaxon()->upload()->files();
163
-        $this->assertCount(1, $aFiles);
164
-        $this->assertCount(2, $aFiles['image']);
165
-        $xFile = $aFiles['image'][0];
166
-        $this->assertEquals('white', $xFile->name());
167
-        $this->assertEquals($this->sNameWhite, $xFile->filename());
168
-        $this->assertEquals('png', $xFile->type());
169
-        $this->assertEquals('png', $xFile->extension());
170
-        $xFile = $aFiles['image'][1];
171
-        $this->assertEquals('blue', $xFile->name());
172
-        $this->assertEquals($this->sNameBlue, $xFile->filename());
173
-        $this->assertEquals('png', $xFile->type());
174
-        $this->assertEquals('png', $xFile->extension());
175
-    }
176
-
177
-    /**
131
+public function testAjaxUploadMultipleFiles()
132
+{
133
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
134
+// Send a request to the registered class
135
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
136
+return $c->g(ServerRequestCreator::class)
137
+    ->fromGlobals()
138
+    ->withParsedBody([
139
+        'jxncall' => json_encode([
140
+            'type' => 'class',
141
+            'name' => 'SampleUpload',
142
+            'method' => 'myMethod',
143
+            'args' => [],
144
+        ]),
145
+    ])
146
+    ->withUploadedFiles([
147
+        'image' => [
148
+            new UploadedFile($this->sPathWhite, $this->sSizeWhite,
149
+                UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
150
+            new UploadedFile($this->sPathBlue, $this->sSizeBlue,
151
+                UPLOAD_ERR_OK, $this->sNameBlue, 'png'),
152
+        ],
153
+    ])
154
+    ->withMethod('POST');
155
+});
156
+
157
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
158
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
159
+jaxon()->processRequest();
160
+
161
+// Uploaded files
162
+$aFiles = jaxon()->upload()->files();
163
+$this->assertCount(1, $aFiles);
164
+$this->assertCount(2, $aFiles['image']);
165
+$xFile = $aFiles['image'][0];
166
+$this->assertEquals('white', $xFile->name());
167
+$this->assertEquals($this->sNameWhite, $xFile->filename());
168
+$this->assertEquals('png', $xFile->type());
169
+$this->assertEquals('png', $xFile->extension());
170
+$xFile = $aFiles['image'][1];
171
+$this->assertEquals('blue', $xFile->name());
172
+$this->assertEquals($this->sNameBlue, $xFile->filename());
173
+$this->assertEquals('png', $xFile->type());
174
+$this->assertEquals('png', $xFile->extension());
175
+}
176
+
177
+/**
178 178
      * @throws RequestException
179 179
      */
180
-    public function testAjaxUploadMultipleNames()
181
-    {
182
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
183
-        // Send a request to the registered class
184
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
185
-            return $c->g(ServerRequestCreator::class)
186
-                ->fromGlobals()
187
-                ->withParsedBody([
188
-                    'jxncall' => json_encode([
189
-                        'type' => 'class',
190
-                        'name' => 'SampleUpload',
191
-                        'method' => 'myMethod',
192
-                        'args' => [],
193
-                    ]),
194
-                ])
195
-                ->withUploadedFiles([
196
-                    'white' => [
197
-                        new UploadedFile($this->sPathWhite, $this->sSizeWhite,
198
-                            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
199
-                    ],
200
-                    'blue' => [
201
-                        new UploadedFile($this->sPathBlue, $this->sSizeBlue,
202
-                            UPLOAD_ERR_OK, $this->sNameBlue, 'png'),
203
-                    ],
204
-                ])
205
-                ->withMethod('POST');
206
-        });
207
-
208
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
209
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
210
-        jaxon()->processRequest();
211
-
212
-        // Uploaded files
213
-        $aFiles = jaxon()->upload()->files();
214
-        $this->assertCount(2, $aFiles);
215
-        $this->assertCount(1, $aFiles['white']);
216
-        $this->assertCount(1, $aFiles['blue']);
217
-        $xFile = $aFiles['white'][0];
218
-        $this->assertEquals('white', $xFile->name());
219
-        $this->assertEquals($this->sNameWhite, $xFile->filename());
220
-        $this->assertEquals('png', $xFile->type());
221
-        $this->assertEquals('png', $xFile->extension());
222
-        $xFile = $aFiles['blue'][0];
223
-        $this->assertEquals('blue', $xFile->name());
224
-        $this->assertEquals($this->sNameBlue, $xFile->filename());
225
-        $this->assertEquals('png', $xFile->type());
226
-        $this->assertEquals('png', $xFile->extension());
227
-    }
228
-
229
-    /**
180
+public function testAjaxUploadMultipleNames()
181
+{
182
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
183
+// Send a request to the registered class
184
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
185
+return $c->g(ServerRequestCreator::class)
186
+    ->fromGlobals()
187
+    ->withParsedBody([
188
+        'jxncall' => json_encode([
189
+            'type' => 'class',
190
+            'name' => 'SampleUpload',
191
+            'method' => 'myMethod',
192
+            'args' => [],
193
+        ]),
194
+    ])
195
+    ->withUploadedFiles([
196
+        'white' => [
197
+            new UploadedFile($this->sPathWhite, $this->sSizeWhite,
198
+                UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
199
+        ],
200
+        'blue' => [
201
+            new UploadedFile($this->sPathBlue, $this->sSizeBlue,
202
+                UPLOAD_ERR_OK, $this->sNameBlue, 'png'),
203
+        ],
204
+    ])
205
+    ->withMethod('POST');
206
+});
207
+
208
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
209
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
210
+jaxon()->processRequest();
211
+
212
+// Uploaded files
213
+$aFiles = jaxon()->upload()->files();
214
+$this->assertCount(2, $aFiles);
215
+$this->assertCount(1, $aFiles['white']);
216
+$this->assertCount(1, $aFiles['blue']);
217
+$xFile = $aFiles['white'][0];
218
+$this->assertEquals('white', $xFile->name());
219
+$this->assertEquals($this->sNameWhite, $xFile->filename());
220
+$this->assertEquals('png', $xFile->type());
221
+$this->assertEquals('png', $xFile->extension());
222
+$xFile = $aFiles['blue'][0];
223
+$this->assertEquals('blue', $xFile->name());
224
+$this->assertEquals($this->sNameBlue, $xFile->filename());
225
+$this->assertEquals('png', $xFile->type());
226
+$this->assertEquals('png', $xFile->extension());
227
+}
228
+
229
+/**
230 230
      * @throws RequestException
231 231
      */
232
-    public function testAjaxUploadNameSanitizer()
233
-    {
234
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
235
-        jaxon()->upload()->sanitizer(function($sFilename, $sVarName) {
236
-            return $sVarName === 'image' ? 'img_' . $sFilename : $sFilename;
237
-        });
238
-        // Send a request to the registered class
239
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
240
-            return $c->g(ServerRequestCreator::class)
241
-                ->fromGlobals()
242
-                ->withParsedBody([
243
-                    'jxncall' => json_encode([
244
-                        'type' => 'class',
245
-                        'name' => 'SampleUpload',
246
-                        'method' => 'myMethod',
247
-                        'args' => [],
248
-                    ]),
249
-                ])
250
-                ->withUploadedFiles([
251
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
252
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
253
-                ])
254
-                ->withMethod('POST');
255
-        });
256
-
257
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
258
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
259
-        jaxon()->processRequest();
260
-
261
-        // Uploaded files
262
-        $aFiles = jaxon()->upload()->files();
263
-        $this->assertCount(1, $aFiles);
264
-        $this->assertCount(1, $aFiles['image']);
265
-        $xFile = $aFiles['image'][0];
266
-        $this->assertEquals('img_white', $xFile->name());
267
-        $this->assertEquals('png', $xFile->type());
268
-        $this->assertEquals('png', $xFile->extension());
269
-        $this->assertEquals($this->sNameWhite, $xFile->filename());
270
-    }
271
-
272
-    /**
232
+public function testAjaxUploadNameSanitizer()
233
+{
234
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
235
+jaxon()->upload()->sanitizer(function($sFilename, $sVarName) {
236
+return $sVarName === 'image' ? 'img_' . $sFilename : $sFilename;
237
+});
238
+// Send a request to the registered class
239
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
240
+return $c->g(ServerRequestCreator::class)
241
+    ->fromGlobals()
242
+    ->withParsedBody([
243
+        'jxncall' => json_encode([
244
+            'type' => 'class',
245
+            'name' => 'SampleUpload',
246
+            'method' => 'myMethod',
247
+            'args' => [],
248
+        ]),
249
+    ])
250
+    ->withUploadedFiles([
251
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
252
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
253
+    ])
254
+    ->withMethod('POST');
255
+});
256
+
257
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
258
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
259
+jaxon()->processRequest();
260
+
261
+// Uploaded files
262
+$aFiles = jaxon()->upload()->files();
263
+$this->assertCount(1, $aFiles);
264
+$this->assertCount(1, $aFiles['image']);
265
+$xFile = $aFiles['image'][0];
266
+$this->assertEquals('img_white', $xFile->name());
267
+$this->assertEquals('png', $xFile->type());
268
+$this->assertEquals('png', $xFile->extension());
269
+$this->assertEquals($this->sNameWhite, $xFile->filename());
270
+}
271
+
272
+/**
273 273
      * @throws RequestException
274 274
      */
275
-    public function testUploadFileTypeValidationOk()
276
-    {
277
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
278
-        jaxon()->setOption('upload.default.types', ['png']);
279
-        // Send a request to the registered class
280
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
281
-            return $c->g(ServerRequestCreator::class)
282
-                ->fromGlobals()
283
-                ->withParsedBody([
284
-                    'jxncall' => json_encode([
285
-                        'type' => 'class',
286
-                        'name' => 'SampleUpload',
287
-                        'method' => 'myMethod',
288
-                        'args' => [],
289
-                    ]),
290
-                ])
291
-                ->withUploadedFiles([
292
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
293
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
294
-                ])->withMethod('POST');
295
-        });
296
-
297
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
298
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
299
-        jaxon()->processRequest();
300
-
301
-        // Return the file name for the next test
302
-        $aFiles = jaxon()->upload()->files();
303
-        $this->assertCount(1, $aFiles);
304
-        $this->assertCount(1, $aFiles['image']);
305
-        $xFile = $aFiles['image'][0];
306
-        $this->assertEquals('white', $xFile->name());
307
-        $this->assertEquals($this->sNameWhite, $xFile->filename());
308
-    }
309
-
310
-    /**
275
+public function testUploadFileTypeValidationOk()
276
+{
277
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
278
+jaxon()->setOption('upload.default.types', ['png']);
279
+// Send a request to the registered class
280
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
281
+return $c->g(ServerRequestCreator::class)
282
+    ->fromGlobals()
283
+    ->withParsedBody([
284
+        'jxncall' => json_encode([
285
+            'type' => 'class',
286
+            'name' => 'SampleUpload',
287
+            'method' => 'myMethod',
288
+            'args' => [],
289
+        ]),
290
+    ])
291
+    ->withUploadedFiles([
292
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
293
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
294
+    ])->withMethod('POST');
295
+});
296
+
297
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
298
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
299
+jaxon()->processRequest();
300
+
301
+// Return the file name for the next test
302
+$aFiles = jaxon()->upload()->files();
303
+$this->assertCount(1, $aFiles);
304
+$this->assertCount(1, $aFiles['image']);
305
+$xFile = $aFiles['image'][0];
306
+$this->assertEquals('white', $xFile->name());
307
+$this->assertEquals($this->sNameWhite, $xFile->filename());
308
+}
309
+
310
+/**
311 311
      * @throws RequestException
312 312
      */
313
-    public function testUploadFileTypeValidationError()
314
-    {
315
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
316
-        jaxon()->setOption('upload.default.types', ['jpg']);
317
-        // Send a request to the registered class
318
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
319
-            return $c->g(ServerRequestCreator::class)
320
-                ->fromGlobals()
321
-                ->withParsedBody([
322
-                    'jxncall' => json_encode([
323
-                        'type' => 'class',
324
-                        'name' => 'SampleUpload',
325
-                        'method' => 'myMethod',
326
-                        'args' => [],
327
-                    ]),
328
-                ])
329
-                ->withUploadedFiles([
330
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
331
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
332
-                ])
333
-                ->withMethod('POST');
334
-        });
335
-
336
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
337
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
338
-        $this->expectException(RequestException::class);
339
-        jaxon()->processRequest();
340
-    }
341
-
342
-    /**
313
+public function testUploadFileTypeValidationError()
314
+{
315
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
316
+jaxon()->setOption('upload.default.types', ['jpg']);
317
+// Send a request to the registered class
318
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
319
+return $c->g(ServerRequestCreator::class)
320
+    ->fromGlobals()
321
+    ->withParsedBody([
322
+        'jxncall' => json_encode([
323
+            'type' => 'class',
324
+            'name' => 'SampleUpload',
325
+            'method' => 'myMethod',
326
+            'args' => [],
327
+        ]),
328
+    ])
329
+    ->withUploadedFiles([
330
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
331
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
332
+    ])
333
+    ->withMethod('POST');
334
+});
335
+
336
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
337
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
338
+$this->expectException(RequestException::class);
339
+jaxon()->processRequest();
340
+}
341
+
342
+/**
343 343
      * @throws RequestException
344 344
      */
345
-    public function testUploadFileExtensionValidationOk()
346
-    {
347
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
348
-        jaxon()->setOption('upload.default.extensions', ['png']);
349
-        // Send a request to the registered class
350
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
351
-            return $c->g(ServerRequestCreator::class)
352
-                ->fromGlobals()
353
-                ->withParsedBody([
354
-                    'jxncall' => json_encode([
355
-                        'type' => 'class',
356
-                        'name' => 'SampleUpload',
357
-                        'method' => 'myMethod',
358
-                        'args' => [],
359
-                    ]),
360
-                ])
361
-                ->withUploadedFiles([
362
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
363
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
364
-                ])
365
-                ->withMethod('POST');
366
-        });
367
-
368
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
369
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
370
-        jaxon()->processRequest();
371
-
372
-        // Return the file name for the next test
373
-        $aFiles = jaxon()->upload()->files();
374
-        $this->assertCount(1, $aFiles);
375
-        $this->assertCount(1, $aFiles['image']);
376
-        $xFile = $aFiles['image'][0];
377
-        $this->assertEquals('white', $xFile->name());
378
-        $this->assertEquals($this->sNameWhite, $xFile->filename());
379
-    }
380
-
381
-    /**
345
+public function testUploadFileExtensionValidationOk()
346
+{
347
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
348
+jaxon()->setOption('upload.default.extensions', ['png']);
349
+// Send a request to the registered class
350
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
351
+return $c->g(ServerRequestCreator::class)
352
+    ->fromGlobals()
353
+    ->withParsedBody([
354
+        'jxncall' => json_encode([
355
+            'type' => 'class',
356
+            'name' => 'SampleUpload',
357
+            'method' => 'myMethod',
358
+            'args' => [],
359
+        ]),
360
+    ])
361
+    ->withUploadedFiles([
362
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
363
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
364
+    ])
365
+    ->withMethod('POST');
366
+});
367
+
368
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
369
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
370
+jaxon()->processRequest();
371
+
372
+// Return the file name for the next test
373
+$aFiles = jaxon()->upload()->files();
374
+$this->assertCount(1, $aFiles);
375
+$this->assertCount(1, $aFiles['image']);
376
+$xFile = $aFiles['image'][0];
377
+$this->assertEquals('white', $xFile->name());
378
+$this->assertEquals($this->sNameWhite, $xFile->filename());
379
+}
380
+
381
+/**
382 382
      * @throws RequestException
383 383
      */
384
-    public function testUploadFileExtensionValidationError()
385
-    {
386
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
387
-        jaxon()->setOption('upload.default.extensions', ['jpg']);
388
-        // Send a request to the registered class
389
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
390
-            return $c->g(ServerRequestCreator::class)
391
-                ->fromGlobals()
392
-                ->withParsedBody([
393
-                    'jxncall' => json_encode([
394
-                        'type' => 'class',
395
-                        'name' => 'SampleUpload',
396
-                        'method' => 'myMethod',
397
-                        'args' => [],
398
-                    ]),
399
-                ])
400
-                ->withUploadedFiles([
401
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
402
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
403
-                ])
404
-                ->withMethod('POST');
405
-        });
406
-
407
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
408
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
409
-        $this->expectException(RequestException::class);
410
-        jaxon()->processRequest();
411
-    }
412
-
413
-    /**
384
+public function testUploadFileExtensionValidationError()
385
+{
386
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
387
+jaxon()->setOption('upload.default.extensions', ['jpg']);
388
+// Send a request to the registered class
389
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
390
+return $c->g(ServerRequestCreator::class)
391
+    ->fromGlobals()
392
+    ->withParsedBody([
393
+        'jxncall' => json_encode([
394
+            'type' => 'class',
395
+            'name' => 'SampleUpload',
396
+            'method' => 'myMethod',
397
+            'args' => [],
398
+        ]),
399
+    ])
400
+    ->withUploadedFiles([
401
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
402
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
403
+    ])
404
+    ->withMethod('POST');
405
+});
406
+
407
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
408
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
409
+$this->expectException(RequestException::class);
410
+jaxon()->processRequest();
411
+}
412
+
413
+/**
414 414
      * @throws RequestException
415 415
      */
416
-    public function testUploadFileMaxSizeValidationOk()
417
-    {
418
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
419
-        jaxon()->setOption('upload.default.max-size', 30000);
420
-        // Send a request to the registered class
421
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
422
-            return $c->g(ServerRequestCreator::class)
423
-                ->fromGlobals()
424
-                ->withParsedBody([
425
-                    'jxncall' => json_encode([
426
-                        'type' => 'class',
427
-                        'name' => 'SampleUpload',
428
-                        'method' => 'myMethod',
429
-                        'args' => [],
430
-                    ]),
431
-                ])
432
-                ->withUploadedFiles([
433
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
434
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
435
-                ])
436
-                ->withMethod('POST');
437
-        });
438
-
439
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
440
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
441
-        jaxon()->processRequest();
442
-
443
-        // Return the file name for the next test
444
-        $aFiles = jaxon()->upload()->files();
445
-        $this->assertCount(1, $aFiles);
446
-        $this->assertCount(1, $aFiles['image']);
447
-        $xFile = $aFiles['image'][0];
448
-        $this->assertEquals('white', $xFile->name());
449
-        $this->assertEquals($this->sNameWhite, $xFile->filename());
450
-    }
451
-
452
-    /**
416
+public function testUploadFileMaxSizeValidationOk()
417
+{
418
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
419
+jaxon()->setOption('upload.default.max-size', 30000);
420
+// Send a request to the registered class
421
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
422
+return $c->g(ServerRequestCreator::class)
423
+    ->fromGlobals()
424
+    ->withParsedBody([
425
+        'jxncall' => json_encode([
426
+            'type' => 'class',
427
+            'name' => 'SampleUpload',
428
+            'method' => 'myMethod',
429
+            'args' => [],
430
+        ]),
431
+    ])
432
+    ->withUploadedFiles([
433
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
434
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
435
+    ])
436
+    ->withMethod('POST');
437
+});
438
+
439
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
440
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
441
+jaxon()->processRequest();
442
+
443
+// Return the file name for the next test
444
+$aFiles = jaxon()->upload()->files();
445
+$this->assertCount(1, $aFiles);
446
+$this->assertCount(1, $aFiles['image']);
447
+$xFile = $aFiles['image'][0];
448
+$this->assertEquals('white', $xFile->name());
449
+$this->assertEquals($this->sNameWhite, $xFile->filename());
450
+}
451
+
452
+/**
453 453
      * @throws RequestException
454 454
      */
455
-    public function testUploadFileMaxSizeValidationError()
456
-    {
457
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
458
-        jaxon()->setOption('upload.default.max-size', 25000);
459
-        // Send a request to the registered class
460
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
461
-            return $c->g(ServerRequestCreator::class)
462
-                ->fromGlobals()
463
-                ->withParsedBody([
464
-                    'jxncall' => json_encode([
465
-                        'type' => 'class',
466
-                        'name' => 'SampleUpload',
467
-                        'method' => 'myMethod',
468
-                        'args' => [],
469
-                    ]),
470
-                ])
471
-                ->withUploadedFiles([
472
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
473
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
474
-                ])
475
-                ->withMethod('POST');
476
-        });
477
-
478
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
479
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
480
-        $this->expectException(RequestException::class);
481
-        jaxon()->processRequest();
482
-    }
483
-
484
-    /**
455
+public function testUploadFileMaxSizeValidationError()
456
+{
457
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
458
+jaxon()->setOption('upload.default.max-size', 25000);
459
+// Send a request to the registered class
460
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
461
+return $c->g(ServerRequestCreator::class)
462
+    ->fromGlobals()
463
+    ->withParsedBody([
464
+        'jxncall' => json_encode([
465
+            'type' => 'class',
466
+            'name' => 'SampleUpload',
467
+            'method' => 'myMethod',
468
+            'args' => [],
469
+        ]),
470
+    ])
471
+    ->withUploadedFiles([
472
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
473
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
474
+    ])
475
+    ->withMethod('POST');
476
+});
477
+
478
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
479
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
480
+$this->expectException(RequestException::class);
481
+jaxon()->processRequest();
482
+}
483
+
484
+/**
485 485
      * @throws RequestException
486 486
      */
487
-    public function testUploadFileMinSizeValidationOk()
488
-    {
489
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
490
-        jaxon()->setOption('upload.default.min-size', 25000);
491
-        // Send a request to the registered class
492
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
493
-            return $c->g(ServerRequestCreator::class)
494
-                ->fromGlobals()
495
-                ->withParsedBody([
496
-                    'jxncall' => json_encode([
497
-                        'type' => 'class',
498
-                        'name' => 'SampleUpload',
499
-                        'method' => 'myMethod',
500
-                        'args' => [],
501
-                    ]),
502
-                ])
503
-                ->withUploadedFiles([
504
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
505
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
506
-                ])
507
-                ->withMethod('POST');
508
-        });
509
-
510
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
511
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
512
-        jaxon()->processRequest();
513
-
514
-        // Return the file name for the next test
515
-        $aFiles = jaxon()->upload()->files();
516
-        $this->assertCount(1, $aFiles);
517
-        $this->assertCount(1, $aFiles['image']);
518
-        $xFile = $aFiles['image'][0];
519
-        $this->assertEquals('white', $xFile->name());
520
-        $this->assertEquals($this->sNameWhite, $xFile->filename());
521
-    }
522
-
523
-    /**
487
+public function testUploadFileMinSizeValidationOk()
488
+{
489
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
490
+jaxon()->setOption('upload.default.min-size', 25000);
491
+// Send a request to the registered class
492
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
493
+return $c->g(ServerRequestCreator::class)
494
+    ->fromGlobals()
495
+    ->withParsedBody([
496
+        'jxncall' => json_encode([
497
+            'type' => 'class',
498
+            'name' => 'SampleUpload',
499
+            'method' => 'myMethod',
500
+            'args' => [],
501
+        ]),
502
+    ])
503
+    ->withUploadedFiles([
504
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
505
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
506
+    ])
507
+    ->withMethod('POST');
508
+});
509
+
510
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
511
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
512
+jaxon()->processRequest();
513
+
514
+// Return the file name for the next test
515
+$aFiles = jaxon()->upload()->files();
516
+$this->assertCount(1, $aFiles);
517
+$this->assertCount(1, $aFiles['image']);
518
+$xFile = $aFiles['image'][0];
519
+$this->assertEquals('white', $xFile->name());
520
+$this->assertEquals($this->sNameWhite, $xFile->filename());
521
+}
522
+
523
+/**
524 524
      * @throws RequestException
525 525
      */
526
-    public function testUploadFileMinSizeValidationError()
527
-    {
528
-        jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
529
-        jaxon()->setOption('upload.default.min-size', 30000);
530
-        // Send a request to the registered class
531
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
532
-            return $c->g(ServerRequestCreator::class)
533
-                ->fromGlobals()
534
-                ->withParsedBody([
535
-                    'jxncall' => json_encode([
536
-                        'type' => 'class',
537
-                        'name' => 'SampleUpload',
538
-                        'method' => 'myMethod',
539
-                        'args' => [],
540
-                    ]),
541
-                ])
542
-                ->withUploadedFiles([
543
-                    'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
544
-                        UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
545
-                ])
546
-                ->withMethod('POST');
547
-        });
548
-
549
-        $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
550
-        $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
551
-        $this->expectException(RequestException::class);
552
-        jaxon()->processRequest();
553
-    }
554
-
555
-    /**
526
+public function testUploadFileMinSizeValidationError()
527
+{
528
+jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst');
529
+jaxon()->setOption('upload.default.min-size', 30000);
530
+// Send a request to the registered class
531
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
532
+return $c->g(ServerRequestCreator::class)
533
+    ->fromGlobals()
534
+    ->withParsedBody([
535
+        'jxncall' => json_encode([
536
+            'type' => 'class',
537
+            'name' => 'SampleUpload',
538
+            'method' => 'myMethod',
539
+            'args' => [],
540
+        ]),
541
+    ])
542
+    ->withUploadedFiles([
543
+        'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite,
544
+            UPLOAD_ERR_OK, $this->sNameWhite, 'png'),
545
+    ])
546
+    ->withMethod('POST');
547
+});
548
+
549
+$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest());
550
+$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest()));
551
+$this->expectException(RequestException::class);
552
+jaxon()->processRequest();
553
+}
554
+
555
+/**
556 556
      * @throws RequestException
557 557
      */
558
-    public function testRequestWithNoPluginNoUpload()
559
-    {
560
-        jaxon()->setOption('core.upload.enabled', false);
561
-        // Send a request to the registered class
562
-        jaxon()->di()->set(ServerRequestInterface::class, function($c) {
563
-            return $c->g(ServerRequestCreator::class)
564
-                ->fromGlobals()
565
-                ->withParsedBody([
566
-                    'jxncall' => json_encode([
567
-                        'who' => 'Nobody',
568
-                        'args' => [],
569
-                    ]),
570
-                ])
571
-                ->withMethod('POST');
572
-        });
573
-
574
-        $this->assertFalse(jaxon()->di()->getRequestHandler()->canProcessRequest());
575
-    }
558
+public function testRequestWithNoPluginNoUpload()
559
+{
560
+jaxon()->setOption('core.upload.enabled', false);
561
+// Send a request to the registered class
562
+jaxon()->di()->set(ServerRequestInterface::class, function($c) {
563
+return $c->g(ServerRequestCreator::class)
564
+    ->fromGlobals()
565
+    ->withParsedBody([
566
+        'jxncall' => json_encode([
567
+            'who' => 'Nobody',
568
+            'args' => [],
569
+        ]),
570
+    ])
571
+    ->withMethod('POST');
572
+});
573
+
574
+$this->assertFalse(jaxon()->di()->getRequestHandler()->canProcessRequest());
575
+}
576 576
 }
Please login to merge, or discard this patch.