Passed
Push — 1.0.0-dev ( 8edc19...2b6704 )
by nguereza
03:32
created
core/classes/EventInfo.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -1,63 +1,63 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	/**
28
-	 * This class represent the event detail to dispatch to correspond listener
29
-	 */
30
-	class EventInfo{
27
+    /**
28
+     * This class represent the event detail to dispatch to correspond listener
29
+     */
30
+    class EventInfo{
31 31
 		
32
-		/**
33
-		 * The event name
34
-		 * @var string
35
-		 */
36
-		public $name;
32
+        /**
33
+         * The event name
34
+         * @var string
35
+         */
36
+        public $name;
37 37
 
38
-		/**
39
-		 * The event data to send to the listeners
40
-		 * @var mixed
41
-		 */
42
-		public $payload;
38
+        /**
39
+         * The event data to send to the listeners
40
+         * @var mixed
41
+         */
42
+        public $payload;
43 43
 
44
-		/**
45
-		 * If the listeners need return the event after treatment or not, false means no need
46
-		 * return true need return the event. 
47
-		 * @var boolean
48
-		 */
49
-		public $returnBack;
44
+        /**
45
+         * If the listeners need return the event after treatment or not, false means no need
46
+         * return true need return the event. 
47
+         * @var boolean
48
+         */
49
+        public $returnBack;
50 50
 
51
-		/**
52
-		 * This variable indicates if need stop the event propagation
53
-		 * @var boolean
54
-		 */
55
-		public $stop;
51
+        /**
52
+         * This variable indicates if need stop the event propagation
53
+         * @var boolean
54
+         */
55
+        public $stop;
56 56
 		
57
-		public function __construct($name, $payload = array(), $returnBack = false, $stop = false){
58
-			$this->name = $name;
59
-			$this->payload = $payload;
60
-			$this->returnBack = $returnBack;
61
-			$this->stop = $stop;
62
-		}
63
-	}
57
+        public function __construct($name, $payload = array(), $returnBack = false, $stop = false){
58
+            $this->name = $name;
59
+            $this->payload = $payload;
60
+            $this->returnBack = $returnBack;
61
+            $this->stop = $stop;
62
+        }
63
+    }
Please login to merge, or discard this patch.
core/classes/database/DatabaseQueryResult.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -1,43 +1,43 @@  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
-  */
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 DatabaseQueryResult{
27
+    class DatabaseQueryResult{
28 28
   	
29
-  	/**
30
-  	 * The database query result
31
-  	 * @var mixed
32
-  	 */
33
-     private $result  = null;
29
+        /**
30
+         * The database query result
31
+         * @var mixed
32
+         */
33
+        private $result  = null;
34 34
   	
35 35
     
36
-  	/**
37
-	 * The number of rows returned by the last query
38
-	 * @var int
39
-     */
40
-     private $numRows = 0;
36
+        /**
37
+         * The number of rows returned by the last query
38
+         * @var int
39
+         */
40
+        private $numRows = 0;
41 41
   	
42 42
 	
43 43
     /**
@@ -51,24 +51,24 @@  discard block
 block discarded – undo
51 51
     }
52 52
 
53 53
     
54
-     /**
55
-     * Return the query result
56
-     *
57
-     * @return mixed
58
-     */
54
+        /**
55
+         * Return the query result
56
+         *
57
+         * @return mixed
58
+         */
59 59
     public function getResult(){
60
-      return $this->result;
60
+        return $this->result;
61 61
     }
62 62
 
63 63
     /**
64 64
      * Set the query result
65 65
      * @param mixed $result the query result
66 66
      *
67
-	 * @return object DatabaseQueryResult
67
+     * @return object DatabaseQueryResult
68 68
      */
69 69
     public function setResult($result){
70
-      $this->result = $result;
71
-      return $this;
70
+        $this->result = $result;
71
+        return $this;
72 72
     }
73 73
     
74 74
     /**
@@ -77,18 +77,18 @@  discard block
 block discarded – undo
77 77
      * @return int
78 78
      */
79 79
     public function getNumRows(){
80
-      return $this->numRows;
80
+        return $this->numRows;
81 81
     }
82 82
 
83 83
     /**
84 84
      * Set the number of rows returned by the query
85 85
      * @param int $numRows the number of rows returned
86 86
      *
87
-	 * @return object DatabaseQueryResult
87
+     * @return object DatabaseQueryResult
88 88
      */
89 89
     public function setNumRows($numRows){
90
-      $this->numRows = $numRows;
91
-      return $this;
90
+        $this->numRows = $numRows;
91
+        return $this;
92 92
     }
93 93
    
94 94
 }
Please login to merge, or discard this patch.
core/classes/Session.php 1 patch
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -1,168 +1,168 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
26
-	class Session{
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26
+    class Session{
27 27
 		
28
-		/**
29
-		 * The session flash key to use
30
-		 * @const
31
-		 */
32
-		const SESSION_FLASH_KEY = 'session_flash';
28
+        /**
29
+         * The session flash key to use
30
+         * @const
31
+         */
32
+        const SESSION_FLASH_KEY = 'session_flash';
33 33
 
34
-		/**
35
-		 * The logger instance
36
-		 * @var Log
37
-		 */
38
-		private static $logger;
34
+        /**
35
+         * The logger instance
36
+         * @var Log
37
+         */
38
+        private static $logger;
39 39
 
40
-		/**
41
-		 * Get the logger singleton instance
42
-		 * @return Log the logger instance
43
-		 */
44
-		private static function getLogger(){
45
-			if(self::$logger == null){
46
-				self::$logger[0] =& class_loader('Log', 'classes');
47
-				self::$logger[0]->setLogger('Library::Session');
48
-			}
49
-			return self::$logger[0];
50
-		}
40
+        /**
41
+         * Get the logger singleton instance
42
+         * @return Log the logger instance
43
+         */
44
+        private static function getLogger(){
45
+            if(self::$logger == null){
46
+                self::$logger[0] =& class_loader('Log', 'classes');
47
+                self::$logger[0]->setLogger('Library::Session');
48
+            }
49
+            return self::$logger[0];
50
+        }
51 51
 
52
-		/**
53
-		 * Get the session item value
54
-		 * @param  string $item    the session item name to get
55
-		 * @param  mixed $default the default value to use if can not find the session item in the list
56
-		 * @return mixed          the session value if exist or the default value
57
-		 */
58
-		public static function get($item, $default = null){
59
-			$logger = self::getLogger();
60
-			$logger->debug('Getting session data for item [' .$item. '] ...');
61
-			if(array_key_exists($item, $_SESSION)){
62
-				$logger->info('Found session data for item [' . $item . '] the vaue is : [' . stringfy_vars($_SESSION[$item]) . ']');
63
-				return $_SESSION[$item];
64
-			}
65
-			$logger->warning('Cannot find session item [' . $item . '] using the default value ['. $default . ']');
66
-			return $default;
67
-		}
52
+        /**
53
+         * Get the session item value
54
+         * @param  string $item    the session item name to get
55
+         * @param  mixed $default the default value to use if can not find the session item in the list
56
+         * @return mixed          the session value if exist or the default value
57
+         */
58
+        public static function get($item, $default = null){
59
+            $logger = self::getLogger();
60
+            $logger->debug('Getting session data for item [' .$item. '] ...');
61
+            if(array_key_exists($item, $_SESSION)){
62
+                $logger->info('Found session data for item [' . $item . '] the vaue is : [' . stringfy_vars($_SESSION[$item]) . ']');
63
+                return $_SESSION[$item];
64
+            }
65
+            $logger->warning('Cannot find session item [' . $item . '] using the default value ['. $default . ']');
66
+            return $default;
67
+        }
68 68
 
69
-		/**
70
-		 * Set the session item value
71
-		 * @param string $item  the session item name to set
72
-		 * @param mixed $value the session item value
73
-		 */
74
-		public static function set($item, $value){
75
-			$logger = self::getLogger();
76
-			$logger->debug('Setting session data for item [' . $item . '], value [' . stringfy_vars($value) . ']');
77
-			$_SESSION[$item] = $value;
78
-		}
69
+        /**
70
+         * Set the session item value
71
+         * @param string $item  the session item name to set
72
+         * @param mixed $value the session item value
73
+         */
74
+        public static function set($item, $value){
75
+            $logger = self::getLogger();
76
+            $logger->debug('Setting session data for item [' . $item . '], value [' . stringfy_vars($value) . ']');
77
+            $_SESSION[$item] = $value;
78
+        }
79 79
 
80
-		/**
81
-		 * Get the session flash item value
82
-		 * @param  string $item    the session flash item name to get
83
-		 * @param  mixed $default the default value to use if can not find the session flash item in the list
84
-		 * @return mixed          the session flash value if exist or the default value
85
-		 */
86
-		public static function getFlash($item, $default = null){
87
-			$logger = self::getLogger();
88
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
89
-			$return = array_key_exists($key, $_SESSION) ?
90
-			($_SESSION[$key]) : $default;
91
-			if(array_key_exists($key, $_SESSION)){
92
-				unset($_SESSION[$key]);
93
-			}
94
-			else{
95
-				$logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']');
96
-			}
97
-			return $return;
98
-		}
80
+        /**
81
+         * Get the session flash item value
82
+         * @param  string $item    the session flash item name to get
83
+         * @param  mixed $default the default value to use if can not find the session flash item in the list
84
+         * @return mixed          the session flash value if exist or the default value
85
+         */
86
+        public static function getFlash($item, $default = null){
87
+            $logger = self::getLogger();
88
+            $key = self::SESSION_FLASH_KEY.'_'.$item;
89
+            $return = array_key_exists($key, $_SESSION) ?
90
+            ($_SESSION[$key]) : $default;
91
+            if(array_key_exists($key, $_SESSION)){
92
+                unset($_SESSION[$key]);
93
+            }
94
+            else{
95
+                $logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']');
96
+            }
97
+            return $return;
98
+        }
99 99
 
100
-		/**
101
-		 * Check whether the given session flash item exists
102
-		 * @param  string  $item the session flash item name
103
-		 * @return boolean 
104
-		 */
105
-		public static function hasFlash($item){
106
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
107
-			return array_key_exists($key, $_SESSION);
108
-		}
100
+        /**
101
+         * Check whether the given session flash item exists
102
+         * @param  string  $item the session flash item name
103
+         * @return boolean 
104
+         */
105
+        public static function hasFlash($item){
106
+            $key = self::SESSION_FLASH_KEY.'_'.$item;
107
+            return array_key_exists($key, $_SESSION);
108
+        }
109 109
 
110
-		/**
111
-		 * Set the session flash item value
112
-		 * @param string $item  the session flash item name to set
113
-		 * @param mixed $value the session flash item value
114
-		 */
115
-		public static function setFlash($item, $value){
116
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
117
-			$_SESSION[$key] = $value;
118
-		}
110
+        /**
111
+         * Set the session flash item value
112
+         * @param string $item  the session flash item name to set
113
+         * @param mixed $value the session flash item value
114
+         */
115
+        public static function setFlash($item, $value){
116
+            $key = self::SESSION_FLASH_KEY.'_'.$item;
117
+            $_SESSION[$key] = $value;
118
+        }
119 119
 
120
-		/**
121
-		 * Clear the session item in the list
122
-		 * @param  string $item the session item name to be deleted
123
-		 */
124
-		public static function clear($item){
125
-			$logger = self::getLogger();
126
-			if(array_key_exists($item, $_SESSION)){
127
-				$logger->info('Deleting of session for item ['.$item.' ]');
128
-				unset($_SESSION[$item]);
129
-			}
130
-			else{
131
-				$logger->warning('Session item ['.$item.'] to be deleted does not exists');
132
-			}
133
-		}
120
+        /**
121
+         * Clear the session item in the list
122
+         * @param  string $item the session item name to be deleted
123
+         */
124
+        public static function clear($item){
125
+            $logger = self::getLogger();
126
+            if(array_key_exists($item, $_SESSION)){
127
+                $logger->info('Deleting of session for item ['.$item.' ]');
128
+                unset($_SESSION[$item]);
129
+            }
130
+            else{
131
+                $logger->warning('Session item ['.$item.'] to be deleted does not exists');
132
+            }
133
+        }
134 134
 		
135
-		/**
136
-		 * Clear the session flash item in the list
137
-		 * @param  string $item the session flash item name to be deleted
138
-		 */
139
-		public static function clearFlash($item){
140
-			$logger = self::getLogger();
141
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
142
-			if(array_key_exists($key, $_SESSION)){
143
-				$logger->info('Delete session flash for item ['.$item.']');
144
-				unset($_SESSION[$item]);
145
-			}
146
-			else{
147
-				$logger->warning('Dession flash item ['.$item.'] to be deleted does not exists');
148
-			}
149
-		}
135
+        /**
136
+         * Clear the session flash item in the list
137
+         * @param  string $item the session flash item name to be deleted
138
+         */
139
+        public static function clearFlash($item){
140
+            $logger = self::getLogger();
141
+            $key = self::SESSION_FLASH_KEY.'_'.$item;
142
+            if(array_key_exists($key, $_SESSION)){
143
+                $logger->info('Delete session flash for item ['.$item.']');
144
+                unset($_SESSION[$item]);
145
+            }
146
+            else{
147
+                $logger->warning('Dession flash item ['.$item.'] to be deleted does not exists');
148
+            }
149
+        }
150 150
 
151
-		/**
152
-		 * Check whether the given session item exists
153
-		 * @param  string  $item the session item name
154
-		 * @return boolean 
155
-		 */
156
-		public static function exists($item){
157
-			return array_key_exists($item, $_SESSION);
158
-		}
151
+        /**
152
+         * Check whether the given session item exists
153
+         * @param  string  $item the session item name
154
+         * @return boolean 
155
+         */
156
+        public static function exists($item){
157
+            return array_key_exists($item, $_SESSION);
158
+        }
159 159
 
160
-		/**
161
-		 * Destroy all session data values
162
-		 */
163
-		public static function clearAll(){
164
-			session_unset();
165
-			session_destroy();
166
-		}
160
+        /**
161
+         * Destroy all session data values
162
+         */
163
+        public static function clearAll(){
164
+            session_unset();
165
+            session_destroy();
166
+        }
167 167
 
168
-	}
168
+    }
Please login to merge, or discard this patch.
core/classes/DBSessionHandler.php 1 patch
Indentation   +344 added lines, -344 removed lines patch added patch discarded remove patch
@@ -1,330 +1,330 @@  discard block
 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
