Completed
Push — master ( 92c7d4...3a82fc )
by Thierry
02:34
created
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 () use ($sClassName) {
308
+        jaxon()->di()->set($sClassName . '_Factory_Rq', function() 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 () use ($sClassName) {
313
+        jaxon()->di()->set($sClassName . '_Factory_Pg', function() 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, '\\', $sRelativePath), '\\');
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 !== null && !$this->validateClass($this->sRequestedClass))
462
+        if ($this->sRequestedClass !== null && !$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 !== null && !$this->validateMethod($this->sRequestedMethod))
468
+        if ($this->sRequestedMethod !== null && !$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.
src/Request/Plugin/FileUpload.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -58,11 +58,11 @@  discard block
 block discarded – undo
58 58
     {
59 59
         $this->sUploadSubdir = uniqid() . DIRECTORY_SEPARATOR;
60 60
 
61
-        if(array_key_exists('jxnupl', $_POST))
61
+        if (array_key_exists('jxnupl', $_POST))
62 62
         {
63 63
             $this->sTempFile = $_POST['jxnupl'];
64 64
         }
65
-        elseif(array_key_exists('jxnupl', $_GET))
65
+        elseif (array_key_exists('jxnupl', $_GET))
66 66
         {
67 67
             $this->sTempFile = $_GET['jxnupl'];
68 68
         }
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
      */
91 91
     protected function filterFilename($sFilename, $sVarName)
92 92
     {
93
-        if(($this->fFileFilter))
93
+        if (($this->fFileFilter))
94 94
         {
95 95
             $fFileFilter = $this->fFileFilter;
96 96
             $sFilename = (string)$fFileFilter($sFilename, $sVarName);
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
         $sUploadDir = $this->getOption('upload.files.' . $sFieldId . '.dir', $sDefaultUploadDir);
113 113
         $sUploadDir = rtrim(trim($sUploadDir), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
114 114
         // Verify that the upload dir exists and is writable
115
-        if(!is_writable($sUploadDir))
115
+        if (!is_writable($sUploadDir))
116 116
         {
117 117
             throw new \Jaxon\Exception\Error($this->trans('errors.upload.access'));
118 118
         }
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
         $sUploadDir = $this->getOption('upload.default.dir');
133 133
         $sUploadDir = rtrim(trim($sUploadDir), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
134 134
         // Verify that the upload dir exists and is writable
135
-        if(!is_writable($sUploadDir))
135
+        if (!is_writable($sUploadDir))
136 136
         {
137 137
             throw new \Jaxon\Exception\Error($this->trans('errors.upload.access'));
138 138
         }
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
         $sUploadDir = rtrim(trim($sUploadDir), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
153 153
         $sUploadDir .= 'tmp' . DIRECTORY_SEPARATOR;
154 154
         $sUploadTempFile = $sUploadDir . $this->sTempFile . '.json';
155
-        if(!is_readable($sUploadTempFile))
155
+        if (!is_readable($sUploadTempFile))
156 156
         {
157 157
             throw new \Jaxon\Exception\Error($this->trans('errors.upload.access'));
158 158
         }
@@ -168,18 +168,18 @@  discard block
 block discarded – undo
168 168
     {
169 169
         // Check validity of the uploaded files
170 170
         $aTempFiles = [];
171
-        foreach($_FILES as $sVarName => $aFile)
171
+        foreach ($_FILES as $sVarName => $aFile)
172 172
         {
173
-            if(is_array($aFile['name']))
173
+            if (is_array($aFile['name']))
174 174
             {
175 175
                 $nFileCount = count($aFile['name']);
176
-                for($i = 0; $i < $nFileCount; $i++)
176
+                for ($i = 0; $i < $nFileCount; $i++)
177 177
                 {
178
-                    if(!$aFile['name'][$i])
178
+                    if (!$aFile['name'][$i])
179 179
                     {
180 180
                         continue;
181 181
                     }
182
-                    if(!array_key_exists($sVarName, $aTempFiles))
182
+                    if (!array_key_exists($sVarName, $aTempFiles))
183 183
                     {
184 184
                         $aTempFiles[$sVarName] = [];
185 185
                     }
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
             }
200 200
             else
201 201
             {
202
-                if(!$aFile['name'])
202
+                if (!$aFile['name'])
203 203
                 {
204 204
                     continue;
205 205
                 }
206
-                if(!array_key_exists($sVarName, $aTempFiles))
206
+                if (!array_key_exists($sVarName, $aTempFiles))
207 207
                 {
208 208
                     $aTempFiles[$sVarName] = [];
209 209
                 }
@@ -223,17 +223,17 @@  discard block
 block discarded – undo
223 223
         }
224 224
 
225 225
         // Check uploaded files validity
226
-        foreach($aTempFiles as $sVarName => $aFiles)
226
+        foreach ($aTempFiles as $sVarName => $aFiles)
227 227
         {
228
-            foreach($aFiles as $aFile)
228
+            foreach ($aFiles as $aFile)
229 229
             {
230 230
                 // Verify upload result
231
-                if($aFile['error'] != 0)
231
+                if ($aFile['error'] != 0)
232 232
                 {
233 233
                     throw new \Jaxon\Exception\Error($this->trans('errors.upload.failed', $aFile));
234 234
                 }
235 235
                 // Verify file validity (format, size)
236
-                if(!$this->validateUploadedFile($sVarName, $aFile))
236
+                if (!$this->validateUploadedFile($sVarName, $aFile))
237 237
                 {
238 238
                     throw new \Jaxon\Exception\Error($this->getValidatorMessage());
239 239
                 }
@@ -243,10 +243,10 @@  discard block
 block discarded – undo
243 243
         }
244 244
 
245 245
         // Copy the uploaded files from the temp dir to the user dir
246
-        foreach($aTempFiles as $sVarName => $aTempFiles)
246
+        foreach ($aTempFiles as $sVarName => $aTempFiles)
247 247
         {
248 248
             $this->aUserFiles[$sVarName] = [];
249
-            foreach($aTempFiles as $aFile)
249
+            foreach ($aTempFiles as $aFile)
250 250
             {
251 251
                 // Get the path to the upload dir
252 252
                 $sUploadDir = $this->getUploadDir($sVarName);
@@ -268,10 +268,10 @@  discard block
 block discarded – undo
268 268
     {
269 269
         // Convert uploaded file to an array
270 270
         $aFiles = [];
271
-        foreach($this->aUserFiles as $sVarName => $aUserFiles)
271
+        foreach ($this->aUserFiles as $sVarName => $aUserFiles)
272 272
         {
273 273
             $aFiles[$sVarName] = [];
274
-            foreach($aUserFiles as $aUserFile)
274
+            foreach ($aUserFiles as $aUserFile)
275 275
             {
276 276
                  $aFiles[$sVarName][] = $aUserFile->toTempData();
277 277
             }
@@ -292,10 +292,10 @@  discard block
 block discarded – undo
292 292
         // Upload temp file
293 293
         $sUploadTempFile = $this->getUploadTempFile();
294 294
         $aFiles = json_decode(file_get_contents($sUploadTempFile), true);
295
-        foreach($aFiles as $sVarName => $aUserFiles)
295
+        foreach ($aFiles as $sVarName => $aUserFiles)
296 296
         {
297 297
             $this->aUserFiles[$sVarName] = [];
298
-            foreach($aUserFiles as $aUserFile)
298
+            foreach ($aUserFiles as $aUserFile)
299 299
             {
300 300
                 $this->aUserFiles[$sVarName][] = UploadedFile::fromTempData($aUserFile);
301 301
             }
@@ -360,15 +360,15 @@  discard block
 block discarded – undo
360 360
      */
361 361
     public function processRequest()
362 362
     {
363
-        if(!$this->canProcessRequest())
363
+        if (!$this->canProcessRequest())
364 364
         {
365 365
             return false;
366 366
         }
367
-        if(count($_FILES) > 0)
367
+        if (count($_FILES) > 0)
368 368
         {
369 369
             $this->readFromHttpData();
370 370
         }
371
-        elseif(($this->sTempFile))
371
+        elseif (($this->sTempFile))
372 372
         {
373 373
             $this->readFromTempFile();
374 374
         }
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
     public function saveUploadedFiles()
384 384
     {
385 385
         // Process uploaded files
386
-        if(!$this->processRequest())
386
+        if (!$this->processRequest())
387 387
         {
388 388
             return '';
389 389
         }
Please login to merge, or discard this patch.