Passed
Push — 1.0.0-dev ( 4efac2...b68981 )
by nguereza
02:49
created
core/classes/model/Model.php 1 patch
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  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
     /**
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
         protected $_temporary_return_type = NULL;
121 121
     	
122 122
     	
123
-    	/**
123
+        /**
124 124
     		The database cache time 
125
-    	*/
126
-    	protected $dbCacheTime = 0;
125
+         */
126
+        protected $dbCacheTime = 0;
127 127
 
128 128
         /**
129 129
          * Instance of the Loader class
@@ -151,12 +151,12 @@  discard block
 block discarded – undo
151 151
             }
152 152
             else{
153 153
                 $obj = & get_instance();
154
-        		if (isset($obj->database) && is_object($obj->database)){
154
+                if (isset($obj->database) && is_object($obj->database)){
155 155
                     /**
156
-                    * NOTE: Need use "clone" because some Model need have the personal instance of the database library
157
-                    * to prevent duplication
158
-                    */
159
-        			$this->setDatabaseInstance(clone $obj->database);
156
+                     * NOTE: Need use "clone" because some Model need have the personal instance of the database library
157
+                     * to prevent duplication
158
+                     */
159
+                    $this->setDatabaseInstance(clone $obj->database);
160 160
                 }
161 161
             }
162 162
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
          */
175 175
         public function get($primary_value)
176 176
         {
177
-    		return $this->get_by($this->primary_key, $primary_value);
177
+            return $this->get_by($this->primary_key, $primary_value);
178 178
         }
179 179
 
180 180
         /**
@@ -189,12 +189,12 @@  discard block
 block discarded – undo
189 189
             {
190 190
                 $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
191 191
             }
192
-    		$this->_set_where($where);
192
+            $this->_set_where($where);
193 193
 
194 194
             $this->trigger('before_get');
195
-			$type = $this->_temporary_return_type == 'array' ? 'array' : false;
195
+            $type = $this->_temporary_return_type == 'array' ? 'array' : false;
196 196
             $this->getQueryBuilder()->from($this->_table);
197
-			$row = $this->_database->get($type);
197
+            $row = $this->_database->get($type);
198 198
             $this->_temporary_return_type = $this->return_type;
199 199
             $row = $this->trigger('after_get', $row);
200 200
             $this->_with = array();
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
             {
232 232
                 $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
233 233
             }
234
-			$type = $this->_temporary_return_type == 'array' ? 'array':false;
234
+            $type = $this->_temporary_return_type == 'array' ? 'array':false;
235 235
             $this->getQueryBuilder()->from($this->_table);
236
-			$result = $this->_database->getAll($type);
236
+            $result = $this->_database->getAll($type);
237 237
             $this->_temporary_return_type = $this->return_type;
238 238
 
239 239
             foreach ($result as $key => &$row)
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
         /**
248 248
          * Insert a new row into the table. $data should be an associative array
249 249
          * of data to be inserted. Returns newly created ID.
250
-		 * @see Database::insert
250
+         * @see Database::insert
251 251
          */
252 252
         public function insert($data = array(), $skip_validation = FALSE, $escape = true)
253 253
         {
@@ -260,11 +260,11 @@  discard block
 block discarded – undo
260 260
             {
261 261
                 $data = $this->trigger('before_create', $data);
262 262
                 $this->getQueryBuilder()->from($this->_table);
263
-				$this->_database->insert($data, $escape);
263
+                $this->_database->insert($data, $escape);
264 264
                 $insert_id = $this->_database->insertId();
265 265
                 $this->trigger('after_create', $insert_id);
266
-				//if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
267
-				return ! $insert_id ? true : $insert_id;
266
+                //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
267
+                return ! $insert_id ? true : $insert_id;
268 268
             }
269 269
             else
270 270
             {
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
             {
325 325
                 $this->getQueryBuilder()->in($this->primary_key, $primary_values)
326 326
                                         ->from($this->_table);
327
-				$result = $this->_database->update($data, $escape);
327
+                $result = $this->_database->update($data, $escape);
328 328
                 $this->trigger('after_update', array($data, $result));
329 329
                 return $result;
330 330
             }
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
             {
357 357
                 $this->_set_where($args);
358 358
                 $this->getQueryBuilder()->from($this->_table);
359
-				$result = $this->_database->update($data);
359
+                $result = $this->_database->update($data);
360 360
                 $this->trigger('after_update', array($data, $result));
361 361
                 return $result;
362 362
             }
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
         {
374 374
             $data = $this->trigger('before_update', $data);
375 375
             $this->getQueryBuilder()->from($this->_table);
376
-			$result = $this->_database->update($data, $escape);
376
+            $result = $this->_database->update($data, $escape);
377 377
             $this->trigger('after_update', array($data, $result));
378 378
             return $result;
379 379
         }
@@ -385,16 +385,16 @@  discard block
 block discarded – undo
385 385
         {
386 386
             $this->trigger('before_delete', $id);
387 387
             $this->getQueryBuilder()->where($this->primary_key, $id);
388
-			$result = false;
388
+            $result = false;
389 389
             if ($this->soft_delete)
390 390
             {
391 391
                 $this->getQueryBuilder()->from($this->_table);	
392
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
392
+                $result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
393 393
             }
394 394
             else
395 395
             {
396 396
                 $this->getQueryBuilder()->from($this->_table); 
397
-				$result = $this->_database->delete();
397
+                $result = $this->_database->delete();
398 398
             }
399 399
 
400 400
             $this->trigger('after_delete', $result);
@@ -407,18 +407,18 @@  discard block
 block discarded – undo
407 407
         public function delete_by()
408 408
         {
409 409
             $where = func_get_args();
410
-    	    $where = $this->trigger('before_delete', $where);
410
+            $where = $this->trigger('before_delete', $where);
411 411
             $this->_set_where($where);
412
-			$result = false;
412
+            $result = false;
413 413
             if ($this->soft_delete)
414 414
             {
415 415
                 $this->getQueryBuilder()->from($this->_table);	
416
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
416
+                $result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
417 417
             }
418 418
             else
419 419
             {
420 420
                 $this->getQueryBuilder()->from($this->_table); 
421
-				$result = $this->_database->delete();
421
+                $result = $this->_database->delete();
422 422
             }
423 423
             $this->trigger('after_delete', $result);
424 424
             return $result;
@@ -431,16 +431,16 @@  discard block
 block discarded – undo
431 431
         {
432 432
             $primary_values = $this->trigger('before_delete', $primary_values);
433 433
             $this->getQueryBuilder()->in($this->primary_key, $primary_values);
434
-			$result = false;
434
+            $result = false;
435 435
             if ($this->soft_delete)
436 436
             {
437 437
                 $this->getQueryBuilder()->from($this->_table);	
438
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
438
+                $result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
439 439
             }
440 440
             else
441 441
             {
442 442
                 $this->getQueryBuilder()->from($this->_table); 
443
-				$result = $this->_database->delete();
443
+                $result = $this->_database->delete();
444 444
             }
445 445
             $this->trigger('after_delete', $result);
446 446
             return $result;
@@ -452,8 +452,8 @@  discard block
 block discarded – undo
452 452
          */
453 453
         public function truncate()
454 454
         {
455
-			$this->getQueryBuilder()->from($this->_table); 
456
-			$result = $this->_database->delete();
455
+            $this->getQueryBuilder()->from($this->_table); 
456
+            $result = $this->_database->delete();
457 457
             return $result;
458 458
         }
459 459
 
@@ -471,14 +471,14 @@  discard block
 block discarded – undo
471 471
             return $this;
472 472
         }
473 473
 		
474
-		/**
475
-		* Relationship
476
-		*/
474
+        /**
475
+         * Relationship
476
+         */
477 477
         public function relate($row)
478 478
         {
479
-    		if (empty($row))
479
+            if (empty($row))
480 480
             {
481
-    		    return $row;
481
+                return $row;
482 482
             }
483 483
 
484 484
             $row = $this->relateBelongsTo($row);
@@ -511,9 +511,9 @@  discard block
 block discarded – undo
511 511
                 $this->getQueryBuilder()->where($this->soft_delete_key, FALSE);
512 512
             }
513 513
             $this->getQueryBuilder()
514
-									 ->select(array($key, $value))
515
-									 ->from($this->_table);
516
-			$result = $this->_database->getAll();
514
+                                        ->select(array($key, $value))
515
+                                        ->from($this->_table);
516
+            $result = $this->_database->getAll();
517 517
             $options = array();
518 518
             foreach ($result as $row)
519 519
             {
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
             $where = func_get_args();
536 536
             $this->_set_where($where);
537 537
             $this->getQueryBuilder()->from($this->_table);
538
-			$this->_database->getAll();
538
+            $this->_database->getAll();
539 539
             return $this->_database->numRows();
540 540
         }
541 541
 
@@ -548,20 +548,20 @@  discard block
 block discarded – undo
548 548
             {
549 549
                 $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
550 550
             }
551
-			$this->getQueryBuilder()->from($this->_table);
552
-			$this->_database->getAll();
551
+            $this->getQueryBuilder()->from($this->_table);
552
+            $this->_database->getAll();
553 553
             return $this->_database->numRows();
554 554
         }
555 555
 		
556
-		/**
557
-		* Enabled cache temporary
558
-		*/
559
-		public function cached($ttl = 0){
560
-		  if ($ttl > 0){
561
-			$this->_database = $this->_database->cached($ttl);
562
-		  }
563
-		  return $this;
564
-		}
556
+        /**
557
+         * Enabled cache temporary
558
+         */
559
+        public function cached($ttl = 0){
560
+            if ($ttl > 0){
561
+            $this->_database = $this->_database->cached($ttl);
562
+            }
563
+            return $this;
564
+        }
565 565
 
566 566
         /**
567 567
          * Tell the class to skip the insert validation
@@ -585,10 +585,10 @@  discard block
 block discarded – undo
585 585
          */
586 586
         public function get_next_id()
587 587
         {
588
-			$this->getQueryBuilder()->select('AUTO_INCREMENT')
589
-									->from('information_schema.TABLES')
590
-									->where('TABLE_NAME', $this->_table)
591
-									->where('TABLE_SCHEMA', $this->_database->getDatabaseName());
588
+            $this->getQueryBuilder()->select('AUTO_INCREMENT')
589
+                                    ->from('information_schema.TABLES')
590
+                                    ->where('TABLE_NAME', $this->_table)
591
+                                    ->where('TABLE_SCHEMA', $this->_database->getDatabaseName());
592 592
             return (int) $this->_database->get()->AUTO_INCREMENT;
593 593
         }
594 594
 
@@ -711,24 +711,24 @@  discard block
 block discarded – undo
711 711
             {
712 712
                 if (is_object($row))
713 713
                 {
714
-					if (isset($row->$attr)){
715
-						unset($row->$attr);
716
-					}
714
+                    if (isset($row->$attr)){
715
+                        unset($row->$attr);
716
+                    }
717 717
                 }
718 718
                 else
719 719
                 {
720
-					if (isset($row[$attr])){
721
-						unset($row[$attr]);
722
-					}
720
+                    if (isset($row[$attr])){
721
+                        unset($row[$attr]);
722
+                    }
723 723
                 }
724 724
             }
725 725
             return $row;
726 726
         }
727 727
 		
728
-		 /**
729
-         * Return the database instance
730
-         * @return Database the database instance
731
-         */
728
+            /**
729
+             * Return the database instance
730
+             * @return Database the database instance
731
+             */
732 732
         public function getDatabaseInstance(){
733 733
             return $this->_database;
734 734
         }
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
          * set the Database instance for future use
738 738
          * @param Database $db the database object
739 739
          */
740
-         public function setDatabaseInstance($db){
740
+            public function setDatabaseInstance($db){
741 741
             $this->_database = $db;
742 742
             if ($this->dbCacheTime > 0){
743 743
                 $this->_database->setCache($this->dbCacheTime);
@@ -756,14 +756,14 @@  discard block
 block discarded – undo
756 756
         /**
757 757
          * Set the loader instance for future use
758 758
          * @param Loader $loader the loader object
759
-		 * @return object
759
+         * @return object
760 760
          */
761
-         public function setLoader($loader){
761
+            public function setLoader($loader){
762 762
             $this->loaderInstance = $loader;
763 763
             return $this;
764 764
         }
765 765
 
766
-		/**
766
+        /**
767 767
          * Return the queryBuilder instance this is the shortcut to database queryBuilder
768 768
          * @return object the DatabaseQueryBuilder instance
769 769
          */
@@ -774,9 +774,9 @@  discard block
 block discarded – undo
774 774
         /**
775 775
          * Set the DatabaseQueryBuilder instance for future use
776 776
          * @param object $queryBuilder the DatabaseQueryBuilder object
777
-		 * @return object
777
+         * @return object
778 778
          */
779
-         public function setQueryBuilder($queryBuilder){
779
+            public function setQueryBuilder($queryBuilder){
780 780
             $this->_database->setQueryBuilder($queryBuilder);
781 781
             return $this;
782 782
         }
@@ -793,9 +793,9 @@  discard block
 block discarded – undo
793 793
         /**
794 794
          * Set the form validation instance for future use
795 795
          * @param FormValidation $fv the form validation object
796
-		 * @return object
796
+         * @return object
797 797
          */
798
-         public function setFormValidation($fv){
798
+            public function setFormValidation($fv){
799 799
             $this->formValidationInstance = $fv;
800 800
             return $this;
801 801
         }
@@ -836,12 +836,12 @@  discard block
 block discarded – undo
836 836
          * INTERNAL METHODS
837 837
          * ------------------------------------------------------------ */
838 838
 
839
-		/**
840
-		* relate for the relation "belongs_to"
841
-		* @return mixed
842
-		*/
843
-		protected function relateBelongsTo($row){
844
-			foreach ($this->belongs_to as $key => $value)
839
+        /**
840
+         * relate for the relation "belongs_to"
841
+         * @return mixed
842
+         */
843
+        protected function relateBelongsTo($row){
844
+            foreach ($this->belongs_to as $key => $value)
845 845
             {
846 846
                 if (is_string($value))
847 847
                 {
@@ -872,15 +872,15 @@  discard block
 block discarded – undo
872 872
                     }
873 873
                 }
874 874
             }
875
-			return $row;
876
-		}
877
-
878
-		/**
879
-		* relate for the relation "has_many"
880
-		* @return mixed
881
-		*/
882
-		protected function relateHasMany($row){
883
-			foreach ($this->has_many as $key => $value)
875
+            return $row;
876
+        }
877
+
878
+        /**
879
+         * relate for the relation "has_many"
880
+         * @return mixed
881
+         */
882
+        protected function relateHasMany($row){
883
+            foreach ($this->has_many as $key => $value)
884 884
             {
885 885
                 if (is_string($value))
886 886
                 {
@@ -911,8 +911,8 @@  discard block
 block discarded – undo
911 911
                     }
912 912
                 }
913 913
             }
914
-			return $row;
915
-		}
914
+            return $row;
915
+        }
916 916
 		
917 917
         /**
918 918
          * Trigger an event and call its observers. Pass through the event name
@@ -977,30 +977,30 @@  discard block
 block discarded – undo
977 977
         }
978 978
 		
979 979
 		
980
-		/**
981
-		* Set WHERE parameters, when is array
982
-		* @param array $params
983
-		*/
984
-		protected function _set_where_array(array $params){
985
-			foreach ($params as $field => $filter)
986
-			{
987
-				if (is_array($filter))
988
-				{
989
-					$this->getQueryBuilder()->in($field, $filter);
990
-				}
991
-				else
992
-				{
993
-					if (is_int($field))
994
-					{
995
-						$this->getQueryBuilder()->where($filter);
996
-					}
997
-					else
998
-					{
999
-						$this->getQueryBuilder()->where($field, $filter);
1000
-					}
1001
-				}
1002
-			}
1003
-		}
980
+        /**
981
+         * Set WHERE parameters, when is array
982
+         * @param array $params
983
+         */
984
+        protected function _set_where_array(array $params){
985
+            foreach ($params as $field => $filter)
986
+            {
987
+                if (is_array($filter))
988
+                {
989
+                    $this->getQueryBuilder()->in($field, $filter);
990
+                }
991
+                else
992
+                {
993
+                    if (is_int($field))
994
+                    {
995
+                        $this->getQueryBuilder()->where($filter);
996
+                    }
997
+                    else
998
+                    {
999
+                        $this->getQueryBuilder()->where($field, $filter);
1000
+                    }
1001
+                }
1002
+            }
1003
+        }
1004 1004
 
1005 1005
 
1006 1006
         /**
@@ -1016,8 +1016,8 @@  discard block
 block discarded – undo
1016 1016
             {
1017 1017
                 $this->getQueryBuilder()->where($params[0]);
1018 1018
             }
1019
-        	else if (count($params) == 2)
1020
-    		{
1019
+            else if (count($params) == 2)
1020
+            {
1021 1021
                 if (is_array($params[1]))
1022 1022
                 {
1023 1023
                     $this->getQueryBuilder()->in($params[0], $params[1]);
@@ -1026,11 +1026,11 @@  discard block
 block discarded – undo
1026 1026
                 {
1027 1027
                     $this->getQueryBuilder()->where($params[0], $params[1]);
1028 1028
                 }
1029
-    		}
1030
-    		else if (count($params) == 3)
1031
-    		{
1032
-    			$this->getQueryBuilder()->where($params[0], $params[1], $params[2]);
1033
-    		}
1029
+            }
1030
+            else if (count($params) == 3)
1031
+            {
1032
+                $this->getQueryBuilder()->where($params[0], $params[1], $params[2]);
1033
+            }
1034 1034
             else
1035 1035
             {
1036 1036
                 if (is_array($params[1]))
@@ -1046,7 +1046,7 @@  discard block
 block discarded – undo
1046 1046
 
1047 1047
         /**
1048 1048
             Shortcut to controller
1049
-        */
1049
+         */
1050 1050
         public function __get($key){
1051 1051
             return get_instance()->{$key};
1052 1052
         }
Please login to merge, or discard this patch.
core/classes/Lang.php 1 patch
Indentation   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -1,208 +1,208 @@
 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
-	*/
26
-
27
-	/**
28
-	 * For application languages management
29
-	 */
30
-	class Lang{
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
+
27
+    /**
28
+     * For application languages management
29
+     */
30
+    class Lang{
31 31
 		
32
-		/**
33
-		 * The supported available language for this application.
34
-		 * @example "en" => "english" 
35
-		 * @see Lang::addLang()
36
-		 * @var array
37
-		 */
38
-		protected $availables = array();
39
-
40
-		/**
41
-		 * The all messages language
42
-		 * @var array
43
-		 */
44
-		protected $languages = array();
45
-
46
-		/**
47
-		 * The default language to use if can not
48
-		 *  determine the client language
49
-		 *  
50
-		 * @example $default = 'en'
51
-		 * @var string
52
-		 */
53
-		protected $default = null;
54
-
55
-		/**
56
-		 * The current client language
57
-		 * @var string
58
-		 */
59
-		protected $current = null;
60
-
61
-		/**
62
-		 * The logger instance
63
-		 * @var Log
64
-		 */
65
-		private $logger;
66
-
67
-		/**
68
-		 * Construct new Lang instance
69
-		 */
70
-		public function __construct(){
71
-	        $this->logger =& class_loader('Log', 'classes');
72
-	        $this->logger->setLogger('Library::Lang');
73
-
74
-			$this->default = get_config('default_language', 'en');
75
-			$this->logger->debug('Setting the supported languages');
32
+        /**
33
+         * The supported available language for this application.
34
+         * @example "en" => "english" 
35
+         * @see Lang::addLang()
36
+         * @var array
37
+         */
38
+        protected $availables = array();
39
+
40
+        /**
41
+         * The all messages language
42
+         * @var array
43
+         */
44
+        protected $languages = array();
45
+
46
+        /**
47
+         * The default language to use if can not
48
+         *  determine the client language
49
+         *  
50
+         * @example $default = 'en'
51
+         * @var string
52
+         */
53
+        protected $default = null;
54
+
55
+        /**
56
+         * The current client language
57
+         * @var string
58
+         */
59
+        protected $current = null;
60
+
61
+        /**
62
+         * The logger instance
63
+         * @var Log
64
+         */
65
+        private $logger;
66
+
67
+        /**
68
+         * Construct new Lang instance
69
+         */
70
+        public function __construct(){
71
+            $this->logger =& class_loader('Log', 'classes');
72
+            $this->logger->setLogger('Library::Lang');
73
+
74
+            $this->default = get_config('default_language', 'en');
75
+            $this->logger->debug('Setting the supported languages');
76 76
 			
77
-			//add the supported languages ('key', 'display name')
78
-			$languages = get_config('languages', null);
79
-			if(! empty($languages)){
80
-				foreach($languages as $key => $displayName){
81
-					$this->addLang($key, $displayName);
82
-				}
83
-			}
84
-			unset($languages);
85
-
86
-			//if the language exists in cookie use it
87
-			$cfgKey = get_config('language_cookie_name');
88
-			$this->logger->debug('Getting current language from cookie [' .$cfgKey. ']');
89
-			$objCookie = & class_loader('Cookie');
90
-			$cookieLang = $objCookie->get($cfgKey);
91
-			if($cookieLang && $this->isValid($cookieLang)){
92
-				$this->current = $cookieLang;
93
-				$this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']');
94
-			}
95
-			else{
96
-				$this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']');
97
-				$this->current = $this->getDefault();
98
-			}
99
-		}
100
-
101
-		/**
102
-		 * Get the all languages messages
103
-		 *
104
-		 * @return array the language message list
105
-		 */
106
-		public function getAll(){
107
-			return $this->languages;
108
-		}
109
-
110
-		/**
111
-		 * Set the language message
112
-		 *
113
-		 * @param string $key the language key to identify
114
-		 * @param string $value the language message value
115
-		 */
116
-		public function set($key, $value){
117
-			$this->languages[$key] = $value;
118
-		}
119
-
120
-		/**
121
-		 * Get the language message for the given key. If can't find return the default value
122
-		 *
123
-		 * @param  string $key the message language key
124
-		 * @param  string $default the default value to return if can not found the language message key
125
-		 *
126
-		 * @return string the language message value
127
-		 */
128
-		public function get($key, $default = 'LANGUAGE_ERROR'){
129
-			if(isset($this->languages[$key])){
130
-				return $this->languages[$key];
131
-			}
132
-			$this->logger->warning('Language key  [' .$key. '] does not exist use the default value [' .$default. ']');
133
-			return $default;
134
-		}
135
-
136
-		/**
137
-		 * Check whether the language file for given name exists
138
-		 *
139
-		 * @param  string  $language the language name like "fr", "en", etc.
140
-		 *
141
-		 * @return boolean true if the language directory exists, false or not
142
-		 */
143
-		public function isValid($language){
144
-			$searchDir = array(CORE_LANG_PATH, APP_LANG_PATH);
145
-			foreach($searchDir as $dir){
146
-				if(file_exists($dir . $language) && is_dir($dir . $language)){
147
-					return true;
148
-				}
149
-			}
150
-			return false;
151
-		}
152
-
153
-		/**
154
-		 * Get the default language value like "en" , "fr", etc.
155
-		 *
156
-		 * @return string the default language
157
-		 */
158
-		public function getDefault(){
159
-			return $this->default;
160
-		}
161
-
162
-		/**
163
-		 * Get the current language defined by cookie or the default value
164
-		 *
165
-		 * @return string the current language
166
-		 */
167
-		public function getCurrent(){
168
-			return $this->current;
169
-		}
170
-
171
-		/**
172
-		 * Add new supported or available language
173
-		 *
174
-		 * @param string $name the short language name like "en", "fr".
175
-		 * @param string $description the human readable description of this language
176
-		 */
177
-		public function addLang($name, $description){
178
-			if(isset($this->availables[$name])){
179
-				return; //already added cost in performance
180
-			}
181
-			if($this->isValid($name)){
182
-				$this->availables[$name] = $description;
183
-			}
184
-			else{
185
-				show_error('The language [' . $name . '] is not valid or does not exists.');
186
-			}
187
-		}
188
-
189
-		/**
190
-		 * Get the list of the application supported language
191
-		 *
192
-		 * @return array the list of the application language
193
-		 */
194
-		public function getSupported(){
195
-			return $this->availables;
196
-		}
197
-
198
-		/**
199
-		 * Add new language messages
200
-		 *
201
-		 * @param array $langs the languages array of the messages to be added
202
-		 */
203
-		public function addLangMessages(array $langs){
204
-			foreach ($langs as $key => $value) {
205
-				$this->set($key, $value);
206
-			}
207
-		}
208
-	}
77
+            //add the supported languages ('key', 'display name')
78
+            $languages = get_config('languages', null);
79
+            if(! empty($languages)){
80
+                foreach($languages as $key => $displayName){
81
+                    $this->addLang($key, $displayName);
82
+                }
83
+            }
84
+            unset($languages);
85
+
86
+            //if the language exists in cookie use it
87
+            $cfgKey = get_config('language_cookie_name');
88
+            $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']');
89
+            $objCookie = & class_loader('Cookie');
90
+            $cookieLang = $objCookie->get($cfgKey);
91
+            if($cookieLang && $this->isValid($cookieLang)){
92
+                $this->current = $cookieLang;
93
+                $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']');
94
+            }
95
+            else{
96
+                $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']');
97
+                $this->current = $this->getDefault();
98
+            }
99
+        }
100
+
101
+        /**
102
+         * Get the all languages messages
103
+         *
104
+         * @return array the language message list
105
+         */
106
+        public function getAll(){
107
+            return $this->languages;
108
+        }
109
+
110
+        /**
111
+         * Set the language message
112
+         *
113
+         * @param string $key the language key to identify
114
+         * @param string $value the language message value
115
+         */
116
+        public function set($key, $value){
117
+            $this->languages[$key] = $value;
118
+        }
119
+
120
+        /**
121
+         * Get the language message for the given key. If can't find return the default value
122
+         *
123
+         * @param  string $key the message language key
124
+         * @param  string $default the default value to return if can not found the language message key
125
+         *
126
+         * @return string the language message value
127
+         */
128
+        public function get($key, $default = 'LANGUAGE_ERROR'){
129
+            if(isset($this->languages[$key])){
130
+                return $this->languages[$key];
131
+            }
132
+            $this->logger->warning('Language key  [' .$key. '] does not exist use the default value [' .$default. ']');
133
+            return $default;
134
+        }
135
+
136
+        /**
137
+         * Check whether the language file for given name exists
138
+         *
139
+         * @param  string  $language the language name like "fr", "en", etc.
140
+         *
141
+         * @return boolean true if the language directory exists, false or not
142
+         */
143
+        public function isValid($language){
144
+            $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH);
145
+            foreach($searchDir as $dir){
146
+                if(file_exists($dir . $language) && is_dir($dir . $language)){
147
+                    return true;
148
+                }
149
+            }
150
+            return false;
151
+        }
152
+
153
+        /**
154
+         * Get the default language value like "en" , "fr", etc.
155
+         *
156
+         * @return string the default language
157
+         */
158
+        public function getDefault(){
159
+            return $this->default;
160
+        }
161
+
162
+        /**
163
+         * Get the current language defined by cookie or the default value
164
+         *
165
+         * @return string the current language
166
+         */
167
+        public function getCurrent(){
168
+            return $this->current;
169
+        }
170
+
171
+        /**
172
+         * Add new supported or available language
173
+         *
174
+         * @param string $name the short language name like "en", "fr".
175
+         * @param string $description the human readable description of this language
176
+         */
177
+        public function addLang($name, $description){
178
+            if(isset($this->availables[$name])){
179
+                return; //already added cost in performance
180
+            }
181
+            if($this->isValid($name)){
182
+                $this->availables[$name] = $description;
183
+            }
184
+            else{
185
+                show_error('The language [' . $name . '] is not valid or does not exists.');
186
+            }
187
+        }
188
+
189
+        /**
190
+         * Get the list of the application supported language
191
+         *
192
+         * @return array the list of the application language
193
+         */
194
+        public function getSupported(){
195
+            return $this->availables;
196
+        }
197
+
198
+        /**
199
+         * Add new language messages
200
+         *
201
+         * @param array $langs the languages array of the messages to be added
202
+         */
203
+        public function addLangMessages(array $langs){
204
+            foreach ($langs as $key => $value) {
205
+                $this->set($key, $value);
206
+            }
207
+        }
208
+    }
Please login to merge, or discard this patch.
core/classes/Config.php 1 patch
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -1,176 +1,176 @@
 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
