@@ -29,14 +29,14 @@ discard block |
||
| 29 | 29 | //put the first letter of class to upper case |
| 30 | 30 | $class = ucfirst($class); |
| 31 | 31 | static $classes = array(); |
| 32 | - if(isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){ |
|
| 32 | + if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log') { |
|
| 33 | 33 | return $classes[$class]; |
| 34 | 34 | } |
| 35 | 35 | $found = false; |
| 36 | 36 | foreach (array(ROOT_PATH, CORE_PATH) as $path) { |
| 37 | 37 | $file = $path . $dir . '/' . $class . '.php'; |
| 38 | - if(file_exists($file)){ |
|
| 39 | - if(class_exists($class, false) === false){ |
|
| 38 | + if (file_exists($file)) { |
|
| 39 | + if (class_exists($class, false) === false) { |
|
| 40 | 40 | require_once $file; |
| 41 | 41 | } |
| 42 | 42 | //already found |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | break; |
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | - if(! $found){ |
|
| 47 | + if (!$found) { |
|
| 48 | 48 | //can't use show_error() at this time because some dependencies not yet loaded |
| 49 | 49 | set_http_status_header(503); |
| 50 | 50 | echo 'Cannot find the class [' . $class . ']'; |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | /* |
| 55 | 55 | TODO use the best method to get the Log instance |
| 56 | 56 | */ |
| 57 | - if($class == 'Log'){ |
|
| 57 | + if ($class == 'Log') { |
|
| 58 | 58 | //can't use the instruction like "return new Log()" |
| 59 | 59 | //because we need return the reference instance of the loaded class. |
| 60 | 60 | $log = new Log(); |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | function & class_loaded($class = null){ |
| 74 | 74 | static $list = array(); |
| 75 | - if($class != null){ |
|
| 75 | + if ($class != null) { |
|
| 76 | 76 | $list[strtolower($class)] = $class; |
| 77 | 77 | } |
| 78 | 78 | return $list; |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | function & load_configurations(array $overwrite_values = array()){ |
| 82 | 82 | static $config; |
| 83 | - if(empty($config)){ |
|
| 83 | + if (empty($config)) { |
|
| 84 | 84 | $file = CONFIG_PATH . 'config.php'; |
| 85 | 85 | require_once $file; |
| 86 | 86 | |
@@ -94,53 +94,53 @@ discard block |
||
| 94 | 94 | /** |
| 95 | 95 | * @test |
| 96 | 96 | */ |
| 97 | - function get_config($key, $default = null){ |
|
| 97 | + function get_config($key, $default = null) { |
|
| 98 | 98 | static $cfg; |
| 99 | - if(empty($cfg)){ |
|
| 99 | + if (empty($cfg)) { |
|
| 100 | 100 | $cfg[0] = & load_configurations(); |
| 101 | 101 | } |
| 102 | 102 | return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - function save_to_log($level, $message, $logger = null){ |
|
| 106 | - echo 'save_to_log('.$level . ',' . $message . ',' . $logger . ")\n"; |
|
| 105 | + function save_to_log($level, $message, $logger = null) { |
|
| 106 | + echo 'save_to_log(' . $level . ',' . $message . ',' . $logger . ")\n"; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | |
| 110 | - function set_http_status_header($code = 200, $text = null){ |
|
| 110 | + function set_http_status_header($code = 200, $text = null) { |
|
| 111 | 111 | echo 'header(' . $code . ', ' . $text . ')'; |
| 112 | 112 | return true; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | |
| 116 | - function show_error($msg, $title = 'error', $logging = true){ |
|
| 116 | + function show_error($msg, $title = 'error', $logging = true) { |
|
| 117 | 117 | //show only and continue to help track of some error occured |
| 118 | 118 | echo 'show_error(' . $msg . ', ' . $title . ', ' . ($logging ? 'Y' : 'N') . ")\n"; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - function is_https(){ |
|
| 121 | + function is_https() { |
|
| 122 | 122 | return false; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
| 126 | 126 | * @test |
| 127 | 127 | */ |
| 128 | - function is_url($url){ |
|
| 128 | + function is_url($url) { |
|
| 129 | 129 | return preg_match('/^(http|https|ftp):\/\/(.*)/', $url); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - function php_exception_handler($ex){ |
|
| 132 | + function php_exception_handler($ex) { |
|
| 133 | 133 | //show only and continue to help track of some error occured |
| 134 | - echo 'php_exception_handler('.$ex->getMessage().', '.$ex->getFile().', '.$ex->getLine() . ")\n"; |
|
| 134 | + echo 'php_exception_handler(' . $ex->getMessage() . ', ' . $ex->getFile() . ', ' . $ex->getLine() . ")\n"; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | |
| 138 | - function php_error_handler($errno , $errstr, $errfile , $errline){ |
|
| 138 | + function php_error_handler($errno, $errstr, $errfile, $errline) { |
|
| 139 | 139 | //show only and continue to help track of some error occured |
| 140 | - echo 'php_error_handler('.$errno .', ' . $errstr.', ' . $errfile.', '.$errline . ")\n"; |
|
| 140 | + echo 'php_error_handler(' . $errno . ', ' . $errstr . ', ' . $errfile . ', ' . $errline . ")\n"; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - function php_shudown_handler(){ |
|
| 143 | + function php_shudown_handler() { |
|
| 144 | 144 | return true; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -148,11 +148,11 @@ discard block |
||
| 148 | 148 | /** |
| 149 | 149 | * @test |
| 150 | 150 | */ |
| 151 | - function attributes_to_string(array $attributes){ |
|
| 151 | + function attributes_to_string(array $attributes) { |
|
| 152 | 152 | $str = ' '; |
| 153 | 153 | //we check that the array passed as an argument is not empty. |
| 154 | - if(! empty($attributes)){ |
|
| 155 | - foreach($attributes as $key => $value){ |
|
| 154 | + if (!empty($attributes)) { |
|
| 155 | + foreach ($attributes as $key => $value) { |
|
| 156 | 156 | $key = trim(htmlspecialchars($key)); |
| 157 | 157 | $value = trim(htmlspecialchars($value)); |
| 158 | 158 | /* |
@@ -162,35 +162,35 @@ discard block |
||
| 162 | 162 | * $attr = array('placeholder' => 'I am a "puple"') |
| 163 | 163 | * $str = attributes_to_string($attr); => placeholder = "I am a \"puple\"" |
| 164 | 164 | */ |
| 165 | - if($value && strpos('"', $value) !== false){ |
|
| 165 | + if ($value && strpos('"', $value) !== false) { |
|
| 166 | 166 | $value = addslashes($value); |
| 167 | 167 | } |
| 168 | - $str .= $key.' = "'.$value.'" '; |
|
| 168 | + $str .= $key . ' = "' . $value . '" '; |
|
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | //remove the space after using rtrim() |
| 172 | 172 | return rtrim($str); |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - function stringfy_vars($var){ |
|
| 175 | + function stringfy_vars($var) { |
|
| 176 | 176 | return print_r($var, true); |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
| 180 | 180 | * @test |
| 181 | 181 | */ |
| 182 | - function clean_input($str){ |
|
| 183 | - if(is_array($str)){ |
|
| 182 | + function clean_input($str) { |
|
| 183 | + if (is_array($str)) { |
|
| 184 | 184 | $str = array_map('clean_input', $str); |
| 185 | 185 | } |
| 186 | - else if(is_object($str)){ |
|
| 186 | + else if (is_object($str)) { |
|
| 187 | 187 | $obj = $str; |
| 188 | 188 | foreach ($str as $var => $value) { |
| 189 | 189 | $obj->$var = clean_input($value); |
| 190 | 190 | } |
| 191 | 191 | $str = $obj; |
| 192 | 192 | } |
| 193 | - else{ |
|
| 193 | + else { |
|
| 194 | 194 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
| 195 | 195 | } |
| 196 | 196 | return $str; |
@@ -199,11 +199,11 @@ discard block |
||
| 199 | 199 | /** |
| 200 | 200 | * @test |
| 201 | 201 | */ |
| 202 | - function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
|
| 202 | + function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') { |
|
| 203 | 203 | //get the string length |
| 204 | 204 | $len = strlen($str); |
| 205 | 205 | //if str is empty |
| 206 | - if($len <= 0){ |
|
| 206 | + if ($len <= 0) { |
|
| 207 | 207 | return str_repeat($hiddenChar, 6); |
| 208 | 208 | } |
| 209 | 209 | //if the length is less than startCount and endCount |
@@ -211,14 +211,14 @@ discard block |
||
| 211 | 211 | //or startCount is negative or endCount is negative |
| 212 | 212 | //return the full string hidden |
| 213 | 213 | |
| 214 | - if((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){ |
|
| 214 | + if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) { |
|
| 215 | 215 | return str_repeat($hiddenChar, $len); |
| 216 | 216 | } |
| 217 | 217 | //the start non hidden string |
| 218 | 218 | $startNonHiddenStr = substr($str, 0, $startCount); |
| 219 | 219 | //the end non hidden string |
| 220 | 220 | $endNonHiddenStr = null; |
| 221 | - if($endCount > 0){ |
|
| 221 | + if ($endCount > 0) { |
|
| 222 | 222 | $endNonHiddenStr = substr($str, - $endCount); |
| 223 | 223 | } |
| 224 | 224 | //the hidden string |
@@ -227,12 +227,12 @@ discard block |
||
| 227 | 227 | return $startNonHiddenStr . $hiddenStr . $endNonHiddenStr; |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - function set_session_config(){ |
|
| 230 | + function set_session_config() { |
|
| 231 | 231 | return true; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | function & get_instance(){ |
| 235 | - if(! Controller::get_instance()){ |
|
| 235 | + if (!Controller::get_instance()) { |
|
| 236 | 236 | $c = new Controller(); |
| 237 | 237 | return $c; |
| 238 | 238 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | /** |
| 61 | 61 | * Custom application path for tests |
| 62 | 62 | */ |
| 63 | - define('APPS_PATH', TESTS_PATH .'hmvc' . DS); |
|
| 63 | + define('APPS_PATH', TESTS_PATH . 'hmvc' . DS); |
|
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * The path to the controller directory of your application. |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
| 197 | 197 | * in HMVC architecture (hierichical, controllers, models, views). |
| 198 | 198 | */ |
| 199 | - define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS); |
|
| 199 | + define('MODULE_PATH', dirname(realpath(__FILE__)) . DS . 'hmvc' . DS . 'modules' . DS); |
|
| 200 | 200 | |
| 201 | 201 | /** |
| 202 | 202 | * The path to the directory of sources external to your application. |
@@ -235,12 +235,12 @@ discard block |
||
| 235 | 235 | //Fix to allow test as if application is running in CLI mode $_SESSION global variable is not available |
| 236 | 236 | $_SESSION = array(); |
| 237 | 237 | |
| 238 | - if(! isset($_SERVER['REMOTE_ADDR'])){ |
|
| 238 | + if (!isset($_SERVER['REMOTE_ADDR'])) { |
|
| 239 | 239 | $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | //check for composer autoload file if exists include it |
| 243 | - if (file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 243 | + if (file_exists(VENDOR_PATH . 'autoload.php')) { |
|
| 244 | 244 | require_once VENDOR_PATH . 'autoload.php'; |
| 245 | 245 | |
| 246 | 246 | //define the class alias for vstream |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | - class DBSessionModel extends DBSessionHandlerModel{ |
|
| 2 | + class DBSessionModel extends DBSessionHandlerModel { |
|
| 3 | 3 | |
| 4 | 4 | protected $_table = 'ses'; |
| 5 | 5 | protected $primary_key = 's_id'; |
@@ -14,14 +14,14 @@ discard block |
||
| 14 | 14 | 'skey' => 'test_id' //VARCHAR(255) |
| 15 | 15 | ); |
| 16 | 16 | |
| 17 | - public function deleteByTime($time){ |
|
| 17 | + public function deleteByTime($time) { |
|
| 18 | 18 | $this->getQueryBuilder()->from($this->_table) |
| 19 | 19 | ->where('s_time', '<', $time); |
| 20 | 20 | $this->_database->delete(); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
| 24 | - public function getKeyValue(){ |
|
| 24 | + public function getKeyValue() { |
|
| 25 | 25 | $user_id = 0; |
| 26 | 26 | return $user_id; |
| 27 | 27 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | //Autoload function |
| 3 | - function tests_autoload($class){ |
|
| 3 | + function tests_autoload($class) { |
|
| 4 | 4 | $classesMap = array( |
| 5 | 5 | //Caches |
| 6 | 6 | 'ApcCache' => CORE_CLASSES_CACHE_PATH . 'ApcCache.php', |
@@ -40,11 +40,11 @@ discard block |
||
| 40 | 40 | 'StringHash' => CORE_LIBRARY_PATH . 'StringHash.php', |
| 41 | 41 | 'Upload' => CORE_LIBRARY_PATH . 'Upload.php', |
| 42 | 42 | ); |
| 43 | - if(isset($classesMap[$class])){ |
|
| 44 | - if(file_exists($classesMap[$class])){ |
|
| 43 | + if (isset($classesMap[$class])) { |
|
| 44 | + if (file_exists($classesMap[$class])) { |
|
| 45 | 45 | require_once $classesMap[$class]; |
| 46 | 46 | } |
| 47 | - else{ |
|
| 47 | + else { |
|
| 48 | 48 | echo 'File for class ' . $class . ' not found'; |
| 49 | 49 | } |
| 50 | 50 | } |
@@ -53,14 +53,14 @@ discard block |
||
| 53 | 53 | //put the first letter of class to upper case |
| 54 | 54 | $class = ucfirst($class); |
| 55 | 55 | static $classes = array(); |
| 56 | - if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){ |
|
| 56 | + if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log') { |
|
| 57 | 57 | return $classes[$class]; |
| 58 | 58 | } |
| 59 | 59 | $found = false; |
| 60 | 60 | foreach (array(ROOT_PATH, CORE_PATH) as $path) { |
| 61 | 61 | $file = $path . $dir . '/' . $class . '.php'; |
| 62 | - if (file_exists($file)){ |
|
| 63 | - if (class_exists($class, false) === false){ |
|
| 62 | + if (file_exists($file)) { |
|
| 63 | + if (class_exists($class, false) === false) { |
|
| 64 | 64 | require_once $file; |
| 65 | 65 | } |
| 66 | 66 | //already found |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | break; |
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | - if (! $found){ |
|
| 71 | + if (!$found) { |
|
| 72 | 72 | //can't use show_error() at this time because some dependencies not yet loaded |
| 73 | 73 | set_http_status_header(503); |
| 74 | 74 | echo 'Cannot find the class [' . $class . ']'; |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | /* |
| 79 | 79 | TODO use the best method to get the Log instance |
| 80 | 80 | */ |
| 81 | - if ($class == 'Log'){ |
|
| 81 | + if ($class == 'Log') { |
|
| 82 | 82 | //can't use the instruction like "return new Log()" |
| 83 | 83 | //because we need return the reference instance of the loaded class. |
| 84 | 84 | $log = new Log(); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | function & class_loaded($class = null){ |
| 104 | 104 | static $list = array(); |
| 105 | - if ($class !== null){ |
|
| 105 | + if ($class !== null) { |
|
| 106 | 106 | $list[strtolower($class)] = $class; |
| 107 | 107 | } |
| 108 | 108 | return $list; |
@@ -117,14 +117,14 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | function & load_configurations(array $overwrite_values = array()){ |
| 119 | 119 | static $config; |
| 120 | - if (empty($config)){ |
|
| 120 | + if (empty($config)) { |
|
| 121 | 121 | $file = CONFIG_PATH . 'config.php'; |
| 122 | 122 | $found = false; |
| 123 | - if (file_exists($file)){ |
|
| 123 | + if (file_exists($file)) { |
|
| 124 | 124 | require_once $file; |
| 125 | 125 | $found = true; |
| 126 | 126 | } |
| 127 | - if (! $found){ |
|
| 127 | + if (!$found) { |
|
| 128 | 128 | set_http_status_header(503); |
| 129 | 129 | echo 'Unable to find the configuration file [' . $file . ']'; |
| 130 | 130 | die(); |
@@ -144,9 +144,9 @@ discard block |
||
| 144 | 144 | * |
| 145 | 145 | * @return mixed the config value |
| 146 | 146 | */ |
| 147 | - function get_config($key, $default = null){ |
|
| 147 | + function get_config($key, $default = null) { |
|
| 148 | 148 | static $cfg; |
| 149 | - if (empty($cfg)){ |
|
| 149 | + if (empty($cfg)) { |
|
| 150 | 150 | $cfg[0] = & load_configurations(); |
| 151 | 151 | } |
| 152 | 152 | return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default; |
@@ -160,9 +160,9 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @codeCoverageIgnore |
| 162 | 162 | */ |
| 163 | - function save_to_log($level, $message, $logger = null){ |
|
| 164 | - $log =& class_loader('Log', 'classes'); |
|
| 165 | - if ($logger){ |
|
| 163 | + function save_to_log($level, $message, $logger = null) { |
|
| 164 | + $log = & class_loader('Log', 'classes'); |
|
| 165 | + if ($logger) { |
|
| 166 | 166 | $log->setLogger($logger); |
| 167 | 167 | } |
| 168 | 168 | $log->writeLog($message, $level); |
@@ -175,8 +175,8 @@ discard block |
||
| 175 | 175 | * |
| 176 | 176 | * @codeCoverageIgnore |
| 177 | 177 | */ |
| 178 | - function set_http_status_header($code = 200, $text = null){ |
|
| 179 | - if (empty($text)){ |
|
| 178 | + function set_http_status_header($code = 200, $text = null) { |
|
| 179 | + if (empty($text)) { |
|
| 180 | 180 | $http_status = array( |
| 181 | 181 | 100 => 'Continue', |
| 182 | 182 | 101 => 'Switching Protocols', |
@@ -224,18 +224,18 @@ discard block |
||
| 224 | 224 | 504 => 'Gateway Timeout', |
| 225 | 225 | 505 => 'HTTP Version Not Supported', |
| 226 | 226 | ); |
| 227 | - if (isset($http_status[$code])){ |
|
| 227 | + if (isset($http_status[$code])) { |
|
| 228 | 228 | $text = $http_status[$code]; |
| 229 | 229 | } |
| 230 | - else{ |
|
| 230 | + else { |
|
| 231 | 231 | show_error('No HTTP status text found for your code please check it.'); |
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - if (strpos(php_sapi_name(), 'cgi') === 0){ |
|
| 235 | + if (strpos(php_sapi_name(), 'cgi') === 0) { |
|
| 236 | 236 | header('Status: ' . $code . ' ' . $text, TRUE); |
| 237 | 237 | } |
| 238 | - else{ |
|
| 238 | + else { |
|
| 239 | 239 | $proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; |
| 240 | 240 | header($proto . ' ' . $code . ' ' . $text, TRUE, $code); |
| 241 | 241 | } |
@@ -250,13 +250,13 @@ discard block |
||
| 250 | 250 | * |
| 251 | 251 | * @codeCoverageIgnore |
| 252 | 252 | */ |
| 253 | - function show_error($msg, $title = 'error', $logging = true){ |
|
| 253 | + function show_error($msg, $title = 'error', $logging = true) { |
|
| 254 | 254 | $title = strtoupper($title); |
| 255 | 255 | $data = array(); |
| 256 | 256 | $data['error'] = $msg; |
| 257 | 257 | $data['title'] = $title; |
| 258 | - if ($logging){ |
|
| 259 | - save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR'); |
|
| 258 | + if ($logging) { |
|
| 259 | + save_to_log('error', '[' . $title . '] ' . strip_tags($msg), 'GLOBAL::ERROR'); |
|
| 260 | 260 | } |
| 261 | 261 | $response = & class_loader('Response', 'classes'); |
| 262 | 262 | $response->sendError($data); |
@@ -270,18 +270,18 @@ discard block |
||
| 270 | 270 | * |
| 271 | 271 | * @return boolean true if the web server uses the https protocol, false if not. |
| 272 | 272 | */ |
| 273 | - function is_https(){ |
|
| 273 | + function is_https() { |
|
| 274 | 274 | /* |
| 275 | 275 | * some servers pass the "HTTPS" parameter in the server variable, |
| 276 | 276 | * if is the case, check if the value is "on", "true", "1". |
| 277 | 277 | */ |
| 278 | - if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){ |
|
| 278 | + if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { |
|
| 279 | 279 | return true; |
| 280 | 280 | } |
| 281 | - else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
| 281 | + else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 282 | 282 | return true; |
| 283 | 283 | } |
| 284 | - else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
| 284 | + else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') { |
|
| 285 | 285 | return true; |
| 286 | 286 | } |
| 287 | 287 | return false; |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | * |
| 297 | 297 | * @return boolean true if is a valid URL address or false. |
| 298 | 298 | */ |
| 299 | - function is_url($url){ |
|
| 299 | + function is_url($url) { |
|
| 300 | 300 | return preg_match('/^(http|https|ftp):\/\/(.*)/', $url) == 1; |
| 301 | 301 | } |
| 302 | 302 | |
@@ -306,8 +306,8 @@ discard block |
||
| 306 | 306 | * @param string $controllerClass the controller class name to be loaded |
| 307 | 307 | * @codeCoverageIgnore |
| 308 | 308 | */ |
| 309 | - function autoload_controller($controllerClass){ |
|
| 310 | - if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){ |
|
| 309 | + function autoload_controller($controllerClass) { |
|
| 310 | + if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')) { |
|
| 311 | 311 | require_once $path; |
| 312 | 312 | } |
| 313 | 313 | } |
@@ -321,11 +321,11 @@ discard block |
||
| 321 | 321 | * |
| 322 | 322 | * @return boolean |
| 323 | 323 | */ |
| 324 | - function php_exception_handler($ex){ |
|
| 325 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
| 326 | - show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
| 324 | + function php_exception_handler($ex) { |
|
| 325 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { |
|
| 326 | + show_error('An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
| 327 | 327 | } |
| 328 | - else{ |
|
| 328 | + else { |
|
| 329 | 329 | save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception'); |
| 330 | 330 | } |
| 331 | 331 | return true; |
@@ -342,16 +342,16 @@ discard block |
||
| 342 | 342 | * |
| 343 | 343 | * @return boolean |
| 344 | 344 | */ |
| 345 | - function php_error_handler($errno , $errstr, $errfile , $errline){ |
|
| 345 | + function php_error_handler($errno, $errstr, $errfile, $errline) { |
|
| 346 | 346 | $isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno); |
| 347 | - if ($isError){ |
|
| 347 | + if ($isError) { |
|
| 348 | 348 | set_http_status_header(500); |
| 349 | 349 | } |
| 350 | - if (! (error_reporting() & $errno)) { |
|
| 350 | + if (!(error_reporting() & $errno)) { |
|
| 351 | 351 | save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ERROR'); |
| 352 | 352 | return; |
| 353 | 353 | } |
| 354 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
| 354 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { |
|
| 355 | 355 | $errorType = 'error'; |
| 356 | 356 | switch ($errno) { |
| 357 | 357 | case E_USER_ERROR: |
@@ -367,9 +367,9 @@ discard block |
||
| 367 | 367 | $errorType = 'error'; |
| 368 | 368 | break; |
| 369 | 369 | } |
| 370 | - show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
| 370 | + show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline . '</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
| 371 | 371 | } |
| 372 | - if ($isError){ |
|
| 372 | + if ($isError) { |
|
| 373 | 373 | die(); |
| 374 | 374 | } |
| 375 | 375 | return true; |
@@ -379,10 +379,10 @@ discard block |
||
| 379 | 379 | * This function is used to run in shutdown situation of the script |
| 380 | 380 | * @codeCoverageIgnore |
| 381 | 381 | */ |
| 382 | - function php_shudown_handler(){ |
|
| 382 | + function php_shudown_handler() { |
|
| 383 | 383 | $lastError = error_get_last(); |
| 384 | 384 | if (isset($lastError) && |
| 385 | - ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){ |
|
| 385 | + ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))) { |
|
| 386 | 386 | php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']); |
| 387 | 387 | } |
| 388 | 388 | } |
@@ -400,11 +400,11 @@ discard block |
||
| 400 | 400 | * |
| 401 | 401 | * @return string string of the HTML attribute. |
| 402 | 402 | */ |
| 403 | - function attributes_to_string(array $attributes){ |
|
| 403 | + function attributes_to_string(array $attributes) { |
|
| 404 | 404 | $str = ' '; |
| 405 | 405 | //we check that the array passed as an argument is not empty. |
| 406 | - if (! empty($attributes)){ |
|
| 407 | - foreach($attributes as $key => $value){ |
|
| 406 | + if (!empty($attributes)) { |
|
| 407 | + foreach ($attributes as $key => $value) { |
|
| 408 | 408 | $key = trim(htmlspecialchars($key)); |
| 409 | 409 | $value = trim(htmlspecialchars($value)); |
| 410 | 410 | /* |
@@ -414,10 +414,10 @@ discard block |
||
| 414 | 414 | * $attr = array('placeholder' => 'I am a "puple"') |
| 415 | 415 | * $str = attributes_to_string($attr); => placeholder = "I am a \"puple\"" |
| 416 | 416 | */ |
| 417 | - if ($value && strpos('"', $value) !== false){ |
|
| 417 | + if ($value && strpos('"', $value) !== false) { |
|
| 418 | 418 | $value = addslashes($value); |
| 419 | 419 | } |
| 420 | - $str .= $key.' = "'.$value.'" '; |
|
| 420 | + $str .= $key . ' = "' . $value . '" '; |
|
| 421 | 421 | } |
| 422 | 422 | } |
| 423 | 423 | //remove the space after using rtrim() |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | * |
| 434 | 434 | * @return string the stringfy value |
| 435 | 435 | */ |
| 436 | - function stringfy_vars($var){ |
|
| 436 | + function stringfy_vars($var) { |
|
| 437 | 437 | return print_r($var, true); |
| 438 | 438 | } |
| 439 | 439 | |
@@ -444,18 +444,18 @@ discard block |
||
| 444 | 444 | * |
| 445 | 445 | * @return mixed the sanitize value |
| 446 | 446 | */ |
| 447 | - function clean_input($str){ |
|
| 448 | - if (is_array($str)){ |
|
| 447 | + function clean_input($str) { |
|
| 448 | + if (is_array($str)) { |
|
| 449 | 449 | $str = array_map('clean_input', $str); |
| 450 | 450 | } |
| 451 | - else if (is_object($str)){ |
|
| 451 | + else if (is_object($str)) { |
|
| 452 | 452 | $obj = $str; |
| 453 | 453 | foreach ($str as $var => $value) { |
| 454 | 454 | $obj->$var = clean_input($value); |
| 455 | 455 | } |
| 456 | 456 | $str = $obj; |
| 457 | 457 | } |
| 458 | - else{ |
|
| 458 | + else { |
|
| 459 | 459 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
| 460 | 460 | } |
| 461 | 461 | return $str; |
@@ -473,11 +473,11 @@ discard block |
||
| 473 | 473 | * |
| 474 | 474 | * @return string the string with the hidden part. |
| 475 | 475 | */ |
| 476 | - function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
|
| 476 | + function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') { |
|
| 477 | 477 | //get the string length |
| 478 | 478 | $len = strlen($str); |
| 479 | 479 | //if str is empty |
| 480 | - if ($len <= 0){ |
|
| 480 | + if ($len <= 0) { |
|
| 481 | 481 | return str_repeat($hiddenChar, 6); |
| 482 | 482 | } |
| 483 | 483 | //if the length is less than startCount and endCount |
@@ -485,14 +485,14 @@ discard block |
||
| 485 | 485 | //or startCount is negative or endCount is negative |
| 486 | 486 | //return the full string hidden |
| 487 | 487 | |
| 488 | - if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){ |
|
| 488 | + if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) { |
|
| 489 | 489 | return str_repeat($hiddenChar, $len); |
| 490 | 490 | } |
| 491 | 491 | //the start non hidden string |
| 492 | 492 | $startNonHiddenStr = substr($str, 0, $startCount); |
| 493 | 493 | //the end non hidden string |
| 494 | 494 | $endNonHiddenStr = null; |
| 495 | - if ($endCount > 0){ |
|
| 495 | + if ($endCount > 0) { |
|
| 496 | 496 | $endNonHiddenStr = substr($str, - $endCount); |
| 497 | 497 | } |
| 498 | 498 | //the hidden string |
@@ -505,40 +505,40 @@ discard block |
||
| 505 | 505 | * This function is used to set the initial session config regarding the configuration |
| 506 | 506 | * @codeCoverageIgnore |
| 507 | 507 | */ |
| 508 | - function set_session_config(){ |
|
| 508 | + function set_session_config() { |
|
| 509 | 509 | //$_SESSION is not available on cli mode |
| 510 | - if (! IS_CLI){ |
|
| 511 | - $logger =& class_loader('Log', 'classes'); |
|
| 510 | + if (!IS_CLI) { |
|
| 511 | + $logger = & class_loader('Log', 'classes'); |
|
| 512 | 512 | $logger->setLogger('PHPSession'); |
| 513 | 513 | //set session params |
| 514 | 514 | $sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files |
| 515 | 515 | $sessionName = get_config('session_name'); |
| 516 | - if ($sessionName){ |
|
| 516 | + if ($sessionName) { |
|
| 517 | 517 | session_name($sessionName); |
| 518 | 518 | } |
| 519 | 519 | $logger->info('Session handler: ' . $sessionHandler); |
| 520 | 520 | $logger->info('Session name: ' . $sessionName); |
| 521 | 521 | |
| 522 | - if ($sessionHandler == 'files'){ |
|
| 522 | + if ($sessionHandler == 'files') { |
|
| 523 | 523 | $sessionSavePath = get_config('session_save_path'); |
| 524 | - if ($sessionSavePath){ |
|
| 525 | - if (! is_dir($sessionSavePath)){ |
|
| 524 | + if ($sessionSavePath) { |
|
| 525 | + if (!is_dir($sessionSavePath)) { |
|
| 526 | 526 | mkdir($sessionSavePath, 1773); |
| 527 | 527 | } |
| 528 | 528 | session_save_path($sessionSavePath); |
| 529 | 529 | $logger->info('Session save path: ' . $sessionSavePath); |
| 530 | 530 | } |
| 531 | 531 | } |
| 532 | - else if ($sessionHandler == 'database'){ |
|
| 532 | + else if ($sessionHandler == 'database') { |
|
| 533 | 533 | //load database session handle library |
| 534 | 534 | //Database Session handler Model |
| 535 | 535 | require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php'; |
| 536 | 536 | |
| 537 | - $DBS =& class_loader('DBSessionHandler', 'classes'); |
|
| 537 | + $DBS = & class_loader('DBSessionHandler', 'classes'); |
|
| 538 | 538 | session_set_save_handler($DBS, true); |
| 539 | 539 | $logger->info('session save path: ' . get_config('session_save_path')); |
| 540 | 540 | } |
| 541 | - else{ |
|
| 541 | + else { |
|
| 542 | 542 | show_error('Invalid session handler configuration'); |
| 543 | 543 | } |
| 544 | 544 | $lifetime = get_config('session_cookie_lifetime', 0); |
@@ -561,9 +561,9 @@ discard block |
||
| 561 | 561 | $logger->info('Session lifetime: ' . $lifetime); |
| 562 | 562 | $logger->info('Session cookie path: ' . $path); |
| 563 | 563 | $logger->info('Session domain: ' . $domain); |
| 564 | - $logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE')); |
|
| 564 | + $logger->info('Session is secure: ' . ($secure ? 'TRUE' : 'FALSE')); |
|
| 565 | 565 | |
| 566 | - if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){ |
|
| 566 | + if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()) { |
|
| 567 | 567 | $logger->info('Session not yet start, start it now'); |
| 568 | 568 | session_start(); |
| 569 | 569 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @copyright Copyright (c) 2012, Jamie Rumbelow <http://jamierumbelow.net> |
| 34 | 34 | */ |
| 35 | 35 | |
| 36 | - class Model{ |
|
| 36 | + class Model { |
|
| 37 | 37 | |
| 38 | 38 | /* -------------------------------------------------------------- |
| 39 | 39 | * VARIABLES |
@@ -140,13 +140,13 @@ discard block |
||
| 140 | 140 | * Initialise the model, tie into the CodeIgniter superobject and |
| 141 | 141 | * try our best to guess the table name. |
| 142 | 142 | */ |
| 143 | - public function __construct(Database $db = null){ |
|
| 144 | - if (is_object($db)){ |
|
| 143 | + public function __construct(Database $db = null) { |
|
| 144 | + if (is_object($db)) { |
|
| 145 | 145 | $this->setDatabaseInstance($db); |
| 146 | 146 | } |
| 147 | - else{ |
|
| 147 | + else { |
|
| 148 | 148 | $obj = & get_instance(); |
| 149 | - if (isset($obj->database) && is_object($obj->database)){ |
|
| 149 | + if (isset($obj->database) && is_object($obj->database)) { |
|
| 150 | 150 | /** |
| 151 | 151 | * NOTE: Need use "clone" because some Model need have the personal instance of the database library |
| 152 | 152 | * to prevent duplication |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | |
| 183 | 183 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
| 184 | 184 | { |
| 185 | - $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
| 185 | + $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted); |
|
| 186 | 186 | } |
| 187 | 187 | $this->_set_where($where); |
| 188 | 188 | |
@@ -224,9 +224,9 @@ discard block |
||
| 224 | 224 | $this->trigger('before_get'); |
| 225 | 225 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
| 226 | 226 | { |
| 227 | - $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
| 227 | + $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted); |
|
| 228 | 228 | } |
| 229 | - $type = $this->_temporary_return_type == 'array' ? 'array':false; |
|
| 229 | + $type = $this->_temporary_return_type == 'array' ? 'array' : false; |
|
| 230 | 230 | $this->getQueryBuilder()->from($this->_table); |
| 231 | 231 | $result = $this->_database->getAll($type); |
| 232 | 232 | $this->_temporary_return_type = $this->return_type; |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | $insert_id = $this->_database->insertId(); |
| 260 | 260 | $this->trigger('after_create', $insert_id); |
| 261 | 261 | //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned |
| 262 | - return ! $insert_id ? true : $insert_id; |
|
| 262 | + return !$insert_id ? true : $insert_id; |
|
| 263 | 263 | } |
| 264 | 264 | else |
| 265 | 265 | { |
@@ -336,13 +336,13 @@ discard block |
||
| 336 | 336 | { |
| 337 | 337 | $args = func_get_args(); |
| 338 | 338 | $data = array(); |
| 339 | - if (count($args) == 2){ |
|
| 340 | - if (is_array($args[1])){ |
|
| 339 | + if (count($args) == 2) { |
|
| 340 | + if (is_array($args[1])) { |
|
| 341 | 341 | $data = array_pop($args); |
| 342 | 342 | } |
| 343 | 343 | } |
| 344 | - else if (count($args) == 3){ |
|
| 345 | - if (is_array($args[2])){ |
|
| 344 | + else if (count($args) == 3) { |
|
| 345 | + if (is_array($args[2])) { |
|
| 346 | 346 | $data = array_pop($args); |
| 347 | 347 | } |
| 348 | 348 | } |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | if ($this->soft_delete) |
| 385 | 385 | { |
| 386 | 386 | $this->getQueryBuilder()->from($this->_table); |
| 387 | - $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
| 387 | + $result = $this->_database->update(array($this->soft_delete_key => TRUE)); |
|
| 388 | 388 | } |
| 389 | 389 | else |
| 390 | 390 | { |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | if ($this->soft_delete) |
| 409 | 409 | { |
| 410 | 410 | $this->getQueryBuilder()->from($this->_table); |
| 411 | - $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
| 411 | + $result = $this->_database->update(array($this->soft_delete_key => TRUE)); |
|
| 412 | 412 | } |
| 413 | 413 | else |
| 414 | 414 | { |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | if ($this->soft_delete) |
| 431 | 431 | { |
| 432 | 432 | $this->getQueryBuilder()->from($this->_table); |
| 433 | - $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
| 433 | + $result = $this->_database->update(array($this->soft_delete_key => TRUE)); |
|
| 434 | 434 | } |
| 435 | 435 | else |
| 436 | 436 | { |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | $key = $this->primary_key; |
| 501 | 501 | $value = $args[0]; |
| 502 | 502 | } |
| 503 | - $this->trigger('before_dropdown', array( $key, $value )); |
|
| 503 | + $this->trigger('before_dropdown', array($key, $value)); |
|
| 504 | 504 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
| 505 | 505 | { |
| 506 | 506 | $this->getQueryBuilder()->where($this->soft_delete_key, FALSE); |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | { |
| 526 | 526 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
| 527 | 527 | { |
| 528 | - $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
| 528 | + $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted); |
|
| 529 | 529 | } |
| 530 | 530 | $where = func_get_args(); |
| 531 | 531 | $this->_set_where($where); |
@@ -541,7 +541,7 @@ discard block |
||
| 541 | 541 | { |
| 542 | 542 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
| 543 | 543 | { |
| 544 | - $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
| 544 | + $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted); |
|
| 545 | 545 | } |
| 546 | 546 | $this->getQueryBuilder()->from($this->_table); |
| 547 | 547 | $this->_database->getAll(); |
@@ -551,8 +551,8 @@ discard block |
||
| 551 | 551 | /** |
| 552 | 552 | * Enabled cache temporary |
| 553 | 553 | */ |
| 554 | - public function cached($ttl = 0){ |
|
| 555 | - if ($ttl > 0){ |
|
| 554 | + public function cached($ttl = 0) { |
|
| 555 | + if ($ttl > 0) { |
|
| 556 | 556 | $this->_database = $this->_database->cached($ttl); |
| 557 | 557 | } |
| 558 | 558 | return $this; |
@@ -706,13 +706,13 @@ discard block |
||
| 706 | 706 | { |
| 707 | 707 | if (is_object($row)) |
| 708 | 708 | { |
| 709 | - if (isset($row->$attr)){ |
|
| 709 | + if (isset($row->$attr)) { |
|
| 710 | 710 | unset($row->$attr); |
| 711 | 711 | } |
| 712 | 712 | } |
| 713 | 713 | else |
| 714 | 714 | { |
| 715 | - if (isset($row[$attr])){ |
|
| 715 | + if (isset($row[$attr])) { |
|
| 716 | 716 | unset($row[$attr]); |
| 717 | 717 | } |
| 718 | 718 | } |
@@ -724,7 +724,7 @@ discard block |
||
| 724 | 724 | * Return the database instance |
| 725 | 725 | * @return Database the database instance |
| 726 | 726 | */ |
| 727 | - public function getDatabaseInstance(){ |
|
| 727 | + public function getDatabaseInstance() { |
|
| 728 | 728 | return $this->_database; |
| 729 | 729 | } |
| 730 | 730 | |
@@ -732,9 +732,9 @@ discard block |
||
| 732 | 732 | * set the Database instance for future use |
| 733 | 733 | * @param Database $db the database object |
| 734 | 734 | */ |
| 735 | - public function setDatabaseInstance($db){ |
|
| 735 | + public function setDatabaseInstance($db) { |
|
| 736 | 736 | $this->_database = $db; |
| 737 | - if ($this->dbCacheTime > 0){ |
|
| 737 | + if ($this->dbCacheTime > 0) { |
|
| 738 | 738 | $this->_database->setCache($this->dbCacheTime); |
| 739 | 739 | } |
| 740 | 740 | return $this; |
@@ -744,7 +744,7 @@ discard block |
||
| 744 | 744 | * Return the loader instance |
| 745 | 745 | * @return Loader the loader instance |
| 746 | 746 | */ |
| 747 | - public function getLoader(){ |
|
| 747 | + public function getLoader() { |
|
| 748 | 748 | return $this->loaderInstance; |
| 749 | 749 | } |
| 750 | 750 | |
@@ -753,7 +753,7 @@ discard block |
||
| 753 | 753 | * @param Loader $loader the loader object |
| 754 | 754 | * @return object |
| 755 | 755 | */ |
| 756 | - public function setLoader($loader){ |
|
| 756 | + public function setLoader($loader) { |
|
| 757 | 757 | $this->loaderInstance = $loader; |
| 758 | 758 | return $this; |
| 759 | 759 | } |
@@ -762,7 +762,7 @@ discard block |
||
| 762 | 762 | * Return the queryBuilder instance this is the shortcut to database queryBuilder |
| 763 | 763 | * @return object the DatabaseQueryBuilder instance |
| 764 | 764 | */ |
| 765 | - public function getQueryBuilder(){ |
|
| 765 | + public function getQueryBuilder() { |
|
| 766 | 766 | return $this->_database->getQueryBuilder(); |
| 767 | 767 | } |
| 768 | 768 | |
@@ -771,7 +771,7 @@ discard block |
||
| 771 | 771 | * @param object $queryBuilder the DatabaseQueryBuilder object |
| 772 | 772 | * @return object |
| 773 | 773 | */ |
| 774 | - public function setQueryBuilder($queryBuilder){ |
|
| 774 | + public function setQueryBuilder($queryBuilder) { |
|
| 775 | 775 | $this->_database->setQueryBuilder($queryBuilder); |
| 776 | 776 | return $this; |
| 777 | 777 | } |
@@ -781,7 +781,7 @@ discard block |
||
| 781 | 781 | * Return the FormValidation instance |
| 782 | 782 | * @return FormValidation the form validation instance |
| 783 | 783 | */ |
| 784 | - public function getFormValidation(){ |
|
| 784 | + public function getFormValidation() { |
|
| 785 | 785 | return $this->formValidationInstance; |
| 786 | 786 | } |
| 787 | 787 | |
@@ -790,7 +790,7 @@ discard block |
||
| 790 | 790 | * @param FormValidation $fv the form validation object |
| 791 | 791 | * @return object |
| 792 | 792 | */ |
| 793 | - public function setFormValidation($fv){ |
|
| 793 | + public function setFormValidation($fv) { |
|
| 794 | 794 | $this->formValidationInstance = $fv; |
| 795 | 795 | return $this; |
| 796 | 796 | } |
@@ -804,7 +804,7 @@ discard block |
||
| 804 | 804 | */ |
| 805 | 805 | public function order_by($criteria, $order = 'ASC') |
| 806 | 806 | { |
| 807 | - if ( is_array($criteria) ) |
|
| 807 | + if (is_array($criteria)) |
|
| 808 | 808 | { |
| 809 | 809 | foreach ($criteria as $key => $value) |
| 810 | 810 | { |
@@ -835,13 +835,13 @@ discard block |
||
| 835 | 835 | * relate for the relation "belongs_to" |
| 836 | 836 | * @return mixed |
| 837 | 837 | */ |
| 838 | - protected function relateBelongsTo($row){ |
|
| 838 | + protected function relateBelongsTo($row) { |
|
| 839 | 839 | foreach ($this->belongs_to as $key => $value) |
| 840 | 840 | { |
| 841 | 841 | if (is_string($value)) |
| 842 | 842 | { |
| 843 | 843 | $relationship = $value; |
| 844 | - $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' ); |
|
| 844 | + $options = array('primary_key' => $value . '_id', 'model' => $value . '_model'); |
|
| 845 | 845 | } |
| 846 | 846 | else |
| 847 | 847 | { |
@@ -851,10 +851,10 @@ discard block |
||
| 851 | 851 | |
| 852 | 852 | if (in_array($relationship, $this->_with)) |
| 853 | 853 | { |
| 854 | - if (is_object($this->loaderInstance)){ |
|
| 854 | + if (is_object($this->loaderInstance)) { |
|
| 855 | 855 | $this->loaderInstance->model($options['model'], $relationship . '_model'); |
| 856 | 856 | } |
| 857 | - else{ |
|
| 857 | + else { |
|
| 858 | 858 | Loader::model($options['model'], $relationship . '_model'); |
| 859 | 859 | } |
| 860 | 860 | if (is_object($row)) |
@@ -874,13 +874,13 @@ discard block |
||
| 874 | 874 | * relate for the relation "has_many" |
| 875 | 875 | * @return mixed |
| 876 | 876 | */ |
| 877 | - protected function relateHasMany($row){ |
|
| 877 | + protected function relateHasMany($row) { |
|
| 878 | 878 | foreach ($this->has_many as $key => $value) |
| 879 | 879 | { |
| 880 | 880 | if (is_string($value)) |
| 881 | 881 | { |
| 882 | 882 | $relationship = $value; |
| 883 | - $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' ); |
|
| 883 | + $options = array('primary_key' => $this->_table . '_id', 'model' => $value . '_model'); |
|
| 884 | 884 | } |
| 885 | 885 | else |
| 886 | 886 | { |
@@ -890,10 +890,10 @@ discard block |
||
| 890 | 890 | |
| 891 | 891 | if (in_array($relationship, $this->_with)) |
| 892 | 892 | { |
| 893 | - if (is_object($this->loaderInstance)){ |
|
| 893 | + if (is_object($this->loaderInstance)) { |
|
| 894 | 894 | $this->loaderInstance->model($options['model'], $relationship . '_model'); |
| 895 | 895 | } |
| 896 | - else{ |
|
| 896 | + else { |
|
| 897 | 897 | Loader::model($options['model'], $relationship . '_model'); |
| 898 | 898 | } |
| 899 | 899 | if (is_object($row)) |
@@ -944,10 +944,10 @@ discard block |
||
| 944 | 944 | if (!empty($this->validate)) |
| 945 | 945 | { |
| 946 | 946 | $fv = null; |
| 947 | - if (is_object($this->formValidationInstance)){ |
|
| 947 | + if (is_object($this->formValidationInstance)) { |
|
| 948 | 948 | $fv = $this->formValidationInstance; |
| 949 | 949 | } |
| 950 | - else{ |
|
| 950 | + else { |
|
| 951 | 951 | Loader::library('FormValidation'); |
| 952 | 952 | $fv = $this->formvalidation; |
| 953 | 953 | $this->setFormValidation($fv); |
@@ -976,7 +976,7 @@ discard block |
||
| 976 | 976 | * Set WHERE parameters, when is array |
| 977 | 977 | * @param array $params |
| 978 | 978 | */ |
| 979 | - protected function _set_where_array(array $params){ |
|
| 979 | + protected function _set_where_array(array $params) { |
|
| 980 | 980 | foreach ($params as $field => $filter) |
| 981 | 981 | { |
| 982 | 982 | if (is_array($filter)) |
@@ -1042,7 +1042,7 @@ discard block |
||
| 1042 | 1042 | /** |
| 1043 | 1043 | Shortcut to controller |
| 1044 | 1044 | */ |
| 1045 | - public function __get($key){ |
|
| 1045 | + public function __get($key) { |
|
| 1046 | 1046 | return get_instance()->{$key}; |
| 1047 | 1047 | } |
| 1048 | 1048 | |
@@ -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,44 +224,44 @@ 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 |
| 263 | 263 | $viewCacheTtl = get_config('cache_ttl'); |
| 264 | - if (!empty($obj->view_cache_ttl)){ |
|
| 264 | + if (!empty($obj->view_cache_ttl)) { |
|
| 265 | 265 | $viewCacheTtl = $obj->view_cache_ttl; |
| 266 | 266 | } |
| 267 | 267 | //the cache handler instance |
@@ -274,14 +274,14 @@ discard block |
||
| 274 | 274 | |
| 275 | 275 | //get the cache information to prepare header to send to browser |
| 276 | 276 | $cacheInfo = $cacheInstance->getInfo($cacheKey); |
| 277 | - if($cacheInfo){ |
|
| 277 | + if ($cacheInfo) { |
|
| 278 | 278 | $lastModified = $cacheInfo['mtime']; |
| 279 | 279 | $expire = $cacheInfo['expire']; |
| 280 | 280 | $maxAge = $expire - time(); |
| 281 | 281 | self::setHeader('Pragma', 'public'); |
| 282 | 282 | self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public'); |
| 283 | - self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT'); |
|
| 284 | - self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT'); |
|
| 283 | + self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT'); |
|
| 284 | + self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); |
|
| 285 | 285 | } |
| 286 | 286 | } |
| 287 | 287 | |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | |
| 294 | 294 | //compress the output if is available |
| 295 | 295 | $type = null; |
| 296 | - if (self::$_canCompressOutput){ |
|
| 296 | + if (self::$_canCompressOutput) { |
|
| 297 | 297 | $type = 'ob_gzhandler'; |
| 298 | 298 | } |
| 299 | 299 | ob_start($type); |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | /** |
| 306 | 306 | * Send the final page output to user if is cached |
| 307 | 307 | */ |
| 308 | - public function renderFinalPageFromCache(&$cache){ |
|
| 308 | + public function renderFinalPageFromCache(&$cache) { |
|
| 309 | 309 | $logger = self::getLogger(); |
| 310 | 310 | $url = $this->_currentUrl; |
| 311 | 311 | //the current page cache key for identification |
@@ -314,25 +314,25 @@ discard block |
||
| 314 | 314 | $logger->debug('Checking if the page content for the URL [' . $url . '] is cached ...'); |
| 315 | 315 | //get the cache information to prepare header to send to browser |
| 316 | 316 | $cacheInfo = $cache->getInfo($pageCacheKey); |
| 317 | - if($cacheInfo){ |
|
| 317 | + if ($cacheInfo) { |
|
| 318 | 318 | $lastModified = $cacheInfo['mtime']; |
| 319 | 319 | $expire = $cacheInfo['expire']; |
| 320 | 320 | $maxAge = $expire - $_SERVER['REQUEST_TIME']; |
| 321 | 321 | self::setHeader('Pragma', 'public'); |
| 322 | 322 | self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public'); |
| 323 | - self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT'); |
|
| 324 | - self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT'); |
|
| 325 | - if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])){ |
|
| 323 | + self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT'); |
|
| 324 | + self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); |
|
| 325 | + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { |
|
| 326 | 326 | $logger->info('The cache page content is not yet expire for the URL [' . $url . '] send 304 header to browser'); |
| 327 | 327 | self::sendHeaders(304); |
| 328 | 328 | return; |
| 329 | 329 | } |
| 330 | - else{ |
|
| 330 | + else { |
|
| 331 | 331 | $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'); |
| 332 | 332 | self::sendHeaders(200); |
| 333 | 333 | //get the cache content |
| 334 | 334 | $content = $cache->get($pageCacheKey); |
| 335 | - if($content){ |
|
| 335 | + if ($content) { |
|
| 336 | 336 | $logger->info('The page content for the URL [' . $url . '] already cached just display it'); |
| 337 | 337 | //load benchmark class |
| 338 | 338 | $benchmark = & class_loader('Benchmark'); |
@@ -345,17 +345,17 @@ discard block |
||
| 345 | 345 | |
| 346 | 346 | ///display the final output |
| 347 | 347 | //compress the output if is available |
| 348 | - if (self::$_canCompressOutput){ |
|
| 348 | + if (self::$_canCompressOutput) { |
|
| 349 | 349 | ob_start('ob_gzhandler'); |
| 350 | 350 | } |
| 351 | - else{ |
|
| 351 | + else { |
|
| 352 | 352 | ob_start(); |
| 353 | 353 | } |
| 354 | 354 | echo $content; |
| 355 | 355 | ob_end_flush(); |
| 356 | 356 | return; |
| 357 | 357 | } |
| 358 | - else{ |
|
| 358 | + else { |
|
| 359 | 359 | $logger->info('The page cache content for the URL [' . $url . '] is not valid may be already expired'); |
| 360 | 360 | $cache->delete($pageCacheKey); |
| 361 | 361 | } |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | * Get the final page to be rendered |
| 368 | 368 | * @return string |
| 369 | 369 | */ |
| 370 | - public function getFinalPageRendered(){ |
|
| 370 | + public function getFinalPageRendered() { |
|
| 371 | 371 | return $this->_pageRender; |
| 372 | 372 | } |
| 373 | 373 | |
@@ -375,14 +375,14 @@ discard block |
||
| 375 | 375 | * Send the HTTP 404 error if can not found the |
| 376 | 376 | * routing information for the current request |
| 377 | 377 | */ |
| 378 | - public static function send404(){ |
|
| 378 | + public static function send404() { |
|
| 379 | 379 | /********* for logs **************/ |
| 380 | 380 | //can't use $obj = & get_instance() here because the global super object will be available until |
| 381 | 381 | //the main controller is loaded even for Loader::library('xxxx'); |
| 382 | 382 | $logger = self::getLogger(); |
| 383 | - $request =& class_loader('Request', 'classes'); |
|
| 384 | - $userAgent =& class_loader('Browser'); |
|
| 385 | - $browser = $userAgent->getPlatform().', '.$userAgent->getBrowser().' '.$userAgent->getVersion(); |
|
| 383 | + $request = & class_loader('Request', 'classes'); |
|
| 384 | + $userAgent = & class_loader('Browser'); |
|
| 385 | + $browser = $userAgent->getPlatform() . ', ' . $userAgent->getBrowser() . ' ' . $userAgent->getVersion(); |
|
| 386 | 386 | |
| 387 | 387 | //here can't use Loader::functions just include the helper manually |
| 388 | 388 | require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
@@ -392,12 +392,12 @@ discard block |
||
| 392 | 392 | $logger->error($str); |
| 393 | 393 | /***********************************/ |
| 394 | 394 | $path = CORE_VIEWS_PATH . '404.php'; |
| 395 | - if(file_exists($path)){ |
|
| 395 | + if (file_exists($path)) { |
|
| 396 | 396 | //compress the output if is available |
| 397 | - if (self::$_canCompressOutput){ |
|
| 397 | + if (self::$_canCompressOutput) { |
|
| 398 | 398 | ob_start('ob_gzhandler'); |
| 399 | 399 | } |
| 400 | - else{ |
|
| 400 | + else { |
|
| 401 | 401 | ob_start(); |
| 402 | 402 | } |
| 403 | 403 | require_once $path; |
@@ -405,8 +405,8 @@ discard block |
||
| 405 | 405 | self::sendHeaders(404); |
| 406 | 406 | echo $output; |
| 407 | 407 | } |
| 408 | - else{ |
|
| 409 | - show_error('The 404 view [' .$path. '] does not exist'); |
|
| 408 | + else { |
|
| 409 | + show_error('The 404 view [' . $path . '] does not exist'); |
|
| 410 | 410 | } |
| 411 | 411 | } |
| 412 | 412 | |
@@ -414,14 +414,14 @@ discard block |
||
| 414 | 414 | * Display the error to user |
| 415 | 415 | * @param array $data the error information |
| 416 | 416 | */ |
| 417 | - public static function sendError(array $data = array()){ |
|
| 417 | + public static function sendError(array $data = array()) { |
|
| 418 | 418 | $path = CORE_VIEWS_PATH . 'errors.php'; |
| 419 | - if(file_exists($path)){ |
|
| 419 | + if (file_exists($path)) { |
|
| 420 | 420 | //compress the output if exists |
| 421 | - if (self::$_canCompressOutput){ |
|
| 421 | + if (self::$_canCompressOutput) { |
|
| 422 | 422 | ob_start('ob_gzhandler'); |
| 423 | 423 | } |
| 424 | - else{ |
|
| 424 | + else { |
|
| 425 | 425 | ob_start(); |
| 426 | 426 | } |
| 427 | 427 | extract($data); |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | self::sendHeaders(503); |
| 431 | 431 | echo $output; |
| 432 | 432 | } |
| 433 | - else{ |
|
| 433 | + else { |
|
| 434 | 434 | //can't use show_error() at this time because some dependencies not yet loaded and to prevent loop |
| 435 | 435 | set_http_status_header(503); |
| 436 | 436 | echo 'The error view [' . $path . '] does not exist'; |
@@ -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 Html{ |
|
| 27 | + class Html { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Generate the html anchor link |
@@ -35,21 +35,21 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | * @return string|void the anchor link generated html if $return is true or display it if not |
| 37 | 37 | */ |
| 38 | - public static function a($link = '', $anchor = null, array $attributes = array(), $return = true){ |
|
| 39 | - if(! is_url($link)){ |
|
| 38 | + public static function a($link = '', $anchor = null, array $attributes = array(), $return = true) { |
|
| 39 | + if (!is_url($link)) { |
|
| 40 | 40 | $link = Url::site_url($link); |
| 41 | 41 | } |
| 42 | - if(! $anchor){ |
|
| 42 | + if (!$anchor) { |
|
| 43 | 43 | $anchor = $link; |
| 44 | 44 | } |
| 45 | 45 | $str = null; |
| 46 | - $str .= '<a href = "'.$link.'"'; |
|
| 46 | + $str .= '<a href = "' . $link . '"'; |
|
| 47 | 47 | $str .= attributes_to_string($attributes); |
| 48 | 48 | $str .= '>'; |
| 49 | 49 | $str .= $anchor; |
| 50 | 50 | $str .= '</a>'; |
| 51 | 51 | |
| 52 | - if($return){ |
|
| 52 | + if ($return) { |
|
| 53 | 53 | return $str; |
| 54 | 54 | } |
| 55 | 55 | echo $str; |
@@ -64,18 +64,18 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @return string|void the generated html for mailto link if $return is true or display it if not |
| 66 | 66 | */ |
| 67 | - public static function mailto($link, $anchor = null, array $attributes = array(), $return = true){ |
|
| 68 | - if(! $anchor){ |
|
| 67 | + public static function mailto($link, $anchor = null, array $attributes = array(), $return = true) { |
|
| 68 | + if (!$anchor) { |
|
| 69 | 69 | $anchor = $link; |
| 70 | 70 | } |
| 71 | 71 | $str = null; |
| 72 | - $str .= '<a href = "mailto:'.$link.'"'; |
|
| 72 | + $str .= '<a href = "mailto:' . $link . '"'; |
|
| 73 | 73 | $str .= attributes_to_string($attributes); |
| 74 | 74 | $str .= '>'; |
| 75 | 75 | $str .= $anchor; |
| 76 | 76 | $str .= '</a>'; |
| 77 | 77 | |
| 78 | - if($return){ |
|
| 78 | + if ($return) { |
|
| 79 | 79 | return $str; |
| 80 | 80 | } |
| 81 | 81 | echo $str; |
@@ -88,14 +88,14 @@ discard block |
||
| 88 | 88 | * |
| 89 | 89 | * @return string|void the generated "br" html if $return is true or display it if not |
| 90 | 90 | */ |
| 91 | - public static function br($nb = 1, $return = true){ |
|
| 91 | + public static function br($nb = 1, $return = true) { |
|
| 92 | 92 | $nb = (int) $nb; |
| 93 | 93 | $str = null; |
| 94 | 94 | for ($i = 1; $i <= $nb; $i++) { |
| 95 | 95 | $str .= '<br />'; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if($return){ |
|
| 98 | + if ($return) { |
|
| 99 | 99 | return $str; |
| 100 | 100 | } |
| 101 | 101 | echo $str; |
@@ -109,13 +109,13 @@ discard block |
||
| 109 | 109 | * |
| 110 | 110 | * @return string|void the generated "hr" html if $return is true or display it if not. |
| 111 | 111 | */ |
| 112 | - public static function hr($nb = 1, array $attributes = array(), $return = true){ |
|
| 112 | + public static function hr($nb = 1, array $attributes = array(), $return = true) { |
|
| 113 | 113 | $nb = (int) $nb; |
| 114 | 114 | $str = null; |
| 115 | 115 | for ($i = 1; $i <= $nb; $i++) { |
| 116 | - $str .= '<hr' .attributes_to_string($attributes). ' />'; |
|
| 116 | + $str .= '<hr' . attributes_to_string($attributes) . ' />'; |
|
| 117 | 117 | } |
| 118 | - if($return){ |
|
| 118 | + if ($return) { |
|
| 119 | 119 | return $str; |
| 120 | 120 | } |
| 121 | 121 | echo $str; |
@@ -131,17 +131,17 @@ discard block |
||
| 131 | 131 | * |
| 132 | 132 | * @return string|void the generated header html if $return is true or display it if not. |
| 133 | 133 | */ |
| 134 | - public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true){ |
|
| 134 | + public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true) { |
|
| 135 | 135 | $nb = (int) $nb; |
| 136 | 136 | $type = (int) $type; |
| 137 | - if($type <= 0 || $type > 6){ |
|
| 137 | + if ($type <= 0 || $type > 6) { |
|
| 138 | 138 | $type = 1; |
| 139 | 139 | } |
| 140 | 140 | $str = null; |
| 141 | 141 | for ($i = 1; $i <= $nb; $i++) { |
| 142 | - $str .= '<h' . $type . attributes_to_string($attributes). '>' .$text. '</h' . $type . '>'; |
|
| 142 | + $str .= '<h' . $type . attributes_to_string($attributes) . '>' . $text . '</h' . $type . '>'; |
|
| 143 | 143 | } |
| 144 | - if($return){ |
|
| 144 | + if ($return) { |
|
| 145 | 145 | return $str; |
| 146 | 146 | } |
| 147 | 147 | echo $str; |
@@ -156,15 +156,15 @@ discard block |
||
| 156 | 156 | * |
| 157 | 157 | * @return string|void the generated "ul" html if $return is true or display it if not. |
| 158 | 158 | */ |
| 159 | - public static function ul($data = array(), $attributes = array(), $return = true){ |
|
| 159 | + public static function ul($data = array(), $attributes = array(), $return = true) { |
|
| 160 | 160 | $data = (array) $data; |
| 161 | 161 | $str = null; |
| 162 | - $str .= '<ul' . (! empty($attributes['ul']) ? attributes_to_string($attributes['ul']):'') . '>'; |
|
| 162 | + $str .= '<ul' . (!empty($attributes['ul']) ? attributes_to_string($attributes['ul']) : '') . '>'; |
|
| 163 | 163 | foreach ($data as $row) { |
| 164 | - $str .= '<li' . (! empty($attributes['li']) ? attributes_to_string($attributes['li']):'') .'>' .$row. '</li>'; |
|
| 164 | + $str .= '<li' . (!empty($attributes['li']) ? attributes_to_string($attributes['li']) : '') . '>' . $row . '</li>'; |
|
| 165 | 165 | } |
| 166 | 166 | $str .= '</ul>'; |
| 167 | - if($return){ |
|
| 167 | + if ($return) { |
|
| 168 | 168 | return $str; |
| 169 | 169 | } |
| 170 | 170 | echo $str; |
@@ -178,15 +178,15 @@ discard block |
||
| 178 | 178 | * @param boolean $return whether need return the generated html or just display it directly |
| 179 | 179 | * @return string|void the generated "ol" html if $return is true or display it if not. |
| 180 | 180 | */ |
| 181 | - public static function ol($data = array(), $attributes = array(), $return = true){ |
|
| 181 | + public static function ol($data = array(), $attributes = array(), $return = true) { |
|
| 182 | 182 | $data = (array) $data; |
| 183 | 183 | $str = null; |
| 184 | - $str .= '<ol' . (!empty($attributes['ol']) ? attributes_to_string($attributes['ol']):'') . '>'; |
|
| 184 | + $str .= '<ol' . (!empty($attributes['ol']) ? attributes_to_string($attributes['ol']) : '') . '>'; |
|
| 185 | 185 | foreach ($data as $row) { |
| 186 | - $str .= '<li' . (!empty($attributes['li']) ? attributes_to_string($attributes['li']):'') .'>' .$row. '</li>'; |
|
| 186 | + $str .= '<li' . (!empty($attributes['li']) ? attributes_to_string($attributes['li']) : '') . '>' . $row . '</li>'; |
|
| 187 | 187 | } |
| 188 | 188 | $str .= '</ol>'; |
| 189 | - if($return){ |
|
| 189 | + if ($return) { |
|
| 190 | 190 | return $str; |
| 191 | 191 | } |
| 192 | 192 | echo $str; |
@@ -204,46 +204,46 @@ discard block |
||
| 204 | 204 | * @param boolean $return whether need return the generated html or just display it directly |
| 205 | 205 | * @return string|void the generated "table" html if $return is true or display it if not. |
| 206 | 206 | */ |
| 207 | - public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true){ |
|
| 207 | + public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true) { |
|
| 208 | 208 | $headers = (array) $headers; |
| 209 | 209 | $body = (array) $body; |
| 210 | 210 | $str = null; |
| 211 | - $str .= '<table' . (! empty($attributes['table']) ? attributes_to_string($attributes['table']):'') . '>'; |
|
| 212 | - if(! empty($headers)){ |
|
| 213 | - $str .= '<thead' . (! empty($attributes['thead']) ? attributes_to_string($attributes['thead']):'') .'>'; |
|
| 214 | - $str .= '<tr' . (! empty($attributes['thead_tr']) ? attributes_to_string($attributes['thead_tr']):'') .'>'; |
|
| 211 | + $str .= '<table' . (!empty($attributes['table']) ? attributes_to_string($attributes['table']) : '') . '>'; |
|
| 212 | + if (!empty($headers)) { |
|
| 213 | + $str .= '<thead' . (!empty($attributes['thead']) ? attributes_to_string($attributes['thead']) : '') . '>'; |
|
| 214 | + $str .= '<tr' . (!empty($attributes['thead_tr']) ? attributes_to_string($attributes['thead_tr']) : '') . '>'; |
|
| 215 | 215 | foreach ($headers as $value) { |
| 216 | - $str .= '<th' . (! empty($attributes['thead_th']) ? attributes_to_string($attributes['thead_th']):'') .'>' .$value. '</th>'; |
|
| 216 | + $str .= '<th' . (!empty($attributes['thead_th']) ? attributes_to_string($attributes['thead_th']) : '') . '>' . $value . '</th>'; |
|
| 217 | 217 | } |
| 218 | 218 | $str .= '</tr>'; |
| 219 | 219 | $str .= '</thead>'; |
| 220 | 220 | } |
| 221 | - else{ |
|
| 221 | + else { |
|
| 222 | 222 | //no need check for footer |
| 223 | 223 | $use_footer = false; |
| 224 | 224 | } |
| 225 | - $str .= '<tbody' . (! empty($attributes['tbody']) ? attributes_to_string($attributes['tbody']):'') .'>'; |
|
| 225 | + $str .= '<tbody' . (!empty($attributes['tbody']) ? attributes_to_string($attributes['tbody']) : '') . '>'; |
|
| 226 | 226 | foreach ($body as $row) { |
| 227 | - if(is_array($row)){ |
|
| 228 | - $str .= '<tr' . (! empty($attributes['tbody_tr']) ? attributes_to_string($attributes['tbody_tr']):'') .'>'; |
|
| 227 | + if (is_array($row)) { |
|
| 228 | + $str .= '<tr' . (!empty($attributes['tbody_tr']) ? attributes_to_string($attributes['tbody_tr']) : '') . '>'; |
|
| 229 | 229 | foreach ($row as $value) { |
| 230 | - $str .= '<td' . (! empty($attributes['tbody_td']) ? attributes_to_string($attributes['tbody_td']):'') .'>' .$value. '</td>'; |
|
| 230 | + $str .= '<td' . (!empty($attributes['tbody_td']) ? attributes_to_string($attributes['tbody_td']) : '') . '>' . $value . '</td>'; |
|
| 231 | 231 | } |
| 232 | 232 | $str .= '</tr>'; |
| 233 | 233 | } |
| 234 | 234 | } |
| 235 | 235 | $str .= '</tbody>'; |
| 236 | - if($use_footer){ |
|
| 237 | - $str .= '<tfoot' . (! empty($attributes['tfoot']) ? attributes_to_string($attributes['tfoot']):'') .'>'; |
|
| 238 | - $str .= '<tr' . (! empty($attributes['tfoot_tr']) ? attributes_to_string($attributes['tfoot_tr']):'') .'>'; |
|
| 236 | + if ($use_footer) { |
|
| 237 | + $str .= '<tfoot' . (!empty($attributes['tfoot']) ? attributes_to_string($attributes['tfoot']) : '') . '>'; |
|
| 238 | + $str .= '<tr' . (!empty($attributes['tfoot_tr']) ? attributes_to_string($attributes['tfoot_tr']) : '') . '>'; |
|
| 239 | 239 | foreach ($headers as $value) { |
| 240 | - $str .= '<th' . (! empty($attributes['tfoot_th']) ? attributes_to_string($attributes['tfoot_th']):'') .'>' .$value. '</th>'; |
|
| 240 | + $str .= '<th' . (!empty($attributes['tfoot_th']) ? attributes_to_string($attributes['tfoot_th']) : '') . '>' . $value . '</th>'; |
|
| 241 | 241 | } |
| 242 | 242 | $str .= '</tr>'; |
| 243 | 243 | $str .= '</tfoot>'; |
| 244 | 244 | } |
| 245 | 245 | $str .= '</table>'; |
| 246 | - if($return){ |
|
| 246 | + if ($return) { |
|
| 247 | 247 | return $str; |
| 248 | 248 | } |
| 249 | 249 | echo $str; |
@@ -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 Module{ |
|
| 27 | + class Module { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * list of loaded module |
@@ -42,9 +42,9 @@ 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){ |
|
| 47 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 45 | + private static function getLogger() { |
|
| 46 | + if (self::$logger == null) { |
|
| 47 | + self::$logger[0] = & class_loader('Log', 'classes'); |
|
| 48 | 48 | self::$logger[0]->setLogger('Library::Module'); |
| 49 | 49 | } |
| 50 | 50 | return self::$logger[0]; |
@@ -53,24 +53,24 @@ discard block |
||
| 53 | 53 | /** |
| 54 | 54 | * Initialise the module list by scanning the directory MODULE_PATH |
| 55 | 55 | */ |
| 56 | - public function init(){ |
|
| 56 | + public function init() { |
|
| 57 | 57 | $logger = self::getLogger(); |
| 58 | 58 | $logger->debug('Check if the application contains the modules ...'); |
| 59 | 59 | $moduleDir = opendir(MODULE_PATH); |
| 60 | - if(is_resource($moduleDir)){ |
|
| 61 | - while(($module = readdir($moduleDir)) !== false){ |
|
| 62 | - if(preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){ |
|
| 60 | + if (is_resource($moduleDir)) { |
|
| 61 | + while (($module = readdir($moduleDir)) !== false) { |
|
| 62 | + if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)) { |
|
| 63 | 63 | self::$list[] = $module; |
| 64 | 64 | } |
| 65 | - else{ |
|
| 66 | - $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name'); |
|
| 65 | + else { |
|
| 66 | + $logger->info('Skipping [' . $module . '], may be this is not a directory or does not exists or is invalid name'); |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | closedir($moduleDir); |
| 70 | 70 | } |
| 71 | 71 | ksort(self::$list); |
| 72 | 72 | |
| 73 | - if(self::hasModule()){ |
|
| 73 | + if (self::hasModule()) { |
|
| 74 | 74 | $logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']'); |
| 75 | 75 | } |
| 76 | 76 | } |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | * Get the list of the custom autoload configuration from module if exists |
| 80 | 80 | * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values |
| 81 | 81 | */ |
| 82 | - public static function getModulesAutoloadConfig(){ |
|
| 82 | + public static function getModulesAutoloadConfig() { |
|
| 83 | 83 | $logger = self::getLogger(); |
| 84 | - if(! self::hasModule()){ |
|
| 84 | + if (!self::hasModule()) { |
|
| 85 | 85 | $logger->info('No module was loaded skipping.'); |
| 86 | 86 | return false; |
| 87 | 87 | } |
@@ -94,10 +94,10 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | foreach (self::$list as $module) { |
| 96 | 96 | $file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php'; |
| 97 | - if(file_exists($file)){ |
|
| 97 | + if (file_exists($file)) { |
|
| 98 | 98 | $autoload = array(); |
| 99 | 99 | require_once $file; |
| 100 | - if(! empty($autoload) && is_array($autoload)){ |
|
| 100 | + if (!empty($autoload) && is_array($autoload)) { |
|
| 101 | 101 | $autoloads = array_merge_recursive($autoloads, $autoload); |
| 102 | 102 | unset($autoload); |
| 103 | 103 | } |
@@ -110,19 +110,19 @@ discard block |
||
| 110 | 110 | * Get the list of the custom routes configuration from module if exists |
| 111 | 111 | * @return array|boolean the routes list or false if no module contains the routes configuration |
| 112 | 112 | */ |
| 113 | - public static function getModulesRoutes(){ |
|
| 113 | + public static function getModulesRoutes() { |
|
| 114 | 114 | $logger = self::getLogger(); |
| 115 | - if(! self::hasModule()){ |
|
| 115 | + if (!self::hasModule()) { |
|
| 116 | 116 | $logger->info('No module was loaded skipping.'); |
| 117 | 117 | return false; |
| 118 | 118 | } |
| 119 | 119 | $routes = array(); |
| 120 | 120 | foreach (self::$list as $module) { |
| 121 | 121 | $file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php'; |
| 122 | - if(file_exists($file)){ |
|
| 122 | + if (file_exists($file)) { |
|
| 123 | 123 | $route = array(); |
| 124 | 124 | require_once $file; |
| 125 | - if(! empty($route) && is_array($route)){ |
|
| 125 | + if (!empty($route) && is_array($route)) { |
|
| 126 | 126 | $routes = array_merge($routes, $route); |
| 127 | 127 | unset($route); |
| 128 | 128 | } |
@@ -138,23 +138,23 @@ discard block |
||
| 138 | 138 | * @param string $module the module name |
| 139 | 139 | * @return boolean|string false or null if no module have this controller, path the full path of the controller |
| 140 | 140 | */ |
| 141 | - public static function findControllerFullPath($class, $module = null){ |
|
| 141 | + public static function findControllerFullPath($class, $module = null) { |
|
| 142 | 142 | $logger = self::getLogger(); |
| 143 | - if(! self::hasModule()){ |
|
| 143 | + if (!self::hasModule()) { |
|
| 144 | 144 | $logger->info('No module was loaded skiping.'); |
| 145 | 145 | return false; |
| 146 | 146 | } |
| 147 | 147 | $class = str_ireplace('.php', '', $class); |
| 148 | 148 | $class = ucfirst($class); |
| 149 | - $classFile = $class.'.php'; |
|
| 150 | - $logger->debug('Checking the controller [' . $class . '] in module [' .$module. '] ...'); |
|
| 149 | + $classFile = $class . '.php'; |
|
| 150 | + $logger->debug('Checking the controller [' . $class . '] in module [' . $module . '] ...'); |
|
| 151 | 151 | $filePath = MODULE_PATH . $module . DS . 'controllers' . DS . $classFile; |
| 152 | - if(file_exists($filePath)){ |
|
| 153 | - $logger->info('Found controller [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 152 | + if (file_exists($filePath)) { |
|
| 153 | + $logger->info('Found controller [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
| 154 | 154 | return $filePath; |
| 155 | 155 | } |
| 156 | - else{ |
|
| 157 | - $logger->info('Controller [' . $class . '] does not exist in the module [' .$module. ']'); |
|
| 156 | + else { |
|
| 157 | + $logger->info('Controller [' . $class . '] does not exist in the module [' . $module . ']'); |
|
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | 160 | } |
@@ -165,23 +165,23 @@ discard block |
||
| 165 | 165 | * @param string $module the module name |
| 166 | 166 | * @return boolean|string false or null if no module have this model, return the full path of this model |
| 167 | 167 | */ |
| 168 | - public static function findModelFullPath($class, $module = null){ |
|
| 168 | + public static function findModelFullPath($class, $module = null) { |
|
| 169 | 169 | $logger = self::getLogger(); |
| 170 | - if(! self::hasModule()){ |
|
| 170 | + if (!self::hasModule()) { |
|
| 171 | 171 | $logger->info('No module was loaded skiping.'); |
| 172 | 172 | return false; |
| 173 | 173 | } |
| 174 | 174 | $class = str_ireplace('.php', '', $class); |
| 175 | 175 | $class = ucfirst($class); |
| 176 | - $classFile = $class.'.php'; |
|
| 177 | - $logger->debug('Checking model [' . $class . '] in module [' .$module. '] ...'); |
|
| 176 | + $classFile = $class . '.php'; |
|
| 177 | + $logger->debug('Checking model [' . $class . '] in module [' . $module . '] ...'); |
|
| 178 | 178 | $filePath = MODULE_PATH . $module . DS . 'models' . DS . $classFile; |
| 179 | - if(file_exists($filePath)){ |
|
| 180 | - $logger->info('Found model [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 179 | + if (file_exists($filePath)) { |
|
| 180 | + $logger->info('Found model [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
| 181 | 181 | return $filePath; |
| 182 | 182 | } |
| 183 | - else{ |
|
| 184 | - $logger->info('Model [' . $class . '] does not exist in the module [' .$module. ']'); |
|
| 183 | + else { |
|
| 184 | + $logger->info('Model [' . $class . '] does not exist in the module [' . $module . ']'); |
|
| 185 | 185 | return false; |
| 186 | 186 | } |
| 187 | 187 | } |
@@ -192,22 +192,22 @@ discard block |
||
| 192 | 192 | * @param string $module the module name |
| 193 | 193 | * @return boolean|string false or null if no module have this configuration, return the full path of this configuration |
| 194 | 194 | */ |
| 195 | - public static function findConfigFullPath($configuration, $module = null){ |
|
| 195 | + public static function findConfigFullPath($configuration, $module = null) { |
|
| 196 | 196 | $logger = self::getLogger(); |
| 197 | - if(! self::hasModule()){ |
|
| 197 | + if (!self::hasModule()) { |
|
| 198 | 198 | $logger->info('No module was loaded skiping.'); |
| 199 | 199 | return false; |
| 200 | 200 | } |
| 201 | 201 | $configuration = str_ireplace('.php', '', $configuration); |
| 202 | - $file = $configuration.'.php'; |
|
| 203 | - $logger->debug('Checking configuration [' . $configuration . '] in module [' .$module. '] ...'); |
|
| 202 | + $file = $configuration . '.php'; |
|
| 203 | + $logger->debug('Checking configuration [' . $configuration . '] in module [' . $module . '] ...'); |
|
| 204 | 204 | $filePath = MODULE_PATH . $module . DS . 'config' . DS . $file; |
| 205 | - if(file_exists($filePath)){ |
|
| 206 | - $logger->info('Found configuration [' . $configuration . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 205 | + if (file_exists($filePath)) { |
|
| 206 | + $logger->info('Found configuration [' . $configuration . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
| 207 | 207 | return $filePath; |
| 208 | 208 | } |
| 209 | - else{ |
|
| 210 | - $logger->info('Configuration [' . $configuration . '] does not exist in the module [' .$module. ']'); |
|
| 209 | + else { |
|
| 210 | + $logger->info('Configuration [' . $configuration . '] does not exist in the module [' . $module . ']'); |
|
| 211 | 211 | return false; |
| 212 | 212 | } |
| 213 | 213 | } |
@@ -218,23 +218,23 @@ discard block |
||
| 218 | 218 | * @param string $module the module name |
| 219 | 219 | * @return boolean|string false or null if no module have this helper, return the full path of this helper |
| 220 | 220 | */ |
| 221 | - public static function findFunctionFullPath($helper, $module = null){ |
|
| 221 | + public static function findFunctionFullPath($helper, $module = null) { |
|
| 222 | 222 | $logger = self::getLogger(); |
| 223 | - if(! self::hasModule()){ |
|
| 223 | + if (!self::hasModule()) { |
|
| 224 | 224 | $logger->info('No module was loaded skiping.'); |
| 225 | 225 | return false; |
| 226 | 226 | } |
| 227 | 227 | $helper = str_ireplace('.php', '', $helper); |
| 228 | 228 | $helper = str_ireplace('function_', '', $helper); |
| 229 | - $file = 'function_'.$helper.'.php'; |
|
| 230 | - $logger->debug('Checking helper [' . $helper . '] in module [' .$module. '] ...'); |
|
| 229 | + $file = 'function_' . $helper . '.php'; |
|
| 230 | + $logger->debug('Checking helper [' . $helper . '] in module [' . $module . '] ...'); |
|
| 231 | 231 | $filePath = MODULE_PATH . $module . DS . 'functions' . DS . $file; |
| 232 | - if(file_exists($filePath)){ |
|
| 233 | - $logger->info('Found helper [' . $helper . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 232 | + if (file_exists($filePath)) { |
|
| 233 | + $logger->info('Found helper [' . $helper . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
| 234 | 234 | return $filePath; |
| 235 | 235 | } |
| 236 | - else{ |
|
| 237 | - $logger->info('Helper [' . $helper . '] does not exist in the module [' .$module. ']'); |
|
| 236 | + else { |
|
| 237 | + $logger->info('Helper [' . $helper . '] does not exist in the module [' . $module . ']'); |
|
| 238 | 238 | return false; |
| 239 | 239 | } |
| 240 | 240 | } |
@@ -246,22 +246,22 @@ discard block |
||
| 246 | 246 | * @param string $module the module name |
| 247 | 247 | * @return boolean|string false or null if no module have this library, return the full path of this library |
| 248 | 248 | */ |
| 249 | - public static function findLibraryFullPath($class, $module = null){ |
|
| 249 | + public static function findLibraryFullPath($class, $module = null) { |
|
| 250 | 250 | $logger = self::getLogger(); |
| 251 | - if(! self::hasModule()){ |
|
| 251 | + if (!self::hasModule()) { |
|
| 252 | 252 | $logger->info('No module was loaded skiping.'); |
| 253 | 253 | return false; |
| 254 | 254 | } |
| 255 | 255 | $class = str_ireplace('.php', '', $class); |
| 256 | - $file = $class.'.php'; |
|
| 257 | - $logger->debug('Checking library [' . $class . '] in module [' .$module. '] ...'); |
|
| 256 | + $file = $class . '.php'; |
|
| 257 | + $logger->debug('Checking library [' . $class . '] in module [' . $module . '] ...'); |
|
| 258 | 258 | $filePath = MODULE_PATH . $module . DS . 'libraries' . DS . $file; |
| 259 | - if(file_exists($filePath)){ |
|
| 260 | - $logger->info('Found library [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 259 | + if (file_exists($filePath)) { |
|
| 260 | + $logger->info('Found library [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
| 261 | 261 | return $filePath; |
| 262 | 262 | } |
| 263 | - else{ |
|
| 264 | - $logger->info('Library [' . $class . '] does not exist in the module [' .$module. ']'); |
|
| 263 | + else { |
|
| 264 | + $logger->info('Library [' . $class . '] does not exist in the module [' . $module . ']'); |
|
| 265 | 265 | return false; |
| 266 | 266 | } |
| 267 | 267 | } |
@@ -273,9 +273,9 @@ discard block |
||
| 273 | 273 | * @param string $module the module name to check |
| 274 | 274 | * @return boolean|string false or null if no module have this view, path the full path of the view |
| 275 | 275 | */ |
| 276 | - public static function findViewFullPath($view, $module = null){ |
|
| 276 | + public static function findViewFullPath($view, $module = null) { |
|
| 277 | 277 | $logger = self::getLogger(); |
| 278 | - if(! self::hasModule()){ |
|
| 278 | + if (!self::hasModule()) { |
|
| 279 | 279 | $logger->info('No module was loaded skiping.'); |
| 280 | 280 | return false; |
| 281 | 281 | } |
@@ -283,14 +283,14 @@ discard block |
||
| 283 | 283 | $view = trim($view, '/\\'); |
| 284 | 284 | $view = str_ireplace('/', DS, $view); |
| 285 | 285 | $viewFile = $view . '.php'; |
| 286 | - $logger->debug('Checking view [' . $view . '] in module [' .$module. '] ...'); |
|
| 286 | + $logger->debug('Checking view [' . $view . '] in module [' . $module . '] ...'); |
|
| 287 | 287 | $filePath = MODULE_PATH . $module . DS . 'views' . DS . $viewFile; |
| 288 | - if(file_exists($filePath)){ |
|
| 289 | - $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 288 | + if (file_exists($filePath)) { |
|
| 289 | + $logger->info('Found view [' . $view . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
| 290 | 290 | return $filePath; |
| 291 | 291 | } |
| 292 | - else{ |
|
| 293 | - $logger->info('View [' . $view . '] does not exist in the module [' .$module. ']'); |
|
| 292 | + else { |
|
| 293 | + $logger->info('View [' . $view . '] does not exist in the module [' . $module . ']'); |
|
| 294 | 294 | return false; |
| 295 | 295 | } |
| 296 | 296 | } |
@@ -302,23 +302,23 @@ discard block |
||
| 302 | 302 | * @param string $appLang the application language like 'en', 'fr' |
| 303 | 303 | * @return boolean|string false or null if no module have this language, return the full path of this language |
| 304 | 304 | */ |
| 305 | - public static function findLanguageFullPath($language, $module = null, $appLang){ |
|
| 305 | + public static function findLanguageFullPath($language, $module = null, $appLang) { |
|
| 306 | 306 | $logger = self::getLogger(); |
| 307 | - if(! self::hasModule()){ |
|
| 307 | + if (!self::hasModule()) { |
|
| 308 | 308 | $logger->info('No module was loaded skiping.'); |
| 309 | 309 | return false; |
| 310 | 310 | } |
| 311 | 311 | $language = str_ireplace('.php', '', $language); |
| 312 | 312 | $language = str_ireplace('lang_', '', $language); |
| 313 | - $file = 'lang_'.$language.'.php'; |
|
| 314 | - $logger->debug('Checking language [' . $language . '] in module [' .$module. '] ...'); |
|
| 313 | + $file = 'lang_' . $language . '.php'; |
|
| 314 | + $logger->debug('Checking language [' . $language . '] in module [' . $module . '] ...'); |
|
| 315 | 315 | $filePath = MODULE_PATH . $module . DS . 'lang' . DS . $appLang . DS . $file; |
| 316 | - if(file_exists($filePath)){ |
|
| 317 | - $logger->info('Found language [' . $language . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 316 | + if (file_exists($filePath)) { |
|
| 317 | + $logger->info('Found language [' . $language . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
| 318 | 318 | return $filePath; |
| 319 | 319 | } |
| 320 | - else{ |
|
| 321 | - $logger->info('Language [' . $language . '] does not exist in the module [' .$module. ']'); |
|
| 320 | + else { |
|
| 321 | + $logger->info('Language [' . $language . '] does not exist in the module [' . $module . ']'); |
|
| 322 | 322 | return false; |
| 323 | 323 | } |
| 324 | 324 | } |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | * Get the list of module loaded |
| 328 | 328 | * @return array the module list |
| 329 | 329 | */ |
| 330 | - public static function getModuleList(){ |
|
| 330 | + public static function getModuleList() { |
|
| 331 | 331 | return self::$list; |
| 332 | 332 | } |
| 333 | 333 | |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | * Check if the application has an module |
| 336 | 336 | * @return boolean |
| 337 | 337 | */ |
| 338 | - public static function hasModule(){ |
|
| 338 | + public static function hasModule() { |
|
| 339 | 339 | return !empty(self::$list); |
| 340 | 340 | } |
| 341 | 341 | |