Completed
Push — master ( 39246a...48ecd1 )
by Thierry
02:57
created
src/Request/Plugin/CallableClass.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -61,19 +61,19 @@  discard block
 block discarded – undo
61 61
 
62 62
     public function __construct()
63 63
     {
64
-        if(!empty($_GET['jxncls']))
64
+        if (!empty($_GET['jxncls']))
65 65
         {
66 66
             $this->sRequestedClass = $_GET['jxncls'];
67 67
         }
68
-        if(!empty($_GET['jxnmthd']))
68
+        if (!empty($_GET['jxnmthd']))
69 69
         {
70 70
             $this->sRequestedMethod = $_GET['jxnmthd'];
71 71
         }
72
-        if(!empty($_POST['jxncls']))
72
+        if (!empty($_POST['jxncls']))
73 73
         {
74 74
             $this->sRequestedClass = $_POST['jxncls'];
75 75
         }
76
-        if(!empty($_POST['jxnmthd']))
76
+        if (!empty($_POST['jxnmthd']))
77 77
         {
78 78
             $this->sRequestedMethod = $_POST['jxnmthd'];
79 79
         }
@@ -100,16 +100,16 @@  discard block
 block discarded – undo
100 100
      */
101 101
     public function register($sType, $sClassName, $aOptions)
102 102
     {
103
-        if($sType != $this->getName())
103
+        if ($sType != $this->getName())
104 104
         {
105 105
             return false;
106 106
         }
107 107
 
108
-        if(!is_string($sClassName))
108
+        if (!is_string($sClassName))
109 109
         {
110 110
             throw new \Jaxon\Exception\Error($this->trans('errors.objects.invalid-declaration'));
111 111
         }
112
-        if(!is_array($aOptions))
112
+        if (!is_array($aOptions))
113 113
         {
114 114
             throw new \Jaxon\Exception\Error($this->trans('errors.objects.invalid-declaration'));
115 115
         }
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
         // at the beginning and the end of the class name.
134 134
         $sClassName = trim(str_replace(['.', '_'], ['\\', '\\'], (string)$sClassName), '\\');
135 135
 
136
-        if(!key_exists($sClassName, $this->aClassOptions))
136
+        if (!key_exists($sClassName, $this->aClassOptions))
137 137
         {
138 138
             return null; // Class not registered
139 139
         }
140 140
 
141
-        if(key_exists($sClassName, $this->aCallableObjects))
141
+        if (key_exists($sClassName, $this->aCallableObjects))
142 142
         {
143 143
             return $this->aCallableObjects[$sClassName];
144 144
         }
@@ -146,9 +146,9 @@  discard block
 block discarded – undo
146 146
         // Create the callable object
147 147
         $xCallableObject = new \Jaxon\Request\Support\CallableObject($sClassName);
148 148
         $aOptions = $this->aClassOptions[$sClassName];
149
-        foreach($aOptions as $sMethod => $aValue)
149
+        foreach ($aOptions as $sMethod => $aValue)
150 150
         {
151
-            foreach($aValue as $sName => $sValue)
151
+            foreach ($aValue as $sName => $sValue)
152 152
             {
153 153
                 $xCallableObject->configure($sMethod, $sName, $sValue);
154 154
             }
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
         // Make sure the registered class exists
158 158
         // We need to check this after the callable object is configured
159 159
         // to take the 'include' option into account.
160
-        if(!class_exists($sClassName))
160
+        if (!class_exists($sClassName))
161 161
         {
162 162
             return null;
163 163
         }
@@ -165,12 +165,12 @@  discard block
 block discarded – undo
165 165
         $this->aCallableObjects[$sClassName] = $xCallableObject;
166 166
         // jaxon()->di()->set($sClassName, $xCallableObject);
167 167
         // Register the request factory for this callable object
168
-        jaxon()->di()->set($sClassName . '_Factory_Rq', function ($di) use ($sClassName) {
168
+        jaxon()->di()->set($sClassName . '_Factory_Rq', function($di) use ($sClassName) {
169 169
             $xCallableObject = $this->aCallableObjects[$sClassName];
170 170
             return new \Jaxon\Factory\Request\Portable($xCallableObject);
171 171
         });
172 172
         // Register the paginator factory for this callable object
173
-        jaxon()->di()->set($sClassName . '_Factory_Pg', function ($di) use ($sClassName) {
173
+        jaxon()->di()->set($sClassName . '_Factory_Pg', function($di) use ($sClassName) {
174 174
             $xCallableObject = $this->aCallableObjects[$sClassName];
175 175
             return new \Jaxon\Factory\Request\Paginator($xCallableObject);
176 176
         });
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
      */
200 200
     private function createCallableObjects()
201 201
     {
202
-        foreach(array_keys($this->aClassOptions) as $sClassName)
202
+        foreach (array_keys($this->aClassOptions) as $sClassName)
203 203
         {
204 204
             $this->getCallableObject($sClassName);
205 205
         }
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
         $this->createCallableObjects();
216 216
 
217 217
         $sHash = '';
218
-        foreach($this->aCallableObjects as $sClassName => $xCallableObject)
218
+        foreach ($this->aCallableObjects as $sClassName => $xCallableObject)
219 219
         {
220 220
             $sHash .= $sClassName . implode('|', $xCallableObject->getMethods());
221 221
         }
@@ -236,19 +236,19 @@  discard block
 block discarded – undo
236 236
         $sJaxonPrefix = $this->getOption('core.prefix.class');
237 237
         $aJsClasses = [];
238 238
         $sCode = '';
239
-        foreach($this->aClassOptions as $sClassName => $aOptions)
239
+        foreach ($this->aClassOptions as $sClassName => $aOptions)
240 240
         {
241
-            if(key_exists('separator', $aOptions) && $aOptions['separator'] != '.')
241
+            if (key_exists('separator', $aOptions) && $aOptions['separator'] != '.')
242 242
             {
243 243
                 continue;
244 244
             }
245 245
             $offset = 0;
246 246
             $sJsClasses = str_replace('\\', '.', $sClassName);
247
-            while(($dotPosition = strpos($sJsClasses, '.', $offset)) !== false)
247
+            while (($dotPosition = strpos($sJsClasses, '.', $offset)) !== false)
248 248
             {
249 249
                 $sJsClass = substr($sJsClasses, 0, $dotPosition);
250 250
                 // Generate code for this object
251
-                if(!key_exists($sJsClass, $aJsClasses))
251
+                if (!key_exists($sJsClass, $aJsClasses))
252 252
                 {
253 253
                     $sCode .= "$sJaxonPrefix$sJsClass = {};\n";
254 254
                     $aJsClasses[$sJsClass] = $sJsClass;
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
                 $offset = $dotPosition + 1;
257 257
             }
258 258
         }
259
-        foreach($this->aCallableObjects as $xCallableObject)
259
+        foreach ($this->aCallableObjects as $xCallableObject)
260 260
         {
261 261
             $sCode .= $xCallableObject->getScript();
262 262
         }
@@ -272,13 +272,13 @@  discard block
 block discarded – undo
272 272
     public function canProcessRequest()
273 273
     {
274 274
         // Check the validity of the class name
275
-        if(($this->sRequestedClass) && !$this->validateClass($this->sRequestedClass))
275
+        if (($this->sRequestedClass) && !$this->validateClass($this->sRequestedClass))
276 276
         {
277 277
             $this->sRequestedClass = null;
278 278
             $this->sRequestedMethod = null;
279 279
         }
280 280
         // Check the validity of the method name
281
-        if(($this->sRequestedMethod) && !$this->validateMethod($this->sRequestedMethod))
281
+        if (($this->sRequestedMethod) && !$this->validateMethod($this->sRequestedMethod))
282 282
         {
283 283
             $this->sRequestedClass = null;
284 284
             $this->sRequestedMethod = null;
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
      */
295 295
     public function processRequest()
296 296
     {
297
-        if(!$this->canProcessRequest())
297
+        if (!$this->canProcessRequest())
298 298
         {
299 299
             return false;
300 300
         }
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 
304 304
         // Find the requested method
305 305
         $xCallableObject = $this->getCallableObject($this->sRequestedClass);
306
-        if(!$xCallableObject || !$xCallableObject->hasMethod($this->sRequestedMethod))
306
+        if (!$xCallableObject || !$xCallableObject->hasMethod($this->sRequestedMethod))
307 307
         {
308 308
             // Unable to find the requested object or method
309 309
             throw new \Jaxon\Exception\Error($this->trans('errors.objects.invalid',
Please login to merge, or discard this patch.
src/Request/Plugin/CallableDir.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -82,19 +82,19 @@  discard block
 block discarded – undo
82 82
 
83 83
     public function __construct()
84 84
     {
85
-        if(!empty($_GET['jxncls']))
85
+        if (!empty($_GET['jxncls']))
86 86
         {
87 87
             $this->sRequestedClass = $_GET['jxncls'];
88 88
         }
89
-        if(!empty($_GET['jxnmthd']))
89
+        if (!empty($_GET['jxnmthd']))
90 90
         {
91 91
             $this->sRequestedMethod = $_GET['jxnmthd'];
92 92
         }
93
-        if(!empty($_POST['jxncls']))
93
+        if (!empty($_POST['jxncls']))
94 94
         {
95 95
             $this->sRequestedClass = $_POST['jxncls'];
96 96
         }
97
-        if(!empty($_POST['jxnmthd']))
97
+        if (!empty($_POST['jxnmthd']))
98 98
         {
99 99
             $this->sRequestedMethod = $_POST['jxnmthd'];
100 100
         }
@@ -145,34 +145,34 @@  discard block
 block discarded – undo
145 145
      */
146 146
     public function register($sType, $sDirectory, $aOptions)
147 147
     {
148
-        if($sType != $this->getName())
148
+        if ($sType != $this->getName())
149 149
         {
150 150
             return false;
151 151
         }
152 152
 
153
-        if(!is_string($sDirectory) || !is_dir($sDirectory))
153
+        if (!is_string($sDirectory) || !is_dir($sDirectory))
154 154
         {
155 155
             throw new \Jaxon\Exception\Error($this->trans('errors.objects.invalid-declaration'));
156 156
         }
157 157
         $sDirectory = trim($sDirectory, DIRECTORY_SEPARATOR);
158 158
 
159
-        if(is_string($aOptions))
159
+        if (is_string($aOptions))
160 160
         {
161 161
             $aOptions = ['namespace' => $aOptions];
162 162
         }
163
-        if(!is_array($aOptions))
163
+        if (!is_array($aOptions))
164 164
         {
165 165
             throw new \Jaxon\Exception\Error($this->trans('errors.objects.invalid-declaration'));
166 166
         }
167 167
 
168
-        if(!is_dir(($sDirectory = trim($sDirectory))))
168
+        if (!is_dir(($sDirectory = trim($sDirectory))))
169 169
         {
170 170
             return false;
171 171
         }
172 172
         $aOptions['directory'] = $sDirectory;
173 173
 
174 174
         $aProtected = key_exists('protected', $aOptions) ? $aOptions['protected'] : [];
175
-        if(!is_array($aProtected))
175
+        if (!is_array($aProtected))
176 176
         {
177 177
             throw new \Jaxon\Exception\Error($this->trans('errors.objects.invalid-declaration'));
178 178
         }
@@ -180,14 +180,14 @@  discard block
 block discarded – undo
180 180
 
181 181
         $sSeparator = key_exists('separator', $aOptions) ? $aOptions['separator'] : '.';
182 182
         // Only '.' and '_' are allowed to be used as separator. Any other value is ignored and '.' is used instead.
183
-        if(($sSeparator = trim($sSeparator)) != '_')
183
+        if (($sSeparator = trim($sSeparator)) != '_')
184 184
         {
185 185
             $sSeparator = '.';
186 186
         }
187 187
         $aOptions['separator'] = $sSeparator;
188 188
 
189 189
         $sNamespace = key_exists('namespace', $aOptions) ? $aOptions['namespace'] : '';
190
-        if(!($sNamespace = trim($sNamespace, ' \\')))
190
+        if (!($sNamespace = trim($sNamespace, ' \\')))
191 191
         {
192 192
             $sNamespace = '';
193 193
         }
@@ -202,10 +202,10 @@  discard block
 block discarded – undo
202 202
         // }
203 203
         // $aOptions['classes'] = $aNewOptions;
204 204
 
205
-        if(($sNamespace))
205
+        if (($sNamespace))
206 206
         {
207 207
             // Register the dir with PSR4 autoloading
208
-            if(($this->xAutoloader))
208
+            if (($this->xAutoloader))
209 209
             {
210 210
                 $this->xAutoloader->setPsr4($sNamespace . '\\', $sDirectory);
211 211
             }
@@ -221,20 +221,20 @@  discard block
 block discarded – undo
221 221
             $itDir = new RecursiveDirectoryIterator($sDirectory);
222 222
             $itFile = new RecursiveIteratorIterator($itDir);
223 223
             // Iterate on dir content
224
-            foreach($itFile as $xFile)
224
+            foreach ($itFile as $xFile)
225 225
             {
226 226
                 // skip everything except PHP files
227
-                if(!$xFile->isFile() || $xFile->getExtension() != 'php')
227
+                if (!$xFile->isFile() || $xFile->getExtension() != 'php')
228 228
                 {
229 229
                     continue;
230 230
                 }
231 231
 
232 232
                 $sClassName = $xFile->getBasename('.php');
233
-                if(($this->xAutoloader))
233
+                if (($this->xAutoloader))
234 234
                 {
235 235
                     $this->xAutoloader->addClassMap([$sClassName => $xFile->getPathname()]);
236 236
                 }
237
-                elseif(!class_exists($sClassName))
237
+                elseif (!class_exists($sClassName))
238 238
                 {
239 239
                     $aOptions['include'] = $xFile->getPathname();
240 240
                 }
@@ -260,27 +260,27 @@  discard block
 block discarded – undo
260 260
         $sClassName = trim(str_replace(['.', '_'], ['\\', '\\'], (string)$sClassName), '\\');
261 261
 
262 262
         // Make sure the registered class exists
263
-        if(!class_exists('\\' . $sClassName))
263
+        if (!class_exists('\\' . $sClassName))
264 264
         {
265 265
             return null;
266 266
         }
267 267
 
268
-        if(key_exists($sClassName, $this->aCallableObjects))
268
+        if (key_exists($sClassName, $this->aCallableObjects))
269 269
         {
270 270
             return $this->aCallableObjects[$sClassName];
271 271
         }
272 272
 
273 273
         // Find the corresponding namespace
274 274
         $sNamespace = null;
275
-        foreach(array_keys($this->aNamespaces) as $_sNamespace)
275
+        foreach (array_keys($this->aNamespaces) as $_sNamespace)
276 276
         {
277
-            if(substr($sClassName, 0, strlen($_sNamespace)) == $_sNamespace)
277
+            if (substr($sClassName, 0, strlen($_sNamespace)) == $_sNamespace)
278 278
             {
279 279
                 $sNamespace = $_sNamespace;
280 280
                 break;
281 281
             }
282 282
         }
283
-        if($sNamespace == null)
283
+        if ($sNamespace == null)
284 284
         {
285 285
             return null; // Class not registered
286 286
         }
@@ -288,13 +288,13 @@  discard block
 block discarded – undo
288 288
         // Create the callable object
289 289
         $xCallableObject = new \Jaxon\Request\Support\CallableObject($sClassName);
290 290
         $aOptions = $this->aNamespaces[$sNamespace];
291
-        foreach($aOptions as $sClass => $aClassOptions)
291
+        foreach ($aOptions as $sClass => $aClassOptions)
292 292
         {
293
-            if($sClass == '*' || trim(str_replace(['.', '_'], ['\\', '\\'], $sClass)) == $sClassName)
293
+            if ($sClass == '*' || trim(str_replace(['.', '_'], ['\\', '\\'], $sClass)) == $sClassName)
294 294
             {
295
-                foreach($aClassOptions as $sMethod => $aValue)
295
+                foreach ($aClassOptions as $sMethod => $aValue)
296 296
                 {
297
-                    foreach($aValue as $sName => $sValue)
297
+                    foreach ($aValue as $sName => $sValue)
298 298
                     {
299 299
                         $xCallableObject->configure($sMethod, $sName, $sValue);
300 300
                     }
@@ -305,12 +305,12 @@  discard block
 block discarded – undo
305 305
         $this->aCallableObjects[$sClassName] = $xCallableObject;
306 306
         // jaxon()->di()->set($sClassName, $xCallableObject);
307 307
         // Register the request factory for this callable object
308
-        jaxon()->di()->set($sClassName . '_Factory_Rq', function ($di) use ($sClassName) {
308
+        jaxon()->di()->set($sClassName . '_Factory_Rq', function($di) use ($sClassName) {
309 309
             $xCallableObject = $this->aCallableObjects[$sClassName];
310 310
             return new \Jaxon\Factory\Request\Portable($xCallableObject);
311 311
         });
312 312
         // Register the paginator factory for this callable object
313
-        jaxon()->di()->set($sClassName . '_Factory_Pg', function ($di) use ($sClassName) {
313
+        jaxon()->di()->set($sClassName . '_Factory_Pg', function($di) use ($sClassName) {
314 314
             $xCallableObject = $this->aCallableObjects[$sClassName];
315 315
             return new \Jaxon\Factory\Request\Paginator($xCallableObject);
316 316
         });
@@ -341,9 +341,9 @@  discard block
 block discarded – undo
341 341
     {
342 342
         $sDS = DIRECTORY_SEPARATOR;
343 343
 
344
-        foreach($this->aNamespaces as $sNamespace => $aOptions)
344
+        foreach ($this->aNamespaces as $sNamespace => $aOptions)
345 345
         {
346
-            if(key_exists($sNamespace, $this->aClassNames))
346
+            if (key_exists($sNamespace, $this->aClassNames))
347 347
             {
348 348
                 continue;
349 349
             }
@@ -354,10 +354,10 @@  discard block
 block discarded – undo
354 354
             $sDirectory = $aOptions['directory'];
355 355
             $itDir = new RecursiveDirectoryIterator($sDirectory);
356 356
             $itFile = new RecursiveIteratorIterator($itDir);
357
-            foreach($itFile as $xFile)
357
+            foreach ($itFile as $xFile)
358 358
             {
359 359
                 // skip everything except PHP files
360
-                if(!$xFile->isFile() || $xFile->getExtension() != 'php')
360
+                if (!$xFile->isFile() || $xFile->getExtension() != 'php')
361 361
                 {
362 362
                     continue;
363 363
                 }
@@ -366,11 +366,11 @@  discard block
 block discarded – undo
366 366
                 $sClassPath = $sNamespace;
367 367
                 $sRelativePath = substr($xFile->getPath(), strlen($sDirectory));
368 368
                 $sRelativePath = trim(str_replace($sDS, '\\', $sClassPath), '\\');
369
-                if(($sRelativePath))
369
+                if (($sRelativePath))
370 370
                 {
371 371
                     $sClassPath .= '\\' . $sRelativePath;
372 372
                 }
373
-                if(!key_exists($sClassPath, $this->aClassNames))
373
+                if (!key_exists($sClassPath, $this->aClassNames))
374 374
                 {
375 375
                     $this->aClassNames[$sClassPath] = [];
376 376
                 }
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
      */
390 390
     public function generateHash()
391 391
     {
392
-        if(count($this->aNamespaces) == 0)
392
+        if (count($this->aNamespaces) == 0)
393 393
         {
394 394
             return '';
395 395
         }
@@ -397,11 +397,11 @@  discard block
 block discarded – undo
397 397
         $this->createCallableObjects();
398 398
 
399 399
         $sHash = '';
400
-        foreach($this->aNamespaces as $sNamespace => $aOptions)
400
+        foreach ($this->aNamespaces as $sNamespace => $aOptions)
401 401
         {
402 402
             $sHash .= $sNamespace . $aOptions['directory'] . $aOptions['separator'];
403 403
         }
404
-        foreach($this->aCallableObjects as $sClassName => $xCallableObject)
404
+        foreach ($this->aCallableObjects as $sClassName => $xCallableObject)
405 405
         {
406 406
             $sHash .= $sClassName . implode('|', $xCallableObject->getMethods());
407 407
         }
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
         $sJaxonPrefix = $this->getOption('core.prefix.class');
423 423
         $aJsClasses = [];
424 424
         $sCode = '';
425
-        foreach(array_keys($this->aClassNames) as $sNamespace)
425
+        foreach (array_keys($this->aClassNames) as $sNamespace)
426 426
         {
427 427
             // if(key_exists('separator', $aOptions) && $aOptions['separator'] != '.')
428 428
             // {
@@ -431,11 +431,11 @@  discard block
 block discarded – undo
431 431
             $offset = 0;
432 432
             $sJsClasses = str_replace('\\', '.', $sNamespace);
433 433
             $sJsClasses .= '.Null'; // This is a sentinel. The last token is not processed in the while loop.
434
-            while(($dotPosition = strpos($sJsClasses, '.', $offset)) !== false)
434
+            while (($dotPosition = strpos($sJsClasses, '.', $offset)) !== false)
435 435
             {
436 436
                 $sJsClass = substr($sJsClasses, 0, $dotPosition);
437 437
                 // Generate code for this object
438
-                if(!key_exists($sJsClass, $aJsClasses))
438
+                if (!key_exists($sJsClass, $aJsClasses))
439 439
                 {
440 440
                     $sCode .= "$sJaxonPrefix$sJsClass = {};\n";
441 441
                     $aJsClasses[$sJsClass] = $sJsClass;
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
                 $offset = $dotPosition + 1;
444 444
             }
445 445
         }
446
-        foreach($this->aCallableObjects as $xCallableObject)
446
+        foreach ($this->aCallableObjects as $xCallableObject)
447 447
         {
448 448
             $sCode .= $xCallableObject->getScript();
449 449
         }
@@ -459,13 +459,13 @@  discard block
 block discarded – undo
459 459
     public function canProcessRequest()
460 460
     {
461 461
         // Check the validity of the class name
462
-        if(($this->sRequestedClass) && !$this->validateClass($this->sRequestedClass))
462
+        if (($this->sRequestedClass) && !$this->validateClass($this->sRequestedClass))
463 463
         {
464 464
             $this->sRequestedClass = null;
465 465
             $this->sRequestedMethod = null;
466 466
         }
467 467
         // Check the validity of the method name
468
-        if(($this->sRequestedMethod) && !$this->validateMethod($this->sRequestedMethod))
468
+        if (($this->sRequestedMethod) && !$this->validateMethod($this->sRequestedMethod))
469 469
         {
470 470
             $this->sRequestedClass = null;
471 471
             $this->sRequestedMethod = null;
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
      */
481 481
     public function processRequest()
482 482
     {
483
-        if(!$this->canProcessRequest())
483
+        if (!$this->canProcessRequest())
484 484
         {
485 485
             return false;
486 486
         }
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
 
490 490
         // Find the requested method
491 491
         $xCallableObject = $this->getCallableObject($this->sRequestedClass);
492
-        if(!$xCallableObject || !$xCallableObject->hasMethod($this->sRequestedMethod))
492
+        if (!$xCallableObject || !$xCallableObject->hasMethod($this->sRequestedMethod))
493 493
         {
494 494
             // Unable to find the requested object or method
495 495
             throw new \Jaxon\Exception\Error($this->trans('errors.objects.invalid',
Please login to merge, or discard this patch.