Completed
Push — master ( 46be75...aab372 )
by Thierry
01:45
created
src/Factory/Request.php 1 patch
Doc Comments   +2 added lines, -5 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
      *
36 36
      * @param string|null            $sClass              The callable class
37 37
      *
38
-     * @return Factory
38
+     * @return Request
39 39
      */
40 40
     public function setClassName($sClass)
41 41
     {
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
      *
59 59
      * @param CallableObject          $xCallable              The callable object
60 60
      *
61
-     * @return Factory
61
+     * @return Request
62 62
      */
63 63
     public function setCallable(CallableObject $xCallable)
64 64
     {
@@ -71,7 +71,6 @@  discard block
 block discarded – undo
71 71
      * Return the javascript call to a Jaxon function or object method
72 72
      *
73 73
      * @param string            $sFunction          The function or method (without class) name
74
-     * @param ...               $xParams            The parameters of the function or method
75 74
      *
76 75
      * @return \Jaxon\Request\Request
77 76
      */
@@ -100,7 +99,6 @@  discard block
 block discarded – undo
100 99
      * Return the javascript call to a generic function
101 100
      *
102 101
      * @param string            $sFunction          The function or method (with class) name
103
-     * @param ...               $xParams            The parameters of the function or method
104 102
      *
105 103
      * @return \Jaxon\Request\Request
106 104
      */
@@ -124,7 +122,6 @@  discard block
 block discarded – undo
124 122
      * @param integer       $nItemsPerPage          The number of items per page page
125 123
      * @param integer       $nCurrentPage           The current page
126 124
      * @param string        $sMethod                The name of function or a method prepended with its class name
127
-     * @param ...           $xParams                The parameters of the function or method
128 125
      *
129 126
      * @return string the pagination links
130 127
      */
Please login to merge, or discard this patch.
src/Request/Support/CallableRepository.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -88,19 +88,19 @@  discard block
 block discarded – undo
88 88
     private function getClassOptions($sClassName, array $aDirectoryOptions, array $aDefaultOptions = [])
89 89
     {
90 90
         $aOptions = $aDefaultOptions;
91
-        if(key_exists('separator', $aDirectoryOptions))
91
+        if (key_exists('separator', $aDirectoryOptions))
92 92
         {
93 93
             $aOptions['separator'] = $aDirectoryOptions['separator'];
94 94
         }
95
-        if(key_exists('protected', $aDirectoryOptions))
95
+        if (key_exists('protected', $aDirectoryOptions))
96 96
         {
97 97
             $aOptions['protected'] = $aDirectoryOptions['protected'];
98 98
         }
99
-        if(key_exists('*', $aDirectoryOptions))
99
+        if (key_exists('*', $aDirectoryOptions))
100 100
         {
101 101
             $aOptions = array_merge($aOptions, $aDirectoryOptions['*']);
102 102
         }
103
-        if(key_exists($sClassName, $aDirectoryOptions))
103
+        if (key_exists($sClassName, $aDirectoryOptions))
104 104
         {
105 105
             $aOptions = array_merge($aOptions, $aDirectoryOptions[$sClassName]);
106 106
         }
@@ -120,17 +120,17 @@  discard block
 block discarded – undo
120 120
         $itDir = new RecursiveDirectoryIterator($sDirectory);
121 121
         $itFile = new RecursiveIteratorIterator($itDir);
122 122
         // Iterate on dir content
123
-        foreach($itFile as $xFile)
123
+        foreach ($itFile as $xFile)
124 124
         {
125 125
             // skip everything except PHP files
126
-            if(!$xFile->isFile() || $xFile->getExtension() != 'php')
126
+            if (!$xFile->isFile() || $xFile->getExtension() != 'php')
127 127
             {
128 128
                 continue;
129 129
             }
130 130
 
131 131
             $aClassOptions = [];
132 132
             // No more classmap autoloading. The file will be included when needed.
133
-            if(($aOptions['autoload']))
133
+            if (($aOptions['autoload']))
134 134
             {
135 135
                 $aClassOptions['include'] = $xFile->getPathname();
136 136
             }
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
      */
163 163
     private function getOptionsFromClass($sClassName)
164 164
     {
165
-        if(!key_exists($sClassName, $this->aClassOptions))
165
+        if (!key_exists($sClassName, $this->aClassOptions))
166 166
         {
167 167
             return null; // Class not registered
168 168
         }
@@ -180,15 +180,15 @@  discard block
 block discarded – undo
180 180
     {
181 181
         // Find the corresponding namespace
182 182
         $sNamespace = null;
183
-        foreach(array_keys($this->aNamespaceOptions) as $_sNamespace)
183
+        foreach (array_keys($this->aNamespaceOptions) as $_sNamespace)
184 184
         {
185
-            if(substr($sClassName, 0, strlen($_sNamespace) + 1) == $_sNamespace . '\\')
185
+            if (substr($sClassName, 0, strlen($_sNamespace) + 1) == $_sNamespace . '\\')
186 186
             {
187 187
                 $sNamespace = $_sNamespace;
188 188
                 break;
189 189
             }
190 190
         }
191
-        if($sNamespace == null)
191
+        if ($sNamespace == null)
192 192
         {
193 193
             return null; // Class not registered
194 194
         }
@@ -210,27 +210,27 @@  discard block
 block discarded – undo
210 210
         // at the beginning and the end of the class name.
211 211
         $sClassName = trim(str_replace(['.', '_'], ['\\', '\\'], (string)$sClassName), '\\');
212 212
 
213
-        if(key_exists($sClassName, $this->aCallableObjects))
213
+        if (key_exists($sClassName, $this->aCallableObjects))
214 214
         {
215 215
             return $this->aCallableObjects[$sClassName];
216 216
         }
217 217
 
218 218
         $aOptions = $this->getOptionsFromClass($sClassName);
219
-        if($aOptions === null)
219
+        if ($aOptions === null)
220 220
         {
221 221
             $aOptions = $this->getOptionsFromNamespace($sClassName);
222 222
         }
223
-        if($aOptions === null)
223
+        if ($aOptions === null)
224 224
         {
225 225
             return null;
226 226
         }
227 227
 
228 228
         // Make sure the registered class exists
229
-        if(key_exists('include', $aOptions))
229
+        if (key_exists('include', $aOptions))
230 230
         {
231 231
             require_once($aOptions['include']);
232 232
         }
233
-        if(!class_exists('\\' . $sClassName))
233
+        if (!class_exists('\\' . $sClassName))
234 234
         {
235 235
             return null;
236 236
         }
@@ -238,13 +238,13 @@  discard block
 block discarded – undo
238 238
         // Create the callable object
239 239
         $xCallableObject = new \Jaxon\Request\Support\CallableObject($sClassName);
240 240
         $this->aCallableOptions[$sClassName] = [];
241
-        foreach($aOptions as $sName => $xValue)
241
+        foreach ($aOptions as $sName => $xValue)
242 242
         {
243
-            if($sName == 'separator' || $sName == 'protected')
243
+            if ($sName == 'separator' || $sName == 'protected')
244 244
             {
245 245
                 $xCallableObject->configure($sName, $xValue);
246 246
             }
247
-            elseif(is_array($xValue) && $sName != 'include')
247
+            elseif (is_array($xValue) && $sName != 'include')
248 248
             {
249 249
                 // These options are to be included in javascript code.
250 250
                 $this->aCallableOptions[$sClassName][$sName] = $xValue;
@@ -253,12 +253,12 @@  discard block
 block discarded – undo
253 253
         $this->aCallableObjects[$sClassName] = $xCallableObject;
254 254
 
255 255
         // Register the request factory for this callable object
256
-        jaxon()->di()->set($sClassName . '_Factory_Rq', function () use ($sClassName) {
256
+        jaxon()->di()->set($sClassName . '_Factory_Rq', function() use ($sClassName) {
257 257
             $xCallableObject = $this->aCallableObjects[$sClassName];
258 258
             return new \Jaxon\Factory\Request\Portable($xCallableObject);
259 259
         });
260 260
         // Register the paginator factory for this callable object
261
-        jaxon()->di()->set($sClassName . '_Factory_Pg', function () use ($sClassName) {
261
+        jaxon()->di()->set($sClassName . '_Factory_Pg', function() use ($sClassName) {
262 262
             $xCallableObject = $this->aCallableObjects[$sClassName];
263 263
             return new \Jaxon\Factory\Request\Paginator($xCallableObject);
264 264
         });
@@ -274,16 +274,16 @@  discard block
 block discarded – undo
274 274
     private function createCallableObjects()
275 275
     {
276 276
         // Create callable objects for registered classes
277
-        foreach(array_keys($this->aClassOptions) as $sClassName)
277
+        foreach (array_keys($this->aClassOptions) as $sClassName)
278 278
         {
279 279
             $this->getCallableObject($sClassName);
280 280
         }
281 281
 
282 282
         // Create callable objects for registered namespaces
283 283
         $sDS = DIRECTORY_SEPARATOR;
284
-        foreach($this->aNamespaceOptions as $sNamespace => $aOptions)
284
+        foreach ($this->aNamespaceOptions as $sNamespace => $aOptions)
285 285
         {
286
-            if(key_exists($sNamespace, $this->aNamespaces))
286
+            if (key_exists($sNamespace, $this->aNamespaces))
287 287
             {
288 288
                 continue;
289 289
             }
@@ -294,10 +294,10 @@  discard block
 block discarded – undo
294 294
             $sDirectory = $aOptions['directory'];
295 295
             $itDir = new RecursiveDirectoryIterator($sDirectory);
296 296
             $itFile = new RecursiveIteratorIterator($itDir);
297
-            foreach($itFile as $xFile)
297
+            foreach ($itFile as $xFile)
298 298
             {
299 299
                 // skip everything except PHP files
300
-                if(!$xFile->isFile() || $xFile->getExtension() != 'php')
300
+                if (!$xFile->isFile() || $xFile->getExtension() != 'php')
301 301
                 {
302 302
                     continue;
303 303
                 }
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
                 $sClassPath = $sNamespace;
307 307
                 $sRelativePath = substr($xFile->getPath(), strlen($sDirectory));
308 308
                 $sRelativePath = trim(str_replace($sDS, '\\', $sRelativePath), '\\');
309
-                if($sRelativePath != '')
309
+                if ($sRelativePath != '')
310 310
                 {
311 311
                     $sClassPath .= '\\' . $sRelativePath;
312 312
                 }
@@ -342,11 +342,11 @@  discard block
 block discarded – undo
342 342
         $this->createCallableObjects();
343 343
 
344 344
         $sHash = '';
345
-        foreach($this->aNamespaces as $sNamespace => $aOptions)
345
+        foreach ($this->aNamespaces as $sNamespace => $aOptions)
346 346
         {
347 347
             $sHash .= $sNamespace . $aOptions['separator'];
348 348
         }
349
-        foreach($this->aCallableObjects as $sClassName => $xCallableObject)
349
+        foreach ($this->aCallableObjects as $sClassName => $xCallableObject)
350 350
         {
351 351
             $sHash .= $sClassName . implode('|', $xCallableObject->getMethods());
352 352
         }
@@ -367,16 +367,16 @@  discard block
 block discarded – undo
367 367
 
368 368
         $aJsClasses = [];
369 369
         $sCode = '';
370
-        foreach(array_keys($this->aNamespaces) as $sNamespace)
370
+        foreach (array_keys($this->aNamespaces) as $sNamespace)
371 371
         {
372 372
             $offset = 0;
373 373
             $sJsNamespace = str_replace('\\', '.', $sNamespace);
374 374
             $sJsNamespace .= '.Null'; // This is a sentinel. The last token is not processed in the while loop.
375
-            while(($dotPosition = strpos($sJsNamespace, '.', $offset)) !== false)
375
+            while (($dotPosition = strpos($sJsNamespace, '.', $offset)) !== false)
376 376
             {
377 377
                 $sJsClass = substr($sJsNamespace, 0, $dotPosition);
378 378
                 // Generate code for this object
379
-                if(!key_exists($sJsClass, $aJsClasses))
379
+                if (!key_exists($sJsClass, $aJsClasses))
380 380
                 {
381 381
                     $sCode .= "$sPrefix$sJsClass = {};\n";
382 382
                     $aJsClasses[$sJsClass] = $sJsClass;
@@ -385,13 +385,13 @@  discard block
 block discarded – undo
385 385
             }
386 386
         }
387 387
 
388
-        foreach($this->aCallableObjects as $sClassName => $xCallableObject)
388
+        foreach ($this->aCallableObjects as $sClassName => $xCallableObject)
389 389
         {
390 390
             $aConfig = $this->aCallableOptions[$sClassName];
391 391
             $aCommonConfig = key_exists('*', $aConfig) ? $aConfig['*'] : [];
392 392
 
393 393
             $aMethods = [];
394
-            foreach($xCallableObject->getMethods() as $sMethodName)
394
+            foreach ($xCallableObject->getMethods() as $sMethodName)
395 395
             {
396 396
                 // Specific options for this method
397 397
                 $aMethodConfig = key_exists($sMethodName, $aConfig) ?
Please login to merge, or discard this patch.
src/Request/Plugin/FileUpload.php 1 patch
Spacing   +29 added lines, -29 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,12 +112,12 @@  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
         }
119 119
         $sUploadDir .= $this->sUploadSubdir;
120
-        if(!@mkdir($sUploadDir))
120
+        if (!@mkdir($sUploadDir))
121 121
         {
122 122
             throw new \Jaxon\Exception\Error($this->trans('errors.upload.access'));
123 123
         }
@@ -135,12 +135,12 @@  discard block
 block discarded – undo
135 135
         $sUploadDir = $this->getOption('upload.default.dir');
136 136
         $sUploadDir = rtrim(trim($sUploadDir), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
137 137
         // Verify that the upload dir exists and is writable
138
-        if(!is_writable($sUploadDir))
138
+        if (!is_writable($sUploadDir))
139 139
         {
140 140
             throw new \Jaxon\Exception\Error($this->trans('errors.upload.access'));
141 141
         }
142 142
         $sUploadDir .= 'tmp' . DIRECTORY_SEPARATOR;
143
-        if(!@mkdir($sUploadDir))
143
+        if (!@mkdir($sUploadDir))
144 144
         {
145 145
             throw new \Jaxon\Exception\Error($this->trans('errors.upload.access'));
146 146
         }
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
         $sUploadDir = rtrim(trim($sUploadDir), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
159 159
         $sUploadDir .= 'tmp' . DIRECTORY_SEPARATOR;
160 160
         $sUploadTempFile = $sUploadDir . $this->sTempFile . '.json';
161
-        if(!is_readable($sUploadTempFile))
161
+        if (!is_readable($sUploadTempFile))
162 162
         {
163 163
             throw new \Jaxon\Exception\Error($this->trans('errors.upload.access'));
164 164
         }
@@ -174,18 +174,18 @@  discard block
 block discarded – undo
174 174
     {
175 175
         // Check validity of the uploaded files
176 176
         $aTempFiles = [];
177
-        foreach($_FILES as $sVarName => $aFile)
177
+        foreach ($_FILES as $sVarName => $aFile)
178 178
         {
179
-            if(is_array($aFile['name']))
179
+            if (is_array($aFile['name']))
180 180
             {
181 181
                 $nFileCount = count($aFile['name']);
182
-                for($i = 0; $i < $nFileCount; $i++)
182
+                for ($i = 0; $i < $nFileCount; $i++)
183 183
                 {
184
-                    if(!$aFile['name'][$i])
184
+                    if (!$aFile['name'][$i])
185 185
                     {
186 186
                         continue;
187 187
                     }
188
-                    if(!array_key_exists($sVarName, $aTempFiles))
188
+                    if (!array_key_exists($sVarName, $aTempFiles))
189 189
                     {
190 190
                         $aTempFiles[$sVarName] = [];
191 191
                     }
@@ -205,11 +205,11 @@  discard block
 block discarded – undo
205 205
             }
206 206
             else
207 207
             {
208
-                if(!$aFile['name'])
208
+                if (!$aFile['name'])
209 209
                 {
210 210
                     continue;
211 211
                 }
212
-                if(!array_key_exists($sVarName, $aTempFiles))
212
+                if (!array_key_exists($sVarName, $aTempFiles))
213 213
                 {
214 214
                     $aTempFiles[$sVarName] = [];
215 215
                 }
@@ -229,17 +229,17 @@  discard block
 block discarded – undo
229 229
         }
230 230
 
231 231
         // Check uploaded files validity
232
-        foreach($aTempFiles as $sVarName => $aFiles)
232
+        foreach ($aTempFiles as $sVarName => $aFiles)
233 233
         {
234
-            foreach($aFiles as $aFile)
234
+            foreach ($aFiles as $aFile)
235 235
             {
236 236
                 // Verify upload result
237
-                if($aFile['error'] != 0)
237
+                if ($aFile['error'] != 0)
238 238
                 {
239 239
                     throw new \Jaxon\Exception\Error($this->trans('errors.upload.failed', $aFile));
240 240
                 }
241 241
                 // Verify file validity (format, size)
242
-                if(!$this->validateUploadedFile($sVarName, $aFile))
242
+                if (!$this->validateUploadedFile($sVarName, $aFile))
243 243
                 {
244 244
                     throw new \Jaxon\Exception\Error($this->getValidatorMessage());
245 245
                 }
@@ -249,10 +249,10 @@  discard block
 block discarded – undo
249 249
         }
250 250
 
251 251
         // Copy the uploaded files from the temp dir to the user dir
252
-        foreach($aTempFiles as $sVarName => $aTempFiles)
252
+        foreach ($aTempFiles as $sVarName => $aTempFiles)
253 253
         {
254 254
             $this->aUserFiles[$sVarName] = [];
255
-            foreach($aTempFiles as $aFile)
255
+            foreach ($aTempFiles as $aFile)
256 256
             {
257 257
                 // Get the path to the upload dir
258 258
                 $sUploadDir = $this->getUploadDir($sVarName);
@@ -274,10 +274,10 @@  discard block
 block discarded – undo
274 274
     {
275 275
         // Convert uploaded file to an array
276 276
         $aFiles = [];
277
-        foreach($this->aUserFiles as $sVarName => $aUserFiles)
277
+        foreach ($this->aUserFiles as $sVarName => $aUserFiles)
278 278
         {
279 279
             $aFiles[$sVarName] = [];
280
-            foreach($aUserFiles as $aUserFile)
280
+            foreach ($aUserFiles as $aUserFile)
281 281
             {
282 282
                  $aFiles[$sVarName][] = $aUserFile->toTempData();
283 283
             }
@@ -298,10 +298,10 @@  discard block
 block discarded – undo
298 298
         // Upload temp file
299 299
         $sUploadTempFile = $this->getUploadTempFile();
300 300
         $aFiles = json_decode(file_get_contents($sUploadTempFile), true);
301
-        foreach($aFiles as $sVarName => $aUserFiles)
301
+        foreach ($aFiles as $sVarName => $aUserFiles)
302 302
         {
303 303
             $this->aUserFiles[$sVarName] = [];
304
-            foreach($aUserFiles as $aUserFile)
304
+            foreach ($aUserFiles as $aUserFile)
305 305
             {
306 306
                 $this->aUserFiles[$sVarName][] = UploadedFile::fromTempData($aUserFile);
307 307
             }
@@ -366,15 +366,15 @@  discard block
 block discarded – undo
366 366
      */
367 367
     public function processRequest()
368 368
     {
369
-        if(!$this->canProcessRequest())
369
+        if (!$this->canProcessRequest())
370 370
         {
371 371
             return false;
372 372
         }
373
-        if(count($_FILES) > 0)
373
+        if (count($_FILES) > 0)
374 374
         {
375 375
             $this->readFromHttpData();
376 376
         }
377
-        elseif(($this->sTempFile))
377
+        elseif (($this->sTempFile))
378 378
         {
379 379
             $this->readFromTempFile();
380 380
         }
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
     public function saveUploadedFiles()
390 390
     {
391 391
         // Process uploaded files
392
-        if(!$this->processRequest())
392
+        if (!$this->processRequest())
393 393
         {
394 394
             return '';
395 395
         }
Please login to merge, or discard this patch.