-	 * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists)
29
-	 */
30
-	if( !interface_exists('SessionHandlerInterface')){
31
-		show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.');
32
-	}
33
-
34
-	class DBSessionHandler implements SessionHandlerInterface{
27
+    /**
28
+     * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists)
29
+     */
30
+    if( !interface_exists('SessionHandlerInterface')){
31
+        show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.');
32
+    }
33
+
34
+    class DBSessionHandler implements SessionHandlerInterface{
35 35
 		
36
-		/**
37
-		 * The encryption method to use to encrypt session data in database
38
-		 * @const string
39
-		 */
40
-		const DB_SESSION_HASH_METHOD = 'AES-256-CBC';
36
+        /**
37
+         * The encryption method to use to encrypt session data in database
38
+         * @const string
39
+         */
40
+        const DB_SESSION_HASH_METHOD = 'AES-256-CBC';
41 41
 		
42
-		/**
43
-		 * Super global instance
44
-		 * @var object
45
-		 */
46
-		protected $OBJ = null;
47
-
48
-		/**
49
-		 * Session secret to use 
50
-		 * @var string
51
-		 */
52
-		private $sessionSecret = null;
53
-
54
-		/**
55
-		 * The initialisation vector to use for openssl
56
-		 * @var string
57
-		 */
58
-		private $iv = null;
59
-
60
-		/**
61
-		 * The model instance name to use after load model
62
-		 * @var object
63
-		 */
64
-		private $modelInstanceName = null;
65
-
66
-		/**
67
-		 * The columns of the table to use to store session data
68
-		 * @var array
69
-		 */
70
-		private $sessionTableColumns = array();
71
-
72
-		/**
73
-		 * The instance of the Log 
74
-		 * @var Log
75
-		 */
76
-		private $logger;
77
-
78
-		/**
42
+        /**
43
+         * Super global instance
44
+         * @var object
45
+         */
46
+        protected $OBJ = null;
47
+
48
+        /**
49
+         * Session secret to use 
50
+         * @var string
51
+         */
52
+        private $sessionSecret = null;
53
+
54
+        /**
55
+         * The initialisation vector to use for openssl
56
+         * @var string
57
+         */
58
+        private $iv = null;
59
+
60
+        /**
61
+         * The model instance name to use after load model
62
+         * @var object
63
+         */
64
+        private $modelInstanceName = null;
65
+
66
+        /**
67
+         * The columns of the table to use to store session data
68
+         * @var array
69
+         */
70
+        private $sessionTableColumns = array();
71
+
72
+        /**
73
+         * The instance of the Log 
74
+         * @var Log
75
+         */
76
+        private $logger;
77
+
78
+        /**
79 79
          * Instance of the Loader class
80 80
          * @var Loader
81 81
          */
82 82
         protected $loader = null;
83 83
 
84
-		public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null){
85
-			/**
86
-	         * instance of the Log class
87
-	         */
88
-	        if(is_object($logger)){
89
-	          $this->setLogger($logger);
90
-	        }
91
-	        else{
92
-	            $this->logger =& class_loader('Log', 'classes');
93
-	            $this->logger->setLogger('Library::DBSessionHandler');
94
-	        }
95
-
96
-	        if(is_object($loader)){
97
-	          $this->setLoader($loader);
98
-	        }
99
-		    $this->OBJ = & get_instance();
84
+        public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null){
85
+            /**
86
+             * instance of the Log class
87
+             */
88
+            if(is_object($logger)){
89
+                $this->setLogger($logger);
90
+            }
91
+            else{
92
+                $this->logger =& class_loader('Log', 'classes');
93
+                $this->logger->setLogger('Library::DBSessionHandler');
94
+            }
95
+
96
+            if(is_object($loader)){
97
+                $this->setLoader($loader);
98
+            }
99
+            $this->OBJ = & get_instance();
100 100
 
101 101
 		    
102
-			if(is_object($modelInstance)){
103
-				$this->setModelInstance($modelInstance);
104
-			}
105
-		}
106
-
107
-		/**
108
-		 * Set the session secret used to encrypt the data in database 
109
-		 * @param string $secret the base64 string secret
110
-		 */
111
-		public function setSessionSecret($secret){
112
-			$this->sessionSecret = $secret;
113
-			return $this;
114
-		}
115
-
116
-		/**
117
-		 * Return the session secret
118
-		 * @return string 
119
-		 */
120
-		public function getSessionSecret(){
121
-			return $this->sessionSecret;
122
-		}
123
-
124
-
125
-		/**
126
-		 * Set the initializer vector for openssl 
127
-		 * @param string $key the session secret used
128
-		 */
129
-		public function setInitializerVector($key){
130
-			$iv_length = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD);
131
-			$key = base64_decode($key);
132
-			$this->iv = substr(hash('sha256', $key), 0, $iv_length);
133
-			return $this;
134
-		}
135
-
136
-		/**
137
-		 * Return the initializer vector
138
-		 * @return string 
139
-		 */
140
-		public function getInitializerVector(){
141
-			return $this->iv;
142
-		}
143
-
144
-		/**
145
-		 * Open the database session handler, here nothing to do just return true
146
-		 * @param  string $savePath    the session save path
147
-		 * @param  string $sessionName the session name
148
-		 * @return boolean 
149
-		 */
150
-		public function open($savePath, $sessionName){
151
-			$this->logger->debug('Opening database session handler for [' . $sessionName . ']');
152
-			//try to check if session secret is set before
153
-			$secret = $this->getSessionSecret();
154
-			if(empty($secret)){
155
-				$secret = get_config('session_secret', null);
156
-				$this->setSessionSecret($secret);
157
-			}
158
-			$this->logger->info('Session secret: ' . $secret);
159
-
160
-			if(! $this->getModelInstance()){
161
-				$this->setModelInstanceFromConfig();
162
-			}
163
-			$this->setInitializerVector($secret);
164
-
165
-			//set session tables columns
166
-			$this->sessionTableColumns = $this->getModelInstance()->getSessionTableColumns();
167
-
168
-			if(empty($this->sessionTableColumns)){
169
-				show_error('The session handler is "database" but the table columns not set');
170
-			}
171
-			$this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns));
102
+            if(is_object($modelInstance)){
103
+                $this->setModelInstance($modelInstance);
104
+            }
105
+        }
106
+
107
+        /**
108
+         * Set the session secret used to encrypt the data in database 
109
+         * @param string $secret the base64 string secret
110
+         */
111
+        public function setSessionSecret($secret){
112
+            $this->sessionSecret = $secret;
113
+            return $this;
114
+        }
115
+
116
+        /**
117
+         * Return the session secret
118
+         * @return string 
119
+         */
120
+        public function getSessionSecret(){
121
+            return $this->sessionSecret;
122
+        }
123
+
124
+
125
+        /**
126
+         * Set the initializer vector for openssl 
127
+         * @param string $key the session secret used
128
+         */
129
+        public function setInitializerVector($key){
130
+            $iv_length = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD);
131
+            $key = base64_decode($key);
132
+            $this->iv = substr(hash('sha256', $key), 0, $iv_length);
133
+            return $this;
134
+        }
135
+
136
+        /**
137
+         * Return the initializer vector
138
+         * @return string 
139
+         */
140
+        public function getInitializerVector(){
141
+            return $this->iv;
142
+        }
143
+
144
+        /**
145
+         * Open the database session handler, here nothing to do just return true
146
+         * @param  string $savePath    the session save path
147
+         * @param  string $sessionName the session name
148
+         * @return boolean 
149
+         */
150
+        public function open($savePath, $sessionName){
151
+            $this->logger->debug('Opening database session handler for [' . $sessionName . ']');
152
+            //try to check if session secret is set before
153
+            $secret = $this->getSessionSecret();
154
+            if(empty($secret)){
155
+                $secret = get_config('session_secret', null);
156
+                $this->setSessionSecret($secret);
157
+            }
158
+            $this->logger->info('Session secret: ' . $secret);
159
+
160
+            if(! $this->getModelInstance()){
161
+                $this->setModelInstanceFromConfig();
162
+            }
163
+            $this->setInitializerVector($secret);
164
+
165
+            //set session tables columns
166
+            $this->sessionTableColumns = $this->getModelInstance()->getSessionTableColumns();
167
+
168
+            if(empty($this->sessionTableColumns)){
169
+                show_error('The session handler is "database" but the table columns not set');
170
+            }
171
+            $this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns));
172 172
 			