-	class Config{
27
+    class Config{
28 28
 		
29
-		/**
30
-		 * The list of loaded configuration
31
-		 * @var array
32
-		 */
33
-		private static $config = array();
29
+        /**
30
+         * The list of loaded configuration
31
+         * @var array
32
+         */
33
+        private static $config = array();
34 34
 
35
-		/**
36
-		 * The logger instance
37
-		 * @var Log
38
-		 */
39
-		private static $logger;
35
+        /**
36
+         * The logger instance
37
+         * @var Log
38
+         */
39
+        private static $logger;
40 40
 
41
-		/**
42
-		 * The signleton of the logger
43
-		 * @return Object the Log instance
44
-		 */
45
-		private static function getLogger(){
46
-			if(self::$logger == null){
47
-				$logger = array();
48
-				$logger[0] =& class_loader('Log', 'classes');
49
-				$logger[0]->setLogger('Library::Config');
50
-				self::$logger = $logger[0];
51
-			}
52
-			return self::$logger;			
53
-		}
41
+        /**
42
+         * The signleton of the logger
43
+         * @return Object the Log instance
44
+         */
45
+        private static function getLogger(){
46
+            if(self::$logger == null){
47
+                $logger = array();
48
+                $logger[0] =& class_loader('Log', 'classes');
49
+                $logger[0]->setLogger('Library::Config');
50
+                self::$logger = $logger[0];
51
+            }
52
+            return self::$logger;			
53
+        }
54 54
 
55
-		/**
56
-		 * Set the log instance for future use
57
-		 * @param Log $logger the log object
58
-		 * @return Log the log instance
59
-		 */
60
-		public static function setLogger($logger){
61
-			self::$logger = $logger;
62
-			return self::$logger;
63
-		}
55
+        /**
56
+         * Set the log instance for future use
57
+         * @param Log $logger the log object
58
+         * @return Log the log instance
59
+         */
60
+        public static function setLogger($logger){
61
+            self::$logger = $logger;
62
+            return self::$logger;
63
+        }
64 64
 
65
-		/**
66
-		 * Initialize the configuration by loading all the configuration from config file
67
-		 */
68
-		public static function init(){
69
-			$logger = static::getLogger();
70
-			$logger->debug('Initialization of the configuration');
71
-			self::$config = & load_configurations();
72
-			self::setBaseUrlUsingServerVar();
73
-			if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
74
-				$logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
75
-			}
76
-			$logger->info('Configuration initialized successfully');
77
-			$logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config));
78
-		}
65
+        /**
66
+         * Initialize the configuration by loading all the configuration from config file
67
+         */
68
+        public static function init(){
69
+            $logger = static::getLogger();
70
+            $logger->debug('Initialization of the configuration');
71
+            self::$config = & load_configurations();
72
+            self::setBaseUrlUsingServerVar();
73
+            if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
74
+                $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
75
+            }
76
+            $logger->info('Configuration initialized successfully');
77
+            $logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config));
78
+        }
79 79
 
80
-		/**
81
-		 * Get the configuration item value
82
-		 * @param  string $item    the configuration item name to get
83
-		 * @param  mixed $default the default value to use if can not find the config item in the list
84
-		 * @return mixed          the config value if exist or the default value
85
-		 */
86
-		public static function get($item, $default = null){
87
-			$logger = static::getLogger();
88
-			if(array_key_exists($item, self::$config)){
89
-				return self::$config[$item];
90
-			}
91
-			$logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
92
-			return $default;
93
-		}
80
+        /**
81
+         * Get the configuration item value
82
+         * @param  string $item    the configuration item name to get
83
+         * @param  mixed $default the default value to use if can not find the config item in the list
84
+         * @return mixed          the config value if exist or the default value
85
+         */
86
+        public static function get($item, $default = null){
87
+            $logger = static::getLogger();
88
+            if(array_key_exists($item, self::$config)){
89
+                return self::$config[$item];
90
+            }
91
+            $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
92
+            return $default;
93
+        }
94 94
 
