Passed
Push — 1.0.0-dev ( 066288...93958a )
by nguereza
09:45
created
core/libraries/Upload.php 1 patch
Indentation   +293 added lines, -293 removed lines patch added patch discarded remove patch
@@ -22,139 +22,139 @@  discard block
 block discarded – undo
22 22
      * You should have received a copy of the GNU General Public License
23 23
      * along with this program; if not, write to the Free Software
24 24
      * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-    */
25
+     */
26 26
 
27 27
 
28 28
 
29 29
     /**
30
-    *    Upload
31
-    *
32
-    *    A complete class to upload files with php 5 or higher, but the best: very simple to use.
33
-    *
34
-    *    @author Olaf Erlandsen <[email protected]>
35
-    *    @author http://www.webdevfreelance.com/
36
-    *
37
-    *    @package FileUpload
38
-    *    @version 1.5
39
-    */
30
+     *    Upload
31
+     *
32
+     *    A complete class to upload files with php 5 or higher, but the best: very simple to use.
33
+     *
34
+     *    @author Olaf Erlandsen <[email protected]>
35
+     *    @author http://www.webdevfreelance.com/
36
+     *
37
+     *    @package FileUpload
38
+     *    @version 1.5
39
+     */
40 40
     class Upload{
41 41
 
42 42
         /**
43
-        *   Version
44
-        *
45
-        *   @since      1.5
46
-        *   @version    1.0
47
-        */
43
+         *   Version
44
+         *
45
+         *   @since      1.5
46
+         *   @version    1.0
47
+         */
48 48
         const VERSION = '1.5';
49 49
 
50 50
         /**
51
-        *    Upload function name
52
-        *    Remember:
53
-        *        Default function: move_uploaded_file
54
-        *        Native options:
55
-        *            - move_uploaded_file (Default and best option)
56
-        *            - copy
57
-        *
58
-        *    @since        1.0
59
-        *    @version    1.0
60
-        *    @var        string
61
-        */
51
+         *    Upload function name
52
+         *    Remember:
53
+         *        Default function: move_uploaded_file
54
+         *        Native options:
55
+         *            - move_uploaded_file (Default and best option)
56
+         *            - copy
57
+         *
58
+         *    @since        1.0
59
+         *    @version    1.0
60
+         *    @var        string
61
+         */
62 62
         private $upload_function = 'move_uploaded_file';
63 63
 
64 64
         /**
65
-        *    Array with the information obtained from the
66
-        *    variable $_FILES or $HTTP_POST_FILES.
67
-        *
68
-        *    @since        1.0
69
-        *    @version    1.0
70
-        *    @var        array
71
-        */
65
+         *    Array with the information obtained from the
66
+         *    variable $_FILES or $HTTP_POST_FILES.
67
+         *
68
+         *    @since        1.0
69
+         *    @version    1.0
70
+         *    @var        array
71
+         */
72 72
         private $file_array    = array();
73 73
 
74 74
         /**
75
-        *    If the file you are trying to upload already exists it will
76
-        *    be overwritten if you set the variable to true.
77
-        *
78
-        *    @since        1.0
79
-        *    @version    1.0
80
-        *    @var        boolean
81
-        */
75
+         *    If the file you are trying to upload already exists it will
76
+         *    be overwritten if you set the variable to true.
77
+         *
78
+         *    @since        1.0
79
+         *    @version    1.0
80
+         *    @var        boolean
81
+         */
82 82
         private $overwrite_file = false;
83 83
 
84 84
         /**
85
-        *    Input element
86
-        *    Example:
87
-        *        <input type="file" name="file" />
88
-        *    Result:
89
-        *        FileUpload::$input = file
90
-        *
91
-        *    @since        1.0
92
-        *    @version    1.0
93
-        *    @var        string
94
-        */
85
+         *    Input element
86
+         *    Example:
87
+         *        <input type="file" name="file" />
88
+         *    Result:
89
+         *        FileUpload::$input = file
90
+         *
91
+         *    @since        1.0
92
+         *    @version    1.0
93
+         *    @var        string
94
+         */
95 95
         private $input;
96 96
 
97 97
         /**
98
-        *    Path output
99
-        *
100
-        *    @since        1.0
101
-        *    @version    1.0
102
-        *    @var        string
103
-        */
98
+         *    Path output
99
+         *
100
+         *    @since        1.0
101
+         *    @version    1.0
102
+         *    @var        string
103
+         */
104 104
         private $destination_directory;
105 105
 
106 106
         /**
107
-        *    Output filename
108
-        *
109
-        *    @since        1.0
110
-        *    @version    1.0
111
-        *    @var        string
112
-        */
107
+         *    Output filename
108
+         *
109
+         *    @since        1.0
110
+         *    @version    1.0
111
+         *    @var        string
112
+         */
113 113
         private $filename;
114 114
 
115 115
         /**
116
-        *    Max file size
117
-        *
118
-        *    @since        1.0
119
-        *    @version    1.0
120
-        *    @var        float
121
-        */
116
+         *    Max file size
117
+         *
118
+         *    @since        1.0
119
+         *    @version    1.0
120
+         *    @var        float
121
+         */
122 122
         private $max_file_size= 0.0;
123 123
 
124 124
         /**
125
-        *    List of allowed mime types
126
-        *
127
-        *    @since        1.0
128
-        *    @version    1.0
129
-        *    @var        array
130
-        */
125
+         *    List of allowed mime types
126
+         *
127
+         *    @since        1.0
128
+         *    @version    1.0
129
+         *    @var        array
130
+         */
131 131
         private $allowed_mime_types = array();
132 132
 
133 133
         /**
134
-        *    Callbacks
135
-        *
136
-        *    @since        1.0
137
-        *    @version    1.0
138
-        *    @var        array
139
-        */
134
+         *    Callbacks
135
+         *
136
+         *    @since        1.0
137
+         *    @version    1.0
138
+         *    @var        array
139
+         */
140 140
         private $callbacks = array('before' => null, 'after' => null);
141 141
 
142 142
         /**
143
-        *    File object
144
-        *
145
-        *    @since        1.0
146
-        *    @version    1.0
147
-        *    @var        object
148
-        */
143
+         *    File object
144
+         *
145
+         *    @since        1.0
146
+         *    @version    1.0
147
+         *    @var        object
148
+         */
149 149
         private $file;
150 150
 
151 151
         /**
152
-        *    Helping mime types
153
-        *
154
-        *    @since        1.0
155
-        *    @version    1.0
156
-        *    @var        array
157
-        */
152
+         *    Helping mime types
153
+         *
154
+         *    @since        1.0
155
+         *    @version    1.0
156
+         *    @var        array
157
+         */
158 158
         private $mime_helping = array(
159 159
             'text'      =>    array('text/plain',),
160 160
             'image'     =>    array(
@@ -210,13 +210,13 @@  discard block
 block discarded – undo
210 210
 
211 211
 
212 212
         /**
213
-        *    Construct
214
-        *
215
-        *    @since     0.1
216
-        *    @version   1.0.1
217
-        *    @return    object
218
-        *    @method    object    __construct
219
-        */
213
+         *    Construct
214
+         *
215
+         *    @since     0.1
216
+         *    @version   1.0.1
217
+         *    @return    object
218
+         *    @method    object    __construct
219
+         */
220 220
         public function __construct(){
221 221
             $this->logger =& class_loader('Log', 'classes');
222 222
             $this->logger->setLogger('Library::Upload');
@@ -260,17 +260,17 @@  discard block
 block discarded – undo
260 260
             $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array));
261 261
         }
262 262
         /**
263
-        *    Set input.
264
-        *    If you have $_FILES["file"], you must use the key "file"
265
-        *    Example:
266
-        *        $object->setInput("file");
267
-        *
268
-        *    @since     1.0
269
-        *    @version   1.0
270
-        *    @param     string      $input
271
-        *    @return    object
272
-        *    @method    boolean     setInput
273
-        */
263
+         *    Set input.
264
+         *    If you have $_FILES["file"], you must use the key "file"
265
+         *    Example:
266
+         *        $object->setInput("file");
267
+         *
268
+         *    @since     1.0
269
+         *    @version   1.0
270
+         *    @param     string      $input
271
+         *    @return    object
272
+         *    @method    boolean     setInput
273
+         */
274 274
         public function setInput($input)
275 275
         {
276 276
             if (!empty($input) && (is_string($input) || is_numeric($input) )) {
@@ -279,18 +279,18 @@  discard block
 block discarded – undo
279 279
             return $this;
280 280
         }
281 281
         /**
282
-        *    Set new filename
283
-        *    Example:
284
-        *        FileUpload::setFilename("new file.txt")
285
-        *    Remember:
286
-        *        Use %s to retrive file extension
287
-        *
288
-        *    @since     1.0
289
-        *    @version   1.0
290
-        *    @param     string      $filename
291
-        *    @return    object
292
-        *    @method    boolean     setFilename
293
-        */
282
+         *    Set new filename
283
+         *    Example:
284
+         *        FileUpload::setFilename("new file.txt")
285
+         *    Remember:
286
+         *        Use %s to retrive file extension
287
+         *
288
+         *    @since     1.0
289
+         *    @version   1.0
290
+         *    @param     string      $filename
291
+         *    @return    object
292
+         *    @method    boolean     setFilename
293
+         */
294 294
         public function setFilename($filename)
295 295
         {
296 296
             if ($this->isFilename($filename)) {
@@ -299,14 +299,14 @@  discard block
 block discarded – undo
299 299
             return $this;
300 300
         }
301 301
         /**
302
-        *    Set automatic filename
303
-        *
304
-        *    @since     1.0
305
-        *    @version   1.5
306
-        *    @param     string      $extension
307
-        *    @return    object
308
-        *    @method    boolean     setAutoFilename
309
-        */
302
+         *    Set automatic filename
303
+         *
304
+         *    @since     1.0
305
+         *    @version   1.5
306
+         *    @param     string      $extension
307
+         *    @return    object
308
+         *    @method    boolean     setAutoFilename
309
+         */
310 310
         public function setAutoFilename()
311 311
         {
312 312
             $this->filename = sha1(mt_rand(1, 9999).uniqid());
@@ -314,14 +314,14 @@  discard block
 block discarded – undo
314 314
             return $this;
315 315
         }
316 316
         /**
317
-        *    Set file size limit
318
-        *
319
-        *    @since     1.0
320
-        *    @version   1.0
321
-        *    @param     double     $file_size
322
-        *    @return    object
323
-        *    @method    boolean     setMaxFileSize
324
-        */
317
+         *    Set file size limit
318
+         *
319
+         *    @since     1.0
320
+         *    @version   1.0
321
+         *    @param     double     $file_size
322
+         *    @return    object
323
+         *    @method    boolean     setMaxFileSize
324
+         */
325 325
         public function setMaxFileSize($file_size)
326 326
         {
327 327
             $file_size = $this->sizeInBytes($file_size);
@@ -337,14 +337,14 @@  discard block
 block discarded – undo
337 337
             return $this;
338 338
         }
339 339
         /**
340
-        *    Set array mime types
341
-        *
342
-        *    @since     1.0
343
-        *    @version   1.0
344
-        *    @param     array       $mimes
345
-        *    @return    object
346
-        *    @method    boolean     setAllowedMimeTypes
347
-        */
340
+         *    Set array mime types
341
+         *
342
+         *    @since     1.0
343
+         *    @version   1.0
344
+         *    @param     array       $mimes
345
+         *    @return    object
346
+         *    @method    boolean     setAllowedMimeTypes
347
+         */
348 348
         public function setAllowedMimeTypes(array $mimes)
349 349
         {
350 350
             if (count($mimes) > 0) {
@@ -353,14 +353,14 @@  discard block
 block discarded – undo
353 353
             return $this;
354 354
         }
355 355
         /**
356
-        *    Set input callback
357
-        *
358
-        *    @since     1.0
359
-        *    @version   1.0
360
-        *    @param     mixed       $callback
361
-        *    @return    object
362
-        *    @method    boolean     setCallbackInput
363
-        */
356
+         *    Set input callback
357
+         *
358
+         *    @since     1.0
359
+         *    @version   1.0
360
+         *    @param     mixed       $callback
361
+         *    @return    object
362
+         *    @method    boolean     setCallbackInput
363
+         */
364 364
         public function setCallbackInput($callback)
365 365
         {
366 366
             if (is_callable($callback, false)) {
@@ -369,14 +369,14 @@  discard block
 block discarded – undo
369 369
             return $this;
370 370
         }
371 371
         /**
372
-        *    Set output callback
373
-        *
374
-        *    @since     1.0
375
-        *    @version   1.0
376
-        *    @param     mixed       $callback
377
-        *    @return    object
378
-        *    @method    boolean     setCallbackOutput
379
-        */
372
+         *    Set output callback
373
+         *
374
+         *    @since     1.0
375
+         *    @version   1.0
376
+         *    @param     mixed       $callback
377
+         *    @return    object
378
+         *    @method    boolean     setCallbackOutput
379
+         */
380 380
         public function setCallbackOutput($callback)
381 381
         {
382 382
             if (is_callable($callback, false)) {
@@ -385,14 +385,14 @@  discard block
 block discarded – undo
385 385
             return $this;
386 386
         }
387 387
         /**
388
-        *    Append a mime type to allowed mime types
389
-        *
390
-        *    @since     1.0
391
-        *    @version   1.0.1
392
-        *    @param     string      $mime
393
-        *    @return    object
394
-        *    @method    boolean     setAllowMimeType
395
-        */
388
+         *    Append a mime type to allowed mime types
389
+         *
390
+         *    @since     1.0
391
+         *    @version   1.0.1
392
+         *    @param     string      $mime
393
+         *    @return    object
394
+         *    @method    boolean     setAllowMimeType
395
+         */
396 396
         public function setAllowMimeType($mime)
397 397
         {
398 398
             if (!empty($mime) && is_string($mime)) {
@@ -402,13 +402,13 @@  discard block
 block discarded – undo
402 402
             return $this;
403 403
         }
404 404
         /**
405
-        *    Set allowed mime types from mime helping
406
-        *
407
-        *    @since     1.0.1
408
-        *    @version   1.0.1
409
-        *    @return    object
410
-        *    @method    boolean    setMimeHelping
411
-        */
405
+         *    Set allowed mime types from mime helping
406
+         *
407
+         *    @since     1.0.1
408
+         *    @version   1.0.1
409
+         *    @return    object
410
+         *    @method    boolean    setMimeHelping
411
+         */
412 412
         public function setMimeHelping($name)
413 413
         {
414 414
             if (!empty($name) && is_string($name)) {
@@ -419,17 +419,17 @@  discard block
 block discarded – undo
419 419
             return $this;
420 420
         }
421 421
         /**
422
-        *    Set function to upload file
423
-        *    Examples:
424
-        *        1.- FileUpload::setUploadFunction("move_uploaded_file");
425
-        *        2.- FileUpload::setUploadFunction("copy");
426
-        *
427
-        *    @since     1.0
428
-        *    @version   1.0
429
-        *    @param     string      $function
430
-        *    @return    object
431
-        *    @method    boolean     setUploadFunction
432
-        */
422
+         *    Set function to upload file
423
+         *    Examples:
424
+         *        1.- FileUpload::setUploadFunction("move_uploaded_file");
425
+         *        2.- FileUpload::setUploadFunction("copy");
426
+         *
427
+         *    @since     1.0
428
+         *    @version   1.0
429
+         *    @param     string      $function
430
+         *    @return    object
431
+         *    @method    boolean     setUploadFunction
432
+         */
433 433
         public function setUploadFunction($function)
434 434
         {
435 435
             if (!empty($function) && (is_array($function) || is_string($function) )) {
@@ -440,13 +440,13 @@  discard block
 block discarded – undo
440 440
             return $this;
441 441
         }
442 442
         /**
443
-        *    Clear allowed mime types cache
444
-        *
445
-        *    @since     1.0
446
-        *    @version   1.0
447
-        *    @return    object
448
-        *    @method    boolean    clearAllowedMimeTypes
449
-        */
443
+         *    Clear allowed mime types cache
444
+         *
445
+         *    @since     1.0
446
+         *    @version   1.0
447
+         *    @return    object
448
+         *    @method    boolean    clearAllowedMimeTypes
449
+         */
450 450
         public function clearAllowedMimeTypes()
451 451
         {
452 452
             $this->allowed_mime_types = array();
@@ -454,15 +454,15 @@  discard block
 block discarded – undo
454 454
             return $this;
455 455
         }
456 456
         /**
457
-        *    Set destination output
458
-        *
459
-        *    @since     1.0
460
-        *    @version   1.0
461
-        *    @param     string      $destination_directory      Destination path
462
-        *    @param     boolean     $create_if_not_exist
463
-        *    @return    object
464
-        *    @method    boolean     setDestinationDirectory
465
-        */
457
+         *    Set destination output
458
+         *
459
+         *    @since     1.0
460
+         *    @version   1.0
461
+         *    @param     string      $destination_directory      Destination path
462
+         *    @param     boolean     $create_if_not_exist
463
+         *    @return    object
464
+         *    @method    boolean     setDestinationDirectory
465
+         */
466 466
         public function setDestinationDirectory($destination_directory, $create_if_not_exist = false) {
467 467
             $destination_directory = realpath($destination_directory);
468 468
             if (substr($destination_directory, -1) != DIRECTORY_SEPARATOR) {
@@ -486,14 +486,14 @@  discard block
 block discarded – undo
486 486
             return $this;
487 487
         }
488 488
         /**
489
-        *    Check file exists
490
-        *
491
-        *    @since      1.0
492
-        *    @version    1.0.1
493
-        *    @param      string     $file_destination
494
-        *    @return     boolean
495
-        *    @method     boolean    fileExists
496
-        */
489
+         *    Check file exists
490
+         *
491
+         *    @since      1.0
492
+         *    @version    1.0.1
493
+         *    @param      string     $file_destination
494
+         *    @return     boolean
495
+         *    @method     boolean    fileExists
496
+         */
497 497
         public function fileExists($file_destination)
498 498
         {
499 499
             if ($this->isFilename($file_destination)) {
@@ -502,14 +502,14 @@  discard block
 block discarded – undo
502 502
             return false;
503 503
         }
504 504
         /**
505
-        *    Check dir exists
506
-        *
507
-        *    @since        1.0
508
-        *    @version    1.0.1
509
-        *    @param      string     $path
510
-        *    @return     boolean
511
-        *    @method     boolean    dirExists
512
-        */
505
+         *    Check dir exists
506
+         *
507
+         *    @since        1.0
508
+         *    @version    1.0.1
509
+         *    @param      string     $path
510
+         *    @return     boolean
511
+         *    @method     boolean    dirExists
512
+         */
513 513
         public function dirExists($path)
514 514
         {
515 515
             if ($this->isDirpath($path)) {
@@ -518,29 +518,29 @@  discard block
 block discarded – undo
518 518
             return false;
519 519
         }
520 520
         /**
521
-        *    Check valid filename
522
-        *
523
-        *    @since     1.0
524
-        *    @version   1.0.1
525
-        *    @param     string      $filename
526
-        *    @return    boolean
527
-        *    @method    boolean     isFilename
528
-        */
521
+         *    Check valid filename
522
+         *
523
+         *    @since     1.0
524
+         *    @version   1.0.1
525
+         *    @param     string      $filename
526
+         *    @return    boolean
527
+         *    @method    boolean     isFilename
528
+         */
529 529
         public function isFilename($filename)
530 530
         {
531 531
             $filename = basename($filename);
532 532
             return (!empty($filename) && (is_string( $filename) || is_numeric($filename)));
533 533
         }
534 534
         /**
535
-        *    Validate mime type with allowed mime types,
536
-        *    but if allowed mime types is empty, this method return true
537
-        *
538
-        *    @since     1.0
539
-        *    @version   1.0
540
-        *    @param     string      $mime
541
-        *    @return    boolean
542
-        *    @method    boolean     checkMimeType
543
-        */
535
+         *    Validate mime type with allowed mime types,
536
+         *    but if allowed mime types is empty, this method return true
537
+         *
538
+         *    @since     1.0
539
+         *    @version   1.0
540
+         *    @param     string      $mime
541
+         *    @return    boolean
542
+         *    @method    boolean     checkMimeType
543
+         */
544 544
         public function checkMimeType($mime)
545 545
         {
546 546
             if (count($this->allowed_mime_types) == 0) {
@@ -549,26 +549,26 @@  discard block
 block discarded – undo
549 549
             return in_array(strtolower($mime), $this->allowed_mime_types);
550 550
         }
551 551
         /**
552
-        *    Retrive status of upload
553
-        *
554
-        *    @since     1.0
555
-        *    @version   1.0
556
-        *    @return    boolean
557
-        *    @method    boolean    getStatus
558
-        */
552
+         *    Retrive status of upload
553
+         *
554
+         *    @since     1.0
555
+         *    @version   1.0
556
+         *    @return    boolean
557
+         *    @method    boolean    getStatus
558
+         */
559 559
         public function getStatus()
560 560
         {
561 561
             return $this->file['status'];
562 562
         }
563 563
         /**
564
-        *    Check valid path
565
-        *
566
-        *    @since        1.0
567
-        *    @version    1.0.1
568
-        *    @param        string    $filename
569
-        *    @return     boolean
570
-        *    @method     boolean    isDirpath
571
-        */
564
+         *    Check valid path
565
+         *
566
+         *    @since        1.0
567
+         *    @version    1.0.1
568
+         *    @param        string    $filename
569
+         *    @return     boolean
570
+         *    @method     boolean    isDirpath
571
+         */
572 572
         public function isDirpath($path)
573 573
         {
574 574
             if (!empty( $path) && (is_string( $path) || is_numeric($path) )) {
@@ -581,26 +581,26 @@  discard block
 block discarded – undo
581 581
             return false;
582 582
         }
583 583
         /**
584
-        *    Allow overwriting files
585
-        *
586
-        *    @since      1.0
587
-        *    @version    1.0
588
-        *    @return     object
589
-        *    @method     boolean    allowOverwriting
590
-        */
584
+         *    Allow overwriting files
585
+         *
586
+         *    @since      1.0
587
+         *    @version    1.0
588
+         *    @return     object
589
+         *    @method     boolean    allowOverwriting
590
+         */
591 591
         public function allowOverwriting()
592 592
         {
593 593
             $this->overwrite_file = true;
594 594
             return $this;
595 595
         }
596 596
         /**
597
-        *    File info
598
-        *
599
-        *    @since      1.0
600
-        *    @version    1.0
601
-        *    @return     object
602
-        *    @method     object    getInfo
603
-        */
597
+         *    File info
598
+         *
599
+         *    @since      1.0
600
+         *    @version    1.0
601
+         *    @return     object
602
+         *    @method     object    getInfo
603
+         */
604 604
         public function getInfo()
605 605
         {
606 606
             return (object)$this->file;
@@ -618,13 +618,13 @@  discard block
 block discarded – undo
618 618
 
619 619
         
620 620
         /**
621
-        *    Upload file
622
-        *
623
-        *    @since     1.0
624
-        *    @version   1.0.1
625
-        *    @return    boolean
626
-        *    @method    boolean    save
627
-        */
621
+         *    Upload file
622
+         *
623
+         *    @since     1.0
624
+         *    @version   1.0.1
625
+         *    @return    boolean
626
+         *    @method    boolean    save
627
+         */
628 628
         public function save(){
629 629
             if (count($this->file_array) > 0 && array_key_exists($this->input, $this->file_array)) {
630 630
                 // set original filename if not have a new name
@@ -681,15 +681,15 @@  discard block
 block discarded – undo
681 681
 
682 682
 
683 683
         /**
684
-        *    File size for humans.
685
-        *
686
-        *    @since      1.0
687
-        *    @version    1.0
688
-        *    @param      integer    $bytes
689
-        *    @param      integer    $precision
690
-        *    @return     string
691
-        *    @method     string     sizeFormat
692
-        */
684
+         *    File size for humans.
685
+         *
686
+         *    @since      1.0
687
+         *    @version    1.0
688
+         *    @param      integer    $bytes
689
+         *    @param      integer    $precision
690
+         *    @return     string
691
+         *    @method     string     sizeFormat
692
+         */
693 693
         public function sizeFormat($size, $precision = 2)
694 694
         {
695 695
             if($size > 0){
@@ -702,14 +702,14 @@  discard block
 block discarded – undo
702 702
 
703 703
         
704 704
         /**
705
-        *    Convert human file size to bytes
706
-        *
707
-        *    @since      1.0
708
-        *    @version    1.0.1
709
-        *    @param      integer|double    $size
710
-        *    @return     integer|double
711
-        *    @method     string     sizeInBytes
712
-        */
705
+         *    Convert human file size to bytes
706
+         *
707
+         *    @since      1.0
708
+         *    @version    1.0.1
709
+         *    @param      integer|double    $size
710
+         *    @return     integer|double
711
+         *    @method     string     sizeInBytes
712
+         */
713 713
         public function sizeInBytes($size)
714 714
         {
715 715
             $unit = 'B';
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
                 return true;
762 762
             }
763 763
 
764
-             //check for php upload error
764
+                //check for php upload error
765 765
             if(is_numeric($this->file['error']) && $this->file['error'] > 0){
766 766
                 $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error']));
767 767
                 return true;
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
                 return true;
774 774
             }
775 775
 
776
-             // Check file size
776
+                // Check file size
777 777
             if ($this->max_file_size > 0 && $this->max_file_size < $this->file['size']) {
778 778
                 $this->setError(sprintf($this->error_messages['max_file_size'], $this->sizeFormat($this->max_file_size)));
779 779
                 return true;
Please login to merge, or discard this patch.
core/constants.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -1,81 +1,81 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	/**
28
-	 *  @file constants.php
29
-	 *    
30
-	 *  This file contains the declaration of most of the constants used in the system, 
31
-	 *  for example: the version, the name of the framework, etc.
32
-	 *  
33
-	 *  @package	core	
34
-	 *  @author	Tony NGUEREZA
35
-	 *  @copyright	Copyright (c) 2017
36
-	 *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
37
-	 *  @link	http://www.iacademy.cf
38
-	 *  @version 1.0.0
39
-	 *  @filesource
40
-	 */
27
+    /**
28
+     *  @file constants.php
29
+     *    
30
+     *  This file contains the declaration of most of the constants used in the system, 
31
+     *  for example: the version, the name of the framework, etc.
32
+     *  
33
+     *  @package	core	
34
+     *  @author	Tony NGUEREZA
35
+     *  @copyright	Copyright (c) 2017
36
+     *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
37
+     *  @link	http://www.iacademy.cf
38
+     *  @version 1.0.0
39
+     *  @filesource
40
+     */
41 41
 
42
-	/**
43
-	 *  The framework name
44
-	 */
45
-	define('TNH_NAME', 'TNH Framework');
42
+    /**
43
+     *  The framework name
44
+     */
45
+    define('TNH_NAME', 'TNH Framework');
46 46
 
47
-	/**
48
-	 *  The version of the framework in X.Y.Z format (Major, minor and bugs). 
49
-	 *  If there is the presence of the word "dev", it means that 
50
-	 *  it is a version under development.
51
-	 */
52
-	define('TNH_VERSION', '1.0.0-dev');
47
+    /**
48
+     *  The version of the framework in X.Y.Z format (Major, minor and bugs). 
49
+     *  If there is the presence of the word "dev", it means that 
50
+     *  it is a version under development.
51
+     */
52
+    define('TNH_VERSION', '1.0.0-dev');
53 53
 
54
-	/**
55
-	 *  The date of publication or release of the framework
56
-	 */
57
-	define('TNH_RELEASE_DATE', '2017/02/05');
54
+    /**
55
+     *  The date of publication or release of the framework
56
+     */
57
+    define('TNH_RELEASE_DATE', '2017/02/05');
58 58
 
59
-	/**
60
-	 *  The author of the framework, the person who developed the framework.
61
-	 */
62
-	define('TNH_AUTHOR', 'Tony NGUEREZA');
59
+    /**
60
+     *  The author of the framework, the person who developed the framework.
61
+     */
62
+    define('TNH_AUTHOR', 'Tony NGUEREZA');
63 63
 
64
-	/**
65
-	 *  Email address of the author of the framework.
66
-	 */
67
-	define('TNH_AUTHOR_EMAIL', '[email protected]');
64
+    /**
65
+     *  Email address of the author of the framework.
66
+     */
67
+    define('TNH_AUTHOR_EMAIL', '[email protected]');
68 68
 
69
-	/**
70
-	 *  The minimum PHP version required to use the framework. 
71
-	 *  If the version of PHP installed is lower, then the application will not work.
72
-	 *  Note: we use the PHP version_compare function to compare the required version with 
73
-	 *  the version installed on your system.
74
-	 */
75
-	define('TNH_REQUIRED_PHP_MIN_VERSION', '5.4');
69
+    /**
70
+     *  The minimum PHP version required to use the framework. 
71
+     *  If the version of PHP installed is lower, then the application will not work.
72
+     *  Note: we use the PHP version_compare function to compare the required version with 
73
+     *  the version installed on your system.
74
+     */
75
+    define('TNH_REQUIRED_PHP_MIN_VERSION', '5.4');
76 76
 
77
-	/**
78
-	 *  The maximum version of PHP required to use the framework. 
79
-	 *  If the version of PHP installed is higher than the required one, then the application will not work.
80
-	 */
81
-	define('TNH_REQUIRED_PHP_MAX_VERSION', '7.1');
82 77
\ No newline at end of file
78
+    /**
79
+     *  The maximum version of PHP required to use the framework. 
80
+     *  If the version of PHP installed is higher than the required one, then the application will not work.
81
+     */
82
+    define('TNH_REQUIRED_PHP_MAX_VERSION', '7.1');
83 83
\ No newline at end of file
Please login to merge, or discard this patch.
core/lang/en/lang_form_validation.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 <?php 
2 2
     defined('ROOT_PATH') || exit('Access denied');
3
- 	/**
4
- 	 * Form validation language message (English) 
5
- 	 */
6
- 	$lang['fv_required']     		= 'Field %1 is required.';
3
+        /**
4
+         * Form validation language message (English) 
5
+         */
6
+        $lang['fv_required']     		= 'Field %1 is required.';
7 7
     $lang['fv_min_length']   		= 'Field %1 must contain at least %2 characters.';
8 8
     $lang['fv_max_length']   		= 'Field %1 must contain at most %2 characters.';
9 9
     $lang['fv_exact_length'] 		= 'Field %1 must contain exactly %2 characters.';
@@ -14,8 +14,8 @@  discard block
 block discarded – undo
14 14
     $lang['fv_not_equal_post_key']  = 'Field %1 must not be the same as field %2.';
15 15
     $lang['fv_not_equal_string']    = 'Field %1 must not contain the value %2.';
16 16
     $lang['fv_depends']      		= 'Field %1 depends on field %2 which is not valid.';
17
-	$lang['fv_is_unique']	   		= 'The value of field %1 already exists.';
18
-	$lang['fv_is_unique_update']	= 'The value of field %1 already exists for another record.';
17
+    $lang['fv_is_unique']	   		= 'The value of field %1 already exists.';
18
+    $lang['fv_is_unique_update']	= 'The value of field %1 already exists for another record.';
19 19
     $lang['fv_exists']	   			= 'The value of the field %1 does not exist.';
20 20
     $lang['fv_regex']	   			= 'The value of the field %1 does not use the correct format.';
21 21
     $lang['fv_in_list']	   			= 'The value of field %1 must be one of the list (%2).';
Please login to merge, or discard this patch.
core/lang/en/lang_file_upload.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@
 block discarded – undo
1 1
 <?php 
2 2
     defined('ROOT_PATH') || exit('Access denied');
3
- 	/**
4
- 	 * File upload language messages (English) 
5
- 	 */
6
- 	$lang['fu_upload_err_ini_size']     = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.';
3
+        /**
4
+         * File upload language messages (English) 
5
+         */
6
+        $lang['fu_upload_err_ini_size']     = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.';
7 7
     $lang['fu_upload_err_form_size']   	= 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.';
8 8
     $lang['fu_upload_err_partial']   	= 'The uploaded file was only partially uploaded.';
9 9
     $lang['fu_upload_err_no_file'] 		= 'No file was choosed. Please select one.';
Please login to merge, or discard this patch.
core/classes/database/DatabaseQueryRunner.php 1 patch
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -1,90 +1,90 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
     defined('ROOT_PATH') || exit('Access denied');
3
-  /**
4
-   * TNH Framework
5
-   *
6
-   * A simple PHP framework using HMVC architecture
7
-   *
8
-   * This content is released under the GNU GPL License (GPL)
9
-   *
10
-   * Copyright (C) 2017 Tony NGUEREZA
11
-   *
12
-   * This program is free software; you can redistribute it and/or
13
-   * modify it under the terms of the GNU General Public License
14
-   * as published by the Free Software Foundation; either version 3
15
-   * of the License, or (at your option) any later version.
16
-   *
17
-   * This program is distributed in the hope that it will be useful,
18
-   * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-   * GNU General Public License for more details.
21
-   *
22
-   * You should have received a copy of the GNU General Public License
23
-   * along with this program; if not, write to the Free Software
24
-   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-  */
26
-  class DatabaseQueryRunner{
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26
+    class DatabaseQueryRunner{
27 27
       
28 28
     /**
29
-	* The logger instance
30
-	* @var object
31
-	*/
29
+     * The logger instance
30
+     * @var object
31
+     */
32 32
     private $logger            = null;
33 33
     
34
-  	/**
35
-  	 * The last query result
36
-  	 * @var object
37
-  	*/
38
-  	private $queryResult       = null;
34
+        /**
35
+         * The last query result
36
+         * @var object
37
+         */
38
+        private $queryResult       = null;
39 39
   	
40
-  	/**
41
-    * The benchmark instance
42
-    * @var object
43
-    */
40
+        /**
41
+         * The benchmark instance
42
+         * @var object
43
+         */
44 44
     private $benchmarkInstance = null;
45 45
     
46 46
     /**
47
-	 * The SQL query statment to execute
48
-	 * @var string
49
-	*/
47
+     * The SQL query statment to execute
48
+     * @var string
49
+     */
50 50
     private $query             = null;
51 51
     
52 52
     /**
53
-	 * Indicate if we need return result as list (boolean) 
53
+     * Indicate if we need return result as list (boolean) 
54 54
      * or the data used to replace the placeholder (array)
55
-	 * @var array|boolean
56
-	 */
57
-     private $returnAsList     = true;
55
+     * @var array|boolean
56
+     */
57
+        private $returnAsList     = true;
58 58
      
59 59
      
60
-     /**
61
-	   * Indicate if we need return result as array or not
62
-     * @var boolean
63
-	   */
64
-     private $returnAsArray     = true;
60
+        /**
61
+         * Indicate if we need return result as array or not
62
+         * @var boolean
63
+         */
64
+        private $returnAsArray     = true;
65 65
      
66
-     /**
67
-     * The last PDOStatment instance
68
-     * @var object
69
-     */
70
-     private $pdoStatment       = null;
66
+        /**
67
+         * The last PDOStatment instance
68
+         * @var object
69
+         */
70
+        private $pdoStatment       = null;
71 71
      
72
-     /**
73
-  	 * The error returned for the last query
74
-  	 * @var string
75
-  	 */
76
-     private $error             = null;
72
+        /**
73
+         * The error returned for the last query
74
+         * @var string
75
+         */
76
+        private $error             = null;
77 77
 	
78 78
     /**
79 79
      * The PDO instance
80 80
      * @var object
81
-    */
81
+     */
82 82
     private $pdo                = null;
83 83
   
84 84
     /**
85 85
      * The database driver name used
86 86
      * @var string
87
-    */
87
+     */
88 88
     private $driver             = null;
89 89
 
90 90
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      */
99 99
     public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false){
100 100
         if (is_object($pdo)){
101
-          $this->pdo = $pdo;
101
+            $this->pdo = $pdo;
102 102
         }
103 103
         $this->query         = $query;
104 104
         $this->returnAsList  = $returnAsList;
@@ -116,10 +116,10 @@  discard block
 block discarded – undo
116 116
         //reset instance
117 117
         $this->reset();
118 118
        
119
-       //for database query execution time
119
+        //for database query execution time
120 120
         $benchmarkMarkerKey = $this->getBenchmarkKey();
121 121
         if (! is_object($this->benchmarkInstance)){
122
-          $this->benchmarkInstance = & class_loader('Benchmark');
122
+            $this->benchmarkInstance = & class_loader('Benchmark');
123 123
         }
124 124
         
125 125
         $this->logger->info('Execute SQL query [' . $this->query . ']');
@@ -132,101 +132,101 @@  discard block
 block discarded – undo
132 132
         $responseTime = $this->benchmarkInstance->elapsedTime(
133 133
                                                                 'DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', 
134 134
                                                                 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')'
135
-                                                              );
136
-		    //TODO use the configuration value for the high response time currently is 1 second
135
+                                                                );
136
+            //TODO use the configuration value for the high response time currently is 1 second
137 137
         if ($responseTime >= 1 ){
138 138
             $this->logger->warning(
139 139
                                     'High response time while processing database query [' . $this->query . ']. 
140 140
                                      The response time is [' .$responseTime. '] sec.'
141
-                                  );
141
+                                    );
142 142
         }
143 143
 		
144 144
         if ($this->pdoStatment !== false){
145
-          $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
146
-          if($isSqlSELECTQuery){
147
-              $this->setResultForSelect();              
148
-          }
149
-          else{
150
-              $this->setResultForNonSelect();
151
-          }
152
-          return $this->queryResult;
145
+            $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
146
+            if($isSqlSELECTQuery){
147
+                $this->setResultForSelect();              
148
+            }
149
+            else{
150
+                $this->setResultForNonSelect();
151
+            }
152
+            return $this->queryResult;
153 153
         }
154 154
         $this->setQueryRunnerError();
155 155
     }
156 156
 	
157
-   /**
158
-   * Return the result for SELECT query
159
-   * @see DatabaseQueryRunner::execute
160
-   */
157
+    /**
158
+     * Return the result for SELECT query
159
+     * @see DatabaseQueryRunner::execute
160
+     */
161 161
     protected function setResultForSelect(){
162
-      //if need return all result like list of record
163
-      $result = null;
164
-      $numRows = 0;
165
-      $fetchMode = PDO::FETCH_OBJ;
166
-      if($this->returnAsArray){
162
+        //if need return all result like list of record
163
+        $result = null;
164
+        $numRows = 0;
165
+        $fetchMode = PDO::FETCH_OBJ;
166
+        if($this->returnAsArray){
167 167
         $fetchMode = PDO::FETCH_ASSOC;
168
-      }
169
-      if ($this->returnAsList){
170
-          $result = $this->pdoStatment->fetchAll($fetchMode);
171
-      }
172
-      else{
173
-          $result = $this->pdoStatment->fetch($fetchMode);
174
-      }
175
-      //Sqlite and pgsql always return 0 when using rowCount()
176
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
168
+        }
169
+        if ($this->returnAsList){
170
+            $result = $this->pdoStatment->fetchAll($fetchMode);
171
+        }
172
+        else{
173
+            $result = $this->pdoStatment->fetch($fetchMode);
174
+        }
175
+        //Sqlite and pgsql always return 0 when using rowCount()
176
+        if (in_array($this->driver, array('sqlite', 'pgsql'))){
177 177
         $numRows = count($result);  
178
-      }
179
-      else{
178
+        }
179
+        else{
180 180
         $numRows = $this->pdoStatment->rowCount(); 
181
-      }
182
-      if(! is_object($this->queryResult)){
183
-          $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
184
-      }
185
-      $this->queryResult->setResult($result);
186
-      $this->queryResult->setNumRows($numRows);
181
+        }
182
+        if(! is_object($this->queryResult)){
183
+            $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
184
+        }
185
+        $this->queryResult->setResult($result);
186
+        $this->queryResult->setNumRows($numRows);
187 187
     }
188 188
 
189 189
     /**
190
-   * Return the result for non SELECT query
191
-   * @see DatabaseQueryRunner::execute
192
-   */
190
+     * Return the result for non SELECT query
191
+     * @see DatabaseQueryRunner::execute
192
+     */
193 193
     protected function setResultForNonSelect(){
194
-      //Sqlite and pgsql always return 0 when using rowCount()
195
-      $result = false;
196
-      $numRows = 0;
197
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
194
+        //Sqlite and pgsql always return 0 when using rowCount()
195
+        $result = false;
196
+        $numRows = 0;
197
+        if (in_array($this->driver, array('sqlite', 'pgsql'))){
198 198
         $result = true; //to test the result for the query like UPDATE, INSERT, DELETE
199 199
         $numRows = 1; //TODO use the correct method to get the exact affected row
200
-      }
201
-      else{
202
-          //to test the result for the query like UPDATE, INSERT, DELETE
203
-          $result  = $this->pdoStatment->rowCount() >= 0; 
204
-          $numRows = $this->pdoStatment->rowCount(); 
205
-      }
206
-      if(! is_object($this->queryResult)){
207
-          $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
208
-      }
209
-      $this->queryResult->setResult($result);
210
-      $this->queryResult->setNumRows($numRows);
200
+        }
201
+        else{
202
+            //to test the result for the query like UPDATE, INSERT, DELETE
203
+            $result  = $this->pdoStatment->rowCount() >= 0; 
204
+            $numRows = $this->pdoStatment->rowCount(); 
205
+        }
206
+        if(! is_object($this->queryResult)){
207
+            $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
208
+        }
209
+        $this->queryResult->setResult($result);
210
+        $this->queryResult->setNumRows($numRows);
211 211
     }
212 212
 
213 213
 
214
-	/**
214
+    /**
215 215
      * Return the benchmark instance
216 216
      * @return Benchmark
217 217
      */
218 218
     public function getBenchmark(){
219
-      return $this->benchmarkInstance;
219
+        return $this->benchmarkInstance;
220 220
     }
221 221
 
222 222
     /**
223 223
      * Set the benchmark instance
224 224
      * @param Benchmark $benchmark the benchmark object
225
-	 * @return object DatabaseQueryRunner
225
+     * @return object DatabaseQueryRunner
226 226
      */
227 227
     public function setBenchmark($benchmark){
228
-      $this->benchmarkInstance = $benchmark;
229
-      return $this;
228
+        $this->benchmarkInstance = $benchmark;
229
+        return $this;
230 230
     }
231 231
     
232 232
     /**
@@ -235,18 +235,18 @@  discard block
 block discarded – undo
235 235
      * @return object DatabaseQueryResult
236 236
      */
237 237
     public function getQueryResult(){
238
-      return $this->queryResult;
238
+        return $this->queryResult;
239 239
     }
240 240
 
241 241
     /**
242 242
      * Set the database query result instance
243 243
      * @param object $queryResult the query result
244 244
      *
245
-	 * @return object DatabaseQueryRunner
245
+     * @return object DatabaseQueryRunner
246 246
      */
247 247
     public function setQueryResult(DatabaseQueryResult $queryResult){
248
-      $this->queryResult = $queryResult;
249
-      return $this;
248
+        $this->queryResult = $queryResult;
249
+        return $this;
250 250
     }
251 251
     
252 252
     /**
@@ -254,17 +254,17 @@  discard block
 block discarded – undo
254 254
      * @return Log
255 255
      */
256 256
     public function getLogger(){
257
-      return $this->logger;
257
+        return $this->logger;
258 258
     }
259 259
 
260 260
     /**
261 261
      * Set the log instance
262 262
      * @param Log $logger the log object
263
-	 * @return object DatabaseQueryRunner
263
+     * @return object DatabaseQueryRunner
264 264
      */
265 265
     public function setLogger($logger){
266
-      $this->logger = $logger;
267
-      return $this;
266
+        $this->logger = $logger;
267
+        return $this;
268 268
     }
269 269
     
270 270
     /**
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
      * @return string
273 273
      */
274 274
     public function getQuery(){
275
-      return $this->query;
275
+        return $this->query;
276 276
     }
277 277
     
278 278
     /**
@@ -281,8 +281,8 @@  discard block
 block discarded – undo
281 281
      * @return object DatabaseQueryRunner
282 282
      */
283 283
     public function setQuery($query){
284
-       $this->query = $query;
285
-       return $this;
284
+        $this->query = $query;
285
+        return $this;
286 286
     }
287 287
     
288 288
     /**
@@ -291,8 +291,8 @@  discard block
 block discarded – undo
291 291
      * @return object DatabaseQueryRunner
292 292
      */
293 293
     public function setReturnType($returnType){
294
-       $this->returnAsList = $returnType;
295
-       return $this;
294
+        $this->returnAsList = $returnType;
295
+        return $this;
296 296
     }
297 297
     
298 298
     /**
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
      * @return object DatabaseQueryRunner
302 302
      */
303 303
     public function setReturnAsArray($status = true){
304
-       $this->returnAsArray = $status;
305
-       return $this;
304
+        $this->returnAsArray = $status;
305
+        return $this;
306 306
     }
307 307
     
308 308
     /**
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
      * @return string
311 311
      */
312 312
     public function getQueryError(){
313
-      return $this->error;
313
+        return $this->error;
314 314
     }
315 315
 
316 316
     /**
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
      * @return object
319 319
      */
320 320
     public function getPdo(){
321
-      return $this->pdo;
321
+        return $this->pdo;
322 322
     }
323 323
 
324 324
     /**
@@ -327,16 +327,16 @@  discard block
 block discarded – undo
327 327
      * @return object DatabaseQueryRunner
328 328
      */
329 329
     public function setPdo(PDO $pdo = null){
330
-      $this->pdo = $pdo;
331
-      return $this;
330
+        $this->pdo = $pdo;
331
+        return $this;
332 332
     }
333 333
   
334
-     /**
335
-     * Return the database driver
336
-     * @return string
337
-     */
334
+        /**
335
+         * Return the database driver
336
+         * @return string
337
+         */
338 338
     public function getDriver(){
339
-      return $this->driver;
339
+        return $this->driver;
340 340
     }
341 341
 
342 342
     /**
@@ -345,8 +345,8 @@  discard block
 block discarded – undo
345 345
      * @return object DatabaseQueryRunner
346 346
      */
347 347
     public function setDriver($driver){
348
-      $this->driver = $driver;
349
-      return $this;
348
+        $this->driver = $driver;
349
+        return $this;
350 350
     }
351 351
     
352 352
     /**
@@ -355,18 +355,18 @@  discard block
 block discarded – undo
355 355
      *  @return string
356 356
      */
357 357
     protected function getBenchmarkKey(){
358
-      return md5($this->query . $this->returnAsList . $this->returnAsArray);
358
+        return md5($this->query . $this->returnAsList . $this->returnAsArray);
359 359
     }
360 360
     
361 361
     /**
362 362
      * Set error for database query execution
363 363
      */
364 364
     protected function setQueryRunnerError(){
365
-      $error = $this->pdo->errorInfo();
366
-      $this->error = isset($error[2]) ? $error[2] : '';
367
-      $this->logger->error('The database query execution got an error: ' . stringfy_vars($error));
368
-	  //show error message
369
-      show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error');
365
+        $error = $this->pdo->errorInfo();
366
+        $this->error = isset($error[2]) ? $error[2] : '';
367
+        $this->logger->error('The database query execution got an error: ' . stringfy_vars($error));
368
+        //show error message
369
+        show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error');
370 370
     }
371 371
     
372 372
     /**
@@ -374,19 +374,19 @@  discard block
 block discarded – undo
374 374
      * @param object $logger the Log instance if not null
375 375
      */
376 376
     protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
377
-      if ($logger !== null){
377
+        if ($logger !== null){
378 378
         $this->logger = $logger;
379
-      }
380
-      else{
381
-          $this->logger =& class_loader('Log', 'classes');
382
-          $this->logger->setLogger('Library::DatabaseQueryRunner');
383
-      }
379
+        }
380
+        else{
381
+            $this->logger =& class_loader('Log', 'classes');
382
+            $this->logger->setLogger('Library::DatabaseQueryRunner');
383
+        }
384 384
     }
385 385
     
386 386
     
387 387
     /**
388
-    * Reset the instance before run each query
389
-    */
388
+     * Reset the instance before run each query
389
+     */
390 390
     private function reset(){
391 391
         $this->error = null;
392 392
         $this->pdoStatment = null;
Please login to merge, or discard this patch.
core/functions/function_user_agent.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -1,75 +1,75 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27 27
 
28
-	/**
29
-	 *  @file function_user_agent.php
30
-	 *    
31
-	 *  Contains most of the utility functions for agent, platform, mobile, browser, and other management.
32
-	 *  
33
-	 *  @package	core
34
-	 *  @author	Tony NGUEREZA
35
-	 *  @copyright	Copyright (c) 2017
36
-	 *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
37
-	 *  @link	http://www.iacademy.cf
38
-	 *  @version 1.0.0
39
-	 *  @since 1.0.0
40
-	 *  @filesource
41
-	 */
28
+    /**
29
+     *  @file function_user_agent.php
30
+     *    
31
+     *  Contains most of the utility functions for agent, platform, mobile, browser, and other management.
32
+     *  
33
+     *  @package	core
34
+     *  @author	Tony NGUEREZA
35
+     *  @copyright	Copyright (c) 2017
36
+     *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
37
+     *  @link	http://www.iacademy.cf
38
+     *  @version 1.0.0
39
+     *  @since 1.0.0
40
+     *  @filesource
41
+     */
42 42
 	
43 43
 	 
44
-	if(! function_exists('get_ip')){
45
-		/**
46
-		 *  Retrieves the user's IP address
47
-		 *  
48
-		 *  This function allows to retrieve the IP address of the client
49
-		 *  even if it uses a proxy, the actual IP address is retrieved.
50
-		 *  
51
-		 *  @return string the IP address.
52
-		 */
53
-		function get_ip(){
54
-			$ip = '127.0.0.1';
55
-			$ipServerVars = array(
56
-								'REMOTE_ADDR',
57
-								'HTTP_CLIENT_IP',
58
-								'HTTP_X_FORWARDED_FOR',
59
-								'HTTP_X_FORWARDED',
60
-								'HTTP_FORWARDED_FOR',
61
-								'HTTP_FORWARDED'
62
-							);
63
-			foreach ($ipServerVars as $var) {
64
-				if(isset($_SERVER[$var])){
65
-					$ip = $_SERVER[$var];
66
-					break;
67
-				}
68
-			}
69
-			// Strip any secondary IP etc from the IP address
70
-			if (strpos($ip, ',') > 0) {
71
-				$ip = substr($ip, 0, strpos($ip, ','));
72
-			}
73
-			return $ip;
74
-		}
75
-	}
44
+    if(! function_exists('get_ip')){
45
+        /**
46
+         *  Retrieves the user's IP address
47
+         *  
48
+         *  This function allows to retrieve the IP address of the client
49
+         *  even if it uses a proxy, the actual IP address is retrieved.
50
+         *  
51
+         *  @return string the IP address.
52
+         */
53
+        function get_ip(){
54
+            $ip = '127.0.0.1';
55
+            $ipServerVars = array(
56
+                                'REMOTE_ADDR',
57
+                                'HTTP_CLIENT_IP',
58
+                                'HTTP_X_FORWARDED_FOR',
59
+                                'HTTP_X_FORWARDED',
60
+                                'HTTP_FORWARDED_FOR',
61
+                                'HTTP_FORWARDED'
62
+                            );
63
+            foreach ($ipServerVars as $var) {
64
+                if(isset($_SERVER[$var])){
65
+                    $ip = $_SERVER[$var];
66
+                    break;
67
+                }
68
+            }
69
+            // Strip any secondary IP etc from the IP address
70
+            if (strpos($ip, ',') > 0) {
71
+                $ip = substr($ip, 0, strpos($ip, ','));
72
+            }
73
+            return $ip;
74
+        }
75
+    }
Please login to merge, or discard this patch.
core/libraries/Assets.php 1 patch
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -1,168 +1,168 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	/**
28
-	 *  @file Assets.php
29
-	 *    
30
-	 *  This class contains static methods for generating static content links (images, Javascript, CSS, etc.).
31
-	 *  
32
-	 *  @package	core	
33
-	 *  @author	Tony NGUEREZA
34
-	 *  @copyright	Copyright (c) 2017
35
-	 *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
36
-	 *  @link	http://www.iacademy.cf
37
-	 *  @version 1.0.0
38
-	 *  @since 1.0.0
39
-	 *  @filesource
40
-	 */
41
-	class Assets{
27
+    /**
28
+     *  @file Assets.php
29
+     *    
30
+     *  This class contains static methods for generating static content links (images, Javascript, CSS, etc.).
31
+     *  
32
+     *  @package	core	
33
+     *  @author	Tony NGUEREZA
34
+     *  @copyright	Copyright (c) 2017
35
+     *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
36
+     *  @link	http://www.iacademy.cf
37
+     *  @version 1.0.0
38
+     *  @since 1.0.0
39
+     *  @filesource
40
+     */
41
+    class Assets{
42 42
 		
43
-		/**
44
-		 * The logger instance
45
-		 * @var object
46
-		 */
47
-		private static $logger;
43
+        /**
44
+         * The logger instance
45
+         * @var object
46
+         */
47
+        private static $logger;
48 48
 
49
-		/**
50
-		 * The signleton of the logger
51
-		 * @return Object the Log instance
52
-		 */
53
-		private static function getLogger(){
54
-			if(self::$logger == null){
55
-				//can't assign reference to static variable
56
-				self::$logger[0] =& class_loader('Log', 'classes');
57
-				self::$logger[0]->setLogger('Library::Assets');
58
-			}
59
-			return self::$logger[0];
60
-		}
49
+        /**
50
+         * The signleton of the logger
51
+         * @return Object the Log instance
52
+         */
53
+        private static function getLogger(){
54
+            if(self::$logger == null){
55
+                //can't assign reference to static variable
56
+                self::$logger[0] =& class_loader('Log', 'classes');
57
+                self::$logger[0]->setLogger('Library::Assets');
58
+            }
59
+            return self::$logger[0];
60
+        }
61 61
 
62 62
 
63
-		/**
64
-		 *  Generate the link of the assets file.
65
-		 *  
66
-		 *  Generates the absolute link of a file inside ASSETS_PATH folder.
67
-		 *  For example :
68
-		 *  	echo Assets::path('foo/bar/css/style.css'); => http://mysite.com/assets/foo/bar/css/style.css
69
-		 *  Note:
70
-		 *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
71
-		 *  
72
-		 *  @param string $asset the name of the assets file path with the extension.
73
-		 *  @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist.
74
-		 */
75
-		public static function path($asset){
76
-			$logger = self::getLogger();	
77
-			$path = ASSETS_PATH . $asset;
63
+        /**
64
+         *  Generate the link of the assets file.
65
+         *  
66
+         *  Generates the absolute link of a file inside ASSETS_PATH folder.
67
+         *  For example :
68
+         *  	echo Assets::path('foo/bar/css/style.css'); => http://mysite.com/assets/foo/bar/css/style.css
69
+         *  Note:
70
+         *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
71
+         *  
72
+         *  @param string $asset the name of the assets file path with the extension.
73
+         *  @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist.
74
+         */
75
+        public static function path($asset){
76
+            $logger = self::getLogger();	
77
+            $path = ASSETS_PATH . $asset;
78 78
 			
79
-			$logger->debug('Including the Assets file [' . $path . ']');
80
-			//Check if the file exists
81
-			if(file_exists($path)){
82
-				$logger->info('Assets file [' . $path . '] included successfully');
83
-				return Url::base_url($path);
84
-			}
85
-			$logger->warning('Assets file [' . $path . '] does not exist');
86
-			return null;
87
-		}
79
+            $logger->debug('Including the Assets file [' . $path . ']');
80
+            //Check if the file exists
81
+            if(file_exists($path)){
82
+                $logger->info('Assets file [' . $path . '] included successfully');
83
+                return Url::base_url($path);
84
+            }
85
+            $logger->warning('Assets file [' . $path . '] does not exist');
86
+            return null;
87
+        }
88 88
 		
89
-		/**
90
-		 *  Generate the link of the css file.
91
-		 *  
92
-		 *  Generates the absolute link of a file containing the CSS style.
93
-		 *  For example :
94
-		 *  	echo Assets::css('mystyle'); => http://mysite.com/assets/css/mystyle.css
95
-		 *  Note:
96
-		 *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
97
-		 *  
98
-		 *  @param string $path the name of the css file without the extension.
99
-		 *  @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist.
100
-		 */
101
-		public static function css($path){
102
-			$logger = self::getLogger();
103
-			/*
89
+        /**
90
+         *  Generate the link of the css file.
91
+         *  
92
+         *  Generates the absolute link of a file containing the CSS style.
93
+         *  For example :
94
+         *  	echo Assets::css('mystyle'); => http://mysite.com/assets/css/mystyle.css
95
+         *  Note:
96
+         *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
97
+         *  
98
+         *  @param string $path the name of the css file without the extension.
99
+         *  @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist.
100
+         */
101
+        public static function css($path){
102
+            $logger = self::getLogger();
103
+            /*
104 104
 			* if the file name contains the ".css" extension, replace it with 
105 105
 			* an empty string for better processing.
106 106
 			*/
107
-			$path = str_ireplace('.css', '', $path);
108
-			$path = ASSETS_PATH . 'css/' . $path . '.css';
107
+            $path = str_ireplace('.css', '', $path);
108
+            $path = ASSETS_PATH . 'css/' . $path . '.css';
109 109
 			
110
-			$logger->debug('Including the Assets file [' . $path . '] for CSS');
111
-			//Check if the file exists
112
-			if(file_exists($path)){
113
-				$logger->info('Assets file [' . $path . '] for CSS included successfully');
114
-				return Url::base_url($path);
115
-			}
116
-			$logger->warning('Assets file [' . $path . '] for CSS does not exist');
117
-			return null;
118
-		}
110
+            $logger->debug('Including the Assets file [' . $path . '] for CSS');
111
+            //Check if the file exists
112
+            if(file_exists($path)){
113
+                $logger->info('Assets file [' . $path . '] for CSS included successfully');
114
+                return Url::base_url($path);
115
+            }
116
+            $logger->warning('Assets file [' . $path . '] for CSS does not exist');
117
+            return null;
118
+        }
119 119
 
120
-		/**
121
-		 *  Generate the link of the javascript file.
122
-		 *  
123
-		 *  Generates the absolute link of a file containing the javascript.
124
-		 *  For example :
125
-		 *  	echo Assets::js('myscript'); => http://mysite.com/assets/js/myscript.js
126
-		 *  Note:
127
-		 *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
128
-		 *  
129
-		 *  @param string $path the name of the javascript file without the extension.
130
-		 *  @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist.
131
-		 */
132
-		public static function js($path){
133
-			$logger = self::getLogger();
134
-			$path = str_ireplace('.js', '', $path);
135
-			$path = ASSETS_PATH . 'js/' . $path . '.js';
136
-			$logger->debug('Including the Assets file [' . $path . '] for javascript');
137
-			if(file_exists($path)){
138
-				$logger->info('Assets file [' . $path . '] for Javascript included successfully');
139
-				return Url::base_url($path);
140
-			}
141
-			$logger->warning('Assets file [' . $path . '] for Javascript does not exist');
142
-			return null;
143
-		}
120
+        /**
121
+         *  Generate the link of the javascript file.
122
+         *  
123
+         *  Generates the absolute link of a file containing the javascript.
124
+         *  For example :
125
+         *  	echo Assets::js('myscript'); => http://mysite.com/assets/js/myscript.js
126
+         *  Note:
127
+         *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
128
+         *  
129
+         *  @param string $path the name of the javascript file without the extension.
130
+         *  @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist.
131
+         */
132
+        public static function js($path){
133
+            $logger = self::getLogger();
134
+            $path = str_ireplace('.js', '', $path);
135
+            $path = ASSETS_PATH . 'js/' . $path . '.js';
136
+            $logger->debug('Including the Assets file [' . $path . '] for javascript');
137
+            if(file_exists($path)){
138
+                $logger->info('Assets file [' . $path . '] for Javascript included successfully');
139
+                return Url::base_url($path);
140
+            }
141
+            $logger->warning('Assets file [' . $path . '] for Javascript does not exist');
142
+            return null;
143
+        }
144 144
 
145
-		/**
146
-		 *  Generate the link of the image file.
147
-		 *  
148
-		 *  Generates the absolute link of a file containing the image.
149
-		 *  For example :
150
-		 *  	echo Assets::img('myimage.png'); => http://mysite.com/assets/images/myimage.png
151
-		 *  Note:
152
-		 *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
153
-		 *  
154
-		 *  @param string $path the name of the image file with the extension.
155
-		 *  @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist.
156
-		 */
157
-		public static function img($path){
158
-			$logger = self::getLogger();
159
-			$path = ASSETS_PATH . 'images/' . $path;
160
-			$logger->debug('Including the Assets file [' . $path . '] for image');
161
-			if(file_exists($path)){
162
-				$logger->info('Assets file [' . $path . '] for image included successfully');
163
-				return Url::base_url($path);
164
-			}
165
-			$logger->warning('Assets file [' . $path . '] for image does not exist');
166
-			return null;
167
-		}
168
-	}
145
+        /**
146
+         *  Generate the link of the image file.
147
+         *  
148
+         *  Generates the absolute link of a file containing the image.
149
+         *  For example :
150
+         *  	echo Assets::img('myimage.png'); => http://mysite.com/assets/images/myimage.png
151
+         *  Note:
152
+         *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
153
+         *  
154
+         *  @param string $path the name of the image file with the extension.
155
+         *  @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist.
156
+         */
157
+        public static function img($path){
158
+            $logger = self::getLogger();
159
+            $path = ASSETS_PATH . 'images/' . $path;
160
+            $logger->debug('Including the Assets file [' . $path . '] for image');
161
+            if(file_exists($path)){
162
+                $logger->info('Assets file [' . $path . '] for image included successfully');
163
+                return Url::base_url($path);
164
+            }
165
+            $logger->warning('Assets file [' . $path . '] for image does not exist');
166
+            return null;
167
+        }
168
+    }
Please login to merge, or discard this patch.
core/classes/Url.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -1,149 +1,149 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27 27
 
28
-	class Url{
28
+    class Url{
29 29
 
30
-		/**
31
-		 * Return the link using base_url config without front controller "index.php"
32
-		 * @param  string $path the link path or full URL
33
-		 * @return string the full link URL
34
-		 */
35
-		public static function base_url($path = ''){
36
-			if(is_url($path)){
37
-				return $path;
38
-			}
39
-			return get_config('base_url') . $path;
40
-		}
30
+        /**
31
+         * Return the link using base_url config without front controller "index.php"
32
+         * @param  string $path the link path or full URL
33
+         * @return string the full link URL
34
+         */
35
+        public static function base_url($path = ''){
36
+            if(is_url($path)){
37
+                return $path;
38
+            }
39
+            return get_config('base_url') . $path;
40
+        }
41 41
 
42
-		/**
43
-		 * Return the link using base_url config with front controller "index.php"
44
-		 * @param  string $path the link path or full URL
45
-		 * @return string the full link URL
46
-		 */
47
-		public static function site_url($path = ''){
48
-			if(is_url($path)){
49
-				return $path;
50
-			}
51
-			$path = rtrim($path, '/');
52
-			$baseUrl = get_config('base_url');
53
-			$frontController = get_config('front_controller');
54
-			$url = $baseUrl;
55
-			if($frontController){
56
-				$url .= $frontController . '/';
57
-			}
58
-			if(($suffix = get_config('url_suffix')) && $path){
59
-				if(strpos($path, '?') !== false){
60
-					$query = explode('?', $path);
61
-					$query[0] = str_ireplace($suffix, '', $query[0]);
62
-					$query[0] = rtrim($query[0], '/');
63
-					$query[0] .= $suffix;
64
-					$path = implode('?', $query);
65
-				}
66
-				else{
67
-					$path .= $suffix;
68
-				}
69
-			}
70
-			return $url . $path;
71
-		}
42
+        /**
43
+         * Return the link using base_url config with front controller "index.php"
44
+         * @param  string $path the link path or full URL
45
+         * @return string the full link URL
46
+         */
47
+        public static function site_url($path = ''){
48
+            if(is_url($path)){
49
+                return $path;
50
+            }
51
+            $path = rtrim($path, '/');
52
+            $baseUrl = get_config('base_url');
53
+            $frontController = get_config('front_controller');
54
+            $url = $baseUrl;
55
+            if($frontController){
56
+                $url .= $frontController . '/';
57
+            }
58
+            if(($suffix = get_config('url_suffix')) && $path){
59
+                if(strpos($path, '?') !== false){
60
+                    $query = explode('?', $path);
61
+                    $query[0] = str_ireplace($suffix, '', $query[0]);
62
+                    $query[0] = rtrim($query[0], '/');
63
+                    $query[0] .= $suffix;
64
+                    $path = implode('?', $query);
65
+                }
66
+                else{
67
+                    $path .= $suffix;
68
+                }
69
+            }
70
+            return $url . $path;
71
+        }
72 72
 
73
-		/**
74
-		 * Return the current site URL
75
-		 * @return string
76
-		 */
77
-		public static function current(){
78
-			$current = '/';
79
-			$requestUri = get_instance()->request->requestUri();
80
-			if($requestUri){
81
-				$current = $requestUri;
82
-			}
83
-			return static::domain() . $current;
84
-		}
73
+        /**
74
+         * Return the current site URL
75
+         * @return string
76
+         */
77
+        public static function current(){
78
+            $current = '/';
79
+            $requestUri = get_instance()->request->requestUri();
80
+            if($requestUri){
81
+                $current = $requestUri;
82
+            }
83
+            return static::domain() . $current;
84
+        }
85 85
 
86
-		/**
87
-		 * Generate a friendly  text to use in link (slugs)
88
-		 * @param  string  $str       the title or text to use to get the friendly text
89
-		 * @param  string  $separator the caracters separator
90
-		 * @param  boolean $lowercase whether to set the final text to lowe case or not
91
-		 * @return string the friendly generated text
92
-		 */
93
-		public static function title($str = null, $separator = '-', $lowercase = true){
94
-			$str = trim($str);
95
-			$from = array('ç','À','Á','Â','Ã','Ä','Å','à','á','â','ã','ä','å','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','È','É','Ê','Ë','è','é','ê','ë','Ç','ç','Ì','Í','Î','Ï','ì','í','î','ï','Ù','Ú','Û','Ü','ù','ú','û','ü','ÿ','Ñ','ñ');
96
-			$to = array('c','a','a','a','a','a','a','a','a','a','a','a','a','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','i','i','i','i','i','i','i','i','u','u','u','u','u','u','u','u','y','n','n');
97
-			$str = str_replace($from, $to, $str);
98
-			$str = preg_replace('#([^a-z0-9]+)#i', $separator, $str);
99
-			$str = str_replace('--', $separator, $str);
100
-			//if after process we get something like one-two-three-, need truncate the last separator "-"
101
-			if(substr($str, -1) == $separator){
102
-				$str = substr($str, 0, -1);
103
-			}
104
-			if($lowercase){
105
-				$str = strtolower($str);
106
-			}
107
-			return $str;
108
-		}
86
+        /**
87
+         * Generate a friendly  text to use in link (slugs)
88
+         * @param  string  $str       the title or text to use to get the friendly text
89
+         * @param  string  $separator the caracters separator
90
+         * @param  boolean $lowercase whether to set the final text to lowe case or not
91
+         * @return string the friendly generated text
92
+         */
93
+        public static function title($str = null, $separator = '-', $lowercase = true){
94
+            $str = trim($str);
95
+            $from = array('ç','À','Á','Â','Ã','Ä','Å','à','á','â','ã','ä','å','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','È','É','Ê','Ë','è','é','ê','ë','Ç','ç','Ì','Í','Î','Ï','ì','í','î','ï','Ù','Ú','Û','Ü','ù','ú','û','ü','ÿ','Ñ','ñ');
96
+            $to = array('c','a','a','a','a','a','a','a','a','a','a','a','a','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','i','i','i','i','i','i','i','i','u','u','u','u','u','u','u','u','y','n','n');
97
+            $str = str_replace($from, $to, $str);
98
+            $str = preg_replace('#([^a-z0-9]+)#i', $separator, $str);
99
+            $str = str_replace('--', $separator, $str);
100
+            //if after process we get something like one-two-three-, need truncate the last separator "-"
101
+            if(substr($str, -1) == $separator){
102
+                $str = substr($str, 0, -1);
103
+            }
104
+            if($lowercase){
105
+                $str = strtolower($str);
106
+            }
107
+            return $str;
108
+        }
109 109
 
110
-		/**
111
-		 * Get the current application domain with protocol
112
-		 * @return string the domain name
113
-		 */
114
-		public static function domain(){
115
-			$domain = 'localhost';
116
-			$port = get_instance()->request->server('SERVER_PORT');
117
-			$protocol = 'http';
118
-			if(is_https()){
119
-				$protocol = 'https';
120
-			}
110
+        /**
111
+         * Get the current application domain with protocol
112
+         * @return string the domain name
113
+         */
114
+        public static function domain(){
115
+            $domain = 'localhost';
116
+            $port = get_instance()->request->server('SERVER_PORT');
117
+            $protocol = 'http';
118
+            if(is_https()){
119
+                $protocol = 'https';
120
+            }
121 121
 
122
-			$domainserverVars = array(
123
-				'HTTP_HOST',
124
-				'SERVER_NAME',
125
-				'SERVER_ADDR'
126
-			);
122
+            $domainserverVars = array(
123
+                'HTTP_HOST',
124
+                'SERVER_NAME',
125
+                'SERVER_ADDR'
126
+            );
127 127
 
128
-			foreach ($domainserverVars as $var) {
129
-				$value = get_instance()->request->server($var);
130
-				if($value){
131
-					$domain = $value;
132
-					break;
133
-				}
134
-			}
128
+            foreach ($domainserverVars as $var) {
129
+                $value = get_instance()->request->server($var);
130
+                if($value){
131
+                    $domain = $value;
132
+                    break;
133
+                }
134
+            }
135 135
 			
136
-			if($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))){
137
-				$domain .= ':'.$port;
138
-			}
139
-			return $protocol.'://'.$domain;
140
-		}
136
+            if($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))){
137
+                $domain .= ':'.$port;
138
+            }
139
+            return $protocol.'://'.$domain;
140
+        }
141 141
 
142
-		/**
143
-		 * Get the current request query string
144
-		 * @return string
145
-		 */
146
-		public static function queryString(){
147
-			return get_instance()->request->server('QUERY_STRING');
148
-		}
149
-	}
142
+        /**
143
+         * Get the current request query string
144
+         * @return string
145
+         */
146
+        public static function queryString(){
147
+            return get_instance()->request->server('QUERY_STRING');
148
+        }
149
+    }
Please login to merge, or discard this patch.
core/classes/cache/FileCache.php 1 patch
Indentation   +289 added lines, -289 removed lines patch added patch discarded remove patch
@@ -1,312 +1,312 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	class FileCache implements CacheInterface{
27
+    class FileCache implements CacheInterface{
28 28
 		
29
-		/**
30
-		 * Whether to enable compression of the cache data file.
31
-		 * @var boolean
32
-		 */
33
-		private $compressCacheData = true;
29
+        /**
30
+         * Whether to enable compression of the cache data file.
31
+         * @var boolean
32
+         */
33
+        private $compressCacheData = true;
34 34
 		
35
-		/**
36
-		 * The logger instance
37
-		 * @var Log
38
-		 */
39
-		private $logger;
35
+        /**
36
+         * The logger instance
37
+         * @var Log
38
+         */
39
+        private $logger;
40 40
 		
41 41
 		
42
-		public function __construct(Log $logger = null){
43
-			if(! $this->isSupported()){
44
-				show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.');
45
-			}
46
-			/**
47
-	         * instance of the Log class
48
-	         */
49
-	        if(is_object($logger)){
50
-	          $this->logger = $logger;
51
-	        }
52
-	        else{
53
-	            $this->logger =& class_loader('Log', 'classes');
54
-	            $this->logger->setLogger('Library::FileCache');
55
-	        }
42
+        public function __construct(Log $logger = null){
43
+            if(! $this->isSupported()){
44
+                show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.');
45
+            }
46
+            /**
47
+             * instance of the Log class
48
+             */
49
+            if(is_object($logger)){
50
+                $this->logger = $logger;
51
+            }
52
+            else{
53
+                $this->logger =& class_loader('Log', 'classes');
54
+                $this->logger->setLogger('Library::FileCache');
55
+            }
56 56
 			
57
-			//if Zlib extension is not loaded set compressCacheData to false
58
-			if(! extension_loaded('zlib')){
59
-				$this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
60
-				$this->compressCacheData = false;
61
-			}
62
-		}
57
+            //if Zlib extension is not loaded set compressCacheData to false
58
+            if(! extension_loaded('zlib')){
59
+                $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
60
+                $this->compressCacheData = false;
61
+            }
62
+        }
63 63
 
64
-		/**
65
-		 * This is used to get the cache data using the key
66
-		 * @param  string $key the key to identify the cache data
67
-		 * @return mixed      the cache data if exists else return false
68
-		 */
69
-		public function get($key){
70
-			$this->logger->debug('Getting cache data for key ['. $key .']');
71
-			$filePath = $this->getFilePath($key);
72
-			if(! file_exists($filePath)){
73
-				$this->logger->info('No cache file found for the key ['. $key .'], return false');
74
-				return false;
75
-			}
76
-			$this->logger->info('The cache file [' .$filePath. '] for the key ['. $key .'] exists, check if the cache data is valid');
77
-			$handle = fopen($filePath,'r');
78
-			if(! is_resource($handle)){
79
-				$this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
80
-				return false;
81
-			}
82
-			// Getting a shared lock 
83
-		    flock($handle, LOCK_SH);
84
-		    $data = file_get_contents($filePath);
85
-      		fclose($handle);
86
-      		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
87
-      		if (! $data) {
88
-      			$this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false');
89
-		         // If unserializing somehow didn't work out, we'll delete the file
90
-		         unlink($filePath);
91
-		         return false;
92
-	      	}
93
-	      	if (time() > $data['expire']) {
94
-	      		$this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']');
95
-		        // Unlinking when the file was expired
96
-		        unlink($filePath);
97
-		        return false;
98
-		     }
99
-		     else{
100
-		     	$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
101
-		     	return $data['data'];
102
-		     }
103
-		}
64
+        /**
65
+         * This is used to get the cache data using the key
66
+         * @param  string $key the key to identify the cache data
67
+         * @return mixed      the cache data if exists else return false
68
+         */
69
+        public function get($key){
70
+            $this->logger->debug('Getting cache data for key ['. $key .']');
71
+            $filePath = $this->getFilePath($key);
72
+            if(! file_exists($filePath)){
73
+                $this->logger->info('No cache file found for the key ['. $key .'], return false');
74
+                return false;
75
+            }
76
+            $this->logger->info('The cache file [' .$filePath. '] for the key ['. $key .'] exists, check if the cache data is valid');
77
+            $handle = fopen($filePath,'r');
78
+            if(! is_resource($handle)){
79
+                $this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
80
+                return false;
81
+            }
82
+            // Getting a shared lock 
83
+            flock($handle, LOCK_SH);
84
+            $data = file_get_contents($filePath);
85
+                fclose($handle);
86
+                $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
87
+                if (! $data) {
88
+                    $this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false');
89
+                    // If unserializing somehow didn't work out, we'll delete the file
90
+                    unlink($filePath);
91
+                    return false;
92
+                }
93
+                if (time() > $data['expire']) {
94
+                    $this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']');
95
+                // Unlinking when the file was expired
96
+                unlink($filePath);
97
+                return false;
98
+                }
99
+                else{
100
+                    $this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
101
+                    return $data['data'];
102
+                }
103
+        }
104 104
 
105 105
 
106
-		/**
107
-		 * Save data to the cache
108
-		 * @param string  $key  the key to identify this cache data
109
-		 * @param mixed  $data the cache data
110
-		 * @param integer $ttl  the cache life time
111
-		 * @return boolean true if success otherwise will return false
112
-		 */
113
-		public function set($key, $data, $ttl = 0){
114
-			$expire = time() + $ttl;
115
-			$this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
116
-			$filePath = $this->getFilePath($key);
117
-			$handle = fopen($filePath,'w');
118
-			if(! is_resource($handle)){
119
-				$this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
120
-				return false;
121
-			}
122
-			flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed
123
-			//Serializing along with the TTL
124
-		    $cacheData = serialize(array(
125
-									'mtime' => time(),
126
-									'expire' => $expire,
127
-									'data' => $data,
128
-									'ttl' => $ttl
129
-									)
130
-								);		   
131
-		    $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData);
132
-		    if(! $result){
133
-		    	$this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
134
-		    	fclose($handle);
135
-		    	return false;
136
-		    }
137
-		    else{
138
-		    	$this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
139
-		    	fclose($handle);
140
-				chmod($filePath, 0640);
141
-				return true;
142
-		    }
143
-		}	
106
+        /**
107
+         * Save data to the cache
108
+         * @param string  $key  the key to identify this cache data
109
+         * @param mixed  $data the cache data
110
+         * @param integer $ttl  the cache life time
111
+         * @return boolean true if success otherwise will return false
112
+         */
113
+        public function set($key, $data, $ttl = 0){
114
+            $expire = time() + $ttl;
115
+            $this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
116
+            $filePath = $this->getFilePath($key);
117
+            $handle = fopen($filePath,'w');
118
+            if(! is_resource($handle)){
119
+                $this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
120
+                return false;
121
+            }
122
+            flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed
123
+            //Serializing along with the TTL
124
+            $cacheData = serialize(array(
125
+                                    'mtime' => time(),
126
+                                    'expire' => $expire,
127
+                                    'data' => $data,
128
+                                    'ttl' => $ttl
129
+                                    )
130
+                                );		   
131
+            $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData);
132
+            if(! $result){
133
+                $this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
134
+                fclose($handle);
135
+                return false;
136
+            }
137
+            else{
138
+                $this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
139
+                fclose($handle);
140
+                chmod($filePath, 0640);
141
+                return true;
142
+            }
143
+        }	
144 144
 
145 145
 
146
-		/**
147
-		 * Delete the cache data for given key
148
-		 * @param  string $key the key for cache to be deleted
149
-		 * @return boolean      true if the cache is delete, false if can't delete 
150
-		 * the cache or the cache with the given key not exist
151
-		 */
152
-		public function delete($key){
153
-			$this->logger->debug('Deleting of cache data for key [' .$key. ']');
154
-			$filePath = $this->getFilePath($key);
155
-			$this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
156
-			if(! file_exists($filePath)){
157
-				$this->logger->info('This cache file does not exists skipping');
158
-				return false;
159
-			}
160
-			else{
161
-				$this->logger->info('Found cache file [' .$filePath. '] remove it');
162
-	      		unlink($filePath);
163
-				return true;
164
-			}
165
-		}
146
+        /**
147
+         * Delete the cache data for given key
148
+         * @param  string $key the key for cache to be deleted
149
+         * @return boolean      true if the cache is delete, false if can't delete 
150
+         * the cache or the cache with the given key not exist
151
+         */
152
+        public function delete($key){
153
+            $this->logger->debug('Deleting of cache data for key [' .$key. ']');
154
+            $filePath = $this->getFilePath($key);
155
+            $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
156
+            if(! file_exists($filePath)){
157
+                $this->logger->info('This cache file does not exists skipping');
158
+                return false;
159
+            }
160
+            else{
161
+                $this->logger->info('Found cache file [' .$filePath. '] remove it');
162
+                    unlink($filePath);
163
+                return true;
164
+            }
165
+        }
166 166
 		
167
-		/**
168
-		 * Get the cache information for given key
169
-		 * @param  string $key the key for cache to get the information for
170
-		 * @return boolean|array    the cache information. The associative array and must contains the following information:
171
-		 * 'mtime' => creation time of the cache (Unix timestamp),
172
-		 * 'expire' => expiration time of the cache (Unix timestamp),
173
-		 * 'ttl' => the time to live of the cache in second
174
-		 */
175
-		public function getInfo($key){
176
-			$this->logger->debug('Getting of cache info for key [' .$key. ']');
177
-			$filePath = $this->getFilePath($key);
178
-			$this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
179
-			if(! file_exists($filePath)){
180
-				$this->logger->info('This cache file does not exists skipping');
181
-				return false;
182
-			}
183
-			$this->logger->info('Found cache file [' .$filePath. '] check the validity');
184
-      		$data = file_get_contents($filePath);
185
-			$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
186
-			if(! $data){
187
-				$this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']');
188
-				return false;
189
-			}
190
-			$this->logger->info('This cache data is OK check for expire');
191
-			if(isset($data['expire']) && $data['expire'] > time()){
192
-				$this->logger->info('This cache not yet expired return cache informations');
193
-				$info = array(
194
-					'mtime' => $data['mtime'],
195
-					'expire' => $data['expire'],
196
-					'ttl' => $data['ttl']
197
-					);
198
-				return $info;
199
-			}
200
-			$this->logger->info('This cache already expired return false');
201
-			return false;
202
-		}
167
+        /**
168
+         * Get the cache information for given key
169
+         * @param  string $key the key for cache to get the information for
170
+         * @return boolean|array    the cache information. The associative array and must contains the following information:
171
+         * 'mtime' => creation time of the cache (Unix timestamp),
172
+         * 'expire' => expiration time of the cache (Unix timestamp),
173
+         * 'ttl' => the time to live of the cache in second
174
+         */
175
+        public function getInfo($key){
176
+            $this->logger->debug('Getting of cache info for key [' .$key. ']');
177
+            $filePath = $this->getFilePath($key);
178
+            $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
179
+            if(! file_exists($filePath)){
180
+                $this->logger->info('This cache file does not exists skipping');
181
+                return false;
182
+            }
183
+            $this->logger->info('Found cache file [' .$filePath. '] check the validity');
184
+                $data = file_get_contents($filePath);
185
+            $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
186
+            if(! $data){
187
+                $this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']');
188
+                return false;
189
+            }
190
+            $this->logger->info('This cache data is OK check for expire');
191
+            if(isset($data['expire']) && $data['expire'] > time()){
192
+                $this->logger->info('This cache not yet expired return cache informations');
193
+                $info = array(
194
+                    'mtime' => $data['mtime'],
195
+                    'expire' => $data['expire'],
196
+                    'ttl' => $data['ttl']
197
+                    );
198
+                return $info;
199
+            }
200
+            $this->logger->info('This cache already expired return false');
201
+            return false;
202
+        }
203 203
 
204 204
 
205
-		/**
206
-		 * Used to delete expired cache data
207
-		 */
208
-		public function deleteExpiredCache(){
209
-			$this->logger->debug('Deleting of expired cache files');
210
-			$list = glob(CACHE_PATH . '*.cache');
211
-			if(! $list){
212
-				$this->logger->info('No cache files were found skipping');
213
-			}
214
-			else{
215
-				$this->logger->info('Found [' . count($list) . '] cache files to remove if expired');
216
-				foreach ($list as $file) {
217
-					$this->logger->debug('Processing the cache file [' . $file . ']');
218
-					$data = file_get_contents($file);
219
-		      		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
220
-		      		if(! $data){
221
-		      			$this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
222
-		      		}
223
-		      		else if(time() > $data['expire']){
224
-		      			$this->logger->info('The cache data for file [' . $file . '] already expired remove it');
225
-		      			unlink($file);
226
-		      		}
227
-		      		else{
228
-		      			$this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
229
-		      		}
230
-				}
231
-			}
232
-		}	
205
+        /**
206
+         * Used to delete expired cache data
207
+         */
208
+        public function deleteExpiredCache(){
209
+            $this->logger->debug('Deleting of expired cache files');
210
+            $list = glob(CACHE_PATH . '*.cache');
211
+            if(! $list){
212
+                $this->logger->info('No cache files were found skipping');
213
+            }
214
+            else{
215
+                $this->logger->info('Found [' . count($list) . '] cache files to remove if expired');
216
+                foreach ($list as $file) {
217
+                    $this->logger->debug('Processing the cache file [' . $file . ']');
218
+                    $data = file_get_contents($file);
219
+                        $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
220
+                        if(! $data){
221
+                            $this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
222
+                        }
223
+                        else if(time() > $data['expire']){
224
+                            $this->logger->info('The cache data for file [' . $file . '] already expired remove it');
225
+                            unlink($file);
226
+                        }
227
+                        else{
228
+                            $this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
229
+                        }
230
+                }
231
+            }
232
+        }	
233 233
 
234
-		/**
235
-		 * Remove all file from cache folder
236
-		 */
237
-		public function clean(){
238
-			$this->logger->debug('Deleting of all cache files');
239
-			$list = glob(CACHE_PATH . '*.cache');
240
-			if(! $list){
241
-				$this->logger->info('No cache files were found skipping');
242
-			}
243
-			else{
244
-				$this->logger->info('Found [' . count($list) . '] cache files to remove');
245
-				foreach ($list as $file) {
246
-					$this->logger->debug('Processing the cache file [' . $file . ']');
247
-					unlink($file);
248
-				}
249
-			}
250
-		}
234
+        /**
235
+         * Remove all file from cache folder
236
+         */
237
+        public function clean(){
238
+            $this->logger->debug('Deleting of all cache files');
239
+            $list = glob(CACHE_PATH . '*.cache');
240
+            if(! $list){
241
+                $this->logger->info('No cache files were found skipping');
242
+            }
243
+            else{
244
+                $this->logger->info('Found [' . count($list) . '] cache files to remove');
245
+                foreach ($list as $file) {
246
+                    $this->logger->debug('Processing the cache file [' . $file . ']');
247
+                    unlink($file);
248
+                }
249
+            }
250
+        }
251 251
 	
252
-	    /**
253
-	     * @return boolean
254
-	     */
255
-	    public function isCompressCacheData(){
256
-	        return $this->compressCacheData;
257
-	    }
252
+        /**
253
+         * @return boolean
254
+         */
255
+        public function isCompressCacheData(){
256
+            return $this->compressCacheData;
257
+        }
258 258
 
259
-	    /**
260
-	     * @param boolean $compressCacheData
261
-	     *
262
-	     * @return object
263
-	     */
264
-	    public function setCompressCacheData($status = true){
265
-			//if Zlib extension is not loaded set compressCacheData to false
266
-			if($status === true && ! extension_loaded('zlib')){
259
+        /**
260
+         * @param boolean $compressCacheData
261
+         *
262
+         * @return object
263
+         */
264
+        public function setCompressCacheData($status = true){
265
+            //if Zlib extension is not loaded set compressCacheData to false
266
+            if($status === true && ! extension_loaded('zlib')){
267 267
 				
268
-				$this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
269
-				$this->compressCacheData = false;
270
-			}
271
-			else{
272
-				$this->compressCacheData = $status;
273
-			}
274
-			return $this;
275
-	    }
268
+                $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
269
+                $this->compressCacheData = false;
270
+            }
271
+            else{
272
+                $this->compressCacheData = $status;
273
+            }
274
+            return $this;
275
+        }
276 276
 		
277
-		/**
278
-		 * Check whether the cache feature for the handle is supported
279
-		 *
280
-		 * @return bool
281
-		 */
282
-		public function isSupported(){
283
-			return CACHE_PATH && is_dir(CACHE_PATH) && is_writable(CACHE_PATH);
284
-		}
277
+        /**
278
+         * Check whether the cache feature for the handle is supported
279
+         *
280
+         * @return bool
281
+         */
282
+        public function isSupported(){
283
+            return CACHE_PATH && is_dir(CACHE_PATH) && is_writable(CACHE_PATH);
284
+        }
285 285
 
286
-		/**
287
-	     * Return the Log instance
288
-	     * @return object
289
-	     */
290
-	    public function getLogger(){
291
-	      return $this->logger;
292
-	    }
286
+        /**
287
+         * Return the Log instance
288
+         * @return object
289
+         */
290
+        public function getLogger(){
291
+            return $this->logger;
292
+        }
293 293
 
294
-	    /**
295
-	     * Set the log instance
296
-	     * @param Log $logger the log object
297
-	     */
298
-	    public function setLogger(Log $logger){
299
-	      $this->logger = $logger;
300
-	      return $this;
301
-	    }
294
+        /**
295
+         * Set the log instance
296
+         * @param Log $logger the log object
297
+         */
298
+        public function setLogger(Log $logger){
299
+            $this->logger = $logger;
300
+            return $this;
301
+        }
302 302
 		
303
-		/**
304
-		* Get the cache file full path for the given key
305
-		*
306
-		* @param string $key the cache item key
307
-		* @return string the full cache file path for this key
308
-		*/
309
-		private function getFilePath($key){
310
-			return CACHE_PATH . md5($key) . '.cache';
311
-		}
312
-	}
303
+        /**
304
+         * Get the cache file full path for the given key
305
+         *
306
+         * @param string $key the cache item key
307
+         * @return string the full cache file path for this key
308
+         */
309
+        private function getFilePath($key){
310
+            return CACHE_PATH . md5($key) . '.cache';
311
+        }
312
+    }
Please login to merge, or discard this patch.