173
-			//delete the expired session
174
-			$timeActivity = get_config('session_inactivity_time', 100);
175
-			$this->gc($timeActivity);
173
+            //delete the expired session
174
+            $timeActivity = get_config('session_inactivity_time', 100);
175
+            $this->gc($timeActivity);
176 176
 			
177
-			return true;
178
-		}
179
-
180
-		/**
181
-		 * Close the session
182
-		 * @return boolean
183
-		 */
184
-		public function close(){
185
-			$this->logger->debug('Closing database session handler');
186
-			return true;
187
-		}
188
-
189
-		/**
190
-		 * Get the session value for the given session id
191
-		 * @param  string $sid the session id to use
192
-		 * @return string      the session data in serialiaze format
193
-		 */
194
-		public function read($sid){
195
-			$this->logger->debug('Reading database session data for SID: ' . $sid);
196
-			$instance = $this->getModelInstance();
197
-			$columns = $this->sessionTableColumns;
198
-			if($this->getLoader()){
199
-				$this->getLoader()->functions('user_agent'); 
200
-				$this->getLoader()->library('Browser'); 
201
-			}
202
-			else{
203
-            	Loader::functions('user_agent');
204
-            	Loader::library('Browser');
177
+            return true;
178
+        }
179
+
180
+        /**
181
+         * Close the session
182
+         * @return boolean
183
+         */
184
+        public function close(){
185
+            $this->logger->debug('Closing database session handler');
186
+            return true;
187
+        }
188
+
189
+        /**
190
+         * Get the session value for the given session id
191
+         * @param  string $sid the session id to use
192
+         * @return string      the session data in serialiaze format
193
+         */
194
+        public function read($sid){
195
+            $this->logger->debug('Reading database session data for SID: ' . $sid);
196
+            $instance = $this->getModelInstance();
197
+            $columns = $this->sessionTableColumns;
198
+            if($this->getLoader()){
199
+                $this->getLoader()->functions('user_agent'); 
200
+                $this->getLoader()->library('Browser'); 
201
+            }
202
+            else{
203
+                Loader::functions('user_agent');
204
+                Loader::library('Browser');
205 205
             }
206 206
 			
207
-			$ip = get_ip();
208
-			$host = @gethostbyaddr($ip) or null;
209
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
207
+            $ip = get_ip();
208
+            $host = @gethostbyaddr($ip) or null;
209
+            $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
210 210
 			
211
-			$data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser));
212
-			if($data && isset($data->{$columns['sdata']})){
213
-				//checking inactivity 
214
-				$timeInactivity = time() - get_config('session_inactivity_time', 100);
215
-				if($data->{$columns['stime']} < $timeInactivity){
216
-					$this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it');
217
-					$this->destroy($sid);
218
-					return null;
219
-				}
220
-				return $this->decode($data->{$columns['sdata']});
221
-			}
222
-			$this->logger->info('Database session data for SID: ' . $sid . ' is not valid return false, may be the session ID is wrong');
223
-			return null;
224
-		}
225
-
226
-		/**
227
-		 * Save the session data
228
-		 * @param  string $sid  the session ID
229
-		 * @param  mixed $data the session data to save in serialize format
230
-		 * @return boolean 
231
-		 */
232
-		public function write($sid, $data){
233
-			$this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data));
234
-			$instance = $this->getModelInstance();
235
-			$columns = $this->sessionTableColumns;
236
-
237
-			if($this->getLoader()){
238
-				$this->getLoader()->functions('user_agent'); 
239
-				$this->getLoader()->library('Browser'); 
240
-			}
241
-			else{
242
-            	Loader::functions('user_agent');
243
-            	Loader::library('Browser');
211
+            $data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser));
212
+            if($data && isset($data->{$columns['sdata']})){
213
+                //checking inactivity 
214
+                $timeInactivity = time() - get_config('session_inactivity_time', 100);
215
+                if($data->{$columns['stime']} < $timeInactivity){
216
+                    $this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it');
217
+                    $this->destroy($sid);
218
+                    return null;
219
+                }
220
+                return $this->decode($data->{$columns['sdata']});
221
+            }
222
+            $this->logger->info('Database session data for SID: ' . $sid . ' is not valid return false, may be the session ID is wrong');
223
+            return null;
224
+        }
225
+
226
+        /**
227
+         * Save the session data
228
+         * @param  string $sid  the session ID
229
+         * @param  mixed $data the session data to save in serialize format
230
+         * @return boolean 
231
+         */
232
+        public function write($sid, $data){
233
+            $this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data));
234
+            $instance = $this->getModelInstance();
235
+            $columns = $this->sessionTableColumns;
236
+
237
+            if($this->getLoader()){
238
+                $this->getLoader()->functions('user_agent'); 
239
+                $this->getLoader()->library('Browser'); 
240
+            }
241
+            else{
242
+                Loader::functions('user_agent');
243
+                Loader::library('Browser');
244
+            }
245
+
246
+            $ip = get_ip();
247
+            $keyValue = $instance->getKeyValue();
248
+            $host = @gethostbyaddr($ip) or null;
249
+            $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
250
+            $data = $this->encode($data);
251
+            $params = array(
252
+                            $columns['sid'] => $sid,
253
+                            $columns['sdata'] => $data,
254
+                            $columns['stime'] => time(),
255
+                            $columns['shost'] => $host,
256
+                            $columns['sbrowser'] => $browser,
257
+                            $columns['sip'] => $ip,
258
+                            $columns['skey'] => $keyValue
259
+                        );
260
+            $this->logger->info('Database session data to save are listed below :' . stringfy_vars($params));
261
+            $exists = $instance->get($sid);
262
+            if($exists){
263
+                $this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it');
264
+                //update
265
+                unset($params[$columns['sid']]);
266
+                $instance->update($sid, $params);
244 267
             }
268
+            else{
269
+                $this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now');
270
+                $instance->insert($params);
271
+            }
272
+            return true;
273
+        }
274
+
275
+
276
+        /**
277
+         * Destroy the session data for the given session id
278
+         * @param  string $sid the session id value
279
+         * @return boolean
280
+         */
281
+        public function destroy($sid){
282
+            $this->logger->debug('Destroy of session data for SID: ' . $sid);
283
+            $instance = $this->modelInstanceName;
284
+            $instance->delete($sid);
285
+            return true;
286
+        }
245 287
 