95
-		/**
96
-		 * Set the configuration item value
97
-		 * @param string $item  the config item name to set
98
-		 * @param mixed $value the config item value
99
-		 */
100
-		public static function set($item, $value){
101
-			self::$config[$item] = $value;
102
-		}
95
+        /**
96
+         * Set the configuration item value
97
+         * @param string $item  the config item name to set
98
+         * @param mixed $value the config item value
99
+         */
100
+        public static function set($item, $value){
101
+            self::$config[$item] = $value;
102
+        }
103 103
 
104
-		/**
105
-		 * Get all the configuration values
106
-		 * @return array the config values
107
-		 */
108
-		public static function getAll(){
109
-			return self::$config;
110
-		}
104
+        /**
105
+         * Get all the configuration values
106
+         * @return array the config values
107
+         */
108
+        public static function getAll(){
109
+            return self::$config;
110
+        }
111 111
 
112
-		/**
113
-		 * Set the configuration values bu merged with the existing configuration
114
-		 * @param array $config the config values to add in the configuration list
115
-		 */
116
-		public static function setAll(array $config = array()){
117
-			self::$config = array_merge(self::$config, $config);
118
-		}
112
+        /**
113
+         * Set the configuration values bu merged with the existing configuration
114
+         * @param array $config the config values to add in the configuration list
115
+         */
116
+        public static function setAll(array $config = array()){
117
+            self::$config = array_merge(self::$config, $config);
118
+        }
119 119
 
120
-		/**
121
-		 * Delete the configuration item in the list
122
-		 * @param  string $item the config item name to be deleted
123
-		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
124
-		 */
125
-		public static function delete($item){
126
-			$logger = static::getLogger();
127
-			if(array_key_exists($item, self::$config)){
128
-				$logger->info('Delete config item ['.$item.']');
129
-				unset(self::$config[$item]);
130
-				return true;
131
-			}
132
-			else{
133
-				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
134
-				return false;
135
-			}
136
-		}
120
+        /**
121
+         * Delete the configuration item in the list
122
+         * @param  string $item the config item name to be deleted
123
+         * @return boolean true if the item exists and is deleted successfully otherwise will return false.
124
+         */
125
+        public static function delete($item){
126
+            $logger = static::getLogger();
127
+            if(array_key_exists($item, self::$config)){
128
+                $logger->info('Delete config item ['.$item.']');
129
+                unset(self::$config[$item]);
130
+                return true;
131
+            }
132
+            else{
133
+                $logger->warning('Config item ['.$item.'] to be deleted does not exists');
134
+                return false;
135
+            }
136
+        }
137 137
 
138
-		/**
139
-		 * Load the configuration file. This an alias to Loader::config()
140
-		 * @param  string $config the config name to be loaded
141
-		 */
142
-		public static function load($config){
143
-			Loader::config($config);
144
-		}
138
+        /**
139
+         * Load the configuration file. This an alias to Loader::config()
140
+         * @param  string $config the config name to be loaded
141
+         */
142
+        public static function load($config){
143
+            Loader::config($config);
144
+        }
145 145
 
146
-		/**
147
-		 * Set the configuration for "base_url" if is not set in the configuration
148
-		 */
149
-		private static function setBaseUrlUsingServerVar(){
150
-			$logger = static::getLogger();
151
-			if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
152
-				if(ENVIRONMENT == 'production'){
153
-					$logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
154
-				}
155
-				$baseUrl = null;
156
-				if (isset($_SERVER['SERVER_ADDR'])){
157
-					//check if the server is running under IPv6
158
-					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
159
-						$baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
160
-					}
161
-					else{
162
-						$baseUrl = $_SERVER['SERVER_ADDR'];
163
-					}
164
-					$port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && ! is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https()) ) ? ':' . $_SERVER['SERVER_PORT'] : '');
165
-					$baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port
166
-						. substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
167
-				}
168
-				else{
169
-					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
170
-					$baseUrl = 'http://localhost/';
171
-				}
172
-				self::set('base_url', $baseUrl);
173
-			}
174
-			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
175
-		}
176
-	}
146
+        /**
147
+         * Set the configuration for "base_url" if is not set in the configuration
148
+         */
149
+        private static function setBaseUrlUsingServerVar(){
150
+            $logger = static::getLogger();
151
+            if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
152
+                if(ENVIRONMENT == 'production'){
153
+                    $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
154
+                }
155
+                $baseUrl = null;
156
+                if (isset($_SERVER['SERVER_ADDR'])){
157
+                    //check if the server is running under IPv6
158
+                    if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
159
+                        $baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
160
+                    }
161
+                    else{
162
+                        $baseUrl = $_SERVER['SERVER_ADDR'];
163
+                    }
164
+                    $port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && ! is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https()) ) ? ':' . $_SERVER['SERVER_PORT'] : '');
165
+                    $baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port
166
+                        . substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
167
+                }
168
+                else{
169
+                    $logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
170
+                    $baseUrl = 'http://localhost/';
171
+                }
172
+                self::set('base_url', $baseUrl);
173
+            }
174
+            self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
175
+        }
176
+    }
Please login to merge, or discard this patch.
core/classes/Database.php 1 patch
Indentation   +380 added lines, -380 removed lines patch added patch discarded remove patch
@@ -1,124 +1,124 @@  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 Database{
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 Database{
27 27
 	
28
-	/**
29
-	 * The PDO instance
30
-	 * @var object
31
-	*/
28
+    /**
29
+     * The PDO instance
30
+     * @var object
31
+     */
32 32
     private $pdo                 = null;
33 33
     
34
-	/**
35
-	 * The database name used for the application
36
-	 * @var string
37
-	*/
38
-	private $databaseName        = null;
34
+    /**
35
+     * The database name used for the application
36
+     * @var string
37
+     */
38
+    private $databaseName        = null;
39 39
 	
40
-	/**
41
-	 * The number of rows returned by the last query
42
-	 * @var int
43
-	*/
40
+    /**
41
+     * The number of rows returned by the last query
42
+     * @var int
43
+     */
44 44
     private $numRows             = 0;
45 45
 	
46
-	/**
47
-	 * The last insert id for the primary key column that have auto increment or sequence
48
-	 * @var mixed
49
-	*/
46
+    /**
47
+     * The last insert id for the primary key column that have auto increment or sequence
48
+     * @var mixed
49
+     */
50 50
     private $insertId            = null;
51 51
 	
52
-	/**
53
-	 * The full SQL query statment after build for each command
54
-	 * @var string
55
-	*/
52
+    /**
53
+     * The full SQL query statment after build for each command
54
+     * @var string
55
+     */
56 56
     private $query               = null;
57 57
 	
58
-	/**
59
-	 * The error returned for the last query
60
-	 * @var string
61
-	*/
58
+    /**
59
+     * The error returned for the last query
60
+     * @var string
61
+     */
62 62
     private $error               = null;
63 63
 	
64
-	/**
65
-	 * The result returned for the last query
66
-	 * @var mixed
67
-	*/
64
+    /**
65
+     * The result returned for the last query
66
+     * @var mixed
67
+     */
68 68
     private $result              = array();
69 69
 	
70
-	/**
71
-	 * The cache default time to live in second. 0 means no need to use the cache feature
72
-	 * @var int
73
-	*/
74
-	private $cacheTtl              = 0;
70
+    /**
71
+     * The cache default time to live in second. 0 means no need to use the cache feature
72
+     * @var int
73
+     */
74
+    private $cacheTtl              = 0;
75 75
 	
76
-	/**
77
-	 * The cache current time to live. 0 means no need to use the cache feature
78
-	 * @var int
79
-	*/
76
+    /**
77
+     * The cache current time to live. 0 means no need to use the cache feature
78
+     * @var int
79
+     */
80 80
     private $temporaryCacheTtl   = 0;
81 81
 	
82
-	/**
83
-	 * The number of executed query for the current request
84
-	 * @var int
85
-	*/
82
+    /**
83
+     * The number of executed query for the current request
84
+     * @var int
85
+     */
86 86
     private $queryCount          = 0;
87 87
 	
88
-	/**
89
-	 * The default data to be used in the statments query INSERT, UPDATE
90
-	 * @var array
91
-	*/
88
+    /**
89
+     * The default data to be used in the statments query INSERT, UPDATE
90
+     * @var array
91
+     */
92 92
     private $data                = array();
93 93
 	
94
-	/**
95
-	 * The database configuration
96
-	 * @var array
97
-	*/
94
+    /**
95
+     * The database configuration
96
+     * @var array
97
+     */
98 98
     private $config              = array();
99 99
 	
100
-	/**
101
-	 * The logger instance
102
-	 * @var object
103
-	 */
100
+    /**
101
+     * The logger instance
102
+     * @var object
103
+     */
104 104
     private $logger              = null;
105 105
 
106 106
     /**
107
-    * The cache instance
108
-    * @var object
109
-    */
107
+     * The cache instance
108
+     * @var object
109
+     */
110 110
     private $cacheInstance       = null;
111 111
 
112 112
     /**
113
-    * The benchmark instance
114
-    * @var object
115
-    */
113
+     * The benchmark instance
114
+     * @var object
115
+     */
116 116
     private $benchmarkInstance   = null;
117 117
 	
118
-	/**
119
-    * The DatabaseQueryBuilder instance
120
-    * @var object
121
-    */
118
+    /**
119
+     * The DatabaseQueryBuilder instance
120
+     * @var object
121
+     */
122 122
     private $queryBuilder        = null;
123 123
 
124 124
 
@@ -130,14 +130,14 @@  discard block
 block discarded – undo
130 130
         //Set Log instance to use
131 131
         $this->setLoggerFromParamOrCreateNewInstance(null);
132 132
 		
133
-		    //Set DatabaseQueryBuilder instance to use
134
-		    $this->setQueryBuilderFromParamOrCreateNewInstance(null);
133
+            //Set DatabaseQueryBuilder instance to use
134
+            $this->setQueryBuilderFromParamOrCreateNewInstance(null);
135 135
 
136 136
         //Set database configuration
137 137
         $this->setDatabaseConfiguration($overwriteConfig);
138 138
 	
139
-		    //cache time to live
140
-    	  $this->temporaryCacheTtl = $this->cacheTtl;
139
+            //cache time to live
140
+            $this->temporaryCacheTtl = $this->cacheTtl;
141 141
     }
142 142
 
143 143
     /**
@@ -145,25 +145,25 @@  discard block
 block discarded – undo
145 145
      * @return bool 
146 146
      */
147 147
     public function connect(){
148
-      $config = $this->getDatabaseConfiguration();
149
-      if (! empty($config)){
148
+        $config = $this->getDatabaseConfiguration();
149
+        if (! empty($config)){
150 150
         try{
151 151
             $this->pdo = new PDO($this->getDsnFromDriver(), $config['username'], $config['password']);
152 152
             $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'");
153 153
             $this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'");
154 154
             $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
155 155
             return true;
156
-          }
157
-          catch (PDOException $e){
156
+            }
157
+            catch (PDOException $e){
158 158
             $this->logger->fatal($e->getMessage());
159 159
             show_error('Cannot connect to Database.');
160 160
             return false;
161
-          }
162
-      }
163
-      else{
161
+            }
162
+        }
163
+        else{
164 164
         show_error('Database configuration is not set.');
165 165
         return false;
166
-      }
166
+        }
167 167
     }
168 168
 
169 169
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      * @return int
173 173
      */
174 174
     public function numRows(){
175
-      return $this->numRows;
175
+        return $this->numRows;
176 176
     }
177 177
 
178 178
     /**
@@ -180,16 +180,16 @@  discard block
 block discarded – undo
180 180
      * @return mixed
181 181
      */
182 182
     public function insertId(){
183
-      return $this->insertId;
183
+        return $this->insertId;
184 184
     }
185 185
 
186 186
     /**
187 187
      * Show an error got from the current query (SQL command synthax error, database driver returned error, etc.)
188 188
      */
189 189
     public function error(){
190
-  		if ($this->error){
191
-  			show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error');
192
-  		}
190
+            if ($this->error){
191
+                show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error');
192
+            }
193 193
     }
194 194
 
195 195
     /**
@@ -199,14 +199,14 @@  discard block
 block discarded – undo
199 199
      * @return mixed       the query SQL string or the record result
200 200
      */
201 201
     public function get($returnSQLQueryOrResultType = false){
202
-      $this->getQueryBuilder()->limit(1);
203
-      $query = $this->getAll(true);
204
-      if ($returnSQLQueryOrResultType === true){
202
+        $this->getQueryBuilder()->limit(1);
203
+        $query = $this->getAll(true);
204
+        if ($returnSQLQueryOrResultType === true){
205 205
         return $query;
206
-      }
207
-      else{
206
+        }
207
+        else{
208 208
         return $this->query($query, false, $returnSQLQueryOrResultType == 'array');
209
-      }
209
+        }
210 210
     }
211 211
 
212 212
     /**
@@ -216,11 +216,11 @@  discard block
 block discarded – undo
216 216
      * @return mixed       the query SQL string or the record result
217 217
      */
218 218
     public function getAll($returnSQLQueryOrResultType = false){
219
-	   $query = $this->getQueryBuilder()->getQuery();
220
-	   if ($returnSQLQueryOrResultType === true){
221
-      	return $query;
222
-      }
223
-      return $this->query($query, true, $returnSQLQueryOrResultType == 'array');
219
+        $query = $this->getQueryBuilder()->getQuery();
220
+        if ($returnSQLQueryOrResultType === true){
221
+            return $query;
222
+        }
223
+        return $this->query($query, true, $returnSQLQueryOrResultType == 'array');
224 224
     }
225 225
 
226 226
     /**
@@ -230,19 +230,19 @@  discard block
 block discarded – undo
230 230
      * @return mixed          the insert id of the new record or null
231 231
      */
232 232
     public function insert($data = array(), $escape = true){
233
-      if (empty($data) && $this->getData()){
233
+        if (empty($data) && $this->getData()){
234 234
         //as when using $this->setData() may be the data already escaped
235 235
         $escape = false;
236 236
         $data = $this->getData();
237
-      }
238
-      $query = $this->getQueryBuilder()->insert($data, $escape)->getQuery();
239
-      $result = $this->query($query);
240
-      if ($result){
237
+        }
238
+        $query = $this->getQueryBuilder()->insert($data, $escape)->getQuery();
239
+        $result = $this->query($query);
240
+        if ($result){
241 241
         $this->insertId = $this->pdo->lastInsertId();
242
-		//if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
242
+        //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
243 243
         return ! $this->insertId() ? true : $this->insertId();
244
-      }
245
-      return false;
244
+        }
245
+        return false;
246 246
     }
247 247
 
248 248
     /**
@@ -252,13 +252,13 @@  discard block
 block discarded – undo
252 252
      * @return mixed          the update status
253 253
      */
254 254
     public function update($data = array(), $escape = true){
255
-      if (empty($data) && $this->getData()){
255
+        if (empty($data) && $this->getData()){
256 256
         //as when using $this->setData() may be the data already escaped
257 257
         $escape = false;
258 258
         $data = $this->getData();
259
-      }
260
-      $query = $this->getQueryBuilder()->update($data, $escape)->getQuery();
261
-      return $this->query($query);
259
+        }
260
+        $query = $this->getQueryBuilder()->update($data, $escape)->getQuery();
261
+        return $this->query($query);
262 262
     }
263 263
 
264 264
     /**
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
      * @return mixed the delete status
267 267
      */
268 268
     public function delete(){
269
-		$query = $this->getQueryBuilder()->delete()->getQuery();
270
-    	return $this->query($query);
269
+        $query = $this->getQueryBuilder()->delete()->getQuery();
270
+        return $this->query($query);
271 271
     }
272 272
 
273 273
     /**
@@ -276,21 +276,21 @@  discard block
 block discarded – undo
276 276
      * @return object        the current Database instance
277 277
      */
278 278
     public function setCache($ttl = 0){
279
-      if ($ttl > 0){
279
+        if ($ttl > 0){
280 280
         $this->cacheTtl = $ttl;
281 281
         $this->temporaryCacheTtl = $ttl;
282
-      }
283
-      return $this;
282
+        }
283
+        return $this;
284 284
     }
285 285
 	
