Completed
Push — master ( 4d3a24...9c85df )
by Thierry
01:45
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,21 +133,21 @@  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
         }
145 145
 
146 146
         // Create the callable object
147 147
         $xCallableObject = new \Jaxon\Request\Support\CallableObject($sClassName);
148
-        foreach($aOptions as $sMethod => $aValue)
148
+        foreach ($aOptions as $sMethod => $aValue)
149 149
         {
150
-            foreach($aValue as $sName => $sValue)
150
+            foreach ($aValue as $sName => $sValue)
151 151
             {
152 152
                 $xCallableObject->configure($sMethod, $sName, $sValue);
153 153
             }
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
         // Make sure the registered class exists
157 157
         // We need to check this after the callable object is configured
158 158
         // to take the 'include' option into account.
159
-        if(!class_exists($sClassName))
159
+        if (!class_exists($sClassName))
160 160
         {
161 161
             return null;
162 162
         }
@@ -164,12 +164,12 @@  discard block
 block discarded – undo
164 164
         $this->aCallableObjects[$sClassName] = $xCallableObject;
165 165
         jaxon()->di()->set($sClassName, $xCallableObject);
166 166
         // Register the request factory for this callable object
167
-        jaxon()->di()->set($sClassName . '_Factory_Rq', function ($di) use ($sClassName) {
167
+        jaxon()->di()->set($sClassName . '_Factory_Rq', function($di) use ($sClassName) {
168 168
             $xCallableObject = $this->aCallableObjects[$sClassName];
169 169
             return new \Jaxon\Factory\Request\Portable($xCallableObject);
170 170
         });
171 171
         // Register the paginator factory for this callable object
172
-        jaxon()->di()->set($sClassName . '_Factory_Pg', function ($di) use ($sClassName) {
172
+        jaxon()->di()->set($sClassName . '_Factory_Pg', function($di) use ($sClassName) {
173 173
             $xCallableObject = $this->aCallableObjects[$sClassName];
174 174
             return new \Jaxon\Factory\Request\Paginator($xCallableObject);
175 175
         });
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
      */
199 199
     private function createCallableObjects()
200 200
     {
201
-        foreach(array_keys($this->aClassOptions) as $sClassName)
201
+        foreach (array_keys($this->aClassOptions) as $sClassName)
202 202
         {
203 203
             $this->getCallableObject($sClassName);
204 204
         }
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
         $this->createCallableObjects();
215 215
 
216 216
         $sHash = '';
217
-        foreach($this->aCallableObjects as $sClassName => $xCallableObject)
217
+        foreach ($this->aCallableObjects as $sClassName => $xCallableObject)
218 218
         {
219 219
             $sHash .= $sClassName . implode('|', $xCallableObject->getMethods());
220 220
         }
@@ -235,19 +235,19 @@  discard block
 block discarded – undo
235 235
         $sJaxonPrefix = $this->getOption('core.prefix.class');
236 236
         $aJsClasses = [];
237 237
         $sCode = '';
238
-        foreach($this->aClassOptions as $sClassName => $aOptions)
238
+        foreach ($this->aClassOptions as $sClassName => $aOptions)
239 239
         {
240
-            if(key_exists('separator', $aOptions) && $aOptions['separator'] != '.')
240
+            if (key_exists('separator', $aOptions) && $aOptions['separator'] != '.')
241 241
             {
242 242
                 continue;
243 243
             }
244 244
             $offset = 0;
245 245
             $sJsClasses = str_replace('\\', '.', $sClassName);
246
-            while(($dotPosition = strpos($sJsClasses, '.', $offset)) !== false)
246
+            while (($dotPosition = strpos($sJsClasses, '.', $offset)) !== false)
247 247
             {
248 248
                 $sJsClass = substr($sJsClasses, 0, $dotPosition);
249 249
                 // Generate code for this object
250
-                if(!key_exists($sJsClass, $aJsClasses))
250
+                if (!key_exists($sJsClass, $aJsClasses))
251 251
                 {
252 252
                     $sCode .= "$sJaxonPrefix$sJsClass = {};\n";
253 253
                     $aJsClasses[$sJsClass] = $sJsClass;
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
                 $offset = $dotPosition + 1;
256 256
             }
257 257
         }
258
-        foreach($this->aCallableObjects as $xCallableObject)
258
+        foreach ($this->aCallableObjects as $xCallableObject)
259 259
         {
260 260
             $sCode .= $xCallableObject->getScript();
261 261
         }
@@ -271,13 +271,13 @@  discard block
 block discarded – undo
271 271
     public function canProcessRequest()
272 272
     {
273 273
         // Check the validity of the class name
274
-        if(($this->sRequestedClass) && !$this->validateClass($this->sRequestedClass))
274
+        if (($this->sRequestedClass) && !$this->validateClass($this->sRequestedClass))
275 275
         {
276 276
             $this->sRequestedClass = null;
277 277
             $this->sRequestedMethod = null;
278 278
         }
279 279
         // Check the validity of the method name
280
-        if(($this->sRequestedMethod) && !$this->validateMethod($this->sRequestedMethod))
280
+        if (($this->sRequestedMethod) && !$this->validateMethod($this->sRequestedMethod))
281 281
         {
282 282
             $this->sRequestedClass = null;
283 283
             $this->sRequestedMethod = null;
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
      */
294 294
     public function processRequest()
295 295
     {
296
-        if(!$this->canProcessRequest())
296
+        if (!$this->canProcessRequest())
297 297
         {
298 298
             return false;
299 299
         }
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 
303 303
         // Find the requested method
304 304
         $xCallableObject = $this->getCallableObject($this->sRequestedClass);
305
-        if(!$xCallableObject || !$xCallableObject->hasMethod($this->sRequestedMethod))
305
+        if (!$xCallableObject || !$xCallableObject->hasMethod($this->sRequestedMethod))
306 306
         {
307 307
             // Unable to find the requested object or method
308 308
             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   +44 added lines, -44 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,9 +288,9 @@  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 $sMethod => $aValue)
291
+        foreach ($aOptions as $sMethod => $aValue)
292 292
         {
293
-            foreach($aValue as $sName => $sValue)
293
+            foreach ($aValue as $sName => $sValue)
294 294
             {
295 295
                 $xCallableObject->configure($sMethod, $sName, $sValue);
296 296
             }
@@ -299,12 +299,12 @@  discard block
 block discarded – undo
299 299
         $this->aCallableObjects[$sClassName] = $xCallableObject;
300 300
         jaxon()->di()->set($sClassName, $xCallableObject);
301 301
         // Register the request factory for this callable object
302
-        jaxon()->di()->set($sClassName . '_Factory_Rq', function ($di) use ($sClassName) {
302
+        jaxon()->di()->set($sClassName . '_Factory_Rq', function($di) use ($sClassName) {
303 303
             $xCallableObject = $this->aCallableObjects[$sClassName];
304 304
             return new \Jaxon\Factory\Request\Portable($xCallableObject);
305 305
         });
306 306
         // Register the paginator factory for this callable object
307
-        jaxon()->di()->set($sClassName . '_Factory_Pg', function ($di) use ($sClassName) {
307
+        jaxon()->di()->set($sClassName . '_Factory_Pg', function($di) use ($sClassName) {
308 308
             $xCallableObject = $this->aCallableObjects[$sClassName];
309 309
             return new \Jaxon\Factory\Request\Paginator($xCallableObject);
310 310
         });
@@ -335,9 +335,9 @@  discard block
 block discarded – undo
335 335
     {
336 336
         $sDS = DIRECTORY_SEPARATOR;
337 337
 
338
-        foreach($this->aNamespaces as $sNamespace => $aOptions)
338
+        foreach ($this->aNamespaces as $sNamespace => $aOptions)
339 339
         {
340
-            if(key_exists($sNamespace, $this->aClassNames))
340
+            if (key_exists($sNamespace, $this->aClassNames))
341 341
             {
342 342
                 continue;
343 343
             }
@@ -348,10 +348,10 @@  discard block
 block discarded – undo
348 348
             $sDirectory = $aOptions['directory'];
349 349
             $itDir = new RecursiveDirectoryIterator($sDirectory);
350 350
             $itFile = new RecursiveIteratorIterator($itDir);
351
-            foreach($itFile as $xFile)
351
+            foreach ($itFile as $xFile)
352 352
             {
353 353
                 // skip everything except PHP files
354
-                if(!$xFile->isFile() || $xFile->getExtension() != 'php')
354
+                if (!$xFile->isFile() || $xFile->getExtension() != 'php')
355 355
                 {
356 356
                     continue;
357 357
                 }
@@ -360,11 +360,11 @@  discard block
 block discarded – undo
360 360
                 $sClassPath = $sNamespace;
361 361
                 $sRelativePath = substr($xFile->getPath(), strlen($sDirectory));
362 362
                 $sRelativePath = trim(str_replace($sDS, '\\', $sClassPath), '\\');
363
-                if(($sRelativePath))
363
+                if (($sRelativePath))
364 364
                 {
365 365
                     $sClassPath .= '\\' . $sRelativePath;
366 366
                 }
367
-                if(!key_exists($sClassPath, $this->aClassNames))
367
+                if (!key_exists($sClassPath, $this->aClassNames))
368 368
                 {
369 369
                     $this->aClassNames[$sClassPath] = [];
370 370
                 }
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
      */
384 384
     public function generateHash()
385 385
     {
386
-        if(count($this->aNamespaces) == 0)
386
+        if (count($this->aNamespaces) == 0)
387 387
         {
388 388
             return '';
389 389
         }
@@ -391,11 +391,11 @@  discard block
 block discarded – undo
391 391
         $this->createCallableObjects();
392 392
 
393 393
         $sHash = '';
394
-        foreach($this->aNamespaces as $sNamespace => $aOptions)
394
+        foreach ($this->aNamespaces as $sNamespace => $aOptions)
395 395
         {
396 396
             $sHash .= $sNamespace . $aOptions['directory'] . $aOptions['separator'];
397 397
         }
398
-        foreach($this->aCallableObjects as $sClassName => $xCallableObject)
398
+        foreach ($this->aCallableObjects as $sClassName => $xCallableObject)
399 399
         {
400 400
             $sHash .= $sClassName . implode('|', $xCallableObject->getMethods());
401 401
         }
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
         $sJaxonPrefix = $this->getOption('core.prefix.class');
417 417
         $aJsClasses = [];
418 418
         $sCode = '';
419
-        foreach(array_keys($this->aClassNames) as $sNamespace)
419
+        foreach (array_keys($this->aClassNames) as $sNamespace)
420 420
         {
421 421
             // if(key_exists('separator', $aOptions) && $aOptions['separator'] != '.')
422 422
             // {
@@ -425,11 +425,11 @@  discard block
 block discarded – undo
425 425
             $offset = 0;
426 426
             $sJsClasses = str_replace('\\', '.', $sNamespace);
427 427
             $sJsClasses .= '.Null'; // This is a sentinel. The last token is not processed in the while loop.
428
-            while(($dotPosition = strpos($sJsClasses, '.', $offset)) !== false)
428
+            while (($dotPosition = strpos($sJsClasses, '.', $offset)) !== false)
429 429
             {
430 430
                 $sJsClass = substr($sJsClasses, 0, $dotPosition);
431 431
                 // Generate code for this object
432
-                if(!key_exists($sJsClass, $aJsClasses))
432
+                if (!key_exists($sJsClass, $aJsClasses))
433 433
                 {
434 434
                     $sCode .= "$sJaxonPrefix$sJsClass = {};\n";
435 435
                     $aJsClasses[$sJsClass] = $sJsClass;
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
                 $offset = $dotPosition + 1;
438 438
             }
439 439
         }
440
-        foreach($this->aCallableObjects as $xCallableObject)
440
+        foreach ($this->aCallableObjects as $xCallableObject)
441 441
         {
442 442
             $sCode .= $xCallableObject->getScript();
443 443
         }
@@ -453,13 +453,13 @@  discard block
 block discarded – undo
453 453
     public function canProcessRequest()
454 454
     {
455 455
         // Check the validity of the class name
456
-        if(($this->sRequestedClass) && !$this->validateClass($this->sRequestedClass))
456
+        if (($this->sRequestedClass) && !$this->validateClass($this->sRequestedClass))
457 457
         {
458 458
             $this->sRequestedClass = null;
459 459
             $this->sRequestedMethod = null;
460 460
         }
461 461
         // Check the validity of the method name
462
-        if(($this->sRequestedMethod) && !$this->validateMethod($this->sRequestedMethod))
462
+        if (($this->sRequestedMethod) && !$this->validateMethod($this->sRequestedMethod))
463 463
         {
464 464
             $this->sRequestedClass = null;
465 465
             $this->sRequestedMethod = null;
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
      */
475 475
     public function processRequest()
476 476
     {
477
-        if(!$this->canProcessRequest())
477
+        if (!$this->canProcessRequest())
478 478
         {
479 479
             return false;
480 480
         }
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
 
484 484
         // Find the requested method
485 485
         $xCallableObject = $this->getCallableObject($this->sRequestedClass);
486
-        if(!$xCallableObject || !$xCallableObject->hasMethod($this->sRequestedMethod))
486
+        if (!$xCallableObject || !$xCallableObject->hasMethod($this->sRequestedMethod))
487 487
         {
488 488
             // Unable to find the requested object or method
489 489
             throw new \Jaxon\Exception\Error($this->trans('errors.objects.invalid',
Please login to merge, or discard this patch.