246
-			$ip = get_ip();
247
-			$keyValue = $instance->getKeyValue();
248
-			$host = @gethostbyaddr($ip) or null;
249
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
250
-			$data = $this->encode($data);
251
-			$params = array(
252
-							$columns['sid'] => $sid,
253
-							$columns['sdata'] => $data,
254
-							$columns['stime'] => time(),
255
-							$columns['shost'] => $host,
256
-							$columns['sbrowser'] => $browser,
257
-							$columns['sip'] => $ip,
258
-							$columns['skey'] => $keyValue
259
-						);
260
-			$this->logger->info('Database session data to save are listed below :' . stringfy_vars($params));
261
-			$exists = $instance->get($sid);
262
-			if($exists){
263
-				$this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it');
264
-				//update
265
-				unset($params[$columns['sid']]);
266
-				$instance->update($sid, $params);
267
-			}
268
-			else{
269
-				$this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now');
270
-				$instance->insert($params);
271
-			}
272
-			return true;
273
-		}
274
-
275
-
276
-		/**
277
-		 * Destroy the session data for the given session id
278
-		 * @param  string $sid the session id value
279
-		 * @return boolean
280
-		 */
281
-		public function destroy($sid){
282
-			$this->logger->debug('Destroy of session data for SID: ' . $sid);
283
-			$instance = $this->modelInstanceName;
284
-			$instance->delete($sid);
285
-			return true;
286
-		}
287
-
288
-		/**
289
-		 * Clean the expire session data to save espace
290
-		 * @param  integer $maxLifetime the max lifetime
291
-		 * @return boolean
292
-		 */
293
-		public function gc($maxLifetime){
294
-			$instance = $this->modelInstanceName;
295
-			$time = time() - $maxLifetime;
296
-			$this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']');
297
-			$instance->deleteByTime($time);
298
-			return true;
299
-		}
300
-
301
-		/**
302
-		 * Encode the session data using the openssl
303
-		 * @param  mixed $data the session data to encode
304
-		 * @return mixed the encoded session data
305
-		 */
306
-		public function encode($data){
307
-			$key = base64_decode($this->sessionSecret);
308
-			$dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
309
-			$output = base64_encode($dataEncrypted);
310
-			return $output;
311
-		}
312
-
313
-
314
-		/**
315
-		 * Decode the session data using the openssl
316
-		 * @param  mixed $data the data to decode
317
-		 * @return mixed       the decoded data
318
-		 */
319
-		public function decode($data){
320
-			$key = base64_decode($this->sessionSecret);
321
-			$data = base64_decode($data);
322
-			$data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
323
-			return $data;
324
-		}
288
+        /**
289
+         * Clean the expire session data to save espace
290
+         * @param  integer $maxLifetime the max lifetime
291
+         * @return boolean
292
+         */
293
+        public function gc($maxLifetime){
294
+            $instance = $this->modelInstanceName;
295
+            $time = time() - $maxLifetime;
296
+            $this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']');
297
+            $instance->deleteByTime($time);
298
+            return true;
299
+        }
300
+
301
+        /**
302
+         * Encode the session data using the openssl
303
+         * @param  mixed $data the session data to encode
304
+         * @return mixed the encoded session data
305
+         */
306
+        public function encode($data){
307
+            $key = base64_decode($this->sessionSecret);
308
+            $dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
309
+            $output = base64_encode($dataEncrypted);
310
+            return $output;
311
+        }
312
+
313
+
314
+        /**
315
+         * Decode the session data using the openssl
316
+         * @param  mixed $data the data to decode
317
+         * @return mixed       the decoded data
318
+         */
319
+        public function decode($data){
320
+            $key = base64_decode($this->sessionSecret);
321
+            $data = base64_decode($data);
322
+            $data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
323
+            return $data;
324
+        }
325 325
 
326 326
 		
327
-		/**
327
+        /**
328 328
          * Return the loader instance
329 329
          * @return object Loader the loader instance
330 330
          */
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
          * set the loader instance for future use
337 337
          * @param object Loader $loader the loader object
338 338
          */