286
-	/**
287
-	 * Enabled cache temporary for the current query not globally	
288
-	 * @param  integer $ttl the cache time to live in second
289
-	 * @return object        the current Database instance
290
-	 */
291
-  	public function cached($ttl = 0){
286
+    /**
287
+     * Enabled cache temporary for the current query not globally	
288
+     * @param  integer $ttl the cache time to live in second
289
+     * @return object        the current Database instance
290
+     */
291
+        public function cached($ttl = 0){
292 292
         if ($ttl > 0){
293
-          $this->temporaryCacheTtl = $ttl;
293
+            $this->temporaryCacheTtl = $ttl;
294 294
         }
295 295
         return $this;
296 296
     }
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
      * @return mixed       the data after escaped or the same data if not
303 303
      */
304 304
     public function escape($data, $escaped = true){
305
-      return $escaped ? 
305
+        return $escaped ? 
306 306
                       $this->getPdo()->quote(trim($data)) 
307 307
                       : $data; 
308 308
     }
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
      * @return int
313 313
      */
314 314
     public function queryCount(){
315
-      return $this->queryCount;
315
+        return $this->queryCount;
316 316
     }
317 317
 
318 318
     /**
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
      * @return string
321 321
      */
322 322
     public function getQuery(){
323
-      return $this->query;
323
+        return $this->query;
324 324
     }
325 325
 
326 326
     /**
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
      * @return string
329 329
      */
330 330
     public function getDatabaseName(){
331
-      return $this->databaseName;
331
+        return $this->databaseName;
332 332
     }
333 333
 
334 334
     /**
@@ -336,17 +336,17 @@  discard block
 block discarded – undo
336 336
      * @return object
337 337
      */
338 338
     public function getPdo(){
339
-      return $this->pdo;
339
+        return $this->pdo;
340 340
     }
341 341
 
342 342
     /**
343 343
      * Set the PDO instance
344 344
      * @param object $pdo the pdo object
345
-	 * @return object Database
345
+     * @return object Database
346 346
      */
347 347
     public function setPdo(PDO $pdo){
348
-      $this->pdo = $pdo;
349
-      return $this;
348
+        $this->pdo = $pdo;
349
+        return $this;
350 350
     }
351 351
 
352 352
 
@@ -355,35 +355,35 @@  discard block
 block discarded – undo
355 355
      * @return Log
356 356
      */
357 357
     public function getLogger(){
358
-      return $this->logger;
358
+        return $this->logger;
359 359
     }
360 360
 
361 361
     /**
362 362
      * Set the log instance
363 363
      * @param Log $logger the log object
364
-	 * @return object Database
364
+     * @return object Database
365 365
      */
366 366
     public function setLogger($logger){
367
-      $this->logger = $logger;
368
-      return $this;
367
+        $this->logger = $logger;
368
+        return $this;
369 369
     }
370 370
 
371
-     /**
372
-     * Return the cache instance
373
-     * @return CacheInterface
374
-     */
371
+        /**
372
+         * Return the cache instance
373
+         * @return CacheInterface
374
+         */
375 375
     public function getCacheInstance(){
376
-      return $this->cacheInstance;
376
+        return $this->cacheInstance;
377 377
     }
378 378
 
379 379
     /**
380 380
      * Set the cache instance
381 381
      * @param CacheInterface $cache the cache object
382
-	 * @return object Database
382
+     * @return object Database
383 383
      */
384 384
     public function setCacheInstance($cache){
385
-      $this->cacheInstance = $cache;
386
-      return $this;
385
+        $this->cacheInstance = $cache;
386
+        return $this;
387 387
     }
388 388
 
389 389
     /**
@@ -391,26 +391,26 @@  discard block
 block discarded – undo
391 391
      * @return Benchmark
392 392
      */
393 393
     public function getBenchmark(){
394
-      return $this->benchmarkInstance;
394
+        return $this->benchmarkInstance;
395 395
     }
396 396
 
397 397
     /**
398 398
      * Set the benchmark instance
399 399
      * @param Benchmark $benchmark the benchmark object
400
-	 * @return object Database
400
+     * @return object Database
401 401
      */
402 402
     public function setBenchmark($benchmark){
403
-      $this->benchmarkInstance = $benchmark;
404
-      return $this;
403
+        $this->benchmarkInstance = $benchmark;
404
+        return $this;
405 405
     }
406 406
 	
407 407
 	
408
-	/**
408
+    /**
409 409
      * Return the DatabaseQueryBuilder instance
410 410
      * @return object DatabaseQueryBuilder
411 411
      */
412 412
     public function getQueryBuilder(){
413
-      return $this->queryBuilder;
413
+        return $this->queryBuilder;
414 414
     }
415 415
 
416 416
     /**
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
      * @param object DatabaseQueryBuilder $queryBuilder the DatabaseQueryBuilder object
419 419
      */
420 420
     public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder){
421
-      $this->queryBuilder = $queryBuilder;
422
-      return $this;
421
+        $this->queryBuilder = $queryBuilder;
422
+        return $this;
423 423
     }
424 424
 
425 425
     /**
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
      * @return array
428 428
      */
429 429
     public function getData(){
430
-      return $this->data;
430
+        return $this->data;
431 431
     }
432 432
 
433 433
     /**
@@ -438,60 +438,60 @@  discard block
 block discarded – undo
438 438
      * @return object        the current Database instance
439 439
      */
440 440
     public function setData($key, $value = null, $escape = true){
441
-  	  if(is_array($key)){
442
-    		foreach($key as $k => $v){
443
-    			$this->setData($k, $v, $escape);
444
-    		}	
445
-  	  } else {
441
+        if(is_array($key)){
442
+            foreach($key as $k => $v){
443
+                $this->setData($k, $v, $escape);
444
+            }	
445
+        } else {
446 446
         $this->data[$key] = $this->escape($value, $escape);
447
-  	  }
448
-      return $this;
447
+        }
448
+        return $this;
449 449
     }
450 450
 
451
-     /**
452
-     * Execute an SQL query
453
-     * @param  string  $query the query SQL string
454
-     * @param  boolean|array $all  if boolean this indicate whether to return all record or not, if array 
455
-     * will 
456
-     * @param  boolean $array return the result as array
457
-     * @return mixed         the query result
458
-     */
451
+        /**
452
+         * Execute an SQL query
453
+         * @param  string  $query the query SQL string
454
+         * @param  boolean|array $all  if boolean this indicate whether to return all record or not, if array 
455
+         * will 
456
+         * @param  boolean $array return the result as array
457
+         * @return mixed         the query result
458
+         */
459 459
     public function query($query, $all = true, $array = false){
460
-      $this->reset();
461
-      $query = $this->getPreparedQuery($query, $all);
462
-      $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query));
460
+        $this->reset();
461
+        $query = $this->getPreparedQuery($query, $all);
462
+        $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query));
463 463
       
464
-      $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
464
+        $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
465 465
 
466
-      $this->logger->info(
467
-                          'Execute SQL query ['.$this->query.'], return type: ' 
468
-                          . ($array?'ARRAY':'OBJECT') .', return as list: ' 
469
-                          . (is_bool($all) && $all ? 'YES':'NO')
466
+        $this->logger->info(
467
+                            'Execute SQL query ['.$this->query.'], return type: ' 
468
+                            . ($array?'ARRAY':'OBJECT') .', return as list: ' 
469
+                            . (is_bool($all) && $all ? 'YES':'NO')
470 470
                         );
471
-      //cache expire time
472
-      $cacheExpire = $this->temporaryCacheTtl;
471
+        //cache expire time
472
+        $cacheExpire = $this->temporaryCacheTtl;
473 473
       
474
-      //return to the initial cache time
475
-      $this->temporaryCacheTtl = $this->cacheTtl;
474
+        //return to the initial cache time
475
+        $this->temporaryCacheTtl = $this->cacheTtl;
476 476
       
477
-      //config for cache
478
-      $cacheEnable = get_config('cache_enable');
477
+        //config for cache
478
+        $cacheEnable = get_config('cache_enable');
479 479
       
480
-      //the database cache content
481
-      $cacheContent = null;
480
+        //the database cache content
481
+        $cacheContent = null;
482 482
 
483
-      //if can use cache feature for this query
484
-      $dbCacheStatus = $cacheEnable && $cacheExpire > 0;
483
+        //if can use cache feature for this query
484
+        $dbCacheStatus = $cacheEnable && $cacheExpire > 0;
485 485
     
486
-      if ($dbCacheStatus && $isSqlSELECTQuery){
487
-          $this->logger->info('The cache is enabled for this query, try to get result from cache'); 
488
-          $cacheContent = $this->getCacheContentForQuery($query, $all, $array);  
489
-      }
486
+        if ($dbCacheStatus && $isSqlSELECTQuery){
487
+            $this->logger->info('The cache is enabled for this query, try to get result from cache'); 
488
+            $cacheContent = $this->getCacheContentForQuery($query, $all, $array);  
489
+        }
490 490
       
491
-      if ( !$cacheContent){
491
+        if ( !$cacheContent){
492 492
         $sqlQuery = $this->runSqlQuery($query, $all, $array);
493 493
         if (is_object($sqlQuery)){
494
-          if ($isSqlSELECTQuery){
494
+            if ($isSqlSELECTQuery){
495 495
             $this->setQueryResultForSelect($sqlQuery, $all, $array);
496 496
             $this->setCacheContentForQuery(
497 497
                                             $this->query, 
@@ -499,36 +499,36 @@  discard block
 block discarded – undo
499 499
                                             $this->result, 
500 500
                                             $dbCacheStatus && $isSqlSELECTQuery, 
501 501
                                             $cacheExpire
502
-                                          );
502
+                                            );
503 503
             if (! $this->result){
504
-              $this->logger->info('No result where found for the query [' . $query . ']');
504
+                $this->logger->info('No result where found for the query [' . $query . ']');
505
+            }
506
+            } else {
507
+                $this->setQueryResultForNonSelect($sqlQuery);
505 508
             }
506
-          } else {
507
-              $this->setQueryResultForNonSelect($sqlQuery);
508
-          }
509 509
         }
510
-      } else if ($isSqlSELECTQuery){
511
-          $this->logger->info('The result for query [' .$this->query. '] already cached use it');
512
-          $this->result = $cacheContent;
513
-          $this->numRows = count($this->result);
514
-      }
515
-      return $this->result;
510
+        } else if ($isSqlSELECTQuery){
511
+            $this->logger->info('The result for query [' .$this->query. '] already cached use it');
512
+            $this->result = $cacheContent;
513
+            $this->numRows = count($this->result);
514
+        }
515
+        return $this->result;
516 516
     }
517 517
 	
518
-	/**
518
+    /**
519 519
      * Run the database SQL query and return the PDOStatment object
520 520
      * @see Database::query
521 521
      * 
522 522
      * @return object|void
523 523
      */
524 524
     public function runSqlQuery($query, $all, $array){
525
-       //for database query execution time
525
+        //for database query execution time
526 526
         $benchmarkMarkerKey = $this->getCacheBenchmarkKeyForQuery($query, $all, $array);
527 527
         $benchmarkInstance = $this->getBenchmark();
528 528
         if (! is_object($benchmarkInstance)){
529
-          $obj = & get_instance();
530
-          $benchmarkInstance = $obj->benchmark; 
531
-          $this->setBenchmark($benchmarkInstance);
529
+            $obj = & get_instance();
530
+            $benchmarkInstance = $obj->benchmark; 
531
+            $this->setBenchmark($benchmarkInstance);
532 532
         }
533 533
         
534 534
         $benchmarkInstance->mark('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')');
@@ -537,34 +537,34 @@  discard block
 block discarded – undo
537 537
         
538 538
         //get response time for this query
539 539
         $responseTime = $benchmarkInstance->elapsedTime('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')');
540
-		    //TODO use the configuration value for the high response time currently is 1 second
540
+            //TODO use the configuration value for the high response time currently is 1 second
541 541
         if ($responseTime >= 1 ){
542 542
             $this->logger->warning('High response time while processing database query [' .$query. ']. The response time is [' .$responseTime. '] sec.');
543 543
         }
544
-		    //count the number of query execution to server
544
+            //count the number of query execution to server
545 545
         $this->queryCount++;
546 546
 		
547 547
         if ($sqlQuery !== false){
548
-          return $sqlQuery;
548
+            return $sqlQuery;
549 549
         }
550 550
         $this->setQueryError();
551 551
     }
552 552
 	
553 553
 	
554
-	 /**
555
-	 * Return the database configuration
556
-	 * @return array
557
-	 */
558
-	public  function getDatabaseConfiguration(){
559
-	  return $this->config;
560
-	}
561
-
562
-   /**
563
-    * Setting the database configuration using the configuration file and additional configuration from param
564
-    * @param array $overwriteConfig the additional configuration to overwrite with the existing one
565
-    * @param boolean $useConfigFile whether to use database configuration file
566
-	  * @return object Database
567
-    */
554
+        /**
555
+         * Return the database configuration
556
+         * @return array
557
+         */
558
+    public  function getDatabaseConfiguration(){
559
+        return $this->config;
560
+    }
561
+
562
+    /**
563
+     * Setting the database configuration using the configuration file and additional configuration from param
564
+     * @param array $overwriteConfig the additional configuration to overwrite with the existing one
565
+     * @param boolean $useConfigFile whether to use database configuration file
566
+     * @return object Database
567
+     */
568 568
     public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true){
569 569
         $db = array();
570 570
         if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')){
@@ -577,67 +577,67 @@  discard block
 block discarded – undo
577 577
         
578 578
         //default configuration
579 579
         $config = array(
580
-          'driver' => 'mysql',
581
-          'username' => 'root',
582
-          'password' => '',
583
-          'database' => '',
584
-          'hostname' => 'localhost',
585
-          'charset' => 'utf8',
586
-          'collation' => 'utf8_general_ci',
587
-          'prefix' => '',
588
-          'port' => ''
580
+            'driver' => 'mysql',
581
+            'username' => 'root',
582
+            'password' => '',
583
+            'database' => '',
584
+            'hostname' => 'localhost',
585
+            'charset' => 'utf8',
586
+            'collation' => 'utf8_general_ci',
587
+            'prefix' => '',
588
+            'port' => ''
589 589
         );
590 590
 		
591
-    		$config = array_merge($config, $db);
592
-    		//determine the port using the hostname like localhost:3307
591
+            $config = array_merge($config, $db);
592
+            //determine the port using the hostname like localhost:3307
593 593
         //hostname will be "localhost", and port "3307"
594 594
         $p = explode(':', $config['hostname']);
595
-    	  if (count($p) >= 2){
596
-    		  $config['hostname'] = $p[0];
597
-    		  $config['port'] = $p[1];
598
-    		}
595
+            if (count($p) >= 2){
596
+                $config['hostname'] = $p[0];
597
+                $config['port'] = $p[1];
598
+            }
599 599
 		
600
-		 $this->databaseName = $config['database'];
601
-		 $this->config = $config;
602
-		 $this->logger->info(
603
-								'The database configuration are listed below: ' 
604
-								. stringfy_vars(array_merge(
605
-															$this->config, 
606
-															array('password' => string_hidden($this->config['password']))
607
-												))
608
-							);
600
+            $this->databaseName = $config['database'];
601
+            $this->config = $config;
602
+            $this->logger->info(
603
+                                'The database configuration are listed below: ' 
604
+                                . stringfy_vars(array_merge(
605
+                                                            $this->config, 
606
+                                                            array('password' => string_hidden($this->config['password']))
607
+                                                ))
608
+                            );
609 609
 	  
610
-		 //Now connect to the database
611
-		 $this->connect();
610
+            //Now connect to the database
611
+            $this->connect();
612 612
 		 
613
-		 //update queryBuilder with some properties needed
614
-		 if(is_object($this->getQueryBuilder())){
615
-			  $this->getQueryBuilder()->setDriver($config['driver']);
616
-			  $this->getQueryBuilder()->setPrefix($config['prefix']);
617
-			  $this->getQueryBuilder()->setPdo($this->getPdo());
618
-		 }
619
-		 return $this;
620
-  }
613
+            //update queryBuilder with some properties needed
614
+            if(is_object($this->getQueryBuilder())){
615
+                $this->getQueryBuilder()->setDriver($config['driver']);
616
+                $this->getQueryBuilder()->setPrefix($config['prefix']);
617
+                $this->getQueryBuilder()->setPdo($this->getPdo());
618
+            }
619
+            return $this;
620
+    }
621 621
 	
