@@ -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 | } |
@@ -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 Response{ |
|
| 27 | + class Response { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The list of request header to send with response |
@@ -65,9 +65,9 @@ discard block |
||
| 65 | 65 | /** |
| 66 | 66 | * Construct new response instance |
| 67 | 67 | */ |
| 68 | - public function __construct(){ |
|
| 69 | - $this->_currentUrl = (! empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '' ) |
|
| 70 | - . (! empty($_SERVER['QUERY_STRING']) ? ('?' . $_SERVER['QUERY_STRING']) : '' ); |
|
| 68 | + public function __construct() { |
|
| 69 | + $this->_currentUrl = (!empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '') |
|
| 70 | + . (!empty($_SERVER['QUERY_STRING']) ? ('?' . $_SERVER['QUERY_STRING']) : ''); |
|
| 71 | 71 | |
| 72 | 72 | $this->_currentUrlCacheKey = md5($this->_currentUrl); |
| 73 | 73 | |
@@ -82,9 +82,9 @@ discard block |
||
| 82 | 82 | * Get the logger singleton instance |
| 83 | 83 | * @return Log the logger instance |
| 84 | 84 | */ |
| 85 | - private static function getLogger(){ |
|
| 86 | - if(self::$logger == null){ |
|
| 87 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 85 | + private static function getLogger() { |
|
| 86 | + if (self::$logger == null) { |
|
| 87 | + self::$logger[0] = & class_loader('Log', 'classes'); |
|
| 88 | 88 | self::$logger[0]->setLogger('Library::Response'); |
| 89 | 89 | } |
| 90 | 90 | return self::$logger[0]; |
@@ -95,12 +95,12 @@ discard block |
||
| 95 | 95 | * @param integer $httpCode the HTTP status code |
| 96 | 96 | * @param array $headers the additional headers to add to the existing headers list |
| 97 | 97 | */ |
| 98 | - public static function sendHeaders($httpCode = 200, array $headers = array()){ |
|
| 98 | + public static function sendHeaders($httpCode = 200, array $headers = array()) { |
|
| 99 | 99 | set_http_status_header($httpCode); |
| 100 | 100 | self::setHeaders($headers); |
| 101 | - if(! headers_sent()){ |
|
| 102 | - foreach(self::getHeaders() as $key => $value){ |
|
| 103 | - header($key .': '.$value); |
|
| 101 | + if (!headers_sent()) { |
|
| 102 | + foreach (self::getHeaders() as $key => $value) { |
|
| 103 | + header($key . ': ' . $value); |
|
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * Get the list of the headers |
| 110 | 110 | * @return array the headers list |
| 111 | 111 | */ |
| 112 | - public static function getHeaders(){ |
|
| 112 | + public static function getHeaders() { |
|
| 113 | 113 | return self::$headers; |
| 114 | 114 | } |
| 115 | 115 | |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * @param string $name the header name |
| 119 | 119 | * @return string the header value |
| 120 | 120 | */ |
| 121 | - public static function getHeader($name){ |
|
| 121 | + public static function getHeader($name) { |
|
| 122 | 122 | return array_key_exists($name, self::$headers) ? self::$headers[$name] : null; |
| 123 | 123 | } |
| 124 | 124 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * @param string $name the header name |
| 129 | 129 | * @param string $value the header value to be set |
| 130 | 130 | */ |
| 131 | - public static function setHeader($name, $value){ |
|
| 131 | + public static function setHeader($name, $value) { |
|
| 132 | 132 | self::$headers[$name] = $value; |
| 133 | 133 | } |
| 134 | 134 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * @param array $headers the list of the headers to set. |
| 138 | 138 | * Note: this will merge with the existing headers |
| 139 | 139 | */ |
| 140 | - public static function setHeaders(array $headers){ |
|
| 140 | + public static function setHeaders(array $headers) { |
|
| 141 | 141 | self::$headers = array_merge(self::getHeaders(), $headers); |
| 142 | 142 | } |
| 143 | 143 | |
@@ -145,17 +145,17 @@ discard block |
||
| 145 | 145 | * Redirect user in the specified page |
| 146 | 146 | * @param string $path the URL or URI to be redirect to |
| 147 | 147 | */ |
| 148 | - public static function redirect($path = ''){ |
|
| 148 | + public static function redirect($path = '') { |
|
| 149 | 149 | $logger = self::getLogger(); |
| 150 | 150 | $url = Url::site_url($path); |
| 151 | - $logger->info('Redirect to URL [' .$url. ']'); |
|
| 152 | - if(! headers_sent()){ |
|
| 153 | - header('Location: '.$url); |
|
| 151 | + $logger->info('Redirect to URL [' . $url . ']'); |
|
| 152 | + if (!headers_sent()) { |
|
| 153 | + header('Location: ' . $url); |
|
| 154 | 154 | exit; |
| 155 | 155 | } |
| 156 | - else{ |
|
| 156 | + else { |
|
| 157 | 157 | echo '<script> |
| 158 | - location.href = "'.$url.'"; |
|
| 158 | + location.href = "'.$url . '"; |
|
| 159 | 159 | </script>'; |
| 160 | 160 | } |
| 161 | 161 | } |
@@ -168,10 +168,10 @@ discard block |
||
| 168 | 168 | * @return void|string if $return is true will return the view content otherwise |
| 169 | 169 | * will display the view content. |
| 170 | 170 | */ |
| 171 | - public function render($view, $data = null, $return = false){ |
|
| 171 | + public function render($view, $data = null, $return = false) { |
|
| 172 | 172 | $logger = self::getLogger(); |
| 173 | 173 | //convert data to an array |
| 174 | - $data = ! is_array($data) ? (array) $data : $data; |
|
| 174 | + $data = !is_array($data) ? (array) $data : $data; |
|
| 175 | 175 | $view = str_ireplace('.php', '', $view); |
| 176 | 176 | $view = trim($view, '/\\'); |
| 177 | 177 | $viewFile = $view . '.php'; |
@@ -180,42 +180,42 @@ discard block |
||
| 180 | 180 | //super instance |
| 181 | 181 | $obj = & get_instance(); |
| 182 | 182 | |
| 183 | - if(Module::hasModule()){ |
|
| 183 | + if (Module::hasModule()) { |
|
| 184 | 184 | //check in module first |
| 185 | 185 | $logger->debug('Checking the view [' . $view . '] from module list ...'); |
| 186 | 186 | $mod = null; |
| 187 | 187 | //check if the request class contains module name |
| 188 | - if(strpos($view, '/') !== false){ |
|
| 188 | + if (strpos($view, '/') !== false) { |
|
| 189 | 189 | $viewPath = explode('/', $view); |
| 190 | - if(isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())){ |
|
| 190 | + if (isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())) { |
|
| 191 | 191 | $mod = $viewPath[0]; |
| 192 | 192 | array_shift($viewPath); |
| 193 | 193 | $view = implode('/', $viewPath); |
| 194 | 194 | $viewFile = $view . '.php'; |
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | - if(! $mod && !empty($obj->moduleName)){ |
|
| 197 | + if (!$mod && !empty($obj->moduleName)) { |
|
| 198 | 198 | $mod = $obj->moduleName; |
| 199 | 199 | } |
| 200 | - if($mod){ |
|
| 200 | + if ($mod) { |
|
| 201 | 201 | $moduleViewPath = Module::findViewFullPath($view, $mod); |
| 202 | - if($moduleViewPath){ |
|
| 202 | + if ($moduleViewPath) { |
|
| 203 | 203 | $path = $moduleViewPath; |
| 204 | - $logger->info('Found view [' . $view . '] in module [' .$mod. '], the file path is [' .$moduleViewPath. '] we will used it'); |
|
| 204 | + $logger->info('Found view [' . $view . '] in module [' . $mod . '], the file path is [' . $moduleViewPath . '] we will used it'); |
|
| 205 | 205 | } |
| 206 | - else{ |
|
| 207 | - $logger->info('Cannot find view [' . $view . '] in module [' .$mod. '] using the default location'); |
|
| 206 | + else { |
|
| 207 | + $logger->info('Cannot find view [' . $view . '] in module [' . $mod . '] using the default location'); |
|
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | - else{ |
|
| 210 | + else { |
|
| 211 | 211 | $logger->info('The current request does not use module using the default location.'); |
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | $logger->info('The view file path to be loaded is [' . $path . ']'); |
| 215 | 215 | $found = false; |
| 216 | - if(file_exists($path)){ |
|
| 217 | - foreach(get_object_vars($obj) as $key => $value){ |
|
| 218 | - if(! isset($this->{$key})){ |
|
| 216 | + if (file_exists($path)) { |
|
| 217 | + foreach (get_object_vars($obj) as $key => $value) { |
|
| 218 | + if (!isset($this->{$key})) { |
|
| 219 | 219 | $this->{$key} = & $obj->{$key}; |
| 220 | 220 | } |
| 221 | 221 | } |
@@ -224,39 +224,39 @@ discard block |
||
| 224 | 224 | //need use require() instead of require_once because can load this view many time |
| 225 | 225 | require $path; |
| 226 | 226 | $content = ob_get_clean(); |
| 227 | - if($return){ |
|
| 227 | + if ($return) { |
|
| 228 | 228 | return $content; |
| 229 | 229 | } |
| 230 | 230 | $this->_pageRender .= $content; |
| 231 | 231 | $found = true; |
| 232 | 232 | } |
| 233 | - if(! $found){ |
|
| 234 | - show_error('Unable to find view [' .$view . ']'); |
|
| 233 | + if (!$found) { |
|
| 234 | + show_error('Unable to find view [' . $view . ']'); |
|
| 235 | 235 | } |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
| 239 | 239 | * Send the final page output to user |
| 240 | 240 | */ |
| 241 | - public function renderFinalPage(){ |
|
| 241 | + public function renderFinalPage() { |
|
| 242 | 242 | $logger = self::getLogger(); |
| 243 | 243 | $obj = & get_instance(); |
| 244 | 244 | $cachePageStatus = get_config('cache_enable', false) && !empty($obj->view_cache_enable); |
| 245 | 245 | $dispatcher = $obj->eventdispatcher; |
| 246 | 246 | $content = $this->_pageRender; |
| 247 | - if(! $content){ |
|
| 247 | + if (!$content) { |
|
| 248 | 248 | $logger->warning('The final view content is empty.'); |
| 249 | 249 | return; |
| 250 | 250 | } |
| 251 | 251 | //dispatch |
| 252 | 252 | $event = $dispatcher->dispatch(new EventInfo('FINAL_VIEW_READY', $content, true)); |
| 253 | - $content = ! empty($event->payload) ? $event->payload : null; |
|
| 254 | - if(empty($content)){ |
|
| 253 | + $content = !empty($event->payload) ? $event->payload : null; |
|
| 254 | + if (empty($content)) { |
|
| 255 | 255 | $logger->warning('The view content is empty after dispatch to event listeners.'); |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | //check whether need save the page into cache. |
| 259 | - if($cachePageStatus){ |
|
| 259 | + if ($cachePageStatus) { |
|
| 260 | 260 | //current page URL |
| 261 | 261 | $url = $this->_currentUrl; |
| 262 | 262 | //Cache view Time to live in second |
@@ -271,14 +271,14 @@ discard block |
||
| 271 | 271 | |
| 272 | 272 | //get the cache information to prepare header to send to browser |
| 273 | 273 | $cacheInfo = $cacheInstance->getInfo($cacheKey); |
| 274 | - if($cacheInfo){ |
|
| 274 | + if ($cacheInfo) { |
|
| 275 | 275 | $lastModified = $cacheInfo['mtime']; |
| 276 | 276 | $expire = $cacheInfo['expire']; |
| 277 | 277 | $maxAge = $expire - time(); |
| 278 | 278 | self::setHeader('Pragma', 'public'); |
| 279 | 279 | self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public'); |
| 280 | - self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT'); |
|
| 281 | - self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT'); |
|
| 280 | + self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT'); |
|
| 281 | + self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); |
|
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | 284 | |
@@ -289,10 +289,10 @@ discard block |
||
| 289 | 289 | $content = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsedTime, $memoryUsage), $content); |
| 290 | 290 | |
| 291 | 291 | //compress the output if is available |
| 292 | - if (self::$_canCompressOutput){ |
|
| 292 | + if (self::$_canCompressOutput) { |
|
| 293 | 293 | ob_start('ob_gzhandler'); |
| 294 | 294 | } |
| 295 | - else{ |
|
| 295 | + else { |
|
| 296 | 296 | ob_start(); |
| 297 | 297 | } |
| 298 | 298 | self::sendHeaders(200); |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | /** |
| 304 | 304 | * Send the final page output to user if is cached |
| 305 | 305 | */ |
| 306 | - public function renderFinalPageFromCache(&$cache){ |
|
| 306 | + public function renderFinalPageFromCache(&$cache) { |
|
| 307 | 307 | $logger = self::getLogger(); |
| 308 | 308 | $url = $this->_currentUrl; |
| 309 | 309 | //the current page cache key for identification |
@@ -312,25 +312,25 @@ discard block |
||
| 312 | 312 | $logger->debug('Checking if the page content for the URL [' . $url . '] is cached ...'); |
| 313 | 313 | //get the cache information to prepare header to send to browser |
| 314 | 314 | $cacheInfo = $cache->getInfo($pageCacheKey); |
| 315 | - if($cacheInfo){ |
|
| 315 | + if ($cacheInfo) { |
|
| 316 | 316 | $lastModified = $cacheInfo['mtime']; |
| 317 | 317 | $expire = $cacheInfo['expire']; |
| 318 | 318 | $maxAge = $expire - $_SERVER['REQUEST_TIME']; |
| 319 | 319 | self::setHeader('Pragma', 'public'); |
| 320 | 320 | self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public'); |
| 321 | - self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT'); |
|
| 322 | - self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT'); |
|
| 323 | - if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])){ |
|
| 321 | + self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT'); |
|
| 322 | + self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); |
|
| 323 | + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { |
|
| 324 | 324 | $logger->info('The cache page content is not yet expire for the URL [' . $url . '] send 304 header to browser'); |
| 325 | 325 | self::sendHeaders(304); |
| 326 | 326 | return; |
| 327 | 327 | } |
| 328 | - else{ |
|
| 328 | + else { |
|
| 329 | 329 | $logger->info('The cache page content is expired or the browser don\'t send the HTTP_IF_MODIFIED_SINCE header for the URL [' . $url . '] send cache headers to tell the browser'); |
| 330 | 330 | self::sendHeaders(200); |
| 331 | 331 | //get the cache content |
| 332 | 332 | $content = $cache->get($pageCacheKey); |
| 333 | - if($content){ |
|
| 333 | + if ($content) { |
|
| 334 | 334 | $logger->info('The page content for the URL [' . $url . '] already cached just display it'); |
| 335 | 335 | //load benchmark class |
| 336 | 336 | $benchmark = & class_loader('Benchmark'); |
@@ -343,17 +343,17 @@ discard block |
||
| 343 | 343 | |
| 344 | 344 | ///display the final output |
| 345 | 345 | //compress the output if is available |
| 346 | - if (self::$_canCompressOutput){ |
|
| 346 | + if (self::$_canCompressOutput) { |
|
| 347 | 347 | ob_start('ob_gzhandler'); |
| 348 | 348 | } |
| 349 | - else{ |
|
| 349 | + else { |
|
| 350 | 350 | ob_start(); |
| 351 | 351 | } |
| 352 | 352 | echo $content; |
| 353 | 353 | ob_end_flush(); |
| 354 | 354 | return; |
| 355 | 355 | } |
| 356 | - else{ |
|
| 356 | + else { |
|
| 357 | 357 | $logger->info('The page cache content for the URL [' . $url . '] is not valid may be already expired'); |
| 358 | 358 | $cache->delete($pageCacheKey); |
| 359 | 359 | } |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | * Get the final page to be rendered |
| 366 | 366 | * @return string |
| 367 | 367 | */ |
| 368 | - public function getFinalPageRendered(){ |
|
| 368 | + public function getFinalPageRendered() { |
|
| 369 | 369 | return $this->_pageRender; |
| 370 | 370 | } |
| 371 | 371 | |
@@ -373,14 +373,14 @@ discard block |
||
| 373 | 373 | * Send the HTTP 404 error if can not found the |
| 374 | 374 | * routing information for the current request |
| 375 | 375 | */ |
| 376 | - public static function send404(){ |
|
| 376 | + public static function send404() { |
|
| 377 | 377 | /********* for logs **************/ |
| 378 | 378 | //can't use $obj = & get_instance() here because the global super object will be available until |
| 379 | 379 | //the main controller is loaded even for Loader::library('xxxx'); |
| 380 | 380 | $logger = self::getLogger(); |
| 381 | - $request =& class_loader('Request', 'classes'); |
|
| 382 | - $userAgent =& class_loader('Browser'); |
|
| 383 | - $browser = $userAgent->getPlatform().', '.$userAgent->getBrowser().' '.$userAgent->getVersion(); |
|
| 381 | + $request = & class_loader('Request', 'classes'); |
|
| 382 | + $userAgent = & class_loader('Browser'); |
|
| 383 | + $browser = $userAgent->getPlatform() . ', ' . $userAgent->getBrowser() . ' ' . $userAgent->getVersion(); |
|
| 384 | 384 | |
| 385 | 385 | //here can't use Loader::functions just include the helper manually |
| 386 | 386 | require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
@@ -390,12 +390,12 @@ discard block |
||
| 390 | 390 | $logger->error($str); |
| 391 | 391 | /***********************************/ |
| 392 | 392 | $path = CORE_VIEWS_PATH . '404.php'; |
| 393 | - if(file_exists($path)){ |
|
| 393 | + if (file_exists($path)) { |
|
| 394 | 394 | //compress the output if is available |
| 395 | - if (self::$_canCompressOutput){ |
|
| 395 | + if (self::$_canCompressOutput) { |
|
| 396 | 396 | ob_start('ob_gzhandler'); |
| 397 | 397 | } |
| 398 | - else{ |
|
| 398 | + else { |
|
| 399 | 399 | ob_start(); |
| 400 | 400 | } |
| 401 | 401 | require_once $path; |
@@ -403,8 +403,8 @@ discard block |
||
| 403 | 403 | self::sendHeaders(404); |
| 404 | 404 | echo $output; |
| 405 | 405 | } |
| 406 | - else{ |
|
| 407 | - show_error('The 404 view [' .$path. '] does not exist'); |
|
| 406 | + else { |
|
| 407 | + show_error('The 404 view [' . $path . '] does not exist'); |
|
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | 410 | |
@@ -412,14 +412,14 @@ discard block |
||
| 412 | 412 | * Display the error to user |
| 413 | 413 | * @param array $data the error information |
| 414 | 414 | */ |
| 415 | - public static function sendError(array $data = array()){ |
|
| 415 | + public static function sendError(array $data = array()) { |
|
| 416 | 416 | $path = CORE_VIEWS_PATH . 'errors.php'; |
| 417 | - if(file_exists($path)){ |
|
| 417 | + if (file_exists($path)) { |
|
| 418 | 418 | //compress the output if exists |
| 419 | - if (self::$_canCompressOutput){ |
|
| 419 | + if (self::$_canCompressOutput) { |
|
| 420 | 420 | ob_start('ob_gzhandler'); |
| 421 | 421 | } |
| 422 | - else{ |
|
| 422 | + else { |
|
| 423 | 423 | ob_start(); |
| 424 | 424 | } |
| 425 | 425 | extract($data); |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | self::sendHeaders(503); |
| 429 | 429 | echo $output; |
| 430 | 430 | } |
| 431 | - else{ |
|
| 431 | + else { |
|
| 432 | 432 | //can't use show_error() at this time because some dependencies not yet loaded and to prevent loop |
| 433 | 433 | set_http_status_header(503); |
| 434 | 434 | echo 'The error view [' . $path . '] does not exist'; |
@@ -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 Config{ |
|
| 27 | + class Config { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The list of loaded configuration |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | * The signleton of the logger |
| 43 | 43 | * @return Object the Log instance |
| 44 | 44 | */ |
| 45 | - private static function getLogger(){ |
|
| 46 | - if(self::$logger == null){ |
|
| 45 | + private static function getLogger() { |
|
| 46 | + if (self::$logger == null) { |
|
| 47 | 47 | $logger = array(); |
| 48 | - $logger[0] =& class_loader('Log', 'classes'); |
|
| 48 | + $logger[0] = & class_loader('Log', 'classes'); |
|
| 49 | 49 | $logger[0]->setLogger('Library::Config'); |
| 50 | 50 | self::$logger = $logger[0]; |
| 51 | 51 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @param Log $logger the log object |
| 58 | 58 | * @return Log the log instance |
| 59 | 59 | */ |
| 60 | - public static function setLogger($logger){ |
|
| 60 | + public static function setLogger($logger) { |
|
| 61 | 61 | self::$logger = $logger; |
| 62 | 62 | return self::$logger; |
| 63 | 63 | } |
@@ -65,12 +65,12 @@ discard block |
||
| 65 | 65 | /** |
| 66 | 66 | * Initialize the configuration by loading all the configuration from config file |
| 67 | 67 | */ |
| 68 | - public static function init(){ |
|
| 68 | + public static function init() { |
|
| 69 | 69 | $logger = static::getLogger(); |
| 70 | 70 | $logger->debug('Initialization of the configuration'); |
| 71 | 71 | self::$config = & load_configurations(); |
| 72 | 72 | self::setBaseUrlUsingServerVar(); |
| 73 | - if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){ |
|
| 73 | + if (ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info', 'all'))) { |
|
| 74 | 74 | $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance'); |
| 75 | 75 | } |
| 76 | 76 | $logger->info('Configuration initialized successfully'); |
@@ -83,12 +83,12 @@ discard block |
||
| 83 | 83 | * @param mixed $default the default value to use if can not find the config item in the list |
| 84 | 84 | * @return mixed the config value if exist or the default value |
| 85 | 85 | */ |
| 86 | - public static function get($item, $default = null){ |
|
| 86 | + public static function get($item, $default = null) { |
|
| 87 | 87 | $logger = static::getLogger(); |
| 88 | - if(array_key_exists($item, self::$config)){ |
|
| 88 | + if (array_key_exists($item, self::$config)) { |
|
| 89 | 89 | return self::$config[$item]; |
| 90 | 90 | } |
| 91 | - $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']'); |
|
| 91 | + $logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']'); |
|
| 92 | 92 | return $default; |
| 93 | 93 | } |
| 94 | 94 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * @param string $item the config item name to set |
| 98 | 98 | * @param mixed $value the config item value |
| 99 | 99 | */ |
| 100 | - public static function set($item, $value){ |
|
| 100 | + public static function set($item, $value) { |
|
| 101 | 101 | self::$config[$item] = $value; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * Get all the configuration values |
| 106 | 106 | * @return array the config values |
| 107 | 107 | */ |
| 108 | - public static function getAll(){ |
|
| 108 | + public static function getAll() { |
|
| 109 | 109 | return self::$config; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * Set the configuration values bu merged with the existing configuration |
| 114 | 114 | * @param array $config the config values to add in the configuration list |
| 115 | 115 | */ |
| 116 | - public static function setAll(array $config = array()){ |
|
| 116 | + public static function setAll(array $config = array()) { |
|
| 117 | 117 | self::$config = array_merge(self::$config, $config); |
| 118 | 118 | } |
| 119 | 119 | |
@@ -122,15 +122,15 @@ discard block |
||
| 122 | 122 | * @param string $item the config item name to be deleted |
| 123 | 123 | * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
| 124 | 124 | */ |
| 125 | - public static function delete($item){ |
|
| 125 | + public static function delete($item) { |
|
| 126 | 126 | $logger = static::getLogger(); |
| 127 | - if(array_key_exists($item, self::$config)){ |
|
| 128 | - $logger->info('Delete config item ['.$item.']'); |
|
| 127 | + if (array_key_exists($item, self::$config)) { |
|
| 128 | + $logger->info('Delete config item [' . $item . ']'); |
|
| 129 | 129 | unset(self::$config[$item]); |
| 130 | 130 | return true; |
| 131 | 131 | } |
| 132 | - else{ |
|
| 133 | - $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
|
| 132 | + else { |
|
| 133 | + $logger->warning('Config item [' . $item . '] to be deleted does not exists'); |
|
| 134 | 134 | return false; |
| 135 | 135 | } |
| 136 | 136 | } |
@@ -139,38 +139,38 @@ discard block |
||
| 139 | 139 | * Load the configuration file. This an alias to Loader::config() |
| 140 | 140 | * @param string $config the config name to be loaded |
| 141 | 141 | */ |
| 142 | - public static function load($config){ |
|
| 142 | + public static function load($config) { |
|
| 143 | 143 | Loader::config($config); |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
| 147 | 147 | * Set the configuration for "base_url" if is not set in the configuration |
| 148 | 148 | */ |
| 149 | - private static function setBaseUrlUsingServerVar(){ |
|
| 149 | + private static function setBaseUrlUsingServerVar() { |
|
| 150 | 150 | $logger = static::getLogger(); |
| 151 | - if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){ |
|
| 152 | - if(ENVIRONMENT == 'production'){ |
|
| 151 | + if (!isset(self::$config['base_url']) || !is_url(self::$config['base_url'])) { |
|
| 152 | + if (ENVIRONMENT == 'production') { |
|
| 153 | 153 | $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time'); |
| 154 | 154 | } |
| 155 | 155 | $baseUrl = null; |
| 156 | - if (isset($_SERVER['SERVER_ADDR'])){ |
|
| 156 | + if (isset($_SERVER['SERVER_ADDR'])) { |
|
| 157 | 157 | //check if the server is running under IPv6 |
| 158 | - if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){ |
|
| 159 | - $baseUrl = '['.$_SERVER['SERVER_ADDR'].']'; |
|
| 158 | + if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) { |
|
| 159 | + $baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']'; |
|
| 160 | 160 | } |
| 161 | - else{ |
|
| 161 | + else { |
|
| 162 | 162 | $baseUrl = $_SERVER['SERVER_ADDR']; |
| 163 | 163 | } |
| 164 | - $port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && ! is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https()) ) ? ':' . $_SERVER['SERVER_PORT'] : ''); |
|
| 165 | - $baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port |
|
| 164 | + $port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && !is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https())) ? ':' . $_SERVER['SERVER_PORT'] : ''); |
|
| 165 | + $baseUrl = (is_https() ? 'https' : 'http') . '://' . $baseUrl . $port |
|
| 166 | 166 | . substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))); |
| 167 | 167 | } |
| 168 | - else{ |
|
| 168 | + else { |
|
| 169 | 169 | $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
| 170 | 170 | $baseUrl = 'http://localhost/'; |
| 171 | 171 | } |
| 172 | 172 | self::set('base_url', $baseUrl); |
| 173 | 173 | } |
| 174 | - self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/'; |
|
| 174 | + self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/'; |
|
| 175 | 175 | } |
| 176 | 176 | } |
@@ -25,13 +25,13 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class FormValidation{ |
|
| 28 | + class FormValidation { |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * The form validation status |
| 32 | 32 | * @var boolean |
| 33 | 33 | */ |
| 34 | - protected $_success = false; |
|
| 34 | + protected $_success = false; |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * The list of errors messages |
@@ -40,31 +40,31 @@ discard block |
||
| 40 | 40 | protected $_errorsMessages = array(); |
| 41 | 41 | |
| 42 | 42 | // Array of rule sets, fieldName => PIPE seperated ruleString |
| 43 | - protected $_rules = array(); |
|
| 43 | + protected $_rules = array(); |
|
| 44 | 44 | |
| 45 | 45 | // Array of errors, niceName => Error Message |
| 46 | - protected $_errors = array(); |
|
| 46 | + protected $_errors = array(); |
|
| 47 | 47 | |
| 48 | 48 | // Array of post Key => Nice name labels |
| 49 | - protected $_labels = array(); |
|
| 49 | + protected $_labels = array(); |
|
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * The errors delimiters |
| 53 | 53 | * @var array |
| 54 | 54 | */ |
| 55 | - protected $_allErrorsDelimiter = array('<div class="error">', '</div>'); |
|
| 55 | + protected $_allErrorsDelimiter = array('<div class="error">', '</div>'); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * The each error delimiter |
| 59 | 59 | * @var array |
| 60 | 60 | */ |
| 61 | - protected $_eachErrorDelimiter = array('<p class="error">', '</p>'); |
|
| 61 | + protected $_eachErrorDelimiter = array('<p class="error">', '</p>'); |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * Indicated if need force the validation to be failed |
| 65 | 65 | * @var boolean |
| 66 | 66 | */ |
| 67 | - protected $_forceFail = false; |
|
| 67 | + protected $_forceFail = false; |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * The list of the error messages overrides by the original |
@@ -98,13 +98,13 @@ discard block |
||
| 98 | 98 | * @return void |
| 99 | 99 | */ |
| 100 | 100 | public function __construct() { |
| 101 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 101 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 102 | 102 | $this->logger->setLogger('Library::FormValidation'); |
| 103 | 103 | |
| 104 | 104 | //Load form validation language message |
| 105 | 105 | Loader::lang('form_validation'); |
| 106 | 106 | $obj = & get_instance(); |
| 107 | - $this->_errorsMessages = array( |
|
| 107 | + $this->_errorsMessages = array( |
|
| 108 | 108 | 'required' => $obj->lang->get('fv_required'), |
| 109 | 109 | 'min_length' => $obj->lang->get('fv_min_length'), |
| 110 | 110 | 'max_length' => $obj->lang->get('fv_max_length'), |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $this->_success = false; |
| 142 | 142 | $this->_forceFail = false; |
| 143 | 143 | $this->data = array(); |
| 144 | - $this->enableCsrfCheck = false; |
|
| 144 | + $this->enableCsrfCheck = false; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * |
| 151 | 151 | * @return FormValidation Current instance of object. |
| 152 | 152 | */ |
| 153 | - public function setData(array $data){ |
|
| 153 | + public function setData(array $data) { |
|
| 154 | 154 | $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data)); |
| 155 | 155 | $this->data = $data; |
| 156 | 156 | return $this; |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * Get the form validation data |
| 161 | 161 | * @return array the form validation data to be validated |
| 162 | 162 | */ |
| 163 | - public function getData(){ |
|
| 163 | + public function getData() { |
|
| 164 | 164 | return $this->data; |
| 165 | 165 | } |
| 166 | 166 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * |
| 170 | 170 | * @return string the function name |
| 171 | 171 | */ |
| 172 | - protected function _toCallCase($funcName, $prefix='_validate') { |
|
| 172 | + protected function _toCallCase($funcName, $prefix = '_validate') { |
|
| 173 | 173 | $funcName = strtolower($funcName); |
| 174 | 174 | $finalFuncName = $prefix; |
| 175 | 175 | foreach (explode('_', $funcName) as $funcNamePart) { |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | * @return boolean Whether or not the form has been submitted or the data is available for validation. |
| 194 | 194 | */ |
| 195 | 195 | public function canDoValidation() { |
| 196 | - return get_instance()->request->method() === 'POST' || ! empty($this->data); |
|
| 196 | + return get_instance()->request->method() === 'POST' || !empty($this->data); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -215,13 +215,13 @@ discard block |
||
| 215 | 215 | * afterwards. |
| 216 | 216 | */ |
| 217 | 217 | protected function _run() { |
| 218 | - if(get_instance()->request->method() == 'POST' || $this->enableCsrfCheck){ |
|
| 218 | + if (get_instance()->request->method() == 'POST' || $this->enableCsrfCheck) { |
|
| 219 | 219 | $this->logger->debug('Check if CSRF is enabled in configuration'); |
| 220 | 220 | //first check for CSRF |
| 221 | - if ((get_config('csrf_enable', false) || $this->enableCsrfCheck) && ! Security::validateCSRF()){ |
|
| 221 | + if ((get_config('csrf_enable', false) || $this->enableCsrfCheck) && !Security::validateCSRF()) { |
|
| 222 | 222 | show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.'); |
| 223 | 223 | } |
| 224 | - else{ |
|
| 224 | + else { |
|
| 225 | 225 | $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it'); |
| 226 | 226 | } |
| 227 | 227 | } |
@@ -229,10 +229,10 @@ discard block |
||
| 229 | 229 | $this->_forceFail = false; |
| 230 | 230 | |
| 231 | 231 | foreach ($this->getData() as $inputName => $inputVal) { |
| 232 | - if(is_array($this->data[$inputName])){ |
|
| 232 | + if (is_array($this->data[$inputName])) { |
|
| 233 | 233 | $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
| 234 | 234 | } |
| 235 | - else{ |
|
| 235 | + else { |
|
| 236 | 236 | $this->data[$inputName] = trim($this->data[$inputName]); |
| 237 | 237 | } |
| 238 | 238 | |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | public function setRule($inputField, $inputLabel, $ruleSets) { |
| 260 | 260 | $this->_rules[$inputField] = $ruleSets; |
| 261 | 261 | $this->_labels[$inputField] = $inputLabel; |
| 262 | - $this->logger->info('Set the field rule: name [' .$inputField. '], label [' .$inputLabel. '], rules [' .$ruleSets. ']'); |
|
| 262 | + $this->logger->info('Set the field rule: name [' . $inputField . '], label [' . $inputLabel . '], rules [' . $ruleSets . ']'); |
|
| 263 | 263 | return $this; |
| 264 | 264 | } |
| 265 | 265 | |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | } |
| 424 | 424 | $errorOutput .= $errorsEnd; |
| 425 | 425 | echo ($echo) ? $errorOutput : ''; |
| 426 | - return (! $echo) ? $errorOutput : null; |
|
| 426 | + return (!$echo) ? $errorOutput : null; |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | /** |
@@ -448,25 +448,25 @@ discard block |
||
| 448 | 448 | /* |
| 449 | 449 | //////////////// hack for regex rule that can contain "|" |
| 450 | 450 | */ |
| 451 | - if(strpos($ruleString, 'regex') !== false){ |
|
| 451 | + if (strpos($ruleString, 'regex') !== false) { |
|
| 452 | 452 | $regexRule = array(); |
| 453 | 453 | $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#'; |
| 454 | 454 | preg_match($rule, $ruleString, $regexRule); |
| 455 | 455 | $ruleStringTemp = preg_replace($rule, '', $ruleString); |
| 456 | - if(!empty($regexRule[0])){ |
|
| 456 | + if (!empty($regexRule[0])) { |
|
| 457 | 457 | $ruleSets[] = $regexRule[0]; |
| 458 | 458 | } |
| 459 | 459 | $ruleStringRegex = explode('|', $ruleStringTemp); |
| 460 | 460 | foreach ($ruleStringRegex as $rule) { |
| 461 | 461 | $rule = trim($rule); |
| 462 | - if($rule){ |
|
| 462 | + if ($rule) { |
|
| 463 | 463 | $ruleSets[] = $rule; |
| 464 | 464 | } |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | } |
| 468 | 468 | /***********************************/ |
| 469 | - else{ |
|
| 469 | + else { |
|
| 470 | 470 | if (strpos($ruleString, '|') !== FALSE) { |
| 471 | 471 | $ruleSets = explode('|', $ruleString); |
| 472 | 472 | } else { |
@@ -498,7 +498,7 @@ discard block |
||
| 498 | 498 | * @return void |
| 499 | 499 | */ |
| 500 | 500 | protected function _validateRule($inputName, $inputVal, $ruleName) { |
| 501 | - $this->logger->debug('Rule validation of field [' .$inputName. '], value [' .$inputVal. '], rule [' .$ruleName. ']'); |
|
| 501 | + $this->logger->debug('Rule validation of field [' . $inputName . '], value [' . $inputVal . '], rule [' . $ruleName . ']'); |
|
| 502 | 502 | // Array to store args |
| 503 | 503 | $ruleArgs = array(); |
| 504 | 504 | |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | $key = $i - 1; |
| 544 | 544 | $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase); |
| 545 | 545 | } |
| 546 | - if (! array_key_exists($inputName, $this->_errors)) { |
|
| 546 | + if (!array_key_exists($inputName, $this->_errors)) { |
|
| 547 | 547 | $this->_errors[$inputName] = $rulePhrase; |
| 548 | 548 | } |
| 549 | 549 | } |
@@ -595,13 +595,13 @@ discard block |
||
| 595 | 595 | */ |
| 596 | 596 | protected function _validateRequired($inputName, $ruleName, array $ruleArgs) { |
| 597 | 597 | $inputVal = $this->post($inputName); |
| 598 | - if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) { |
|
| 598 | + if (array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) { |
|
| 599 | 599 | $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]); |
| 600 | 600 | if ($inputVal == '' && $callbackReturn == true) { |
| 601 | 601 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 602 | 602 | } |
| 603 | 603 | } |
| 604 | - else if($inputVal == '') { |
|
| 604 | + else if ($inputVal == '') { |
|
| 605 | 605 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 606 | 606 | } |
| 607 | 607 | } |
@@ -627,7 +627,7 @@ discard block |
||
| 627 | 627 | protected function _validateCallback($inputName, $ruleName, array $ruleArgs) { |
| 628 | 628 | if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) { |
| 629 | 629 | $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]); |
| 630 | - if(! $result){ |
|
| 630 | + if (!$result) { |
|
| 631 | 631 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
| 632 | 632 | } |
| 633 | 633 | } |
@@ -661,7 +661,7 @@ discard block |
||
| 661 | 661 | continue; |
| 662 | 662 | } |
| 663 | 663 | } |
| 664 | - else{ |
|
| 664 | + else { |
|
| 665 | 665 | if ($inputVal == $doNotEqual) { |
| 666 | 666 | $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual)); |
| 667 | 667 | continue; |
@@ -691,8 +691,8 @@ discard block |
||
| 691 | 691 | */ |
| 692 | 692 | protected function _validateValidEmail($inputName, $ruleName, array $ruleArgs) { |
| 693 | 693 | $inputVal = $this->post($inputName); |
| 694 | - if (! preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) { |
|
| 695 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 694 | + if (!preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) { |
|
| 695 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 696 | 696 | return; |
| 697 | 697 | } |
| 698 | 698 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | protected function _validateExactLength($inputName, $ruleName, array $ruleArgs) { |
| 709 | 709 | $inputVal = $this->post($inputName); |
| 710 | 710 | if (strlen($inputVal) != $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
| 711 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 711 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 712 | 712 | return; |
| 713 | 713 | } |
| 714 | 714 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -724,7 +724,7 @@ discard block |
||
| 724 | 724 | protected function _validateMaxLength($inputName, $ruleName, array $ruleArgs) { |
| 725 | 725 | $inputVal = $this->post($inputName); |
| 726 | 726 | if (strlen($inputVal) > $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
| 727 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 727 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 728 | 728 | return; |
| 729 | 729 | } |
| 730 | 730 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -740,7 +740,7 @@ discard block |
||
| 740 | 740 | protected function _validateMinLength($inputName, $ruleName, array $ruleArgs) { |
| 741 | 741 | $inputVal = $this->post($inputName); |
| 742 | 742 | if (strlen($inputVal) < $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
| 743 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 743 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 744 | 744 | return; |
| 745 | 745 | } |
| 746 | 746 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) { |
| 757 | 757 | $inputVal = $this->post($inputName); |
| 758 | 758 | if ($inputVal >= $ruleArgs[1]) { |
| 759 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 759 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 760 | 760 | return; |
| 761 | 761 | } |
| 762 | 762 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -772,7 +772,7 @@ discard block |
||
| 772 | 772 | protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) { |
| 773 | 773 | $inputVal = $this->post($inputName); |
| 774 | 774 | if ($inputVal <= $ruleArgs[1]) { |
| 775 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 775 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 776 | 776 | return; |
| 777 | 777 | } |
| 778 | 778 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -787,8 +787,8 @@ discard block |
||
| 787 | 787 | */ |
| 788 | 788 | protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) { |
| 789 | 789 | $inputVal = $this->post($inputName); |
| 790 | - if (! is_numeric($inputVal)) { |
|
| 791 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 790 | + if (!is_numeric($inputVal)) { |
|
| 791 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 792 | 792 | return; |
| 793 | 793 | } |
| 794 | 794 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -804,7 +804,7 @@ discard block |
||
| 804 | 804 | protected function _validateExists($inputName, $ruleName, array $ruleArgs) { |
| 805 | 805 | $inputVal = $this->post($inputName); |
| 806 | 806 | $obj = & get_instance(); |
| 807 | - if(! isset($obj->database)){ |
|
| 807 | + if (!isset($obj->database)) { |
|
| 808 | 808 | return; |
| 809 | 809 | } |
| 810 | 810 | list($table, $column) = explode('.', $ruleArgs[1]); |
@@ -813,7 +813,7 @@ discard block |
||
| 813 | 813 | ->get(); |
| 814 | 814 | $nb = $obj->database->numRows(); |
| 815 | 815 | if ($nb == 0) { |
| 816 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 816 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 817 | 817 | return; |
| 818 | 818 | } |
| 819 | 819 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -829,7 +829,7 @@ discard block |
||
| 829 | 829 | protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) { |
| 830 | 830 | $inputVal = $this->post($inputName); |
| 831 | 831 | $obj = & get_instance(); |
| 832 | - if(! isset($obj->database)){ |
|
| 832 | + if (!isset($obj->database)) { |
|
| 833 | 833 | return; |
| 834 | 834 | } |
| 835 | 835 | list($table, $column) = explode('.', $ruleArgs[1]); |
@@ -838,7 +838,7 @@ discard block |
||
| 838 | 838 | ->get(); |
| 839 | 839 | $nb = $obj->database->numRows(); |
| 840 | 840 | if ($nb != 0) { |
| 841 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 841 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 842 | 842 | return; |
| 843 | 843 | } |
| 844 | 844 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -854,11 +854,11 @@ discard block |
||
| 854 | 854 | protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) { |
| 855 | 855 | $inputVal = $this->post($inputName); |
| 856 | 856 | $obj = & get_instance(); |
| 857 | - if(! isset($obj->database)){ |
|
| 857 | + if (!isset($obj->database)) { |
|
| 858 | 858 | return; |
| 859 | 859 | } |
| 860 | 860 | $data = explode(',', $ruleArgs[1]); |
| 861 | - if(count($data) < 2){ |
|
| 861 | + if (count($data) < 2) { |
|
| 862 | 862 | return; |
| 863 | 863 | } |
| 864 | 864 | list($table, $column) = explode('.', $data[0]); |
@@ -869,7 +869,7 @@ discard block |
||
| 869 | 869 | ->get(); |
| 870 | 870 | $nb = $obj->database->numRows(); |
| 871 | 871 | if ($nb != 0) { |
| 872 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 872 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 873 | 873 | return; |
| 874 | 874 | } |
| 875 | 875 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -886,8 +886,8 @@ discard block |
||
| 886 | 886 | $inputVal = $this->post($inputName); |
| 887 | 887 | $list = explode(',', $ruleArgs[1]); |
| 888 | 888 | $list = array_map('trim', $list); |
| 889 | - if (! in_array($inputVal, $list)) { |
|
| 890 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 889 | + if (!in_array($inputVal, $list)) { |
|
| 890 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 891 | 891 | return; |
| 892 | 892 | } |
| 893 | 893 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -903,8 +903,8 @@ discard block |
||
| 903 | 903 | protected function _validateRegex($inputName, $ruleName, array $ruleArgs) { |
| 904 | 904 | $inputVal = $this->post($inputName); |
| 905 | 905 | $regex = $ruleArgs[1]; |
| 906 | - if (! preg_match($regex, $inputVal)) { |
|
| 907 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 906 | + if (!preg_match($regex, $inputVal)) { |
|
| 907 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 908 | 908 | return; |
| 909 | 909 | } |
| 910 | 910 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -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 | } |