339
-         public function setLoader($loader){
339
+            public function setLoader($loader){
340 340
             $this->loader = $loader;
341 341
             return $this;
342 342
         }
@@ -353,47 +353,47 @@  discard block
 block discarded – undo
353 353
          * set the model instance for future use
354 354
          * @param DBSessionHandlerModel $modelInstance the model object
355 355
          */
356
-         public function setModelInstance(DBSessionHandlerModel $modelInstance){
356
+            public function setModelInstance(DBSessionHandlerModel $modelInstance){
357 357
             $this->modelInstanceName = $modelInstance;
358 358
             return $this;
359 359
         }
360 360
 
361 361
         /**
362
-	     * Return the Log instance
363
-	     * @return Log
364
-	     */
365
-	    public function getLogger(){
366
-	      return $this->logger;
367
-	    }
368
-
369
-	    /**
370
-	     * Set the log instance
371
-	     * @param Log $logger the log object
372
-	     */
373
-	    public function setLogger(Log $logger){
374
-	      $this->logger = $logger;
375
-	      return $this;
376
-	    }
377
-
378
-	    /**
379
-	     * Set the model instance using the configuration for session
380
-	     */
381
-	    private function setModelInstanceFromConfig(){
382
-	    	$modelName = get_config('session_save_path');
383
-			$this->logger->info('The database session model: ' . $modelName);
384
-			if($this->getLoader()){
385
-				$this->getLoader()->model($modelName, 'dbsessionhandlerinstance'); 
386
-			}
387
-			//@codeCoverageIgnoreStart
388
-			else{
389
-            	Loader::model($modelName, 'dbsessionhandlerinstance'); 
362
+         * Return the Log instance
363
+         * @return Log
364
+         */
365
+        public function getLogger(){
366
+            return $this->logger;
367
+        }
368
+
369
+        /**
370
+         * Set the log instance
371
+         * @param Log $logger the log object
372
+         */
373
+        public function setLogger(Log $logger){
374
+            $this->logger = $logger;
375
+            return $this;
376
+        }
377
+
378
+        /**
379
+         * Set the model instance using the configuration for session
380
+         */
381
+        private function setModelInstanceFromConfig(){
382
+            $modelName = get_config('session_save_path');
383
+            $this->logger->info('The database session model: ' . $modelName);
384
+            if($this->getLoader()){
385
+                $this->getLoader()->model($modelName, 'dbsessionhandlerinstance'); 
386
+            }
387
+            //@codeCoverageIgnoreStart
388
+            else{
389
+                Loader::model($modelName, 'dbsessionhandlerinstance'); 
390 390
             }
391 391
             if(isset($this->OBJ->dbsessionhandlerinstance) && ! $this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel){
392
-				show_error('To use database session handler, your class model "'.get_class($this->OBJ->dbsessionhandlerinstance).'" need extends "DBSessionHandlerModel"');
393
-			}  
394
-			//@codeCoverageIgnoreEnd
392
+                show_error('To use database session handler, your class model "'.get_class($this->OBJ->dbsessionhandlerinstance).'" need extends "DBSessionHandlerModel"');
393
+            }  
394
+            //@codeCoverageIgnoreEnd
395 395
 			
396
-			//set model instance
397
-			$this->setModelInstance($this->OBJ->dbsessionhandlerinstance);
398
-	    }
399
-	}
396
+            //set model instance
397
+            $this->setModelInstance($this->OBJ->dbsessionhandlerinstance);
398
+        }
399
+    }
Please login to merge, or discard this patch.
core/classes/Request.php 1 patch
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -1,256 +1,256 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	class Request{
27
+    class Request{
28 28
 		
29
-		/**
30
-		 * The value for the super global $_GET
31
-		 * @var array
32
-		 */
33
-		public $get = null;
29
+        /**
30
+         * The value for the super global $_GET
31
+         * @var array
32
+         */
33
+        public $get = null;
34 34
 
35
-		/**
36
-		 * The value for the super global $_POST
37
-		 * @var array
38
-		 */
39
-		public $post = null;
35
+        /**
36
+         * The value for the super global $_POST
37
+         * @var array
38
+         */
39
+        public $post = null;
40 40
 
41
-		/**
42
-		 * The value for the super global $_SERVER
43
-		 * @var array
44
-		 */
45
-		public $server = null;
41
+        /**
42
+         * The value for the super global $_SERVER
43
+         * @var array
44
+         */
45
+        public $server = null;
46 46
 
47
-		/**
48
-		 * The value for the super global $_COOKIE
49
-		 * @var array
50
-		 */
51
-		public $cookie = null;
47
+        /**
48
+         * The value for the super global $_COOKIE
49
+         * @var array
50
+         */
51
+        public $cookie = null;
52 52
 
53
-		/**
54
-		 * The value for the super global $_FILES
55
-		 * @var array
56
-		 */
57
-		public $file = null;
53
+        /**
54
+         * The value for the super global $_FILES
55
+         * @var array
56
+         */
57
+        public $file = null;
58 58
 
59
-		/**
60
-		 * The value for the super global $_REQUEST
61
-		 * @var array
62
-		 */
63
-		public $query = null;
59
+        /**
60
+         * The value for the super global $_REQUEST
61
+         * @var array
62
+         */
63
+        public $query = null;
64 64
 		
65
-		/**
66
-		 * The session instance
67
-		 * @var Session
68
-		 */
69
-		public $session = null;
65
+        /**
66
+         * The session instance
67
+         * @var Session
68
+         */
69
+        public $session = null;
70 70
 		
71
-		/**
72
-		 * The request headers
73
-		 * @var array
74
-		 */
75
-		public $header = null;
71
+        /**
72
+         * The request headers
73
+         * @var array
74
+         */
75
+        public $header = null;
76 76
 
77
-		/**
78
-		 * The current request method 'GET', 'POST', 'PUT', etc.
79
-		 * @var null
80
-		 */
81
-		private $method = null;
77
+        /**
78
+         * The current request method 'GET', 'POST', 'PUT', etc.
79
+         * @var null
80
+         */
81
+        private $method = null;
82 82
 
83
-		/**
84
-		 * The current request URI
85
-		 * @var string
86
-		 */
87
-		private $requestUri = null;
83
+        /**
84
+         * The current request URI
85
+         * @var string
86
+         */
87
+        private $requestUri = null;
88 88
 		
89 89
 		
90
-		/**
91
-		 * Construct new request instance
92
-		 */
93
-		public function __construct(){
94
-			$this->get = $_GET;
95
-			$this->post = $_POST;
96
-			$this->server = $_SERVER;
97
-			$this->query = $_REQUEST;
98
-			$this->cookie = $_COOKIE;
99
-			$this->file = $_FILES;
100
-			$this->session =& class_loader('Session', 'classes');
101
-			$this->method = $this->server('REQUEST_METHOD');
102
-			$this->requestUri = $this->server('REQUEST_URI');
103
-			$this->header = array();
104
-			if(function_exists('apache_request_headers')){
105
-				$this->header = apache_request_headers();
106
-			}
107
-			else if(function_exists('getallheaders')){
108
-				$this->header = getallheaders();
109
-			}
110
-		}
90
+        /**
91
+         * Construct new request instance
92
+         */
93
+        public function __construct(){
94
+            $this->get = $_GET;
95
+            $this->post = $_POST;
96
+            $this->server = $_SERVER;
97
+            $this->query = $_REQUEST;
98
+            $this->cookie = $_COOKIE;
99
+            $this->file = $_FILES;
100
+            $this->session =& class_loader('Session', 'classes');
101
+            $this->method = $this->server('REQUEST_METHOD');
102
+            $this->requestUri = $this->server('REQUEST_URI');
103
+            $this->header = array();
104
+            if(function_exists('apache_request_headers')){
105
+                $this->header = apache_request_headers();
106
+            }
107
+            else if(function_exists('getallheaders')){
108
+                $this->header = getallheaders();
109
+            }
110
+        }
111 111
 
112
-		/**
113
-		 * Get the request method
114
-		 * @return string
115
-		 */
116
-		public function method(){
117
-			return $this->method;
118
-		}
112
+        /**
113
+         * Get the request method
114
+         * @return string
115
+         */
116
+        public function method(){
117
+            return $this->method;
118
+        }
119 119
 		
120
-		/**
121
-		 * Get the request URI
122
-		 * @return string
123
-		 */
124
-		public function requestUri(){
125
-			return $this->requestUri;
126
-		}
120
+        /**
121
+         * Get the request URI
122
+         * @return string
123
+         */
124
+        public function requestUri(){
125
+            return $this->requestUri;
126
+        }
127 127
 
128
-		/**
129
-		 * Get the value from $_REQUEST for given key. if the key is empty will return the all values
130
-		 * @param  string  $key the item key to be fetched
131
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
132
-		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
133
-		 */
134
-		public function query($key = null, $xss = true){
135
-			if(empty($key)){
136
-				//return all
137
-				return $xss ? clean_input($this->query) : $this->query;
138
-			}
139
-			$query = array_key_exists($key, $this->query) ? $this->query[$key] : null;
140
-			if($xss){
141
-				$query = clean_input($query);
142
-			}
143
-			return $query;
144
-		}
128
+        /**
129
+         * Get the value from $_REQUEST for given key. if the key is empty will return the all values
130
+         * @param  string  $key the item key to be fetched
131
+         * @param  boolean $xss if need apply some XSS attack rule on the value
132
+         * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
133
+         */
134
+        public function query($key = null, $xss = true){
135
+            if(empty($key)){
136
+                //return all
137
+                return $xss ? clean_input($this->query) : $this->query;
138
+            }
139
+            $query = array_key_exists($key, $this->query) ? $this->query[$key] : null;
140
+            if($xss){
141
+                $query = clean_input($query);
142
+            }
143
+            return $query;
144
+        }
145 145
 		
146
-		/**
147
-		 * Get the value from $_GET for given key. if the key is empty will return the all values
148
-		 * @param  string  $key the item key to be fetched
149
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
150
-		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
151
-		 */
152
-		public function get($key = null, $xss = true){
153
-			if(empty($key)){
154
-				//return all
155
-				return $xss ? clean_input($this->get) : $this->get;
156
-			}
157
-			$get = array_key_exists($key, $this->get) ? $this->get[$key] : null;
158
-			if($xss){
159
-				$get = clean_input($get);
160
-			}
161
-			return $get;
162
-		}
146
+        /**
147
+         * Get the value from $_GET for given key. if the key is empty will return the all values
148
+         * @param  string  $key the item key to be fetched
149
+         * @param  boolean $xss if need apply some XSS attack rule on the value
150
+         * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
151
+         */
152
+        public function get($key = null, $xss = true){
153
+            if(empty($key)){
154
+                //return all
155
+                return $xss ? clean_input($this->get) : $this->get;
156
+            }
157
+            $get = array_key_exists($key, $this->get) ? $this->get[$key] : null;
158
+            if($xss){
159
+                $get = clean_input($get);
160
+            }
161
+            return $get;
162
+        }
163 163
 		
164
-		/**
165
-		 * Get the value from $_POST for given key. if the key is empty will return the all values
166
-		 * @param  string  $key the item key to be fetched
167
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
168
-		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
169
-		 */
170
-		public function post($key = null, $xss = true){
171
-			if(empty($key)){
172
-				//return all
173
-				return $xss ? clean_input($this->post) : $this->post;
174
-			}
175
-			$post = array_key_exists($key, $this->post) ? $this->post[$key] : null;
176
-			if($xss){
177
-				$post = clean_input($post);
178
-			}
179
-			return $post;
180
-		}
164
+        /**
165
+         * Get the value from $_POST for given key. if the key is empty will return the all values
166
+         * @param  string  $key the item key to be fetched
167
+         * @param  boolean $xss if need apply some XSS attack rule on the value
168
+         * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
169
+         */
170
+        public function post($key = null, $xss = true){
171
+            if(empty($key)){
172
+                //return all
173
+                return $xss ? clean_input($this->post) : $this->post;
174
+            }
175
+            $post = array_key_exists($key, $this->post) ? $this->post[$key] : null;
176
+            if($xss){
177
+                $post = clean_input($post);
178
+            }
179
+            return $post;
180
+        }
181 181
 		
182
-		/**
183
-		 * Get the value from $_SERVER for given key. if the key is empty will return the all values
184
-		 * @param  string  $key the item key to be fetched
185
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
186
-		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
187
-		 */
188
-		public function server($key = null, $xss = true){
189
-			if(empty($key)){
190
-				//return all
191
-				return $xss ? clean_input($this->server) : $this->server;
192
-			}
193
-			$server = array_key_exists($key, $this->server) ? $this->server[$key] : null;
194
-			if($xss){
195
-				$server = clean_input($server);
196
-			}
197
-			return $server;
198
-		}
182
+        /**
183
+         * Get the value from $_SERVER for given key. if the key is empty will return the all values
184
+         * @param  string  $key the item key to be fetched
185
+         * @param  boolean $xss if need apply some XSS attack rule on the value
186
+         * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
187
+         */
188
+        public function server($key = null, $xss = true){
189
+            if(empty($key)){
190
+                //return all
191
+                return $xss ? clean_input($this->server) : $this->server;
192
+            }
193
+            $server = array_key_exists($key, $this->server) ? $this->server[$key] : null;
194
+            if($xss){
195
+                $server = clean_input($server);
196
+            }
197
+            return $server;
198
+        }
199 199
 		
200
-		/**
201
-		 * Get the value from $_COOKIE for given key. if the key is empty will return the all values
202
-		 * @param  string  $key the item key to be fetched
203
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
204
-		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
205
-		 */
206
-		public function cookie($key = null, $xss = true){
207
-			if(empty($key)){
208
-				//return all
209
-				return $xss ? clean_input($this->cookie) : $this->cookie;
210
-			}
211
-			$cookie = array_key_exists($key, $this->cookie) ? $this->cookie[$key] : null;
212
-			if($xss){
213
-				$cookie = clean_input($cookie);
214
-			}
215
-			return $cookie;
216
-		}
200
+        /**
201
+         * Get the value from $_COOKIE for given key. if the key is empty will return the all values
202
+         * @param  string  $key the item key to be fetched
203
+         * @param  boolean $xss if need apply some XSS attack rule on the value
204
+         * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
205
+         */
206
+        public function cookie($key = null, $xss = true){
207
+            if(empty($key)){
208
+                //return all
209
+                return $xss ? clean_input($this->cookie) : $this->cookie;
210
+            }
211
+            $cookie = array_key_exists($key, $this->cookie) ? $this->cookie[$key] : null;
212
+            if($xss){
213
+                $cookie = clean_input($cookie);
214
+            }
215
+            return $cookie;
216
+        }
217 217
 		
218
-		/**
219
-		 * Get the value from $_FILES for given key. if the key is empty will return the all values
220
-		 * @param  string  $key the item key to be fetched
221
-		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
222
-		 */
223
-		public function file($key){
224
-			$file = array_key_exists($key, $this->file) ? $this->file[$key] : null;
225
-			return $file;
226
-		}
218
+        /**
219
+         * Get the value from $_FILES for given key. if the key is empty will return the all values
220
+         * @param  string  $key the item key to be fetched
221
+         * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
222
+         */
223
+        public function file($key){
224
+            $file = array_key_exists($key, $this->file) ? $this->file[$key] : null;
225
+            return $file;
226
+        }
227 227
 		
228
-		/**
229
-		 * Get the value from $_SESSION for given key. if the key is empty will return the all values
230
-		 * @param  string  $key the item key to be fetched
231
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
232
-		 * @return array|mixed       the item value if the key exists or null if the key does not exists
233
-		 */
234
-		public function session($key, $xss = true){
235
-			$session = $this->session->get($key);
236
-			if($xss){
237
-				$session = clean_input($session);
238
-			}
239
-			return $session;
240
-		}
228
+        /**
229
+         * Get the value from $_SESSION for given key. if the key is empty will return the all values
230
+         * @param  string  $key the item key to be fetched
231
+         * @param  boolean $xss if need apply some XSS attack rule on the value
232
+         * @return array|mixed       the item value if the key exists or null if the key does not exists
233
+         */
234
+        public function session($key, $xss = true){
235
+            $session = $this->session->get($key);
236
+            if($xss){
237
+                $session = clean_input($session);
238
+            }
239
+            return $session;
240
+        }
241 241
 
242
-		/**
243
-		 * Get the value from header array for given key.
244
-		 * @param  string  $key the item key to be fetched
245
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
246
-		 * @return mixed       the item value if the key exists or null if the key does not exists
247
-		 */
248
-		public function header($key, $xss = true){
249
-			$header = array_key_exists($key, $this->header) ? $this->header[$key] : null;
250
-			if($xss){
251
-				$header = clean_input($header);
252
-			}
253
-			return $header;
254
-		}
242
+        /**
243
+         * Get the value from header array for given key.
244
+         * @param  string  $key the item key to be fetched
245
+         * @param  boolean $xss if need apply some XSS attack rule on the value
246
+         * @return mixed       the item value if the key exists or null if the key does not exists
247
+         */
248
+        public function header($key, $xss = true){
249
+            $header = array_key_exists($key, $this->header) ? $this->header[$key] : null;
250
+            if($xss){
251
+                $header = clean_input($header);
252
+            }
253
+            return $header;
254
+        }
255 255
 		
256
-	}
256
+    }
Please login to merge, or discard this patch.
core/classes/cache/ApcCache.php 1 patch
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -1,215 +1,215 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 	
27
-	class ApcCache implements CacheInterface{
27
+    class ApcCache implements CacheInterface{
28 28
 
29
-		/**
30
-		 * The logger instance
31
-		 * @var Log
32
-		 */
33
-		private $logger;
29
+        /**
30
+         * The logger instance
31
+         * @var Log
32
+         */
33
+        private $logger;
34 34
 		
35 35
 		
36
-		public function __construct(Log $logger = null){
37
-			if(! $this->isSupported()){
38
-				show_error('The cache for APC[u] driver is not available. Check if APC[u] extension is loaded and enabled.');
39
-			}
36
+        public function __construct(Log $logger = null){
37
+            if(! $this->isSupported()){
38
+                show_error('The cache for APC[u] driver is not available. Check if APC[u] extension is loaded and enabled.');
39
+            }
40 40
 
41
-			/**
42
-	         * instance of the Log class
43
-	         */
44
-	        if(is_object($logger)){
45
-	          $this->logger = $logger;
46
-	        }
47
-	        else{
48
-	            $this->logger =& class_loader('Log', 'classes');
49
-	            $this->logger->setLogger('Library::ApcCache');
50
-	        }
51
-		}
41
+            /**
42
+             * instance of the Log class
43
+             */
44
+            if(is_object($logger)){
45
+                $this->logger = $logger;
46
+            }
47
+            else{
48
+                $this->logger =& class_loader('Log', 'classes');
49
+                $this->logger->setLogger('Library::ApcCache');
50
+            }
51
+        }
52 52
 
53
-		/**
54
-		 * This is used to get the cache data using the key
55
-		 * @param  string $key the key to identify the cache data
56
-		 * @return mixed      the cache data if exists else return false
57
-		 */
58
-		public function get($key){
59
-			$this->logger->debug('Getting cache data for key ['. $key .']');
60
-			$success = false;
61
-			$data = apc_fetch($key, $success);
62
-			if($success === false){
63
-				$this->logger->info('No cache found for the key ['. $key .'], return false');
64
-				return false;
65
-			}
66
-			else{
67
-				$cacheInfo = $this->_getCacheInfo($key);
68
-				$expire = time();
69
-				if($cacheInfo){
70
-					$expire = $cacheInfo['creation_time'] + $cacheInfo['ttl'];
71
-				}
72
-				$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']');
73
-				return $data;
74
-			}
75
-		}
53
+        /**
54
+         * This is used to get the cache data using the key
55
+         * @param  string $key the key to identify the cache data
56
+         * @return mixed      the cache data if exists else return false
57
+         */
58
+        public function get($key){
59
+            $this->logger->debug('Getting cache data for key ['. $key .']');
60
+            $success = false;
61
+            $data = apc_fetch($key, $success);
62
+            if($success === false){
63
+                $this->logger->info('No cache found for the key ['. $key .'], return false');
64
+                return false;
65
+            }
66
+            else{
67
+                $cacheInfo = $this->_getCacheInfo($key);
68
+                $expire = time();
69
+                if($cacheInfo){
70
+                    $expire = $cacheInfo['creation_time'] + $cacheInfo['ttl'];
71
+                }
72
+                $this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']');
73
+                return $data;
74
+            }
75
+        }
76 76
 