622
-   /**
623
-   * Set the result for SELECT query using PDOStatment
624
-   * @see Database::query
625
-   */
622
+    /**
623
+     * Set the result for SELECT query using PDOStatment
624
+     * @see Database::query
625
+     */
626 626
     protected function setQueryResultForSelect($pdoStatment, $all, $array){
627
-      //if need return all result like list of record
628
-      if (is_bool($all) && $all){
629
-          $this->result = ($array === false) ? $pdoStatment->fetchAll(PDO::FETCH_OBJ) : $pdoStatment->fetchAll(PDO::FETCH_ASSOC);
630
-      }
631
-      else{
632
-          $this->result = ($array === false) ? $pdoStatment->fetch(PDO::FETCH_OBJ) : $pdoStatment->fetch(PDO::FETCH_ASSOC);
633
-      }
634
-      //Sqlite and pgsql always return 0 when using rowCount()
635
-      if (in_array($this->config['driver'], array('sqlite', 'pgsql'))){
627
+        //if need return all result like list of record
628
+        if (is_bool($all) && $all){
629
+            $this->result = ($array === false) ? $pdoStatment->fetchAll(PDO::FETCH_OBJ) : $pdoStatment->fetchAll(PDO::FETCH_ASSOC);
630
+        }
631
+        else{
632
+            $this->result = ($array === false) ? $pdoStatment->fetch(PDO::FETCH_OBJ) : $pdoStatment->fetch(PDO::FETCH_ASSOC);
633
+        }
634
+        //Sqlite and pgsql always return 0 when using rowCount()
635
+        if (in_array($this->config['driver'], array('sqlite', 'pgsql'))){
636 636
         $this->numRows = count($this->result);  
637
-      }
638
-      else{
637
+        }
638
+        else{
639 639
         $this->numRows = $pdoStatment->rowCount(); 
640
-      }
640
+        }
641 641
     }
642 642
 
643 643
     /**
@@ -645,15 +645,15 @@  discard block
 block discarded – undo
645 645
      * @see Database::query
646 646
      */
647 647
     protected function setQueryResultForNonSelect($pdoStatment){
648
-      //Sqlite and pgsql always return 0 when using rowCount()
649
-      if (in_array($this->config['driver'], array('sqlite', 'pgsql'))){
648
+        //Sqlite and pgsql always return 0 when using rowCount()
649
+        if (in_array($this->config['driver'], array('sqlite', 'pgsql'))){
650 650
         $this->result = true; //to test the result for the query like UPDATE, INSERT, DELETE
651 651
         $this->numRows = 1; //TODO use the correct method to get the exact affected row
652
-      }
653
-      else{
654
-          $this->result = $pdoStatment->rowCount() >= 0; //to test the result for the query like UPDATE, INSERT, DELETE
655
-          $this->numRows = $pdoStatment->rowCount(); 
656
-      }
652
+        }
653
+        else{
654
+            $this->result = $pdoStatment->rowCount() >= 0; //to test the result for the query like UPDATE, INSERT, DELETE
655
+            $this->numRows = $pdoStatment->rowCount(); 
656
+        }
657 657
     }
658 658
 
659 659
 	
@@ -663,8 +663,8 @@  discard block
 block discarded – undo
663 663
      * @return string the DSN string
664 664
      */
665 665
     protected function getDsnFromDriver(){
666
-      $config = $this->getDatabaseConfiguration();
667
-      if (! empty($config)){
666
+        $config = $this->getDatabaseConfiguration();
667
+        if (! empty($config)){
668 668
         $driver = $config['driver'];
669 669
         $driverDsnMap = array(
670 670
                                 'mysql' => 'mysql:host=' . $config['hostname'] . ';' 
@@ -677,30 +677,30 @@  discard block
 block discarded – undo
677 677
                                 'oracle' => 'oci:dbname=' . $config['hostname'] 
678 678
                                             . (($config['port']) != '' ? ':' . $config['port'] : '')
679 679
                                             . '/' . $config['database']
680
-                              );
680
+                                );
681 681
         return isset($driverDsnMap[$driver]) ? $driverDsnMap[$driver] : '';
682
-      }                   
683
-      return null;
682
+        }                   
683
+        return null;
684 684
     }
685 685
 
686
-     /**
687
-     * Transform the prepared query like (?, ?, ?) into string format
688
-     * @see Database::query
689
-     *
690
-     * @return string
691
-     */
686
+        /**
687
+         * Transform the prepared query like (?, ?, ?) into string format
688
+         * @see Database::query
689
+         *
690
+         * @return string
691
+         */
692 692
     protected function getPreparedQuery($query, $data){
693
-      if (is_array($data)){
694
-  			$x = explode('?', $query);
695
-  			$q = '';
696
-  			foreach($x as $k => $v){
697
-  			  if (! empty($v)){
698
-  				  $q .= $v . (isset($data[$k]) ? $this->escape($data[$k]) : '');
699
-  			  }
700
-  			}
701
-  			return $q;
702
-      }
703
-      return $query;
693
+        if (is_array($data)){
694
+                $x = explode('?', $query);
695
+                $q = '';
696
+                foreach($x as $k => $v){
697
+                if (! empty($v)){
698
+                    $q .= $v . (isset($data[$k]) ? $this->escape($data[$k]) : '');
699
+                }
700
+                }
701
+                return $q;
702
+        }
703
+        return $query;
704 704
     }
705 705
 
706 706
     /**
@@ -712,11 +712,11 @@  discard block
 block discarded – undo
712 712
     protected function getCacheContentForQuery($query, $all, $array){
713 713
         $cacheKey = $this->getCacheBenchmarkKeyForQuery($query, $all, $array);
714 714
         if (! is_object($this->getCacheInstance())){
715
-    			//can not call method with reference in argument
716
-    			//like $this->setCacheInstance(& get_instance()->cache);
717
-    			//use temporary variable
718
-    			$instance = & get_instance()->cache;
719
-    			$this->setCacheInstance($instance);
715
+                //can not call method with reference in argument
716
+                //like $this->setCacheInstance(& get_instance()->cache);
717
+                //use temporary variable
718
+                $instance = & get_instance()->cache;
719
+                $this->setCacheInstance($instance);
720 720
         }
721 721
         return $this->getCacheInstance()->get($cacheKey);
722 722
     }
@@ -729,91 +729,91 @@  discard block
 block discarded – undo
729 729
      * @param boolean $status whether can save the query result into cache
730 730
      * @param int $expire the cache TTL
731 731
      */
732
-     protected function setCacheContentForQuery($query, $key, $result, $status, $expire){
732
+        protected function setCacheContentForQuery($query, $key, $result, $status, $expire){
733 733
         if ($status){
734 734
             $this->logger->info('Save the result for query [' .$query. '] into cache for future use');
735 735
             if (! is_object($this->getCacheInstance())){
736
-      				//can not call method with reference in argument
737
-      				//like $this->setCacheInstance(& get_instance()->cache);
738
-      				//use temporary variable
739
-      				$instance = & get_instance()->cache;
740
-      				$this->setCacheInstance($instance);
741
-      			}
736
+                        //can not call method with reference in argument
737
+                        //like $this->setCacheInstance(& get_instance()->cache);
738
+                        //use temporary variable
739
+                        $instance = & get_instance()->cache;
740
+                        $this->setCacheInstance($instance);
741
+                    }
742 742
             $this->getCacheInstance()->set($key, $result, $expire);
743 743
         }
744
-     }
744
+        }
745 745
 
746 746
     
747 747
     /**
748 748
      * Set error for database query execution
749 749
      */
750 750
     protected function setQueryError(){
751
-      $error = $this->pdo->errorInfo();
752
-      $this->error = isset($error[2]) ? $error[2] : '';
753
-      $this->logger->error('The database query execution got error: ' . stringfy_vars($error));
754
-	    //show error message
755
-      $this->error();
756
-    }
757
-
758
-	  /**
759
-     * Return the cache key for the given query
760
-     * @see Database::query
761
-     * 
762
-     *  @return string
763
-     */
751
+        $error = $this->pdo->errorInfo();
752
+        $this->error = isset($error[2]) ? $error[2] : '';
753
+        $this->logger->error('The database query execution got error: ' . stringfy_vars($error));
754
+        //show error message
755
+        $this->error();
756
+    }
757
+
758
+        /**
759
+         * Return the cache key for the given query
760
+         * @see Database::query
761
+         * 
762
+         *  @return string
763
+         */
764 764
     protected function getCacheBenchmarkKeyForQuery($query, $all, $array){
765
-      if (is_array($all)){
765
+        if (is_array($all)){
766 766
         $all = 'array';
767
-      }
768
-      return md5($query . $all . $array);
767
+        }
768
+        return md5($query . $all . $array);
769 769
     }
770 770
     
771
-	   /**
772
-     * Set the Log instance using argument or create new instance
773
-     * @param object $logger the Log instance if not null
774
-     */
771
+        /**
772
+         * Set the Log instance using argument or create new instance
773
+         * @param object $logger the Log instance if not null
774
+         */
775 775
     protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
776
-      if ($logger !== null){
776
+        if ($logger !== null){
777 777
         $this->setLogger($logger);
778
-      }
779
-      else{
780
-          $this->logger =& class_loader('Log', 'classes');
781
-          $this->logger->setLogger('Library::Database');
782
-      }
778
+        }
779
+        else{
780
+            $this->logger =& class_loader('Log', 'classes');
781
+            $this->logger->setLogger('Library::Database');
782
+        }
783 783
     }
784 784
 	
785
-   /**
786
-   * Set the DatabaseQueryBuilder instance using argument or create new instance
787
-   * @param object $queryBuilder the DatabaseQueryBuilder instance if not null
788
-   */
789
-	protected function setQueryBuilderFromParamOrCreateNewInstance(DatabaseQueryBuilder $queryBuilder = null){
790
-	  if ($queryBuilder !== null){
791
-      $this->setQueryBuilder($queryBuilder);
792
-	  }
793
-	  else{
794
-		  $this->queryBuilder =& class_loader('DatabaseQueryBuilder', 'classes');
795
-	  }
796
-	}
785
+    /**
786
+     * Set the DatabaseQueryBuilder instance using argument or create new instance
787
+     * @param object $queryBuilder the DatabaseQueryBuilder instance if not null
788
+     */
789
+    protected function setQueryBuilderFromParamOrCreateNewInstance(DatabaseQueryBuilder $queryBuilder = null){
790
+        if ($queryBuilder !== null){
791
+        $this->setQueryBuilder($queryBuilder);
792
+        }
793
+        else{
794
+            $this->queryBuilder =& class_loader('DatabaseQueryBuilder', 'classes');
795
+        }
796
+    }
797 797
 
798 798
     /**
799 799
      * Reset the database class attributs to the initail values before each query.
800 800
      */
801 801
     private function reset(){
802
-	   //query builder reset
803
-      $this->getQueryBuilder()->reset();
804
-      $this->numRows  = 0;
805
-      $this->insertId = null;
806
-      $this->query    = null;
807
-      $this->error    = null;
808
-      $this->result   = array();
809
-      $this->data     = array();
802
+        //query builder reset
803
+        $this->getQueryBuilder()->reset();
804
+        $this->numRows  = 0;
805
+        $this->insertId = null;
806
+        $this->query    = null;
807
+        $this->error    = null;
808
+        $this->result   = array();
809
+        $this->data     = array();
810 810
     }
811 811
 
812 812
     /**
813 813
      * The class destructor
814 814
      */
815 815
     public function __destruct(){
816
-      $this->pdo = null;
816
+        $this->pdo = null;
817 817
     }
818 818
 
819 819
 }
Please login to merge, or discard this patch.
core/functions/function_lang.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -1,52 +1,52 @@
 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
-	if(! function_exists('__')){
28
-		/**
29
-		 * function for the shortcut to Lang::get()
30
-		 * @param  string $key the language key to retrieve
31
-		 * @param mixed $default the default value to return if can not find the value
32
-		 * for the given key
33
-		 * @return string  the language value
34
-		 */
35
-		function __($key, $default = 'LANGUAGE_ERROR'){
36
-			return get_instance()->lang->get($key, $default);
37
-		}
27
+    if(! function_exists('__')){
28
+        /**
29
+         * function for the shortcut to Lang::get()
30
+         * @param  string $key the language key to retrieve
31
+         * @param mixed $default the default value to return if can not find the value
32
+         * for the given key
33
+         * @return string  the language value
34
+         */
35
+        function __($key, $default = 'LANGUAGE_ERROR'){
36
+            return get_instance()->lang->get($key, $default);
37
+        }
38 38
 
39
-	}
39
+    }
40 40
 
41 41
 
42
-	if(! function_exists('get_languages')){
43
-		/**
44
-		 * function for the shortcut to Lang::getSupported()
45
-		 * 
46
-		 * @return array all the supported languages
47
-		 */
48
-		function get_languages(){
49
-			return get_instance()->lang->getSupported();
50
-		}
42
+    if(! function_exists('get_languages')){
43
+        /**
44
+         * function for the shortcut to Lang::getSupported()
45
+         * 
46
+         * @return array all the supported languages
47
+         */
48
+        function get_languages(){
49
+            return get_instance()->lang->getSupported();
50
+        }
51 51
 
52
-	}
53 52
\ No newline at end of file
53
+    }
54 54
\ No newline at end of file
Please login to merge, or discard this patch.
core/functions/function_user_agent.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -1,78 +1,78 @@
 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 = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
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 = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
55 55
 
56
-			if (isset($_SERVER["HTTP_CLIENT_IP"])) {
57
-				$ip = $_SERVER["HTTP_CLIENT_IP"];
58
-			}
59
-			else if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
60
-				$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
61
-			} 
62
-			else if (isset($_SERVER["HTTP_X_FORWARDED"])) {
63
-				$ip = $_SERVER["HTTP_X_FORWARDED"];
64
-			} 
65
-			else if (isset($_SERVER["HTTP_FORWARDED_FOR"])) {
66
-				$ip = $_SERVER["HTTP_FORWARDED_FOR"];
67
-			} 
68
-			else if (isset($_SERVER["HTTP_FORWARDED"])) {
69
-				$ip = $_SERVER["HTTP_FORWARDED"];
70
-			} 
56
+            if (isset($_SERVER["HTTP_CLIENT_IP"])) {
57
+                $ip = $_SERVER["HTTP_CLIENT_IP"];
58
+            }
59
+            else if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
60
+                $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
61
+            } 
62
+            else if (isset($_SERVER["HTTP_X_FORWARDED"])) {
63
+                $ip = $_SERVER["HTTP_X_FORWARDED"];
64
+            } 
65
+            else if (isset($_SERVER["HTTP_FORWARDED_FOR"])) {
66
+                $ip = $_SERVER["HTTP_FORWARDED_FOR"];
67
+            } 
68
+            else if (isset($_SERVER["HTTP_FORWARDED"])) {
69
+                $ip = $_SERVER["HTTP_FORWARDED"];
70
+            } 
71 71
 
72
-			// Strip any secondary IP etc from the IP address
73
-			if (strpos($ip, ',') > 0) {
74
-				$ip = substr($ip, 0, strpos($ip, ','));
75
-			}
76
-			return $ip;
77
-		}
78
-	}
72
+            // Strip any secondary IP etc from the IP address
73
+            if (strpos($ip, ',') > 0) {
74
+                $ip = substr($ip, 0, strpos($ip, ','));
75
+            }
76
+            return $ip;
77
+        }
78
+    }
Please login to merge, or discard this patch.
core/functions/function_string.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -1,74 +1,74 @@
 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 function_string.php
