@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * For application languages management |
| 29 | 29 | */ |
| 30 | - class Lang{ |
|
| 30 | + class Lang { |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * The supported available language for this application. |
@@ -67,8 +67,8 @@ discard block |
||
| 67 | 67 | /** |
| 68 | 68 | * Construct new Lang instance |
| 69 | 69 | */ |
| 70 | - public function __construct(){ |
|
| 71 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 70 | + public function __construct() { |
|
| 71 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 72 | 72 | $this->logger->setLogger('Library::Lang'); |
| 73 | 73 | |
| 74 | 74 | $this->default = get_config('default_language', 'en'); |
@@ -76,8 +76,8 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | //add the supported languages ('key', 'display name') |
| 78 | 78 | $languages = get_config('languages', null); |
| 79 | - if(! empty($languages)){ |
|
| 80 | - foreach($languages as $key => $displayName){ |
|
| 79 | + if (!empty($languages)) { |
|
| 80 | + foreach ($languages as $key => $displayName) { |
|
| 81 | 81 | $this->addLang($key, $displayName); |
| 82 | 82 | } |
| 83 | 83 | } |
@@ -85,15 +85,15 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | //if the language exists in cookie use it |
| 87 | 87 | $cfgKey = get_config('language_cookie_name'); |
| 88 | - $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']'); |
|
| 88 | + $this->logger->debug('Getting current language from cookie [' . $cfgKey . ']'); |
|
| 89 | 89 | $objCookie = & class_loader('Cookie'); |
| 90 | 90 | $cookieLang = $objCookie->get($cfgKey); |
| 91 | - if($cookieLang && $this->isValid($cookieLang)){ |
|
| 91 | + if ($cookieLang && $this->isValid($cookieLang)) { |
|
| 92 | 92 | $this->current = $cookieLang; |
| 93 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']'); |
|
| 93 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is valid so we will set the language using the cookie value [' . $cookieLang . ']'); |
|
| 94 | 94 | } |
| 95 | - else{ |
|
| 96 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
|
| 95 | + else { |
|
| 96 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is not set, use the default value [' . $this->getDefault() . ']'); |
|
| 97 | 97 | $this->current = $this->getDefault(); |
| 98 | 98 | } |
| 99 | 99 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * @return array the language message list |
| 105 | 105 | */ |
| 106 | - public function getAll(){ |
|
| 106 | + public function getAll() { |
|
| 107 | 107 | return $this->languages; |
| 108 | 108 | } |
| 109 | 109 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * @param string $key the language key to identify |
| 114 | 114 | * @param string $value the language message value |
| 115 | 115 | */ |
| 116 | - public function set($key, $value){ |
|
| 116 | + public function set($key, $value) { |
|
| 117 | 117 | $this->languages[$key] = $value; |
| 118 | 118 | } |
| 119 | 119 | |
@@ -125,11 +125,11 @@ discard block |
||
| 125 | 125 | * |
| 126 | 126 | * @return string the language message value |
| 127 | 127 | */ |
| 128 | - public function get($key, $default = 'LANGUAGE_ERROR'){ |
|
| 129 | - if(isset($this->languages[$key])){ |
|
| 128 | + public function get($key, $default = 'LANGUAGE_ERROR') { |
|
| 129 | + if (isset($this->languages[$key])) { |
|
| 130 | 130 | return $this->languages[$key]; |
| 131 | 131 | } |
| 132 | - $this->logger->warning('Language key [' .$key. '] does not exist use the default value [' .$default. ']'); |
|
| 132 | + $this->logger->warning('Language key [' . $key . '] does not exist use the default value [' . $default . ']'); |
|
| 133 | 133 | return $default; |
| 134 | 134 | } |
| 135 | 135 | |
@@ -140,10 +140,10 @@ discard block |
||
| 140 | 140 | * |
| 141 | 141 | * @return boolean true if the language directory exists, false or not |
| 142 | 142 | */ |
| 143 | - public function isValid($language){ |
|
| 143 | + public function isValid($language) { |
|
| 144 | 144 | $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH); |
| 145 | - foreach($searchDir as $dir){ |
|
| 146 | - if(file_exists($dir . $language) && is_dir($dir . $language)){ |
|
| 145 | + foreach ($searchDir as $dir) { |
|
| 146 | + if (file_exists($dir . $language) && is_dir($dir . $language)) { |
|
| 147 | 147 | return true; |
| 148 | 148 | } |
| 149 | 149 | } |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * |
| 156 | 156 | * @return string the default language |
| 157 | 157 | */ |
| 158 | - public function getDefault(){ |
|
| 158 | + public function getDefault() { |
|
| 159 | 159 | return $this->default; |
| 160 | 160 | } |
| 161 | 161 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | * |
| 165 | 165 | * @return string the current language |
| 166 | 166 | */ |
| 167 | - public function getCurrent(){ |
|
| 167 | + public function getCurrent() { |
|
| 168 | 168 | return $this->current; |
| 169 | 169 | } |
| 170 | 170 | |
@@ -174,14 +174,14 @@ discard block |
||
| 174 | 174 | * @param string $name the short language name like "en", "fr". |
| 175 | 175 | * @param string $description the human readable description of this language |
| 176 | 176 | */ |
| 177 | - public function addLang($name, $description){ |
|
| 178 | - if(isset($this->availables[$name])){ |
|
| 177 | + public function addLang($name, $description) { |
|
| 178 | + if (isset($this->availables[$name])) { |
|
| 179 | 179 | return; //already added cost in performance |
| 180 | 180 | } |
| 181 | - if($this->isValid($name)){ |
|
| 181 | + if ($this->isValid($name)) { |
|
| 182 | 182 | $this->availables[$name] = $description; |
| 183 | 183 | } |
| 184 | - else{ |
|
| 184 | + else { |
|
| 185 | 185 | show_error('The language [' . $name . '] is not valid or does not exists.'); |
| 186 | 186 | } |
| 187 | 187 | } |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | * |
| 192 | 192 | * @return array the list of the application language |
| 193 | 193 | */ |
| 194 | - public function getSupported(){ |
|
| 194 | + public function getSupported() { |
|
| 195 | 195 | return $this->availables; |
| 196 | 196 | } |
| 197 | 197 | |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | * |
| 201 | 201 | * @param array $langs the languages array of the messages to be added |
| 202 | 202 | */ |
| 203 | - public function addLangMessages(array $langs){ |
|
| 203 | + public function addLangMessages(array $langs) { |
|
| 204 | 204 | foreach ($langs as $key => $value) { |
| 205 | 205 | $this->set($key, $value); |
| 206 | 206 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | - class Session{ |
|
| 26 | + class Session { |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * The session flash key to use |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | * Get the logger singleton instance |
| 42 | 42 | * @return Log the logger instance |
| 43 | 43 | */ |
| 44 | - private static function getLogger(){ |
|
| 45 | - if(self::$logger == null){ |
|
| 46 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 44 | + private static function getLogger() { |
|
| 45 | + if (self::$logger == null) { |
|
| 46 | + self::$logger[0] = & class_loader('Log', 'classes'); |
|
| 47 | 47 | self::$logger[0]->setLogger('Library::Session'); |
| 48 | 48 | } |
| 49 | 49 | return self::$logger[0]; |
@@ -55,14 +55,14 @@ discard block |
||
| 55 | 55 | * @param mixed $default the default value to use if can not find the session item in the list |
| 56 | 56 | * @return mixed the session value if exist or the default value |
| 57 | 57 | */ |
| 58 | - public static function get($item, $default = null){ |
|
| 58 | + public static function get($item, $default = null) { |
|
| 59 | 59 | $logger = self::getLogger(); |
| 60 | - $logger->debug('Getting session data for item [' .$item. '] ...'); |
|
| 61 | - if(array_key_exists($item, $_SESSION)){ |
|
| 60 | + $logger->debug('Getting session data for item [' . $item . '] ...'); |
|
| 61 | + if (array_key_exists($item, $_SESSION)) { |
|
| 62 | 62 | $logger->info('Found session data for item [' . $item . '] the vaue is : [' . stringfy_vars($_SESSION[$item]) . ']'); |
| 63 | 63 | return $_SESSION[$item]; |
| 64 | 64 | } |
| 65 | - $logger->warning('Cannot find session item [' . $item . '] using the default value ['. $default . ']'); |
|
| 65 | + $logger->warning('Cannot find session item [' . $item . '] using the default value [' . $default . ']'); |
|
| 66 | 66 | return $default; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * @param string $item the session item name to set |
| 72 | 72 | * @param mixed $value the session item value |
| 73 | 73 | */ |
| 74 | - public static function set($item, $value){ |
|
| 74 | + public static function set($item, $value) { |
|
| 75 | 75 | $logger = self::getLogger(); |
| 76 | 76 | $logger->debug('Setting session data for item [' . $item . '], value [' . stringfy_vars($value) . ']'); |
| 77 | 77 | $_SESSION[$item] = $value; |
@@ -83,16 +83,16 @@ discard block |
||
| 83 | 83 | * @param mixed $default the default value to use if can not find the session flash item in the list |
| 84 | 84 | * @return mixed the session flash value if exist or the default value |
| 85 | 85 | */ |
| 86 | - public static function getFlash($item, $default = null){ |
|
| 86 | + public static function getFlash($item, $default = null) { |
|
| 87 | 87 | $logger = self::getLogger(); |
| 88 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 88 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
| 89 | 89 | $return = array_key_exists($key, $_SESSION) ? |
| 90 | 90 | ($_SESSION[$key]) : $default; |
| 91 | - if(array_key_exists($key, $_SESSION)){ |
|
| 91 | + if (array_key_exists($key, $_SESSION)) { |
|
| 92 | 92 | unset($_SESSION[$key]); |
| 93 | 93 | } |
| 94 | - else{ |
|
| 95 | - $logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']'); |
|
| 94 | + else { |
|
| 95 | + $logger->warning('Cannot find session flash item [' . $key . '] using the default value [' . $default . ']'); |
|
| 96 | 96 | } |
| 97 | 97 | return $return; |
| 98 | 98 | } |
@@ -102,8 +102,8 @@ discard block |
||
| 102 | 102 | * @param string $item the session flash item name |
| 103 | 103 | * @return boolean |
| 104 | 104 | */ |
| 105 | - public static function hasFlash($item){ |
|
| 106 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 105 | + public static function hasFlash($item) { |
|
| 106 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
| 107 | 107 | return array_key_exists($key, $_SESSION); |
| 108 | 108 | } |
| 109 | 109 | |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | * @param string $item the session flash item name to set |
| 113 | 113 | * @param mixed $value the session flash item value |
| 114 | 114 | */ |
| 115 | - public static function setFlash($item, $value){ |
|
| 116 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 115 | + public static function setFlash($item, $value) { |
|
| 116 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
| 117 | 117 | $_SESSION[$key] = $value; |
| 118 | 118 | } |
| 119 | 119 | |
@@ -121,14 +121,14 @@ discard block |
||
| 121 | 121 | * Clear the session item in the list |
| 122 | 122 | * @param string $item the session item name to be deleted |
| 123 | 123 | */ |
| 124 | - public static function clear($item){ |
|
| 124 | + public static function clear($item) { |
|
| 125 | 125 | $logger = self::getLogger(); |
| 126 | - if(array_key_exists($item, $_SESSION)){ |
|
| 127 | - $logger->info('Deleting of session for item ['.$item.' ]'); |
|
| 126 | + if (array_key_exists($item, $_SESSION)) { |
|
| 127 | + $logger->info('Deleting of session for item [' . $item . ' ]'); |
|
| 128 | 128 | unset($_SESSION[$item]); |
| 129 | 129 | } |
| 130 | - else{ |
|
| 131 | - $logger->warning('Session item ['.$item.'] to be deleted does not exists'); |
|
| 130 | + else { |
|
| 131 | + $logger->warning('Session item [' . $item . '] to be deleted does not exists'); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
@@ -136,15 +136,15 @@ discard block |
||
| 136 | 136 | * Clear the session flash item in the list |
| 137 | 137 | * @param string $item the session flash item name to be deleted |
| 138 | 138 | */ |
| 139 | - public static function clearFlash($item){ |
|
| 139 | + public static function clearFlash($item) { |
|
| 140 | 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.']'); |
|
| 141 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
| 142 | + if (array_key_exists($key, $_SESSION)) { |
|
| 143 | + $logger->info('Delete session flash for item [' . $item . ']'); |
|
| 144 | 144 | unset($_SESSION[$item]); |
| 145 | 145 | } |
| 146 | - else{ |
|
| 147 | - $logger->warning('Dession flash item ['.$item.'] to be deleted does not exists'); |
|
| 146 | + else { |
|
| 147 | + $logger->warning('Dession flash item [' . $item . '] to be deleted does not exists'); |
|
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
@@ -153,14 +153,14 @@ discard block |
||
| 153 | 153 | * @param string $item the session item name |
| 154 | 154 | * @return boolean |
| 155 | 155 | */ |
| 156 | - public static function exists($item){ |
|
| 156 | + public static function exists($item) { |
|
| 157 | 157 | return array_key_exists($item, $_SESSION); |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
| 161 | 161 | * Destroy all session data values |
| 162 | 162 | */ |
| 163 | - public static function clearAll(){ |
|
| 163 | + public static function clearAll() { |
|
| 164 | 164 | session_unset(); |
| 165 | 165 | session_destroy(); |
| 166 | 166 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - class Request{ |
|
| 27 | + class Request { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The value for the super global $_GET |
@@ -90,21 +90,21 @@ discard block |
||
| 90 | 90 | /** |
| 91 | 91 | * Construct new request instance |
| 92 | 92 | */ |
| 93 | - public function __construct(){ |
|
| 93 | + public function __construct() { |
|
| 94 | 94 | $this->get = $_GET; |
| 95 | 95 | $this->post = $_POST; |
| 96 | 96 | $this->server = $_SERVER; |
| 97 | 97 | $this->query = $_REQUEST; |
| 98 | 98 | $this->cookie = $_COOKIE; |
| 99 | 99 | $this->file = $_FILES; |
| 100 | - $this->session =& class_loader('Session', 'classes'); |
|
| 100 | + $this->session = & class_loader('Session', 'classes'); |
|
| 101 | 101 | $this->method = $this->server('REQUEST_METHOD'); |
| 102 | 102 | $this->requestUri = $this->server('REQUEST_URI'); |
| 103 | 103 | $this->header = array(); |
| 104 | - if(function_exists('apache_request_headers')){ |
|
| 104 | + if (function_exists('apache_request_headers')) { |
|
| 105 | 105 | $this->header = apache_request_headers(); |
| 106 | 106 | } |
| 107 | - else if(function_exists('getallheaders')){ |
|
| 107 | + else if (function_exists('getallheaders')) { |
|
| 108 | 108 | $this->header = getallheaders(); |
| 109 | 109 | } |
| 110 | 110 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * Get the request method |
| 114 | 114 | * @return string |
| 115 | 115 | */ |
| 116 | - public function method(){ |
|
| 116 | + public function method() { |
|
| 117 | 117 | return $this->method; |
| 118 | 118 | } |
| 119 | 119 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * Get the request URI |
| 122 | 122 | * @return string |
| 123 | 123 | */ |
| 124 | - public function requestUri(){ |
|
| 124 | + public function requestUri() { |
|
| 125 | 125 | return $this->requestUri; |
| 126 | 126 | } |
| 127 | 127 | |
@@ -131,13 +131,13 @@ discard block |
||
| 131 | 131 | * @param boolean $xss if need apply some XSS attack rule on the value |
| 132 | 132 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
| 133 | 133 | */ |
| 134 | - public function query($key = null, $xss = true){ |
|
| 135 | - if(empty($key)){ |
|
| 134 | + public function query($key = null, $xss = true) { |
|
| 135 | + if (empty($key)) { |
|
| 136 | 136 | //return all |
| 137 | 137 | return $xss ? clean_input($this->query) : $this->query; |
| 138 | 138 | } |
| 139 | 139 | $query = array_key_exists($key, $this->query) ? $this->query[$key] : null; |
| 140 | - if($xss){ |
|
| 140 | + if ($xss) { |
|
| 141 | 141 | $query = clean_input($query); |
| 142 | 142 | } |
| 143 | 143 | return $query; |
@@ -149,13 +149,13 @@ discard block |
||
| 149 | 149 | * @param boolean $xss if need apply some XSS attack rule on the value |
| 150 | 150 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
| 151 | 151 | */ |
| 152 | - public function get($key = null, $xss = true){ |
|
| 153 | - if(empty($key)){ |
|
| 152 | + public function get($key = null, $xss = true) { |
|
| 153 | + if (empty($key)) { |
|
| 154 | 154 | //return all |
| 155 | 155 | return $xss ? clean_input($this->get) : $this->get; |
| 156 | 156 | } |
| 157 | 157 | $get = array_key_exists($key, $this->get) ? $this->get[$key] : null; |
| 158 | - if($xss){ |
|
| 158 | + if ($xss) { |
|
| 159 | 159 | $get = clean_input($get); |
| 160 | 160 | } |
| 161 | 161 | return $get; |
@@ -167,13 +167,13 @@ discard block |
||
| 167 | 167 | * @param boolean $xss if need apply some XSS attack rule on the value |
| 168 | 168 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
| 169 | 169 | */ |
| 170 | - public function post($key = null, $xss = true){ |
|
| 171 | - if(empty($key)){ |
|
| 170 | + public function post($key = null, $xss = true) { |
|
| 171 | + if (empty($key)) { |
|
| 172 | 172 | //return all |
| 173 | 173 | return $xss ? clean_input($this->post) : $this->post; |
| 174 | 174 | } |
| 175 | 175 | $post = array_key_exists($key, $this->post) ? $this->post[$key] : null; |
| 176 | - if($xss){ |
|
| 176 | + if ($xss) { |
|
| 177 | 177 | $post = clean_input($post); |
| 178 | 178 | } |
| 179 | 179 | return $post; |
@@ -185,13 +185,13 @@ discard block |
||
| 185 | 185 | * @param boolean $xss if need apply some XSS attack rule on the value |
| 186 | 186 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
| 187 | 187 | */ |
| 188 | - public function server($key = null, $xss = true){ |
|
| 189 | - if(empty($key)){ |
|
| 188 | + public function server($key = null, $xss = true) { |
|
| 189 | + if (empty($key)) { |
|
| 190 | 190 | //return all |
| 191 | 191 | return $xss ? clean_input($this->server) : $this->server; |
| 192 | 192 | } |
| 193 | 193 | $server = array_key_exists($key, $this->server) ? $this->server[$key] : null; |
| 194 | - if($xss){ |
|
| 194 | + if ($xss) { |
|
| 195 | 195 | $server = clean_input($server); |
| 196 | 196 | } |
| 197 | 197 | return $server; |
@@ -203,13 +203,13 @@ discard block |
||
| 203 | 203 | * @param boolean $xss if need apply some XSS attack rule on the value |
| 204 | 204 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
| 205 | 205 | */ |
| 206 | - public function cookie($key = null, $xss = true){ |
|
| 207 | - if(empty($key)){ |
|
| 206 | + public function cookie($key = null, $xss = true) { |
|
| 207 | + if (empty($key)) { |
|
| 208 | 208 | //return all |
| 209 | 209 | return $xss ? clean_input($this->cookie) : $this->cookie; |
| 210 | 210 | } |
| 211 | 211 | $cookie = array_key_exists($key, $this->cookie) ? $this->cookie[$key] : null; |
| 212 | - if($xss){ |
|
| 212 | + if ($xss) { |
|
| 213 | 213 | $cookie = clean_input($cookie); |
| 214 | 214 | } |
| 215 | 215 | return $cookie; |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | * @param string $key the item key to be fetched |
| 221 | 221 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
| 222 | 222 | */ |
| 223 | - public function file($key){ |
|
| 223 | + public function file($key) { |
|
| 224 | 224 | $file = array_key_exists($key, $this->file) ? $this->file[$key] : null; |
| 225 | 225 | return $file; |
| 226 | 226 | } |
@@ -231,9 +231,9 @@ discard block |
||
| 231 | 231 | * @param boolean $xss if need apply some XSS attack rule on the value |
| 232 | 232 | * @return array|mixed the item value if the key exists or null if the key does not exists |
| 233 | 233 | */ |
| 234 | - public function session($key, $xss = true){ |
|
| 234 | + public function session($key, $xss = true) { |
|
| 235 | 235 | $session = $this->session->get($key); |
| 236 | - if($xss){ |
|
| 236 | + if ($xss) { |
|
| 237 | 237 | $session = clean_input($session); |
| 238 | 238 | } |
| 239 | 239 | return $session; |
@@ -245,9 +245,9 @@ discard block |
||
| 245 | 245 | * @param boolean $xss if need apply some XSS attack rule on the value |
| 246 | 246 | * @return mixed the item value if the key exists or null if the key does not exists |
| 247 | 247 | */ |
| 248 | - public function header($key, $xss = true){ |
|
| 248 | + public function header($key, $xss = true) { |
|
| 249 | 249 | $header = array_key_exists($key, $this->header) ? $this->header[$key] : null; |
| 250 | - if($xss){ |
|
| 250 | + if ($xss) { |
|
| 251 | 251 | $header = clean_input($header); |
| 252 | 252 | } |
| 253 | 253 | return $header; |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - class Security{ |
|
| 27 | + class Security { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The logger instance |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | * Get the logger singleton instance |
| 37 | 37 | * @return Log the logger instance |
| 38 | 38 | */ |
| 39 | - private static function getLogger(){ |
|
| 40 | - if(self::$logger == null){ |
|
| 41 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 39 | + private static function getLogger() { |
|
| 40 | + if (self::$logger == null) { |
|
| 41 | + self::$logger[0] = & class_loader('Log', 'classes'); |
|
| 42 | 42 | self::$logger[0]->setLogger('Library::Security'); |
| 43 | 43 | } |
| 44 | 44 | return self::$logger[0]; |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * This method is used to generate the CSRF token |
| 50 | 50 | * @return string the generated CSRF token |
| 51 | 51 | */ |
| 52 | - public static function generateCSRF(){ |
|
| 52 | + public static function generateCSRF() { |
|
| 53 | 53 | $logger = self::getLogger(); |
| 54 | 54 | $logger->debug('Generation of CSRF ...'); |
| 55 | 55 | |
@@ -57,14 +57,14 @@ discard block |
||
| 57 | 57 | $expire = get_config('csrf_expire', 60); |
| 58 | 58 | $keyExpire = 'csrf_expire'; |
| 59 | 59 | $currentTime = time(); |
| 60 | - if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){ |
|
| 60 | + if (Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime) { |
|
| 61 | 61 | $logger->info('The CSRF token not yet expire just return it'); |
| 62 | 62 | return Session::get($key); |
| 63 | 63 | } |
| 64 | - else{ |
|
| 64 | + else { |
|
| 65 | 65 | $newTime = $currentTime + $expire; |
| 66 | 66 | $token = sha1(uniqid()) . sha1(uniqid()); |
| 67 | - $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']'); |
|
| 67 | + $logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . '], token [' . $token . ']'); |
|
| 68 | 68 | Session::set($keyExpire, $newTime); |
| 69 | 69 | Session::set($key, $token); |
| 70 | 70 | return Session::get($key); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * This method is used to check the CSRF if is valid, not yet expire, etc. |
| 76 | 76 | * @return boolean true if valid, false if not valid |
| 77 | 77 | */ |
| 78 | - public static function validateCSRF(){ |
|
| 78 | + public static function validateCSRF() { |
|
| 79 | 79 | $logger = self::getLogger(); |
| 80 | 80 | $logger->debug('Validation of CSRF ...'); |
| 81 | 81 | |
@@ -83,23 +83,23 @@ discard block |
||
| 83 | 83 | $expire = get_config('csrf_expire', 60); |
| 84 | 84 | $keyExpire = 'csrf_expire'; |
| 85 | 85 | $currentTime = time(); |
| 86 | - $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. ']'); |
|
| 87 | - if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){ |
|
| 86 | + $logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . ']'); |
|
| 87 | + if (!Session::exists($key) || Session::get($keyExpire) <= $currentTime) { |
|
| 88 | 88 | $logger->warning('The CSRF session data is not valide'); |
| 89 | 89 | return false; |
| 90 | 90 | } |
| 91 | - else{ |
|
| 91 | + else { |
|
| 92 | 92 | //perform form data |
| 93 | 93 | //need use request->query() for best retrieve |
| 94 | 94 | //super instance |
| 95 | 95 | $obj = & get_instance(); |
| 96 | 96 | $token = $obj->request->query($key); |
| 97 | - if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){ |
|
| 98 | - $logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job'); |
|
| 97 | + if (!$token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime) { |
|
| 98 | + $logger->warning('The CSRF data [' . $token . '] is not valide may be attacker do his job'); |
|
| 99 | 99 | return false; |
| 100 | 100 | } |
| 101 | - else{ |
|
| 102 | - $logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue'); |
|
| 101 | + else { |
|
| 102 | + $logger->info('The CSRF data [' . $token . '] is valide the form data is safe continue'); |
|
| 103 | 103 | //remove the token from session |
| 104 | 104 | Session::clear($key); |
| 105 | 105 | Session::clear($keyExpire); |
@@ -111,24 +111,24 @@ discard block |
||
| 111 | 111 | /** |
| 112 | 112 | * This method is used to check the whitelist IP address access |
| 113 | 113 | */ |
| 114 | - public static function checkWhiteListIpAccess(){ |
|
| 114 | + public static function checkWhiteListIpAccess() { |
|
| 115 | 115 | $logger = self::getLogger(); |
| 116 | 116 | $logger->debug('Validation of the IP address access ...'); |
| 117 | 117 | $logger->debug('Check if whitelist IP access is enabled in the configuration ...'); |
| 118 | 118 | $isEnable = get_config('white_list_ip_enable', false); |
| 119 | - if($isEnable){ |
|
| 119 | + if ($isEnable) { |
|
| 120 | 120 | $logger->info('Whitelist IP access is enabled in the configuration'); |
| 121 | 121 | $list = get_config('white_list_ip_addresses', array()); |
| 122 | - if(! empty($list)){ |
|
| 122 | + if (!empty($list)) { |
|
| 123 | 123 | //Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing |
| 124 | 124 | require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
| 125 | 125 | $ip = get_ip(); |
| 126 | - if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){ |
|
| 126 | + if ((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)) { |
|
| 127 | 127 | $logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP'); |
| 128 | 128 | //wildcard to access all ip address |
| 129 | 129 | return; |
| 130 | 130 | } |
| 131 | - else{ |
|
| 131 | + else { |
|
| 132 | 132 | // go through all whitelisted ips |
| 133 | 133 | foreach ($list as $ipaddr) { |
| 134 | 134 | // find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*") |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | - else{ |
|
| 157 | + else { |
|
| 158 | 158 | $logger->info('Whitelist IP access is not enabled in the configuration, ignore checking'); |
| 159 | 159 | } |
| 160 | 160 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * This class represent the event detail to dispatch to correspond listener |
| 29 | 29 | */ |
| 30 | - class EventInfo{ |
|
| 30 | + class EventInfo { |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * The event name |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public $stop; |
| 56 | 56 | |
| 57 | - public function __construct($name, $payload = array(), $returnBack = false, $stop = false){ |
|
| 57 | + public function __construct($name, $payload = array(), $returnBack = false, $stop = false) { |
|
| 58 | 58 | $this->name = $name; |
| 59 | 59 | $this->payload = $payload; |
| 60 | 60 | $this->returnBack = $returnBack; |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * also to dispatch the event |
| 30 | 30 | */ |
| 31 | 31 | |
| 32 | - class EventDispatcher{ |
|
| 32 | + class EventDispatcher { |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * The list of the registered listeners |
@@ -44,8 +44,8 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | private $logger; |
| 46 | 46 | |
| 47 | - public function __construct(){ |
|
| 48 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 47 | + public function __construct() { |
|
| 48 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 49 | 49 | $this->logger->setLogger('Library::EventDispatcher'); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -54,13 +54,13 @@ discard block |
||
| 54 | 54 | * @param string $eventName the name of the event to register for |
| 55 | 55 | * @param callable $listener the function or class method to receive the event information after dispatch |
| 56 | 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])){ |
|
| 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 | 60 | $this->logger->info('This event does not have the registered event listener before, adding new one'); |
| 61 | 61 | $this->listeners[$eventName] = array(); |
| 62 | 62 | } |
| 63 | - else{ |
|
| 63 | + else { |
|
| 64 | 64 | $this->logger->info('This event already have the registered listener, add this listener to the list'); |
| 65 | 65 | } |
| 66 | 66 | $this->listeners[$eventName][] = $listener; |
@@ -71,19 +71,19 @@ discard block |
||
| 71 | 71 | * @param string $eventName the event name |
| 72 | 72 | * @param callable $listener the listener callback |
| 73 | 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])){ |
|
| 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 | 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'); |
|
| 78 | + if (false !== $index = array_search($listener, $this->listeners[$eventName], true)) { |
|
| 79 | + $this->logger->info('Found the listener at index [' . $index . '] remove it'); |
|
| 80 | 80 | unset($this->listeners[$eventName][$index]); |
| 81 | 81 | } |
| 82 | - else{ |
|
| 82 | + else { |
|
| 83 | 83 | $this->logger->info('Cannot found this listener in the event listener list'); |
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | - else{ |
|
| 86 | + else { |
|
| 87 | 87 | $this->logger->info('This event does not have this listener ignore remove'); |
| 88 | 88 | } |
| 89 | 89 | } |
@@ -93,13 +93,13 @@ discard block |
||
| 93 | 93 | * remove all listeners for this event |
| 94 | 94 | * @param string $eventName the event name |
| 95 | 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])){ |
|
| 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 | 99 | $this->logger->info('The event name is set of exist in the listener just remove all event listener for this event'); |
| 100 | 100 | unset($this->listeners[$eventName]); |
| 101 | 101 | } |
| 102 | - else{ |
|
| 102 | + else { |
|
| 103 | 103 | $this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener'); |
| 104 | 104 | $this->listeners = array(); |
| 105 | 105 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @param string $eventName the event name |
| 111 | 111 | * @return array the listeners for this event or empty array if this event does not contain any listener |
| 112 | 112 | */ |
| 113 | - public function getListeners($eventName){ |
|
| 113 | + public function getListeners($eventName) { |
|
| 114 | 114 | return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array(); |
| 115 | 115 | } |
| 116 | 116 | |
@@ -119,21 +119,21 @@ discard block |
||
| 119 | 119 | * @param mixed|object $event the event information |
| 120 | 120 | * @return void|object if event need return, will return the final EventInfo object. |
| 121 | 121 | */ |
| 122 | - public function dispatch($event){ |
|
| 123 | - if(! $event || !$event instanceof EventInfo){ |
|
| 122 | + public function dispatch($event) { |
|
| 123 | + if (!$event || !$event instanceof EventInfo) { |
|
| 124 | 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 | 125 | $event = new EventInfo((string) $event); |
| 126 | 126 | } |
| 127 | - $this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']'); |
|
| 128 | - if(isset($event->stop) && $event->stop){ |
|
| 127 | + $this->logger->debug('Dispatch to the event listener, the event [' . stringfy_vars($event) . ']'); |
|
| 128 | + if (isset($event->stop) && $event->stop) { |
|
| 129 | 129 | $this->logger->info('This event need stopped, no need call any listener'); |
| 130 | 130 | return; |
| 131 | 131 | } |
| 132 | - if($event->returnBack){ |
|
| 132 | + if ($event->returnBack) { |
|
| 133 | 133 | $this->logger->info('This event need return back, return the result for future use'); |
| 134 | 134 | return $this->dispatchToListerners($event); |
| 135 | 135 | } |
| 136 | - else{ |
|
| 136 | + else { |
|
| 137 | 137 | $this->logger->info('This event no need return back the result, just dispatch it'); |
| 138 | 138 | $this->dispatchToListerners($event); |
| 139 | 139 | } |
@@ -144,38 +144,38 @@ discard block |
||
| 144 | 144 | * @param object EventInfo $event the event information |
| 145 | 145 | * @return void|object if event need return, will return the final EventInfo instance. |
| 146 | 146 | */ |
| 147 | - private function dispatchToListerners(EventInfo $event){ |
|
| 147 | + private function dispatchToListerners(EventInfo $event) { |
|
| 148 | 148 | $eBackup = $event; |
| 149 | 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){ |
|
| 150 | + if (empty($list)) { |
|
| 151 | + $this->logger->info('No event listener is registered for the event [' . $event->name . '] skipping.'); |
|
| 152 | + if ($event->returnBack) { |
|
| 153 | 153 | return $event; |
| 154 | 154 | } |
| 155 | 155 | return; |
| 156 | 156 | } |
| 157 | - else{ |
|
| 158 | - $this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list)); |
|
| 157 | + else { |
|
| 158 | + $this->logger->info('Found the registered event listener for the event [' . $event->name . '] the list are: ' . stringfy_vars($list)); |
|
| 159 | 159 | } |
| 160 | - foreach($list as $listener){ |
|
| 161 | - if($eBackup->returnBack){ |
|
| 160 | + foreach ($list as $listener) { |
|
| 161 | + if ($eBackup->returnBack) { |
|
| 162 | 162 | $returnedEvent = call_user_func_array($listener, array($event)); |
| 163 | - if($returnedEvent instanceof EventInfo){ |
|
| 163 | + if ($returnedEvent instanceof EventInfo) { |
|
| 164 | 164 | $event = $returnedEvent; |
| 165 | 165 | } |
| 166 | - else{ |
|
| 167 | - show_error('This event [' .$event->name. '] need you return the event object after processing'); |
|
| 166 | + else { |
|
| 167 | + show_error('This event [' . $event->name . '] need you return the event object after processing'); |
|
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | - else{ |
|
| 170 | + else { |
|
| 171 | 171 | call_user_func_array($listener, array($event)); |
| 172 | 172 | } |
| 173 | - if($event->stop){ |
|
| 173 | + if ($event->stop) { |
|
| 174 | 174 | break; |
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | //only test for original event may be during the flow some listeners change this parameter |
| 178 | - if($eBackup->returnBack){ |
|
| 178 | + if ($eBackup->returnBack) { |
|
| 179 | 179 | return $event; |
| 180 | 180 | } |
| 181 | 181 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - public function testDefaultValue(){ |
|
| 28 | + public function testDefaultValue() { |
|
| 29 | 29 | $e = new EventInfo('foo'); |
| 30 | 30 | $this->assertSame($e->name, 'foo'); |
| 31 | 31 | $this->assertSame($e->payload, array()); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $this->assertFalse($e->stop); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - public function testPayloadValueIsSet(){ |
|
| 36 | + public function testPayloadValueIsSet() { |
|
| 37 | 37 | $e = new EventInfo('foo', array('bar')); |
| 38 | 38 | $this->assertSame($e->name, 'foo'); |
| 39 | 39 | $this->assertSame($e->payload, array('bar')); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $this->assertFalse($e->stop); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - public function testReturnBackValueIsSetToTrue(){ |
|
| 44 | + public function testReturnBackValueIsSetToTrue() { |
|
| 45 | 45 | $e = new EventInfo('foo', array('bar'), true); |
| 46 | 46 | $this->assertSame($e->name, 'foo'); |
| 47 | 47 | $this->assertSame($e->payload, array('bar')); |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $this->assertFalse($e->stop); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - public function testStopValueIsSetToTue(){ |
|
| 52 | + public function testStopValueIsSetToTue() { |
|
| 53 | 53 | $e = new EventInfo('foo', array('bar'), true, true); |
| 54 | 54 | $this->assertSame($e->name, 'foo'); |
| 55 | 55 | $this->assertSame($e->payload, array('bar')); |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - class Controller{ |
|
| 27 | + class Controller { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The name of the module if this controller belong to an module |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * Class constructor |
| 49 | 49 | * @param object $logger the Log instance to use if is null will create one |
| 50 | 50 | */ |
| 51 | - public function __construct(Log $logger = null){ |
|
| 51 | + public function __construct(Log $logger = null) { |
|
| 52 | 52 | //setting the Log instance |
| 53 | 53 | $this->setLoggerFromParamOrCreateNewInstance($logger); |
| 54 | 54 | |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | /** |
| 85 | 85 | * This method is used to set the module name |
| 86 | 86 | */ |
| 87 | - protected function setModuleNameFromRouter(){ |
|
| 87 | + protected function setModuleNameFromRouter() { |
|
| 88 | 88 | //determine the current module |
| 89 | - if(isset($this->router) && $this->router->getModule()){ |
|
| 89 | + if (isset($this->router) && $this->router->getModule()) { |
|
| 90 | 90 | $this->moduleName = $this->router->getModule(); |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -95,13 +95,13 @@ discard block |
||
| 95 | 95 | * Set the cache using the argument otherwise will use the configuration |
| 96 | 96 | * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured |
| 97 | 97 | */ |
| 98 | - protected function setCacheFromParamOrConfig(CacheInterface $cache = null){ |
|
| 98 | + protected function setCacheFromParamOrConfig(CacheInterface $cache = null) { |
|
| 99 | 99 | $this->logger->debug('Setting the cache handler instance'); |
| 100 | 100 | //set cache handler instance |
| 101 | - if(get_config('cache_enable', false)){ |
|
| 102 | - if ($cache !== null){ |
|
| 101 | + if (get_config('cache_enable', false)) { |
|
| 102 | + if ($cache !== null) { |
|
| 103 | 103 | $this->cache = $cache; |
| 104 | - } else if (isset($this->{strtolower(get_config('cache_handler'))})){ |
|
| 104 | + } else if (isset($this->{strtolower(get_config('cache_handler'))})) { |
|
| 105 | 105 | $this->cache = $this->{strtolower(get_config('cache_handler'))}; |
| 106 | 106 | unset($this->{strtolower(get_config('cache_handler'))}); |
| 107 | 107 | } |
@@ -112,12 +112,12 @@ discard block |
||
| 112 | 112 | * Set the Log instance using argument or create new instance |
| 113 | 113 | * @param object $logger the Log instance if not null |
| 114 | 114 | */ |
| 115 | - protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
|
| 116 | - if($logger !== null){ |
|
| 115 | + protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) { |
|
| 116 | + if ($logger !== null) { |
|
| 117 | 117 | $this->logger = $logger; |
| 118 | 118 | } |
| 119 | - else{ |
|
| 120 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 119 | + else { |
|
| 120 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 121 | 121 | $this->logger->setLogger('MainController'); |
| 122 | 122 | } |
| 123 | 123 | } |
@@ -126,20 +126,20 @@ discard block |
||
| 126 | 126 | * This method is used to load the required resources for framework to work |
| 127 | 127 | * @return void |
| 128 | 128 | */ |
| 129 | - private function loadRequiredResources(){ |
|
| 129 | + private function loadRequiredResources() { |
|
| 130 | 130 | $this->logger->debug('Adding the loaded classes to the super instance'); |
| 131 | - foreach (class_loaded() as $var => $class){ |
|
| 132 | - $this->$var =& class_loader($class); |
|
| 131 | + foreach (class_loaded() as $var => $class) { |
|
| 132 | + $this->$var = & class_loader($class); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | $this->logger->debug('Loading the required classes into super instance'); |
| 136 | - $this->eventdispatcher =& class_loader('EventDispatcher', 'classes'); |
|
| 137 | - $this->loader =& class_loader('Loader', 'classes'); |
|
| 138 | - $this->lang =& class_loader('Lang', 'classes'); |
|
| 139 | - $this->request =& class_loader('Request', 'classes'); |
|
| 136 | + $this->eventdispatcher = & class_loader('EventDispatcher', 'classes'); |
|
| 137 | + $this->loader = & class_loader('Loader', 'classes'); |
|
| 138 | + $this->lang = & class_loader('Lang', 'classes'); |
|
| 139 | + $this->request = & class_loader('Request', 'classes'); |
|
| 140 | 140 | //dispatch the request instance created event |
| 141 | 141 | $this->eventdispatcher->dispatch('REQUEST_CREATED'); |
| 142 | - $this->response =& class_loader('Response', 'classes', 'classes'); |
|
| 142 | + $this->response = & class_loader('Response', 'classes', 'classes'); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | } |
@@ -27,11 +27,11 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists) |
| 29 | 29 | */ |
| 30 | - if( !interface_exists('SessionHandlerInterface')){ |
|
| 30 | + if (!interface_exists('SessionHandlerInterface')) { |
|
| 31 | 31 | show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.'); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - class DBSessionHandler implements SessionHandlerInterface{ |
|
| 34 | + class DBSessionHandler implements SessionHandlerInterface { |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * The encryption method to use to encrypt session data in database |
@@ -81,25 +81,25 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | protected $loader = null; |
| 83 | 83 | |
| 84 | - public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null){ |
|
| 84 | + public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null) { |
|
| 85 | 85 | /** |
| 86 | 86 | * instance of the Log class |
| 87 | 87 | */ |
| 88 | - if(is_object($logger)){ |
|
| 88 | + if (is_object($logger)) { |
|
| 89 | 89 | $this->setLogger($logger); |
| 90 | 90 | } |
| 91 | - else{ |
|
| 92 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 91 | + else { |
|
| 92 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 93 | 93 | $this->logger->setLogger('Library::DBSessionHandler'); |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - if(is_object($loader)){ |
|
| 96 | + if (is_object($loader)) { |
|
| 97 | 97 | $this->setLoader($loader); |
| 98 | 98 | } |
| 99 | 99 | $this->OBJ = & get_instance(); |
| 100 | 100 | |
| 101 | 101 | |
| 102 | - if(is_object($modelInstance)){ |
|
| 102 | + if (is_object($modelInstance)) { |
|
| 103 | 103 | $this->setModelInstance($modelInstance); |
| 104 | 104 | } |
| 105 | 105 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * Set the session secret used to encrypt the data in database |
| 109 | 109 | * @param string $secret the base64 string secret |
| 110 | 110 | */ |
| 111 | - public function setSessionSecret($secret){ |
|
| 111 | + public function setSessionSecret($secret) { |
|
| 112 | 112 | $this->sessionSecret = $secret; |
| 113 | 113 | return $this; |
| 114 | 114 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * Return the session secret |
| 118 | 118 | * @return string |
| 119 | 119 | */ |
| 120 | - public function getSessionSecret(){ |
|
| 120 | + public function getSessionSecret() { |
|
| 121 | 121 | return $this->sessionSecret; |
| 122 | 122 | } |
| 123 | 123 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * Set the initializer vector for openssl |
| 127 | 127 | * @param string $key the session secret used |
| 128 | 128 | */ |
| 129 | - public function setInitializerVector($key){ |
|
| 129 | + public function setInitializerVector($key) { |
|
| 130 | 130 | $iv_length = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD); |
| 131 | 131 | $key = base64_decode($key); |
| 132 | 132 | $this->iv = substr(hash('sha256', $key), 0, $iv_length); |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * Return the initializer vector |
| 138 | 138 | * @return string |
| 139 | 139 | */ |
| 140 | - public function getInitializerVector(){ |
|
| 140 | + public function getInitializerVector() { |
|
| 141 | 141 | return $this->iv; |
| 142 | 142 | } |
| 143 | 143 | |
@@ -147,17 +147,17 @@ discard block |
||
| 147 | 147 | * @param string $sessionName the session name |
| 148 | 148 | * @return boolean |
| 149 | 149 | */ |
| 150 | - public function open($savePath, $sessionName){ |
|
| 150 | + public function open($savePath, $sessionName) { |
|
| 151 | 151 | $this->logger->debug('Opening database session handler for [' . $sessionName . ']'); |
| 152 | 152 | //try to check if session secret is set before |
| 153 | 153 | $secret = $this->getSessionSecret(); |
| 154 | - if(empty($secret)){ |
|
| 154 | + if (empty($secret)) { |
|
| 155 | 155 | $secret = get_config('session_secret', null); |
| 156 | 156 | $this->setSessionSecret($secret); |
| 157 | 157 | } |
| 158 | 158 | $this->logger->info('Session secret: ' . $secret); |
| 159 | 159 | |
| 160 | - if(! $this->getModelInstance()){ |
|
| 160 | + if (!$this->getModelInstance()) { |
|
| 161 | 161 | $this->setModelInstanceFromConfig(); |
| 162 | 162 | } |
| 163 | 163 | $this->setInitializerVector($secret); |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | //set session tables columns |
| 166 | 166 | $this->sessionTableColumns = $this->getModelInstance()->getSessionTableColumns(); |
| 167 | 167 | |
| 168 | - if(empty($this->sessionTableColumns)){ |
|
| 168 | + if (empty($this->sessionTableColumns)) { |
|
| 169 | 169 | show_error('The session handler is "database" but the table columns not set'); |
| 170 | 170 | } |
| 171 | 171 | $this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns)); |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * Close the session |
| 182 | 182 | * @return boolean |
| 183 | 183 | */ |
| 184 | - public function close(){ |
|
| 184 | + public function close() { |
|
| 185 | 185 | $this->logger->debug('Closing database session handler'); |
| 186 | 186 | return true; |
| 187 | 187 | } |
@@ -191,28 +191,28 @@ discard block |
||
| 191 | 191 | * @param string $sid the session id to use |
| 192 | 192 | * @return string the session data in serialiaze format |
| 193 | 193 | */ |
| 194 | - public function read($sid){ |
|
| 194 | + public function read($sid) { |
|
| 195 | 195 | $this->logger->debug('Reading database session data for SID: ' . $sid); |
| 196 | 196 | $instance = $this->getModelInstance(); |
| 197 | 197 | $columns = $this->sessionTableColumns; |
| 198 | - if($this->getLoader()){ |
|
| 198 | + if ($this->getLoader()) { |
|
| 199 | 199 | $this->getLoader()->functions('user_agent'); |
| 200 | 200 | $this->getLoader()->library('Browser'); |
| 201 | 201 | } |
| 202 | - else{ |
|
| 202 | + else { |
|
| 203 | 203 | Loader::functions('user_agent'); |
| 204 | 204 | Loader::library('Browser'); |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | $ip = get_ip(); |
| 208 | 208 | $host = @gethostbyaddr($ip) or null; |
| 209 | - $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion(); |
|
| 209 | + $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion(); |
|
| 210 | 210 | |
| 211 | 211 | $data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser)); |
| 212 | - if($data && isset($data->{$columns['sdata']})){ |
|
| 212 | + if ($data && isset($data->{$columns['sdata']})) { |
|
| 213 | 213 | //checking inactivity |
| 214 | 214 | $timeInactivity = time() - get_config('session_inactivity_time', 100); |
| 215 | - if($data->{$columns['stime']} < $timeInactivity){ |
|
| 215 | + if ($data->{$columns['stime']} < $timeInactivity) { |
|
| 216 | 216 | $this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it'); |
| 217 | 217 | $this->destroy($sid); |
| 218 | 218 | return null; |
@@ -229,16 +229,16 @@ discard block |
||
| 229 | 229 | * @param mixed $data the session data to save in serialize format |
| 230 | 230 | * @return boolean |
| 231 | 231 | */ |
| 232 | - public function write($sid, $data){ |
|
| 232 | + public function write($sid, $data) { |
|
| 233 | 233 | $this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data)); |
| 234 | 234 | $instance = $this->getModelInstance(); |
| 235 | 235 | $columns = $this->sessionTableColumns; |
| 236 | 236 | |
| 237 | - if($this->getLoader()){ |
|
| 237 | + if ($this->getLoader()) { |
|
| 238 | 238 | $this->getLoader()->functions('user_agent'); |
| 239 | 239 | $this->getLoader()->library('Browser'); |
| 240 | 240 | } |
| 241 | - else{ |
|
| 241 | + else { |
|
| 242 | 242 | Loader::functions('user_agent'); |
| 243 | 243 | Loader::library('Browser'); |
| 244 | 244 | } |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | $ip = get_ip(); |
| 247 | 247 | $keyValue = $instance->getKeyValue(); |
| 248 | 248 | $host = @gethostbyaddr($ip) or null; |
| 249 | - $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion(); |
|
| 249 | + $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion(); |
|
| 250 | 250 | $data = $this->encode($data); |
| 251 | 251 | $params = array( |
| 252 | 252 | $columns['sid'] => $sid, |
@@ -259,13 +259,13 @@ discard block |
||
| 259 | 259 | ); |
| 260 | 260 | $this->logger->info('Database session data to save are listed below :' . stringfy_vars($params)); |
| 261 | 261 | $exists = $instance->get($sid); |
| 262 | - if($exists){ |
|
| 262 | + if ($exists) { |
|
| 263 | 263 | $this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it'); |
| 264 | 264 | //update |
| 265 | 265 | unset($params[$columns['sid']]); |
| 266 | 266 | $instance->update($sid, $params); |
| 267 | 267 | } |
| 268 | - else{ |
|
| 268 | + else { |
|
| 269 | 269 | $this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now'); |
| 270 | 270 | $instance->insert($params); |
| 271 | 271 | } |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | * @param string $sid the session id value |
| 279 | 279 | * @return boolean |
| 280 | 280 | */ |
| 281 | - public function destroy($sid){ |
|
| 281 | + public function destroy($sid) { |
|
| 282 | 282 | $this->logger->debug('Destroy of session data for SID: ' . $sid); |
| 283 | 283 | $instance = $this->modelInstanceName; |
| 284 | 284 | $instance->delete($sid); |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * @param integer $maxLifetime the max lifetime |
| 291 | 291 | * @return boolean |
| 292 | 292 | */ |
| 293 | - public function gc($maxLifetime){ |
|
| 293 | + public function gc($maxLifetime) { |
|
| 294 | 294 | $instance = $this->modelInstanceName; |
| 295 | 295 | $time = time() - $maxLifetime; |
| 296 | 296 | $this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']'); |
@@ -303,9 +303,9 @@ discard block |
||
| 303 | 303 | * @param mixed $data the session data to encode |
| 304 | 304 | * @return mixed the encoded session data |
| 305 | 305 | */ |
| 306 | - public function encode($data){ |
|
| 306 | + public function encode($data) { |
|
| 307 | 307 | $key = base64_decode($this->sessionSecret); |
| 308 | - $dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
|
| 308 | + $dataEncrypted = openssl_encrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
|
| 309 | 309 | $output = base64_encode($dataEncrypted); |
| 310 | 310 | return $output; |
| 311 | 311 | } |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | * @param mixed $data the data to decode |
| 317 | 317 | * @return mixed the decoded data |
| 318 | 318 | */ |
| 319 | - public function decode($data){ |
|
| 319 | + public function decode($data) { |
|
| 320 | 320 | $key = base64_decode($this->sessionSecret); |
| 321 | 321 | $data = base64_decode($data); |
| 322 | 322 | $data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | * Return the loader instance |
| 329 | 329 | * @return object Loader the loader instance |
| 330 | 330 | */ |
| 331 | - public function getLoader(){ |
|
| 331 | + public function getLoader() { |
|
| 332 | 332 | return $this->loader; |
| 333 | 333 | } |
| 334 | 334 | |
@@ -336,7 +336,7 @@ discard block |
||
| 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 | } |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | * Return the model instance |
| 346 | 346 | * @return object DBSessionHandlerModel the model instance |
| 347 | 347 | */ |
| 348 | - public function getModelInstance(){ |
|
| 348 | + public function getModelInstance() { |
|
| 349 | 349 | return $this->modelInstanceName; |
| 350 | 350 | } |
| 351 | 351 | |
@@ -353,7 +353,7 @@ discard block |
||
| 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 | } |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | * Return the Log instance |
| 363 | 363 | * @return Log |
| 364 | 364 | */ |
| 365 | - public function getLogger(){ |
|
| 365 | + public function getLogger() { |
|
| 366 | 366 | return $this->logger; |
| 367 | 367 | } |
| 368 | 368 | |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | * Set the log instance |
| 371 | 371 | * @param Log $logger the log object |
| 372 | 372 | */ |
| 373 | - public function setLogger(Log $logger){ |
|
| 373 | + public function setLogger(Log $logger) { |
|
| 374 | 374 | $this->logger = $logger; |
| 375 | 375 | return $this; |
| 376 | 376 | } |
@@ -378,18 +378,18 @@ discard block |
||
| 378 | 378 | /** |
| 379 | 379 | * Set the model instance using the configuration for session |
| 380 | 380 | */ |
| 381 | - private function setModelInstanceFromConfig(){ |
|
| 381 | + private function setModelInstanceFromConfig() { |
|
| 382 | 382 | $modelName = get_config('session_save_path'); |
| 383 | 383 | $this->logger->info('The database session model: ' . $modelName); |
| 384 | - if($this->getLoader()){ |
|
| 384 | + if ($this->getLoader()) { |
|
| 385 | 385 | $this->getLoader()->model($modelName, 'dbsessionhandlerinstance'); |
| 386 | 386 | } |
| 387 | 387 | //@codeCoverageIgnoreStart |
| 388 | - else{ |
|
| 388 | + else { |
|
| 389 | 389 | Loader::model($modelName, 'dbsessionhandlerinstance'); |
| 390 | 390 | } |
| 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"'); |
|
| 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 | 393 | } |
| 394 | 394 | //@codeCoverageIgnoreEnd |
| 395 | 395 | |