77 77
 
78
-		/**
79
-		 * Save data to the cache
80
-		 * @param string  $key  the key to identify this cache data
81
-		 * @param mixed  $data the cache data to be saved
82
-		 * @param integer $ttl  the cache life time
83
-		 * @return boolean true if success otherwise will return false
84
-		 */
85
-		public function set($key, $data, $ttl = 0){
86
-			$expire = time() + $ttl;
87
-			$this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
88
-			$result = apc_store($key, $data, $ttl);
89
-			if($result === false){
90
-		    	$this->logger->error('Can not write cache data for the key ['. $key .'], return false');
91
-		    	return false;
92
-		    }
93
-		    else{
94
-		    	$this->logger->info('Cache data saved for the key ['. $key .']');
95
-		    	return true;
96
-		    }
97
-		}
78
+        /**
79
+         * Save data to the cache
80
+         * @param string  $key  the key to identify this cache data
81
+         * @param mixed  $data the cache data to be saved
82
+         * @param integer $ttl  the cache life time
83
+         * @return boolean true if success otherwise will return false
84
+         */
85
+        public function set($key, $data, $ttl = 0){
86
+            $expire = time() + $ttl;
87
+            $this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
88
+            $result = apc_store($key, $data, $ttl);
89
+            if($result === false){
90
+                $this->logger->error('Can not write cache data for the key ['. $key .'], return false');
91
+                return false;
92
+            }
93
+            else{
94
+                $this->logger->info('Cache data saved for the key ['. $key .']');
95
+                return true;
96
+            }
97
+        }
98 98
 
99 99
 
100
-		/**
101
-		 * Delete the cache data for given key
102
-		 * @param  string $key the key for cache to be deleted
103
-		 * @return boolean      true if the cache is deleted, false if can't delete 
104
-		 * the cache or the cache with the given key not exist
105
-		 */
106
-		public function delete($key){
107
-			$this->logger->debug('Deleting of cache data for key [' .$key. ']');
108
-			$cacheInfo = $this->_getCacheInfo($key);
109
-			if($cacheInfo === false){
110
-				$this->logger->info('This cache data does not exists skipping');
111
-				return false;
112
-			}
113
-			else{
114
-				$this->logger->info('Found cache data for the key [' .$key. '] remove it');
115
-	      		return apc_delete($key) === true;
116
-			}
117
-		}
100
+        /**
101
+         * Delete the cache data for given key
102
+         * @param  string $key the key for cache to be deleted
103
+         * @return boolean      true if the cache is deleted, false if can't delete 
104
+         * the cache or the cache with the given key not exist
105
+         */
106
+        public function delete($key){
107
+            $this->logger->debug('Deleting of cache data for key [' .$key. ']');
108
+            $cacheInfo = $this->_getCacheInfo($key);
109
+            if($cacheInfo === false){
110
+                $this->logger->info('This cache data does not exists skipping');
111
+                return false;
112
+            }
113
+            else{
114
+                $this->logger->info('Found cache data for the key [' .$key. '] remove it');
115
+                    return apc_delete($key) === true;
116
+            }
117
+        }
118 118
 		
119
-		/**
120
-		 * Get the cache information for given key
121
-		 * @param  string $key the key for cache to get the information for
122
-		 * @return boolean|array    the cache information. The associative array and must contains the following information:
123
-		 * 'mtime' => creation time of the cache (Unix timestamp),
124
-		 * 'expire' => expiration time of the cache (Unix timestamp),
125
-		 * 'ttl' => the time to live of the cache in second
126
-		 */
127
-		public function getInfo($key){
128
-			$this->logger->debug('Getting of cache info for key [' .$key. ']');
129
-			$cacheInfos = $this->_getCacheInfo($key);
130
-			if($cacheInfos){
131
-				$data = array(
132
-							'mtime' => $cacheInfos['creation_time'],
133
-							'expire' => $cacheInfos['creation_time'] + $cacheInfos['ttl'],
134
-							'ttl' => $cacheInfos['ttl']
135
-							);
136
-				return $data;
137
-			}
138
-			else{
139
-				$this->logger->info('This cache does not exists skipping');
140
-				return false;
141
-			}
142
-		}
119
+        /**
120
+         * Get the cache information for given key
121
+         * @param  string $key the key for cache to get the information for
122
+         * @return boolean|array    the cache information. The associative array and must contains the following information:
123
+         * 'mtime' => creation time of the cache (Unix timestamp),
124
+         * 'expire' => expiration time of the cache (Unix timestamp),
125
+         * 'ttl' => the time to live of the cache in second
126
+         */
127
+        public function getInfo($key){
128
+            $this->logger->debug('Getting of cache info for key [' .$key. ']');
129
+            $cacheInfos = $this->_getCacheInfo($key);
130
+            if($cacheInfos){
131
+                $data = array(
132
+                            'mtime' => $cacheInfos['creation_time'],
133
+                            'expire' => $cacheInfos['creation_time'] + $cacheInfos['ttl'],
134
+                            'ttl' => $cacheInfos['ttl']
135
+                            );
136
+                return $data;
137
+            }
138
+            else{
139
+                $this->logger->info('This cache does not exists skipping');
140
+                return false;
141
+            }
142
+        }
143 143
 
144 144
 
145
-		/**
146
-		 * Used to delete expired cache data
147
-		 */
148
-		public function deleteExpiredCache(){
149
-			//for APC[u] is done automatically
150
-			return true;
151
-		}
145
+        /**
146
+         * Used to delete expired cache data
147
+         */
148
+        public function deleteExpiredCache(){
149
+            //for APC[u] is done automatically
150
+            return true;
151
+        }
152 152
 
153
-		/**
154
-		 * Remove all cache data
155
-		 */
156
-		public function clean(){
157
-			$this->logger->debug('Deleting of all cache data');
158
-			$cacheInfos = apc_cache_info('user');
159
-			if(empty($cacheInfos['cache_list'])){
160
-				$this->logger->info('No cache data were found skipping');
161
-				return false;
162
-			}
163
-			else{
164
-				$this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove');
165
-				return apc_clear_cache('user');
166
-			}
167
-		}
153
+        /**
154
+         * Remove all cache data
155
+         */
156
+        public function clean(){
157
+            $this->logger->debug('Deleting of all cache data');
158
+            $cacheInfos = apc_cache_info('user');
159
+            if(empty($cacheInfos['cache_list'])){
160
+                $this->logger->info('No cache data were found skipping');
161
+                return false;
162
+            }
163
+            else{
164
+                $this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove');
165
+                return apc_clear_cache('user');
166
+            }
167
+        }
168 168
 		
169 169
 		