29
-	 *
30
-	 *  This file contains the definition of the functions relating to the processing of strings characters.
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
-	 */
27
+    /**
28
+     *  @file function_string.php
29
+     *
30
+     *  This file contains the definition of the functions relating to the processing of strings characters.
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 41
 
42
-	if(! function_exists('get_random_string')){
43
-		/**
44
-		 * Generate a random string
45
-		 * @param  string $type the type of generation. It can take the values: "alpha" for alphabetic characters,
46
-		 * "alnum" for alpha-numeric characters and "num" for numbers.
47
-		 * By default it is "alnum".
48
-		 * @param  integer $length the length of the string to generate. By default it is 10.
49
-		 * @param  boolean $lower if we return the generated string in lowercase (true). By default it's false.
50
-		 * @return string the generated string.
51
-		 */
52
-		function get_random_string($type = 'alnum', $length = 10, $lower = false){
53
-			$str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
54
-			switch($type){
55
-				case 'alpha':
56
-					$str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
57
-				break;
58
-				case 'alnum':
59
-					$str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
60
-				break;
61
-				case 'num':
62
-					$str = '1234567890';
63
-				break;
64
-			}
65
-			$random = null;
66
-			for($i = 0; $i < $length; $i++){
67
-				$random .= $str[mt_rand() % strlen($str)];
68
-			}
69
-			if($lower){
70
-				$random = strtolower($random);
71
-			}
72
-			return $random;
73
-		}
74
-	}
42
+    if(! function_exists('get_random_string')){
43
+        /**
44
+         * Generate a random string
45
+         * @param  string $type the type of generation. It can take the values: "alpha" for alphabetic characters,
46
+         * "alnum" for alpha-numeric characters and "num" for numbers.
47
+         * By default it is "alnum".
48
+         * @param  integer $length the length of the string to generate. By default it is 10.
49
+         * @param  boolean $lower if we return the generated string in lowercase (true). By default it's false.
50
+         * @return string the generated string.
51
+         */
52
+        function get_random_string($type = 'alnum', $length = 10, $lower = false){
53
+            $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
54
+            switch($type){
55
+                case 'alpha':
56
+                    $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
57
+                break;
58
+                case 'alnum':
59
+                    $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
60
+                break;
61
+                case 'num':
62
+                    $str = '1234567890';
63
+                break;
64
+            }
65
+            $random = null;
66
+            for($i = 0; $i < $length; $i++){
67
+                $random .= $str[mt_rand() % strlen($str)];
68
+            }
69
+            if($lower){
70
+                $random = strtolower($random);
71
+            }
72
+            return $random;
73
+        }
74
+    }
Please login to merge, or discard this patch.
core/libraries/Email.php 1 patch
Indentation   +730 added lines, -730 removed lines patch added patch discarded remove patch
@@ -1,739 +1,739 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * Simple Mail
5
-	 *
6
-	 * A simple PHP wrapper class for sending email using the mail() method.
7
-	 *
8
-	 * PHP version > 5.2
9
-	 *
10
-	 * LICENSE: This source file is subject to the MIT license, which is
11
-	 * available through the world-wide-web at the following URI:
12
-	 * http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt
13
-	 *
14
-	 * @category  SimpleMail
15
-	 * @package   SimpleMail
16
-	 * @author    Eoghan O'Brien <[email protected]>
17
-	 * @copyright 2009 - 2017 Eoghan O'Brien
18
-	 * @license   http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT
19
-	 * @version   1.7.1
20
-	 * @link      http://github.com/eoghanobrien/php-simple-mail
21
-	 */
22
-
23
-	/**
24
-	 * Simple Mail class.
25
-	 *
26
-	 * @category  SimpleMail
27
-	 * @package   SimpleMail
28
-	 * @author    Eoghan O'Brien <[email protected]>
29
-	 * @copyright 2009 - 2017 Eoghan O'Brien
30
-	 * @license   http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT
31
-	 * @version   1.7.1
32
-	 * @link      http://github.com/eoghanobrien/php-simple-mail
33
-	 */
34
-	class Email
35
-	{
36
-		/**
37
-		 * @var int $_wrap
38
-		 */
39
-		protected $_wrap = 78;
40
-
41
-		/**
42
-		 * @var array $_to
43
-		 */
44
-		protected $_to = array();
45
-
46
-		/**
47
-		 * @var string $_subject
48
-		 */
49
-		protected $_subject;
50
-
51
-		/**
52
-		 * @var string $_message
53
-		 */
54
-		protected $_message;
55
-
56
-		/**
57
-		 * @var array $_headers
58
-		 */
59
-		protected $_headers = array();
60
-
61
-		/**
62
-		 * @var string $_parameters
63
-		 */
64
-		protected $_params;
65
-
66
-		/**
67
-		 * @var array $_attachments
68
-		 */
69
-		protected $_attachments = array();
70
-
71
-		/**
72
-		 * @var string $_uid
73
-		 */
74
-		protected $_uid;
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * Simple Mail
5
+     *
6
+     * A simple PHP wrapper class for sending email using the mail() method.
7
+     *
8
+     * PHP version > 5.2
9
+     *
10
+     * LICENSE: This source file is subject to the MIT license, which is
11
+     * available through the world-wide-web at the following URI:
12
+     * http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt
13
+     *
14
+     * @category  SimpleMail
15
+     * @package   SimpleMail
16
+     * @author    Eoghan O'Brien <[email protected]>
17
+     * @copyright 2009 - 2017 Eoghan O'Brien
18
+     * @license   http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT
19
+     * @version   1.7.1
20
+     * @link      http://github.com/eoghanobrien/php-simple-mail
21
+     */
22
+
23
+    /**
24
+     * Simple Mail class.
25
+     *
26
+     * @category  SimpleMail
27
+     * @package   SimpleMail
28
+     * @author    Eoghan O'Brien <[email protected]>
29
+     * @copyright 2009 - 2017 Eoghan O'Brien
30
+     * @license   http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT
31
+     * @version   1.7.1
32
+     * @link      http://github.com/eoghanobrien/php-simple-mail
33
+     */
34
+    class Email
35
+    {
36
+        /**
37
+         * @var int $_wrap
38
+         */
39
+        protected $_wrap = 78;
40
+
41
+        /**
42
+         * @var array $_to
43
+         */
44
+        protected $_to = array();
45
+
46
+        /**
47
+         * @var string $_subject
48
+         */
49
+        protected $_subject;
50
+
51
+        /**
52
+         * @var string $_message
53
+         */
54
+        protected $_message;
55
+
56
+        /**
57
+         * @var array $_headers
58
+         */
59
+        protected $_headers = array();
60
+
61
+        /**
62
+         * @var string $_parameters
63
+         */
64
+        protected $_params;
65
+
66
+        /**
67
+         * @var array $_attachments
68
+         */
69
+        protected $_attachments = array();
70
+
71
+        /**
72
+         * @var string $_uid
73
+         */
74
+        protected $_uid;
75 75
 		
76
-		/**
76
+        /**
77 77
          * The logger instance
78 78
          * @var Log
79 79
          */
80
-		private $logger;
80
+        private $logger;
81 81
 
82
-		/**
83
-		 * __construct
84
-		 *
85
-		 * Resets the class properties.
86
-		 */
87
-		public function __construct()
88
-		{
89
-			$this->logger =& class_loader('Log', 'classes');
82
+        /**
83
+         * __construct
84
+         *
85
+         * Resets the class properties.
86
+         */
87
+        public function __construct()
88
+        {
89
+            $this->logger =& class_loader('Log', 'classes');
90 90
             $this->logger->setLogger('Library::Email');
91
-			$this->reset();
92
-		}
93
-
94
-		/**
95
-		 * reset
96
-		 *
97
-		 * Resets all properties to initial state.
98
-		 *
99
-		 * @return self
100
-		 */
101
-		public function reset()
102
-		{
103
-			$this->_to = array();
104
-			$this->_headers = array();
105
-			$this->_subject = null;
106
-			$this->_message = null;
107
-			$this->_wrap = 78;
108
-			$this->_params = null;
109
-			$this->_attachments = array();
110
-			$this->_uid = $this->getUniqueId();
111
-			return $this;
112
-		}
91
+            $this->reset();
92
+        }
93
+
94
+        /**
95
+         * reset
96
+         *
97
+         * Resets all properties to initial state.
98
+         *
99
+         * @return self
100
+         */
101
+        public function reset()
102
+        {
103
+            $this->_to = array();
104
+            $this->_headers = array();
105
+            $this->_subject = null;
106
+            $this->_message = null;
107
+            $this->_wrap = 78;
108
+            $this->_params = null;
109
+            $this->_attachments = array();
110
+            $this->_uid = $this->getUniqueId();
111
+            return $this;
112
+        }
113 113
 		
114
-		 /**
115
-		 * setFrom
116
-		 *
117
-		 * @param string $email The email to send as from.
118
-		 * @param string $name  The name to send as from.
119
-		 *
120
-		 * @return self
121
-		 */
122
-		public function setFrom($email, $name = null)
123
-		{
124
-			$this->addMailHeader('From', (string) $email, (string) $name);
125
-			return $this;
126
-		}
127
-
128
-		/**
129
-		 * setTo
130
-		 *
131
-		 * @param string $email The email address to send to.
132
-		 * @param string $name  The name of the person to send to.
133
-		 *
134
-		 * @return self
135
-		 */
136
-		public function setTo($email, $name = null)
137
-		{
138
-			$this->_to[] = $this->formatHeader((string) $email, (string) $name);
139
-			return $this;
140
-		}
114
+            /**
115
+             * setFrom
116
+             *
117
+             * @param string $email The email to send as from.
118
+             * @param string $name  The name to send as from.
119
+             *
120
+             * @return self
121
+             */
122
+        public function setFrom($email, $name = null)
123
+        {
124
+            $this->addMailHeader('From', (string) $email, (string) $name);
125
+            return $this;
126
+        }
127
+
128
+        /**
129
+         * setTo
130
+         *
131
+         * @param string $email The email address to send to.
132
+         * @param string $name  The name of the person to send to.
133
+         *
134
+         * @return self
135
+         */
136
+        public function setTo($email, $name = null)
137
+        {
138
+            $this->_to[] = $this->formatHeader((string) $email, (string) $name);
139
+            return $this;
140
+        }
141 141
 		
142
-		/**
143
-		* Set destination using array
144
-		* @params array $emails the list of recipient. This is an associative array name => email
145
-		* @example array('John Doe' => '[email protected]')
146
-		* @return Object the current instance
147
-		*/
148
-		public function setTos(array $emails)
149
-		{
150
-			foreach ($emails as $name => $email) {
151
-				if(is_numeric($name)){
152
-					$this->setTo($email);
153
-				}
154
-				else{
155
-					$this->setTo($email, $name);
156
-				}
157
-			}
158
-			return $this;
159
-		}
160
-
161
-
162
-		/**
163
-		 * getTo
164
-		 *
165
-		 * Return an array of formatted To addresses.
166
-		 *
167
-		 * @return array
168
-		 */
169
-		public function getTo()
170
-		{
171
-			return $this->_to;
172
-		}
173
-
174
-
175
-		/**
176
-		 * setCc
177
-		 *
178
-		 * @param array  $pairs  An array of name => email pairs.
179
-		 *
180
-		 * @return self
181
-		 */
182
-		public function setCc(array $pairs)
183
-		{
184
-			return $this->addMailHeaders('Cc', $pairs);
185
-		}
186
-
187
-		/**
188
-		 * setBcc
189
-		 *
190
-		 * @param array  $pairs  An array of name => email pairs.
191
-		 *
192
-		 * @return self
193
-		 */
194
-		public function setBcc(array $pairs)
195
-		{
196
-			return $this->addMailHeaders('Bcc', $pairs);
197
-		}
198
-
199
-		/**
200
-		 * setReplyTo
201
-		 *
202
-		 * @param string $email
203
-		 * @param string $name
204
-		 *
205
-		 * @return self
206
-		 */
207
-		public function setReplyTo($email, $name = null)
208
-		{
209
-			return $this->addMailHeader('Reply-To', $email, $name);
210
-		}
211
-
212
-		/**
213
-		 * setHtml
214
-		 *
215
-		 * @return self
216
-		 */
217
-		public function setHtml()
218
-		{
219
-			$this->addGenericHeader(
220
-				'Content-Type', 'text/html; charset="utf-8"'
221
-			);
222
-			return $this;
223
-		}
224
-
225
-		/**
226
-		 * setSubject
227
-		 *
228
-		 * @param string $subject The email subject
229
-		 *
230
-		 * @return self
231
-		 */
232
-		public function setSubject($subject)
233
-		{
234
-			$this->_subject = $this->encodeUtf8(
235
-				$this->filterOther((string) $subject)
236
-			);
237
-			return $this;
238
-		}
239
-
240
-		/**
241
-		 * getSubject function.
242
-		 *
243
-		 * @return string
244
-		 */
245
-		public function getSubject()
246
-		{
247
-			return $this->_subject;
248
-		}
249
-
250
-		/**
251
-		 * setMessage
252
-		 *
253
-		 * @param string $message The message to send.
254
-		 *
255
-		 * @return self
256
-		 */
257
-		public function setMessage($message)
258
-		{
259
-			$this->_message = str_replace("\n.", "\n..", (string) $message);
260
-			return $this;
261
-		}
262
-
263
-		/**
264
-		 * getMessage
265
-		 *
266
-		 * @return string
267
-		 */
268
-		public function getMessage()
269
-		{
270
-			return $this->_message;
271
-		}
272
-
273
-		/**
274
-		 * addAttachment
275
-		 *
276
-		 * @param string $path The file path to the attachment.
277
-		 * @param string $filename The filename of the attachment when emailed.
278
-		 * @param string $data
279
-		 * 
280
-		 * @return self
281
-		 */
282
-		public function addAttachment($path, $filename = null, $data = null)
283
-		{
284
-			if(! file_exists($path)){
285
-				show_error('The file [' .$path. '] does not exists.');
286
-			}
287
-			$filename = empty($filename) ? basename($path) : $filename;
288
-			$filename = $this->encodeUtf8($this->filterOther((string) $filename));
289
-			$data = empty($data) ? $this->getAttachmentData($path) : $data;
290
-			$this->_attachments[] = array(
291
-				'path' => $path,
292
-				'file' => $filename,
293
-				'data' => chunk_split(base64_encode($data))
294
-			);
295
-			return $this;
296
-		}
297
-
298
-		/**
299
-		 * getAttachmentData
300
-		 *
301
-		 * @param string $path The path to the attachment file.
302
-		 *
303
-		 * @return string
304
-		 */
305
-		public function getAttachmentData($path)
306
-		{
307
-			if(! file_exists($path)){
308
-				show_error('The file [' .$path. '] does not exists.');
309
-			}
310
-			$filesize = filesize($path);
311
-			$handle = fopen($path, "r");
312
-			$attachment = null;
313
-			if(is_resource($handle)){
314
-				$attachment = fread($handle, $filesize);
315
-				fclose($handle);
316
-			}
317
-			return $attachment;
318
-		}
319
-
320
-		/**
321
-		 * addMailHeader
322
-		 *
323
-		 * @param string $header The header to add.
324
-		 * @param string $email  The email to add.
325
-		 * @param string $name   The name to add.
326
-		 *
327
-		 * @return self
328
-		 */
329
-		public function addMailHeader($header, $email, $name = null)
330
-		{
331
-			$address = $this->formatHeader((string) $email, (string) $name);
332
-			$this->_headers[] = sprintf('%s: %s', (string) $header, $address);
333
-			return $this;
334
-		}
335
-
336
-		/**
337
-		 * addMailHeaders
338
-		 *
339
-		 * @param string $header The header to add.
340
-		 * @param array  $pairs  An array of name => email pairs.
341
-		 *
342
-		 * @return self
343
-		 */
344
-		public function addMailHeaders($header, array $pairs)
345
-		{
346
-			if (count($pairs) === 0) {
347
-				show_error('You must pass at least one name => email pair.');
348
-			}
349
-			$addresses = array();
350
-			foreach ($pairs as $name => $email) {
351
-				$name = is_numeric($name) ? null : $name;
352
-				$addresses[] = $this->formatHeader($email, $name);
353
-			}
354
-			$this->addGenericHeader($header, implode(',', $addresses));
355
-			return $this;
356
-		}
357
-
358
-		/**
359
-		 * addGenericHeader
360
-		 *
361
-		 * @param string $name The generic header to add.
362
-		 * @param mixed  $value  The value of the header.
363
-		 *
364
-		 * @return self
365
-		 */
366
-		public function addGenericHeader($name, $value)
367
-		{
368
-			$this->_headers[] = sprintf(
369
-				'%s: %s',
370
-				(string) $name,
371
-				(string) $value
372
-			);
373
-			return $this;
374
-		}
375
-
376
-		/**
377
-		 * getHeaders
378
-		 *
379
-		 * Return the headers registered so far as an array.
380
-		 *
381
-		 * @return array
382
-		 */
383
-		public function getHeaders()
384
-		{
385
-			return $this->_headers;
386
-		}
387
-
388
-		/**
389
-		 * setAdditionalParameters
390
-		 *
391
-		 * Such as "[email protected]
392
-		 *
393
-		 * @param string $additionalParameters The addition mail parameter.
394
-		 *
395
-		 * @return self
396
-		 */
397
-		public function setParameters($additionalParameters)
398
-		{
399
-			$this->_params = (string) $additionalParameters;
400
-			return $this;
401
-		}
402
-
403
-		/**
404
-		 * getAdditionalParameters
405
-		 *
406
-		 * @return string
407
-		 */
408
-		public function getParameters()
409
-		{
410
-			return $this->_params;
411
-		}
412
-
413
-		/**
414
-		 * setWrap
415
-		 *
416
-		 * @param int $wrap The number of characters at which the message will wrap.
417
-		 *
418
-		 * @return self
419
-		 */
420
-		public function setWrap($wrap = 78)
421
-		{
422
-			$wrap = (int) $wrap;
423
-			if ($wrap < 1) {
424
-				$wrap = 78;
425
-			}
426
-			$this->_wrap = $wrap;
427
-			return $this;
428
-		}
429
-
430
-		/**
431
-		 * getWrap
432
-		 *
433
-		 * @return int
434
-		 */
435
-		public function getWrap()
436
-		{
437
-			return $this->_wrap;
438
-		}
439
-
440
-		/**
441
-		 * hasAttachments
442
-		 * 
443
-		 * Checks if the email has any registered attachments.
444
-		 *
445
-		 * @return bool
446
-		 */
447
-		public function hasAttachments()
448
-		{
449
-			return !empty($this->_attachments);
450
-		}
451
-
452
-		/**
453
-		 * assembleAttachment
454
-		 *
455
-		 * @return string
456
-		 */
457
-		public function assembleAttachmentHeaders()
458
-		{
459
-			$head = array();
460
-			$head[] = "MIME-Version: 1.0";
461
-			$head[] = "Content-Type: multipart/mixed; boundary=\"{$this->_uid}\"";
462
-
463
-			return join(PHP_EOL, $head);
464
-		}
465
-
466
-		/**
467
-		 * assembleAttachmentBody
468
-		 *
469
-		 * @return string
470
-		 */
471
-		public function assembleAttachmentBody()
472
-		{
473
-			$body = array();
474
-			$body[] = "This is a multi-part message in MIME format.";
475
-			$body[] = "--{$this->_uid}";
476
-			$body[] = "Content-Type: text/html; charset=\"utf-8\"";
477
-			$body[] = "Content-Transfer-Encoding: quoted-printable";
478
-			$body[] = "";
479
-			$body[] = quoted_printable_encode($this->_message);
480
-			$body[] = "";
481
-			$body[] = "--{$this->_uid}";
482
-
483
-			foreach ($this->_attachments as $attachment) {
484
-				$body[] = $this->getAttachmentMimeTemplate($attachment);
485
-			}
486
-
487
-			return implode(PHP_EOL, $body) . '--';
488
-		}
489
-
490
-		/**
491
-		 * getAttachmentMimeTemplate
492
-		 *
493
-		 * @param array  $attachment An array containing 'file' and 'data' keys.
494
-		 *
495
-		 * @return string
496
-		 */
497
-		public function getAttachmentMimeTemplate($attachment)
498
-		{
499
-			$file = $attachment['file'];
500
-			$data = $attachment['data'];
501
-
502
-			$head = array();
503
-			$head[] = "Content-Type: application/octet-stream; name=\"{$file}\"";
504
-			$head[] = "Content-Transfer-Encoding: base64";
505
-			$head[] = "Content-Disposition: attachment; filename=\"{$file}\"";
506
-			$head[] = "";
507
-			$head[] = $data;
508
-			$head[] = "";
509
-			$head[] = "--{$this->_uid}";
510
-
511
-			return implode(PHP_EOL, $head);
512
-		}
513
-
514
-		/**
515
-		 * send the email
516
-		 *
517
-		 * @return boolean
518
-		 */
519
-		public function send()
520
-		{
521
-			$to = $this->getToForSend();
522
-			$headers = $this->getHeadersForSend();
523
-
524
-			if (empty($to)) {
525
-				show_error('Unable to send, no To address has been set.');
526
-			}
527
-
528
-			if ($this->hasAttachments()) {
529
-				$message  = $this->assembleAttachmentBody();
530
-				$headers .= PHP_EOL . $this->assembleAttachmentHeaders();
531
-			} else {
532
-				$message = $this->getWrapMessage();
533
-			}
534
-			$this->logger->info('Sending new mail, the information are listed below: destination: ' . $to . ', headers: ' . $headers . ', message: ' . $message);
535
-			return mail($to, $this->_subject, $message, $headers, $this->_params);
536
-		}
537
-
538
-		/**
539
-		 * debug
540
-		 *
541
-		 * @return string
542
-		 */
543
-		public function debug()
544
-		{
545
-			return '<pre>' . print_r($this, true) . '</pre>';
546
-		}
547
-
548
-		/**
549
-		 * magic __toString function
550
-		 *
551
-		 * @return string
552
-		 */
553
-		public function __toString()
554
-		{
555
-			return print_r($this, true);
556
-		}
557
-
558
-		/**
559
-		 * formatHeader
560
-		 *
561
-		 * Formats a display address for emails according to RFC2822 e.g.
562
-		 * Name <[email protected]>
563
-		 *
564
-		 * @param string $email The email address.
565
-		 * @param string $name  The display name.
566
-		 *
567
-		 * @return string
568
-		 */
569
-		public function formatHeader($email, $name = null)
570
-		{
571
-			$email = $this->filterEmail((string) $email);
572
-			if (empty($name)) {
573
-				return $email;
574
-			}
575
-			$name = $this->encodeUtf8($this->filterName((string) $name));
576
-			return sprintf('"%s" <%s>', $name, $email);
577
-		}
578
-
579
-		/**
580
-		 * encodeUtf8
581
-		 *
582
-		 * @param string $value The value to encode.
583
-		 *
584
-		 * @return string
585
-		 */
586
-		public function encodeUtf8($value)
587
-		{
588
-			$value = trim($value);
589
-			if (preg_match('/(\s)/', $value)) {
590
-				return $this->encodeUtf8Words($value);
591
-			}
592
-			return $this->encodeUtf8Word($value);
593
-		}
594
-
595
-		/**
596
-		 * encodeUtf8Word
597
-		 *
598
-		 * @param string $value The word to encode.
599
-		 *
600
-		 * @return string
601
-		 */
602
-		public function encodeUtf8Word($value)
603
-		{
604
-			return sprintf('=?UTF-8?B?%s?=', base64_encode($value));
605
-		}
606
-
607
-		/**
608
-		 * encodeUtf8Words
609
-		 *
610
-		 * @param string $value The words to encode.
611
-		 *
612
-		 * @return string
613
-		 */
614
-		public function encodeUtf8Words($value)
615
-		{
616
-			$words = explode(' ', $value);
617
-			$encoded = array();
618
-			foreach ($words as $word) {
619
-				$encoded[] = $this->encodeUtf8Word($word);
620
-			}
621
-			return join($this->encodeUtf8Word(' '), $encoded);
622
-		}
623
-
624
-		/**
625
-		 * filterEmail
626
-		 *
627
-		 * Removes any carriage return, line feed, tab, double quote, comma
628
-		 * and angle bracket characters before sanitizing the email address.
629
-		 *
630
-		 * @param string $email The email to filter.
631
-		 *
632
-		 * @return string
633
-		 */
634
-		public function filterEmail($email)
635
-		{
636
-			$rule = array(
637
-				"\r" => '',
638
-				"\n" => '',
639
-				"\t" => '',
640
-				'"'  => '',
641
-				','  => '',
642
-				'<'  => '',
643
-				'>'  => ''
644
-			);
645
-			$email = strtr($email, $rule);
646
-			$email = filter_var($email, FILTER_SANITIZE_EMAIL);
647
-			return $email;
648
-		}
649
-
650
-		/**
651
-		 * filterName
652
-		 *
653
-		 * Removes any carriage return, line feed or tab characters. Replaces
654
-		 * double quotes with single quotes and angle brackets with square
655
-		 * brackets, before sanitizing the string and stripping out html tags.
656
-		 *
657
-		 * @param string $name The name to filter.
658
-		 *
659
-		 * @return string
660
-		 */
661
-		public function filterName($name)
662
-		{
663
-			$rule = array(
664
-				"\r" => '',
665
-				"\n" => '',
666
-				"\t" => '',
667
-				'"'  => "'",
668
-				'<'  => '[',
669
-				'>'  => ']',
670
-			);
671
-			$filtered = filter_var(
672
-				$name,
673
-				FILTER_SANITIZE_STRING,
674
-				FILTER_FLAG_NO_ENCODE_QUOTES
675
-			);
676
-			return trim(strtr($filtered, $rule));
677
-		}
678
-
679
-		/**
680
-		 * filterOther
681
-		 *
682
-		 * Removes ASCII control characters including any carriage return, line
683
-		 * feed or tab characters.
684
-		 *
685
-		 * @param string $data The data to filter.
686
-		 *
687
-		 * @return string
688
-		 */
689
-		public function filterOther($data)
690
-		{
691
-			return filter_var($data, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
692
-		}
693
-
694
-		/**
695
-		 * getHeadersForSend
696
-		 *
697
-		 * @return string
698
-		 */
699
-		public function getHeadersForSend()
700
-		{
701
-			if (empty($this->_headers)) {
702
-				return '';
703
-			}
704
-			return join(PHP_EOL, $this->_headers);
705
-		}
706
-
707
-		/**
708
-		 * getToForSend
709
-		 *
710
-		 * @return string
711
-		 */
712
-		public function getToForSend()
713
-		{
714
-			if (empty($this->_to)) {
715
-				return '';
716
-			}
717
-			return join(', ', $this->_to);
718
-		}
719
-
720
-		/**
721
-		 * getUniqueId
722
-		 *
723
-		 * @return string
724
-		 */
725
-		public function getUniqueId()
726
-		{
727
-			return md5(uniqid(time()));
728
-		}
729
-
730
-		/**
731
-		 * getWrapMessage
732
-		 *
733
-		 * @return string
734
-		 */
735
-		public function getWrapMessage()
736
-		{
737
-			return wordwrap($this->_message, $this->_wrap);
738
-		}
739
-	}
142
+        /**
143
+         * Set destination using array
144
+         * @params array $emails the list of recipient. This is an associative array name => email
145
+         * @example array('John Doe' => '[email protected]')
146
+         * @return Object the current instance
147
+         */
148
+        public function setTos(array $emails)
149
+        {
150
+            foreach ($emails as $name => $email) {
151
+                if(is_numeric($name)){
152
+                    $this->setTo($email);
153
+                }
154
+                else{
155
+                    $this->setTo($email, $name);
156
+                }
157
+            }
158
+            return $this;
159
+        }
160
+
161
+
162
+        /**
163
+         * getTo
164
+         *
165
+         * Return an array of formatted To addresses.
166
+         *
167
+         * @return array
168
+         */
169
+        public function getTo()
170
+        {
171
+            return $this->_to;
172
+        }
173
+
174
+
175
+        /**
176
+         * setCc
177
+         *
178
+         * @param array  $pairs  An array of name => email pairs.
179
+         *
180
+         * @return self
181
+         */
182
+        public function setCc(array $pairs)
183
+        {
184
+            return $this->addMailHeaders('Cc', $pairs);
185
+        }
186
+
187
+        /**
188
+         * setBcc
189
+         *
190
+         * @param array  $pairs  An array of name => email pairs.
191
+         *
192
+         * @return self
193
+         */
194
+        public function setBcc(array $pairs)
195
+        {
196
+            return $this->addMailHeaders('Bcc', $pairs);
197
+        }
198
+
199
+        /**
200
+         * setReplyTo
201
+         *
202
+         * @param string $email
203
+         * @param string $name
204
+         *
205
+         * @return self
206
+         */
207
+        public function setReplyTo($email, $name = null)
208
+        {
209
+            return $this->addMailHeader('Reply-To', $email, $name);
210
+        }
211
+
212
+        /**
213
+         * setHtml
214
+         *
215
+         * @return self
216
+         */
217
+        public function setHtml()
218
+        {
219
+            $this->addGenericHeader(
220
+                'Content-Type', 'text/html; charset="utf-8"'
221
+            );
222
+            return $this;
223
+        }
224
+
225
+        /**
226
+         * setSubject
227
+         *
228
+         * @param string $subject The email subject
229
+         *
230
+         * @return self
231
+         */
232
+        public function setSubject($subject)
233
+        {
234
+            $this->_subject = $this->encodeUtf8(
235
+                $this->filterOther((string) $subject)
236
+            );
237
+            return $this;
238
+        }
239
+
240
+        /**
241
+         * getSubject function.
242
+         *
243
+         * @return string
244
+         */
245
+        public function getSubject()
246
+        {
247
+            return $this->_subject;
248
+        }
249
+
250
+        /**
251
+         * setMessage
252
+         *
253
+         * @param string $message The message to send.
254
+         *
255
+         * @return self
256
+         */
257
+        public function setMessage($message)
258
+        {
259
+            $this->_message = str_replace("\n.", "\n..", (string) $message);
260
+            return $this;
261
+        }
262
+
263
+        /**
264
+         * getMessage
265
+         *
266
+         * @return string
267
+         */
268
+        public function getMessage()
269
+        {
270
+            return $this->_message;
271
+        }
272
+
273
+        /**
274
+         * addAttachment
275
+         *
276
+         * @param string $path The file path to the attachment.
277
+         * @param string $filename The filename of the attachment when emailed.
278
+         * @param string $data
279
+         * 
280
+         * @return self
281
+         */
282
+        public function addAttachment($path, $filename = null, $data = null)
283
+        {
284
+            if(! file_exists($path)){
285
+                show_error('The file [' .$path. '] does not exists.');
286
+            }
287
+            $filename = empty($filename) ? basename($path) : $filename;
288
+            $filename = $this->encodeUtf8($this->filterOther((string) $filename));
289
+            $data = empty($data) ? $this->getAttachmentData($path) : $data;
290
+            $this->_attachments[] = array(
291
+                'path' => $path,
292
+                'file' => $filename,
293
+                'data' => chunk_split(base64_encode($data))
294
+            );
295
+            return $this;
296
+        }
297
+
298
+        /**
299
+         * getAttachmentData
300
+         *
301
+         * @param string $path The path to the attachment file.
302
+         *
303
+         * @return string
304
+         */
305
+        public function getAttachmentData($path)
306
+        {
307
+            if(! file_exists($path)){
308
+                show_error('The file [' .$path. '] does not exists.');
309
+            }
310
+            $filesize = filesize($path);
311
+            $handle = fopen($path, "r");
312
+            $attachment = null;
313
+            if(is_resource($handle)){
314
+                $attachment = fread($handle, $filesize);
315
+                fclose($handle);
316
+            }
317
+            return $attachment;
318
+        }
319
+
320
+        /**
321
+         * addMailHeader
322
+         *
323
+         * @param string $header The header to add.
324
+         * @param string $email  The email to add.
325
+         * @param string $name   The name to add.
326
+         *
327
+         * @return self
328
+         */
329
+        public function addMailHeader($header, $email, $name = null)
330
+        {
331
+            $address = $this->formatHeader((string) $email, (string) $name);
332
+            $this->_headers[] = sprintf('%s: %s', (string) $header, $address);
333
+            return $this;
334
+        }
335
+
336
+        /**
337
+         * addMailHeaders
338
+         *
339
+         * @param string $header The header to add.
340
+         * @param array  $pairs  An array of name => email pairs.
341
+         *
342
+         * @return self
343
+         */
344
+        public function addMailHeaders($header, array $pairs)
345
+        {
346
+            if (count($pairs) === 0) {
347
+                show_error('You must pass at least one name => email pair.');
348
+            }
349
+            $addresses = array();
350
+            foreach ($pairs as $name => $email) {
351
+                $name = is_numeric($name) ? null : $name;
352
+                $addresses[] = $this->formatHeader($email, $name);
353
+            }
354
+            $this->addGenericHeader($header, implode(',', $addresses));
355
+            return $this;
356
+        }
357
+
358
+        /**
359
+         * addGenericHeader
360
+         *
361
+         * @param string $name The generic header to add.
362
+         * @param mixed  $value  The value of the header.
363
+         *
364
+         * @return self
365
+         */
366
+        public function addGenericHeader($name, $value)
367
+        {
368
+            $this->_headers[] = sprintf(
369
+                '%s: %s',
370
+                (string) $name,
371
+                (string) $value
372
+            );
373
+            return $this;
374
+        }
375
+
376
+        /**
377
+         * getHeaders
378
+         *
379
+         * Return the headers registered so far as an array.
380
+         *
381
+         * @return array
382
+         */
383
+        public function getHeaders()
384
+        {
385
+            return $this->_headers;
386
+        }
387
+
388
+        /**
389
+         * setAdditionalParameters
390
+         *
391
+         * Such as "[email protected]
392
+         *
393
+         * @param string $additionalParameters The addition mail parameter.
394
+         *
395
+         * @return self
396
+         */
397
+        public function setParameters($additionalParameters)
398
+        {
399
+            $this->_params = (string) $additionalParameters;
400
+            return $this;
401
+        }
402
+
403
+        /**
404
+         * getAdditionalParameters
405
+         *
406
+         * @return string
407
+         */
408
+        public function getParameters()
409
+        {
410
+            return $this->_params;
411
+        }
412
+
413
+        /**
414
+         * setWrap
415
+         *
416
+         * @param int $wrap The number of characters at which the message will wrap.
417
+         *
418
+         * @return self
419
+         */
420
+        public function setWrap($wrap = 78)
421
+        {
422
+            $wrap = (int) $wrap;
423
+            if ($wrap < 1) {
424
+                $wrap = 78;
425
+            }
426
+            $this->_wrap = $wrap;
427
+            return $this;
428
+        }
429
+
430
+        /**
431
+         * getWrap
432
+         *
433
+         * @return int
434
+         */
435
+        public function getWrap()
436
+        {
437
+            return $this->_wrap;
438
+        }
439
+
440
+        /**
441
+         * hasAttachments
442
+         * 
443
+         * Checks if the email has any registered attachments.
444
+         *
445
+         * @return bool
446
+         */
447
+        public function hasAttachments()
448
+        {
449
+            return !empty($this->_attachments);
450
+        }
451
+
452
+        /**
453
+         * assembleAttachment
454
+         *
455
+         * @return string
456
+         */
457
+        public function assembleAttachmentHeaders()
458
+        {
459
+            $head = array();
460
+            $head[] = "MIME-Version: 1.0";
461
+            $head[] = "Content-Type: multipart/mixed; boundary=\"{$this->_uid}\"";
462
+
463
+            return join(PHP_EOL, $head);
464
+        }
465
+
466
+        /**
467
+         * assembleAttachmentBody
468
+         *
469
+         * @return string
470
+         */
471
+        public function assembleAttachmentBody()
472
+        {
473
+            $body = array();
474
+            $body[] = "This is a multi-part message in MIME format.";
475
+            $body[] = "--{$this->_uid}";
476
+            $body[] = "Content-Type: text/html; charset=\"utf-8\"";
477
+            $body[] = "Content-Transfer-Encoding: quoted-printable";
478
+            $body[] = "";
479
+            $body[] = quoted_printable_encode($this->_message);
480
+            $body[] = "";
481
+            $body[] = "--{$this->_uid}";
482
+
483
+            foreach ($this->_attachments as $attachment) {
484
+                $body[] = $this->getAttachmentMimeTemplate($attachment);
485
+            }
486
+
487
+            return implode(PHP_EOL, $body) . '--';
488
+        }
489
+
490
+        /**
491
+         * getAttachmentMimeTemplate
492
+         *
493
+         * @param array  $attachment An array containing 'file' and 'data' keys.
494
+         *
495
+         * @return string
496
+         */
497
+        public function getAttachmentMimeTemplate($attachment)
498
+        {
499
+            $file = $attachment['file'];
500
+            $data = $attachment['data'];
501
+
502
+            $head = array();
503
+            $head[] = "Content-Type: application/octet-stream; name=\"{$file}\"";
504
+            $head[] = "Content-Transfer-Encoding: base64";
505
+            $head[] = "Content-Disposition: attachment; filename=\"{$file}\"";
506
+            $head[] = "";
507
+            $head[] = $data;
508
+            $head[] = "";
509
+            $head[] = "--{$this->_uid}";
510
+
511
+            return implode(PHP_EOL, $head);
512
+        }
513
+
514
+        /**
515
+         * send the email
516
+         *
517
+         * @return boolean
518
+         */
519
+        public function send()
520
+        {
521
+            $to = $this->getToForSend();
522
+            $headers = $this->getHeadersForSend();
523
+
524
+            if (empty($to)) {
525
+                show_error('Unable to send, no To address has been set.');
526
+            }
527
+
528
+            if ($this->hasAttachments()) {
529
+                $message  = $this->assembleAttachmentBody();
530
+                $headers .= PHP_EOL . $this->assembleAttachmentHeaders();
531
+            } else {
532
+                $message = $this->getWrapMessage();
533
+            }
534
+            $this->logger->info('Sending new mail, the information are listed below: destination: ' . $to . ', headers: ' . $headers . ', message: ' . $message);
535
+            return mail($to, $this->_subject, $message, $headers, $this->_params);
536
+        }
537
+
538
+        /**
539
+         * debug
540
+         *
541
+         * @return string
542
+         */
543
+        public function debug()
544
+        {
545
+            return '<pre>' . print_r($this, true) . '</pre>';
546
+        }
547
+
548
+        /**
549
+         * magic __toString function
550
+         *
551
+         * @return string
552
+         */
553
+        public function __toString()
554
+        {
555
+            return print_r($this, true);
556
+        }
557
+
558
+        /**
559
+         * formatHeader
560
+         *
561
+         * Formats a display address for emails according to RFC2822 e.g.
562
+         * Name <[email protected]>
563
+         *
564
+         * @param string $email The email address.
565
+         * @param string $name  The display name.
566
+         *
567
+         * @return string
568
+         */
569
+        public function formatHeader($email, $name = null)
570
+        {
571
+            $email = $this->filterEmail((string) $email);
572
+            if (empty($name)) {
573
+                return $email;
574
+            }
575
+            $name = $this->encodeUtf8($this->filterName((string) $name));
576
+            return sprintf('"%s" <%s>', $name, $email);
577
+        }
578
+
579
+        /**
580
+         * encodeUtf8
581
+         *
582
+         * @param string $value The value to encode.
583
+         *
584
+         * @return string
585
+         */
586
+        public function encodeUtf8($value)
587
+        {
588
+            $value = trim($value);
589
+            if (preg_match('/(\s)/', $value)) {
590
+                return $this->encodeUtf8Words($value);
591
+            }
592
+            return $this->encodeUtf8Word($value);
593
+        }
594
+
595
+        /**
596
+         * encodeUtf8Word
597
+         *
598
+         * @param string $value The word to encode.
599
+         *
600
+         * @return string
601
+         */
602
+        public function encodeUtf8Word($value)
603
+        {
604
+            return sprintf('=?UTF-8?B?%s?=', base64_encode($value));
605
+        }
606
+
607
+        /**
608
+         * encodeUtf8Words
609
+         *
610
+         * @param string $value The words to encode.
611
+         *
612
+         * @return string
613
+         */
614
+        public function encodeUtf8Words($value)
615
+        {
616
+            $words = explode(' ', $value);
617
+            $encoded = array();
618
+            foreach ($words as $word) {
619
+                $encoded[] = $this->encodeUtf8Word($word);
620
+            }
621
+            return join($this->encodeUtf8Word(' '), $encoded);
622
+        }
623
+
624
+        /**
625
+         * filterEmail
626
+         *
627
+         * Removes any carriage return, line feed, tab, double quote, comma
628
+         * and angle bracket characters before sanitizing the email address.
629
+         *
630
+         * @param string $email The email to filter.
631
+         *
632
+         * @return string
633
+         */
634
+        public function filterEmail($email)
635
+        {
636
+            $rule = array(
637
+                "\r" => '',
638
+                "\n" => '',
639
+                "\t" => '',
640
+                '"'  => '',
641
+                ','  => '',
642
+                '<'  => '',
643
+                '>'  => ''
644
+            );
645
+            $email = strtr($email, $rule);
646
+            $email = filter_var($email, FILTER_SANITIZE_EMAIL);
647
+            return $email;
648
+        }
649
+
650
+        /**
651
+         * filterName
652
+         *
653
+         * Removes any carriage return, line feed or tab characters. Replaces
654
+         * double quotes with single quotes and angle brackets with square
655
+         * brackets, before sanitizing the string and stripping out html tags.
656
+         *
657
+         * @param string $name The name to filter.
658
+         *
659
+         * @return string
660
+         */
661
+        public function filterName($name)
662
+        {
663
+            $rule = array(
664
+                "\r" => '',
665
+                "\n" => '',
666
+                "\t" => '',
667
+                '"'  => "'",
668
+                '<'  => '[',
669
+                '>'  => ']',
670
+            );
671
+            $filtered = filter_var(
672
+                $name,
673
+                FILTER_SANITIZE_STRING,
674
+                FILTER_FLAG_NO_ENCODE_QUOTES
675
+            );
676
+            return trim(strtr($filtered, $rule));
677
+        }
678
+
679
+        /**
680
+         * filterOther
681
+         *
682
+         * Removes ASCII control characters including any carriage return, line
683
+         * feed or tab characters.
684
+         *
685
+         * @param string $data The data to filter.
686
+         *
687
+         * @return string
688
+         */
689
+        public function filterOther($data)
690
+        {
691
+            return filter_var($data, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
692
+        }
693
+
694
+        /**
695
+         * getHeadersForSend
696
+         *
697
+         * @return string
698
+         */
699
+        public function getHeadersForSend()
700
+        {
701
+            if (empty($this->_headers)) {
702
+                return '';
703
+            }
704
+            return join(PHP_EOL, $this->_headers);
705
+        }
706
+
707
+        /**
708
+         * getToForSend
709
+         *
710
+         * @return string
711
+         */
712
+        public function getToForSend()
713
+        {
714
+            if (empty($this->_to)) {
715
+                return '';
716
+            }
717
+            return join(', ', $this->_to);
718
+        }
719
+
720
+        /**
721
+         * getUniqueId
722
+         *
723
+         * @return string
724
+         */
725
+        public function getUniqueId()
726
+        {
727
+            return md5(uniqid(time()));
728
+        }
729
+
730
+        /**
731
+         * getWrapMessage
732
+         *
733
+         * @return string
734
+         */
735
+        public function getWrapMessage()
736
+        {
737
+            return wordwrap($this->_message, $this->_wrap);
738
+        }
739
+    }
Please login to merge, or discard this patch.
core/libraries/Cookie.php 1 patch
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -1,112 +1,112 @@
 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
-	class Cookie{
27
+    class Cookie{
28 28
 		
29
-		/**
30
-		 * The logger instance
31
-		 * @var Log
32
-		 */
33
-		private static $logger;
29
+        /**
30
+         * The logger instance
31
+         * @var Log
32
+         */
33
+        private static $logger;
34 34
 
35
-		/**
36
-		 * The signleton of the logger
37
-		 * @return Object the Log instance
38
-		 */
39
-		private static function getLogger(){
40
-			if(self::$logger == null){
41
-				self::$logger[0] =& class_loader('Log', 'classes');
42
-				self::$logger[0]->setLogger('Library::Cookie');
43
-			}
44
-			return self::$logger[0];
45
-		}
35
+        /**
36
+         * The signleton of the logger
37
+         * @return Object the Log instance
38
+         */
39
+        private static function getLogger(){
40
+            if(self::$logger == null){
41
+                self::$logger[0] =& class_loader('Log', 'classes');
42
+                self::$logger[0]->setLogger('Library::Cookie');
43
+            }
44
+            return self::$logger[0];
45
+        }
46 46
 
47
-		/**
48
-		 * Get the cookie item value
49
-		 * @param  string $item    the cookie item name to get
50
-		 * @param  mixed $default the default value to use if can not find the cokkie item in the list
51
-		 * @return mixed          the cookie value if exist or the default value
52
-		 */
53
-		public static function get($item, $default = null){
54
-			$logger = self::getLogger();
55
-			if(array_key_exists($item, $_COOKIE)){
56
-				return $_COOKIE[$item];
57
-			}
58
-			$logger->warning('Cannot find cookie item [' . $item . '], using the default value [' . $default . ']');
59
-			return $default;
60
-		}
47
+        /**
48
+         * Get the cookie item value
49
+         * @param  string $item    the cookie item name to get
50
+         * @param  mixed $default the default value to use if can not find the cokkie item in the list
51
+         * @return mixed          the cookie value if exist or the default value
52
+         */
53
+        public static function get($item, $default = null){
54
+            $logger = self::getLogger();
55
+            if(array_key_exists($item, $_COOKIE)){
56
+                return $_COOKIE[$item];
57
+            }
58
+            $logger->warning('Cannot find cookie item [' . $item . '], using the default value [' . $default . ']');
59
+            return $default;
60
+        }
61 61
 
62
-		/**
63
-		 * Set the cookie item value
64
-		 * @param string  $name     the cookie item name
65
-		 * @param string  $value    the cookie value to set
66
-		 * @param integer $expire   the time to live for this cookie
67
-		 * @param string  $path     the path that the cookie will be available
68
-		 * @param string  $domain   the domain that the cookie will be available
69
-		 * @param boolean $secure   if this cookie will be available on secure connection or not
70
-		 * @param boolean $httponly if this cookie will be available under HTTP protocol.
71
-		 */
72
-		public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false){
73
-			if(headers_sent()){
74
-				show_error('There exists a cookie that we wanted to create that we couldn\'t 
62
+        /**
63
+         * Set the cookie item value
64
+         * @param string  $name     the cookie item name
65
+         * @param string  $value    the cookie value to set
66
+         * @param integer $expire   the time to live for this cookie
67
+         * @param string  $path     the path that the cookie will be available
68
+         * @param string  $domain   the domain that the cookie will be available
69
+         * @param boolean $secure   if this cookie will be available on secure connection or not
70
+         * @param boolean $httponly if this cookie will be available under HTTP protocol.
71
+         */
72
+        public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false){
73
+            if(headers_sent()){
74
+                show_error('There exists a cookie that we wanted to create that we couldn\'t 
75 75
 						    because headers was already sent. Make sure to do this first 
76 76
 							before outputing anything.');
77
-			}
78
-			$timestamp = $expire;
79
-			if($expire){
80
-				$timestamp = time() + $expire;
81
-			}
82
-			setcookie($name, $value, $timestamp, $path, $domain, $secure, $httponly);
83
-		}
77
+            }
78
+            $timestamp = $expire;
79
+            if($expire){
80
+                $timestamp = time() + $expire;
81
+            }
82
+            setcookie($name, $value, $timestamp, $path, $domain, $secure, $httponly);
83
+        }
84 84
 
85
-		/**
86
-		 * Delete the cookie item in the list
87
-		 * @param  string $item the cookie item name to be cleared
88
-		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
89
-		 */
90
-		public static function delete($item){
91
-			$logger = self::getLogger();
92
-			if(array_key_exists($item, $_COOKIE)){
93
-				$logger->info('Delete cookie item ['.$item.']');
94
-				unset($_COOKIE[$item]);
95
-				return true;
96
-			}
97
-			else{
98
-				$logger->warning('Cookie item ['.$item.'] to be deleted does not exists');
99
-				return false;
100
-			}
101
-		}
85
+        /**
86
+         * Delete the cookie item in the list
87
+         * @param  string $item the cookie item name to be cleared
88
+         * @return boolean true if the item exists and is deleted successfully otherwise will return false.
89
+         */
90
+        public static function delete($item){
91
+            $logger = self::getLogger();
92
+            if(array_key_exists($item, $_COOKIE)){
93
+                $logger->info('Delete cookie item ['.$item.']');
94
+                unset($_COOKIE[$item]);
95
+                return true;
96
+            }
97
+            else{
98
+                $logger->warning('Cookie item ['.$item.'] to be deleted does not exists');
99
+                return false;
100
+            }
101
+        }
102 102
 
103
-		/**
104
-		 * Check if the given cookie item exists
105
-		 * @param  string $item the cookie item name
106
-		 * @return boolean       true if the cookie item is set, false or not
107
-		 */
108
-		public static function exists($item){
109
-			return array_key_exists($item, $_COOKIE);
110
-		}
103
+        /**
104
+         * Check if the given cookie item exists
105
+         * @param  string $item the cookie item name
106
+         * @return boolean       true if the cookie item is set, false or not
107
+         */
108
+        public static function exists($item){
109
+            return array_key_exists($item, $_COOKIE);
110
+        }
111 111
 
112
-	}
112
+    }
Please login to merge, or discard this patch.