170
-		/**
171
-		 * Check whether the cache feature for the handle is supported
172
-		 *
173
-		 * @return bool
174
-		 */
175
-		public function isSupported(){
176
-			return (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled');
177
-		}
170
+        /**
171
+         * Check whether the cache feature for the handle is supported
172
+         *
173
+         * @return bool
174
+         */
175
+        public function isSupported(){
176
+            return (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled');
177
+        }
178 178
 
179
-		/**
180
-	     * Return the Log instance
181
-	     * @return Log
182
-	     */
183
-	    public function getLogger(){
184
-	      return $this->logger;
185
-	    }
179
+        /**
180
+         * Return the Log instance
181
+         * @return Log
182
+         */
183
+        public function getLogger(){
184
+            return $this->logger;
185
+        }
186 186
 
187
-	    /**
188
-	     * Set the log instance
189
-	     * @param Log $logger the log object
190
-	     */
191
-	    public function setLogger(Log $logger){
192
-	      $this->logger = $logger;
193
-	      return $this;
194
-	    }
187
+        /**
188
+         * Set the log instance
189
+         * @param Log $logger the log object
190
+         */
191
+        public function setLogger(Log $logger){
192
+            $this->logger = $logger;
193
+            return $this;
194
+        }
195 195
 		
196
-		/**
197
-		* Return the array of cache information
198
-		*
199
-		* @param string $key the cache key to get the cache information 
200
-		* @return boolean|array
201
-		*/
202
-		private function _getCacheInfo($key){
203
-			$caches = apc_cache_info('user');
204
-			if(! empty($caches['cache_list'])){
205
-				$cacheLists = $caches['cache_list'];
206
-				foreach ($cacheLists as $c){
207
-					if(isset($c['info']) && $c['info'] === $key){
208
-						return $c;
209
-					}
210
-				}
196
+        /**
197
+         * Return the array of cache information
198
+         *
199
+         * @param string $key the cache key to get the cache information 
200
+         * @return boolean|array
201
+         */
202
+        private function _getCacheInfo($key){
203
+            $caches = apc_cache_info('user');
204
+            if(! empty($caches['cache_list'])){
205
+                $cacheLists = $caches['cache_list'];
206
+                foreach ($cacheLists as $c){
207
+                    if(isset($c['info']) && $c['info'] === $key){
208
+                        return $c;
209
+                    }
210
+                }
211 211
 				
212
-			}
213
-			return false;
214
-		}
215
-	}
212
+            }
213
+            return false;
214
+        }
215
+    }
Please login to merge, or discard this patch.
core/classes/cache/CacheInterface.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -1,84 +1,84 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 	
27
-	interface CacheInterface{
27
+    interface CacheInterface{
28 28
 
29
-		/**
30
-		 * This is used to get the cache data using the key
31
-		 * @param  string $key the key to identify the cache data
32
-		 * @return mixed      the cache data if exists else return false
33
-		 */
34
-		public function get($key);
29
+        /**
30
+         * This is used to get the cache data using the key
31
+         * @param  string $key the key to identify the cache data
32
+         * @return mixed      the cache data if exists else return false
33
+         */
34
+        public function get($key);
35 35
 
36 36
 
37
-		/**
38
-		 * Save data to the cache
39
-		 * @param string  $key  the key to identify this cache data
40
-		 * @param mixed  $data the cache data to be saved
41
-		 * @param integer $ttl  the cache life time
42
-		 * @return boolean true if success otherwise will return false
43
-		 */
44
-		public function set($key, $data, $ttl = 0);
37
+        /**
38
+         * Save data to the cache
39
+         * @param string  $key  the key to identify this cache data
40
+         * @param mixed  $data the cache data to be saved
41
+         * @param integer $ttl  the cache life time
42
+         * @return boolean true if success otherwise will return false
43
+         */
44
+        public function set($key, $data, $ttl = 0);
45 45
 
46 46
 
47
-		/**
48
-		 * Delete the cache data for given key
49
-		 * @param  string $key the key for cache to be deleted
50
-		 * @return boolean      true if the cache is deleted, false if can't delete 
51
-		 * the cache or the cache with the given key not exist
52
-		 */
53
-		public function delete($key);
47
+        /**
48
+         * Delete the cache data for given key
49
+         * @param  string $key the key for cache to be deleted
50
+         * @return boolean      true if the cache is deleted, false if can't delete 
51
+         * the cache or the cache with the given key not exist
52
+         */
53
+        public function delete($key);
54 54
 		
55 55
 		
56
-		/**
57
-		 * Get the cache information for given key
58
-		 * @param  string $key the key for cache to get the information for
59
-		 * @return boolean|array    the cache information. The associative array and must contains the following information:
60
-		 * 'mtime' => creation time of the cache (Unix timestamp),
61
-		 * 'expire' => expiration time of the cache (Unix timestamp),
62
-		 * 'ttl' => the time to live of the cache in second
63
-		 */
64
-		public function getInfo($key);
56
+        /**
57
+         * Get the cache information for given key
58
+         * @param  string $key the key for cache to get the information for
59
+         * @return boolean|array    the cache information. The associative array and must contains the following information:
60
+         * 'mtime' => creation time of the cache (Unix timestamp),
61
+         * 'expire' => expiration time of the cache (Unix timestamp),
62
+         * 'ttl' => the time to live of the cache in second
63
+         */
64
+        public function getInfo($key);
65 65
 
66 66
 
67
-		/**
68
-		 * Used to delete expired cache data
69
-		 */
70
-		public function deleteExpiredCache();
67
+        /**
68
+         * Used to delete expired cache data
69
+         */
70
+        public function deleteExpiredCache();
71 71
 
72
-		/**
73
-		 * Remove all cache data
74
-		 */
75
-		public function clean();
72
+        /**
73
+         * Remove all cache data
74
+         */
75
+        public function clean();
76 76
 		
77 77
 		
78
-		/**
79
-		 * Check whether the cache feature for the handle is supported
80
-		 *
81
-		 * @return bool
82
-		 */
83
-		public function isSupported();
84
-	}
78
+        /**
79
+         * Check whether the cache feature for the handle is supported
80
+         *
81
+         * @return bool
82
+         */
83
+        public function isSupported();
84
+    }
Please login to merge, or discard this patch.
core/classes/EventDispatcher.php 1 patch
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -1,182 +1,182 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	/**
28
-	 * This class represent the event dispatcher management, permit to record the listener and 
29
-	 * also to dispatch the event
30
-	 */
27
+    /**
28
+     * This class represent the event dispatcher management, permit to record the listener and 
29
+     * also to dispatch the event
30
+     */
31 31
 	
32
-	class EventDispatcher{
32
+    class EventDispatcher{
33 33
 		
34
-		/**
35
-		 * The list of the registered listeners
36
-		 * @var array
37
-		 */
38
-		private $listeners = array();
34
+        /**
35
+         * The list of the registered listeners
36
+         * @var array
37
+         */
38
+        private $listeners = array();
39 39
 		
40 40
 
41
-		/**
42
-		 * The logger instance
43
-		 * @var Log
44
-		 */
45
-		private $logger;
41
+        /**
42
+         * The logger instance
43
+         * @var Log
44
+         */
45
+        private $logger;
46 46
 
47
-		public function __construct(){
48
-			$this->logger =& class_loader('Log', 'classes');
49
-			$this->logger->setLogger('Library::EventDispatcher');
50
-		}
47
+        public function __construct(){
48
+            $this->logger =& class_loader('Log', 'classes');
49
+            $this->logger->setLogger('Library::EventDispatcher');
50
+        }
51 51
 
52
-		/**
53
-		 * Register new listener
54
-		 * @param string   $eventName the name of the event to register for
55
-		 * @param callable $listener  the function or class method to receive the event information after dispatch
56
-		 */
57
-		public function addListener($eventName, callable $listener){
58
-			$this->logger->debug('Adding new event listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
59
-			if(! isset($this->listeners[$eventName])){
60
-				$this->logger->info('This event does not have the registered event listener before, adding new one');
61
-				$this->listeners[$eventName] = array();
62
-			}
63
-			else{
64
-				$this->logger->info('This event already have the registered listener, add this listener to the list');
65
-			}
66
-			$this->listeners[$eventName][] = $listener;
67
-		}
52
+        /**
53
+         * Register new listener
54
+         * @param string   $eventName the name of the event to register for
55
+         * @param callable $listener  the function or class method to receive the event information after dispatch
56
+         */
57
+        public function addListener($eventName, callable $listener){
58
+            $this->logger->debug('Adding new event listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
59
+            if(! isset($this->listeners[$eventName])){
60
+                $this->logger->info('This event does not have the registered event listener before, adding new one');
61
+                $this->listeners[$eventName] = array();
62
+            }
63
+            else{
64
+                $this->logger->info('This event already have the registered listener, add this listener to the list');
65
+            }
66
+            $this->listeners[$eventName][] = $listener;
67
+        }
68 68
 		
69
-		/**
70
-		 * Remove the event listener from list
71
-		 * @param  string   $eventName the event name
72
-		 * @param  callable $listener  the listener callback
73
-		 */
74
-		public function removeListener($eventName, callable $listener){
75
-			$this->logger->debug('Removing of the event listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
76
-			if(isset($this->listeners[$eventName])){
77
-				$this->logger->info('This event have the listeners, check if this listener exists');
78
-				if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){
79
-					$this->logger->info('Found the listener at index [' .$index. '] remove it');
80
-					unset($this->listeners[$eventName][$index]);
81
-				}
82
-				else{
83
-					$this->logger->info('Cannot found this listener in the event listener list');
84
-				}
85
-			}
86
-			else{
87
-				$this->logger->info('This event does not have this listener ignore remove');
88
-			}
89
-		}
69
+        /**
70
+         * Remove the event listener from list
71
+         * @param  string   $eventName the event name
72
+         * @param  callable $listener  the listener callback
73
+         */
74
+        public function removeListener($eventName, callable $listener){
75
+            $this->logger->debug('Removing of the event listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
76
+            if(isset($this->listeners[$eventName])){
77
+                $this->logger->info('This event have the listeners, check if this listener exists');
78
+                if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){
79
+                    $this->logger->info('Found the listener at index [' .$index. '] remove it');
80
+                    unset($this->listeners[$eventName][$index]);
81
+                }
82
+                else{
83
+                    $this->logger->info('Cannot found this listener in the event listener list');
84
+                }
85
+            }
86
+            else{
87
+                $this->logger->info('This event does not have this listener ignore remove');
88
+            }
89
+        }
90 90
 		
91
-		/**
92
-		 * Remove all the event listener. If event name is null will remove all listeners, else will just 
93
-		 * remove all listeners for this event
94
-		 * @param  string $eventName the event name
95
-		 */
96
-		public function removeAllListener($eventName = null){
97
-			$this->logger->debug('Removing of all event listener, the event name [' .$eventName. ']');
98
-			if($eventName !== null && isset($this->listeners[$eventName])){
99
-				$this->logger->info('The event name is set of exist in the listener just remove all event listener for this event');
100
-				unset($this->listeners[$eventName]);
101
-			}
102
-			else{
103
-				$this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener');
104
-				$this->listeners = array();
105
-			}
106
-		}
91
+        /**
92
+         * Remove all the event listener. If event name is null will remove all listeners, else will just 
93
+         * remove all listeners for this event
94
+         * @param  string $eventName the event name
95
+         */
96
+        public function removeAllListener($eventName = null){
97
+            $this->logger->debug('Removing of all event listener, the event name [' .$eventName. ']');
98
+            if($eventName !== null && isset($this->listeners[$eventName])){
99
+                $this->logger->info('The event name is set of exist in the listener just remove all event listener for this event');
100
+                unset($this->listeners[$eventName]);
101
+            }
102
+            else{
103
+                $this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener');
104
+                $this->listeners = array();
105
+            }
106
+        }
107 107
 		
108
-		/**
109
-		 * Get the list of listener for this event
110
-		 * @param string $eventName the event name
111
-		 * @return array the listeners for this event or empty array if this event does not contain any listener
112
-		 */
113
-		public function getListeners($eventName){
114
-			return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array();
115
-		}
108
+        /**
109
+         * Get the list of listener for this event
110
+         * @param string $eventName the event name
111
+         * @return array the listeners for this event or empty array if this event does not contain any listener
112
+         */
113
+        public function getListeners($eventName){
114
+            return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array();
115
+        }
116 116
 		
117
-		/**
118
-		 * Dispatch the event to the registered listeners.
119
-		 * @param  mixed|object $event the event information
120
-		 * @return void|object if event need return, will return the final EventInfo object.
121
-		 */	
122
-		public function dispatch($event){
123
-			if(! $event || !$event instanceof EventInfo){
124
-				$this->logger->info('The event is not set or is not an instance of "EventInfo" create the default "EventInfo" object to use instead of.');
125
-				$event = new EventInfo((string) $event);
126
-			}			
127
-			$this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']');
128
-			if(isset($event->stop) && $event->stop){
129
-				$this->logger->info('This event need stopped, no need call any listener');
130
-				return;
131
-			}
132
-			if($event->returnBack){
133
-				$this->logger->info('This event need return back, return the result for future use');
134
-				return $this->dispatchToListerners($event);
135
-			}
136
-			else{
137
-				$this->logger->info('This event no need return back the result, just dispatch it');
138
-				$this->dispatchToListerners($event);
139
-			}
140
-		}
117
+        /**
118
+         * Dispatch the event to the registered listeners.
119
+         * @param  mixed|object $event the event information
120
+         * @return void|object if event need return, will return the final EventInfo object.
121
+         */	
122
+        public function dispatch($event){
123
+            if(! $event || !$event instanceof EventInfo){
124
+                $this->logger->info('The event is not set or is not an instance of "EventInfo" create the default "EventInfo" object to use instead of.');
125
+                $event = new EventInfo((string) $event);
126
+            }			
127
+            $this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']');
128
+            if(isset($event->stop) && $event->stop){
129
+                $this->logger->info('This event need stopped, no need call any listener');
130
+                return;
131
+            }
132
+            if($event->returnBack){
133
+                $this->logger->info('This event need return back, return the result for future use');
134
+                return $this->dispatchToListerners($event);
135
+            }
136
+            else{
137
+                $this->logger->info('This event no need return back the result, just dispatch it');
138
+                $this->dispatchToListerners($event);
139
+            }
140
+        }
141 141
 		
142
-		/**
143
-		 * Dispatch the event to the registered listeners.
144
-		 * @param  object EventInfo $event  the event information
145
-		 * @return void|object if event need return, will return the final EventInfo instance.
146
-		 */	
147
-		private function dispatchToListerners(EventInfo $event){
148
-			$eBackup = $event;
149
-			$list = $this->getListeners($event->name);
150
-			if(empty($list)){
151
-				$this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.');
152
-				if($event->returnBack){
153
-					return $event;
154
-				}
155
-				return;
156
-			}
157
-			else{
158
-				$this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list));
159
-			}
160
-			foreach($list as $listener){
161
-				if($eBackup->returnBack){
162
-					$returnedEvent = call_user_func_array($listener, array($event));
163
-					if($returnedEvent instanceof EventInfo){
164
-						$event = $returnedEvent;
165
-					}
166
-					else{
167
-						show_error('This event [' .$event->name. '] need you return the event object after processing');
168
-					}
169
-				}
170
-				else{
171
-					call_user_func_array($listener, array($event));
172
-				}
173
-				if($event->stop){
174
-					break;
175
-				}
176
-			}
177
-			//only test for original event may be during the flow some listeners change this parameter
178
-			if($eBackup->returnBack){
179
-				return $event;
180
-			}
181
-		}
182
-	}
142
+        /**
143
+         * Dispatch the event to the registered listeners.
144
+         * @param  object EventInfo $event  the event information
145
+         * @return void|object if event need return, will return the final EventInfo instance.
146
+         */	
147
+        private function dispatchToListerners(EventInfo $event){
148
+            $eBackup = $event;
149
+            $list = $this->getListeners($event->name);
150
+            if(empty($list)){
151
+                $this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.');
152
+                if($event->returnBack){
153
+                    return $event;
154
+                }
155
+                return;
156
+            }
157
+            else{
158
+                $this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list));
159
+            }
160
+            foreach($list as $listener){
161
+                if($eBackup->returnBack){
162
+                    $returnedEvent = call_user_func_array($listener, array($event));
163
+                    if($returnedEvent instanceof EventInfo){
164
+                        $event = $returnedEvent;
165
+                    }
166
+                    else{
167
+                        show_error('This event [' .$event->name. '] need you return the event object after processing');
168
+                    }
169
+                }
170
+                else{
171
+                    call_user_func_array($listener, array($event));
172
+                }
173
+                if($event->stop){
174
+                    break;
175
+                }
176
+            }
177
+            //only test for original event may be during the flow some listeners change this parameter
178
+            if($eBackup->returnBack){
179
+                return $event;
180
+            }
181
+        }
182
+    }
Please login to merge, or discard this patch.
core/classes/model/DBSessionHandlerModel.php 1 patch
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -1,39 +1,39 @@  discard block
 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
-	 * DB session handler class
29
-	 */
30
- 	abstract class DBSessionHandlerModel extends Model {
27
+    /**
28
+     * DB session handler class
29
+     */
30
+        abstract class DBSessionHandlerModel extends Model {
31 31
 		
32
-		/**
33
-		 * The session table columns to use
34
-		 * @var array
35
-		 * @example
36
-		 * 	array(
32
+        /**
33
+         * The session table columns to use
34
+         * @var array
35
+         * @example
36
+         * 	array(
37 37
 				'sid' => '', //VARCHAR(255) Note: this a primary key
38 38
 				'sdata' => '', //TEXT
39 39
 				'stime' => '', //unix timestamp (INT|BIGINT)
@@ -42,41 +42,41 @@  discard block
 block discarded – undo
42 42
 				'sbrowser' => '', //VARCHAR(255) 
43 43
 				'skey' => '' //VARCHAR(255) 
44 44
 			);
45
-		 */
46
-		protected $sessionTableColumns = array();
45
+         */
46
+        protected $sessionTableColumns = array();
47 47
 
48
-		public function __construct(Database $db = null){
49
-			parent::__construct($db);
50
-		}
48
+        public function __construct(Database $db = null){
49
+            parent::__construct($db);
50
+        }
51 51
 
52
-		/**
53
-		 * Return the session database table columns
54
-		 * @return array 
55
-		 */
56
-		public function getSessionTableColumns(){
57
-			return $this->sessionTableColumns;
58
-		}
52
+        /**
53
+         * Return the session database table columns
54
+         * @return array 
55
+         */
56
+        public function getSessionTableColumns(){
57
+            return $this->sessionTableColumns;
58
+        }
59 59
 
60
-		/**
61
-		 * Set the session database table columns
62
-		 * @param array $columns the columns definition
63
-		 */
64
-		public function setSessionTableColumns(array $columns){
65
-			$this->sessionTableColumns = $columns;
66
-			return $this;
67
-		}
60
+        /**
61
+         * Set the session database table columns
62
+         * @param array $columns the columns definition
63
+         */
64
+        public function setSessionTableColumns(array $columns){
65
+            $this->sessionTableColumns = $columns;
66
+            return $this;
67
+        }
68 68
 
69
-		/**
70
-		 * Delete the expire session
71
-		 * @param  int $time the unix timestamp
72
-		 * @return int       affected rows
73
-		 */
74
-		abstract public function deleteByTime($time);
69
+        /**
70
+         * Delete the expire session
71
+         * @param  int $time the unix timestamp
72
+         * @return int       affected rows
73
+         */
74
+        abstract public function deleteByTime($time);
75 75
 
76 76
 		
77
-		/**
78
-		 * How to get the value of the table column key. Generally is the session key
79
-		 * @return mixed the key value like used to identify the data
80
-		 */
81
-		abstract public function getKeyValue();
82
-	}
77
+        /**
78
+         * How to get the value of the table column key. Generally is the session key
79
+         * @return mixed the key value like used to identify the data
80
+         */
81
+        abstract public function getKeyValue();
82
+    }
Please login to merge, or discard this patch.