@@ -170,21 +170,21 @@ discard block |
||
| 170 | 170 | //check in module first |
| 171 | 171 | $logger->debug('Checking the view [' . $view . '] from module list ...'); |
| 172 | 172 | $moduleInfo = $this->getModuleInfoForView($view); |
| 173 | - $module = $moduleInfo['module']; |
|
| 174 | - $view = $moduleInfo['view']; |
|
| 173 | + $module = $moduleInfo['module']; |
|
| 174 | + $view = $moduleInfo['view']; |
|
| 175 | 175 | |
| 176 | 176 | $moduleViewPath = Module::findViewFullPath($view, $module); |
| 177 | - if($moduleViewPath){ |
|
| 177 | + if ($moduleViewPath) { |
|
| 178 | 178 | $path = $moduleViewPath; |
| 179 | - $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$moduleViewPath. '] we will used it'); |
|
| 180 | - } else{ |
|
| 181 | - $logger->info('Cannot find view [' . $view . '] in module [' .$module. '] using the default location'); |
|
| 179 | + $logger->info('Found view [' . $view . '] in module [' . $module . '], the file path is [' . $moduleViewPath . '] we will used it'); |
|
| 180 | + } else { |
|
| 181 | + $logger->info('Cannot find view [' . $view . '] in module [' . $module . '] using the default location'); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | $logger->info('The view file path to be loaded is [' . $path . ']'); |
| 185 | 185 | |
| 186 | 186 | ///////// |
| 187 | - if($return){ |
|
| 187 | + if ($return) { |
|
| 188 | 188 | return $this->loadView($path, $data, true); |
| 189 | 189 | } |
| 190 | 190 | $this->loadView($path, $data, false); |
@@ -298,8 +298,8 @@ discard block |
||
| 298 | 298 | $output = ob_get_clean(); |
| 299 | 299 | self::sendHeaders(404); |
| 300 | 300 | echo $output; |
| 301 | - } else{ |
|
| 302 | - show_error('The 404 view [' .$path. '] does not exist'); |
|
| 301 | + } else { |
|
| 302 | + show_error('The 404 view [' . $path . '] does not exist'); |
|
| 303 | 303 | } |
| 304 | 304 | } |
| 305 | 305 | |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | $output = ob_get_clean(); |
| 322 | 322 | self::sendHeaders(503); |
| 323 | 323 | echo $output; |
| 324 | - } else{ |
|
| 324 | + } else { |
|
| 325 | 325 | //can't use show_error() at this time because some dependencies not yet loaded and to prevent loop |
| 326 | 326 | set_http_status_header(503); |
| 327 | 327 | echo 'The error view [' . $path . '] does not exist'; |
@@ -92,14 +92,14 @@ discard block |
||
| 92 | 92 | * @param string $item the config item name to be deleted |
| 93 | 93 | * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
| 94 | 94 | */ |
| 95 | - public static function delete($item){ |
|
| 95 | + public static function delete($item) { |
|
| 96 | 96 | $logger = self::getLogger(); |
| 97 | - if(array_key_exists($item, self::$config)){ |
|
| 98 | - $logger->info('Delete config item ['.$item.']'); |
|
| 97 | + if (array_key_exists($item, self::$config)) { |
|
| 98 | + $logger->info('Delete config item [' . $item . ']'); |
|
| 99 | 99 | unset(self::$config[$item]); |
| 100 | 100 | return true; |
| 101 | - } else{ |
|
| 102 | - $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
|
| 101 | + } else { |
|
| 102 | + $logger->warning('Config item [' . $item . '] to be deleted does not exists'); |
|
| 103 | 103 | return false; |
| 104 | 104 | } |
| 105 | 105 | } |
@@ -147,12 +147,12 @@ discard block |
||
| 147 | 147 | 0, |
| 148 | 148 | strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])) |
| 149 | 149 | ); |
| 150 | - } else{ |
|
| 150 | + } else { |
|
| 151 | 151 | $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
| 152 | 152 | $baseUrl = 'http://localhost/'; |
| 153 | 153 | } |
| 154 | 154 | self::set('base_url', $baseUrl); |
| 155 | 155 | } |
| 156 | - self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/'; |
|
| 156 | + self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/'; |
|
| 157 | 157 | } |
| 158 | 158 | } |
@@ -74,25 +74,25 @@ discard block |
||
| 74 | 74 | $class = $moduleInfo['class']; |
| 75 | 75 | |
| 76 | 76 | $moduleModelFilePath = Module::findModelFullPath($class, $module); |
| 77 | - if ($moduleModelFilePath){ |
|
| 78 | - $logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it'); |
|
| 77 | + if ($moduleModelFilePath) { |
|
| 78 | + $logger->info('Found model [' . $class . '] from module [' . $module . '], the file path is [' . $moduleModelFilePath . '] we will used it'); |
|
| 79 | 79 | $classFilePath = $moduleModelFilePath; |
| 80 | - } else{ |
|
| 80 | + } else { |
|
| 81 | 81 | $logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
| 82 | 82 | } |
| 83 | 83 | $logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
| 84 | - if (file_exists($classFilePath)){ |
|
| 84 | + if (file_exists($classFilePath)) { |
|
| 85 | 85 | require_once $classFilePath; |
| 86 | - if (class_exists($class)){ |
|
| 86 | + if (class_exists($class)) { |
|
| 87 | 87 | $c = new $class(); |
| 88 | 88 | $obj = & get_instance(); |
| 89 | 89 | $obj->{$instance} = $c; |
| 90 | 90 | static::$loaded[$instance] = $class; |
| 91 | 91 | $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
| 92 | - } else{ |
|
| 93 | - show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']'); |
|
| 92 | + } else { |
|
| 93 | + show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']'); |
|
| 94 | 94 | } |
| 95 | - } else{ |
|
| 95 | + } else { |
|
| 96 | 96 | show_error('Unable to find the model [' . $class . ']'); |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -131,17 +131,17 @@ discard block |
||
| 131 | 131 | } |
| 132 | 132 | $libraryFilePath = null; |
| 133 | 133 | $logger->debug('Check if this is a system library ...'); |
| 134 | - if (file_exists(CORE_LIBRARY_PATH . $file)){ |
|
| 134 | + if (file_exists(CORE_LIBRARY_PATH . $file)) { |
|
| 135 | 135 | $libraryFilePath = CORE_LIBRARY_PATH . $file; |
| 136 | 136 | $class = ucfirst($class); |
| 137 | 137 | $logger->info('This library is a system library'); |
| 138 | - } else{ |
|
| 138 | + } else { |
|
| 139 | 139 | $logger->info('This library is not a system library'); |
| 140 | 140 | //first check if this library is in the module |
| 141 | 141 | $libraryFilePath = self::getLibraryPathUsingModuleInfo($class); |
| 142 | 142 | //*************** |
| 143 | 143 | } |
| 144 | - if (! $libraryFilePath && file_exists(LIBRARY_PATH . $file)){ |
|
| 144 | + if (!$libraryFilePath && file_exists(LIBRARY_PATH . $file)) { |
|
| 145 | 145 | $libraryFilePath = LIBRARY_PATH . $file; |
| 146 | 146 | } |
| 147 | 147 | $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']'); |
@@ -173,21 +173,21 @@ discard block |
||
| 173 | 173 | $moduleInfo = self::getModuleInfoForFunction($function); |
| 174 | 174 | $module = $moduleInfo['module']; |
| 175 | 175 | $function = $moduleInfo['function']; |
| 176 | - if(! empty($moduleInfo['file'])){ |
|
| 176 | + if (!empty($moduleInfo['file'])) { |
|
| 177 | 177 | $file = $moduleInfo['file']; |
| 178 | 178 | } |
| 179 | 179 | $moduleFunctionPath = Module::findFunctionFullPath($function, $module); |
| 180 | - if ($moduleFunctionPath){ |
|
| 181 | - $logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it'); |
|
| 180 | + if ($moduleFunctionPath) { |
|
| 181 | + $logger->info('Found helper [' . $function . '] from module [' . $module . '], the file path is [' . $moduleFunctionPath . '] we will used it'); |
|
| 182 | 182 | $functionFilePath = $moduleFunctionPath; |
| 183 | - } else{ |
|
| 183 | + } else { |
|
| 184 | 184 | $logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
| 185 | 185 | } |
| 186 | - if (! $functionFilePath){ |
|
| 186 | + if (!$functionFilePath) { |
|
| 187 | 187 | $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH); |
| 188 | - foreach($searchDir as $dir){ |
|
| 188 | + foreach ($searchDir as $dir) { |
|
| 189 | 189 | $filePath = $dir . $file; |
| 190 | - if (file_exists($filePath)){ |
|
| 190 | + if (file_exists($filePath)) { |
|
| 191 | 191 | $functionFilePath = $filePath; |
| 192 | 192 | //is already found not to continue |
| 193 | 193 | break; |
@@ -195,11 +195,11 @@ discard block |
||
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | 197 | $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']'); |
| 198 | - if ($functionFilePath){ |
|
| 198 | + if ($functionFilePath) { |
|
| 199 | 199 | require_once $functionFilePath; |
| 200 | 200 | static::$loaded['function_' . $function] = $functionFilePath; |
| 201 | 201 | $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
| 202 | - } else{ |
|
| 202 | + } else { |
|
| 203 | 203 | show_error('Unable to find helper file [' . $file . ']'); |
| 204 | 204 | } |
| 205 | 205 | } |
@@ -229,25 +229,25 @@ discard block |
||
| 229 | 229 | $module = $moduleInfo['module']; |
| 230 | 230 | $filename = $moduleInfo['filename']; |
| 231 | 231 | $moduleConfigPath = Module::findConfigFullPath($filename, $module); |
| 232 | - if ($moduleConfigPath){ |
|
| 233 | - $logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it'); |
|
| 232 | + if ($moduleConfigPath) { |
|
| 233 | + $logger->info('Found config [' . $filename . '] from module [' . $module . '], the file path is [' . $moduleConfigPath . '] we will used it'); |
|
| 234 | 234 | $configFilePath = $moduleConfigPath; |
| 235 | - } else{ |
|
| 235 | + } else { |
|
| 236 | 236 | $logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
| 237 | 237 | } |
| 238 | 238 | $logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
| 239 | 239 | $config = array(); |
| 240 | - if (file_exists($configFilePath)){ |
|
| 240 | + if (file_exists($configFilePath)) { |
|
| 241 | 241 | require_once $configFilePath; |
| 242 | - if (! empty($config) && is_array($config)){ |
|
| 242 | + if (!empty($config) && is_array($config)) { |
|
| 243 | 243 | Config::setAll($config); |
| 244 | 244 | static::$loaded['config_' . $filename] = $configFilePath; |
| 245 | 245 | $logger->info('Configuration [' . $configFilePath . '] loaded successfully.'); |
| 246 | 246 | $logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config)); |
| 247 | 247 | unset($config); |
| 248 | 248 | } |
| 249 | - } else{ |
|
| 250 | - show_error('Unable to find config file ['. $configFilePath . ']'); |
|
| 249 | + } else { |
|
| 250 | + show_error('Unable to find config file [' . $configFilePath . ']'); |
|
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | |
@@ -278,21 +278,21 @@ discard block |
||
| 278 | 278 | $moduleInfo = self::getModuleInfoForLanguage($language); |
| 279 | 279 | $module = $moduleInfo['module']; |
| 280 | 280 | $language = $moduleInfo['language']; |
| 281 | - if(! empty($moduleInfo['file'])){ |
|
| 281 | + if (!empty($moduleInfo['file'])) { |
|
| 282 | 282 | $file = $moduleInfo['file']; |
| 283 | 283 | } |
| 284 | 284 | $moduleLanguagePath = Module::findLanguageFullPath($language, $appLang, $module); |
| 285 | - if ($moduleLanguagePath){ |
|
| 286 | - $logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it'); |
|
| 285 | + if ($moduleLanguagePath) { |
|
| 286 | + $logger->info('Found language [' . $language . '] from module [' . $module . '], the file path is [' . $moduleLanguagePath . '] we will used it'); |
|
| 287 | 287 | $languageFilePath = $moduleLanguagePath; |
| 288 | - } else{ |
|
| 288 | + } else { |
|
| 289 | 289 | $logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
| 290 | 290 | } |
| 291 | - if (! $languageFilePath){ |
|
| 291 | + if (!$languageFilePath) { |
|
| 292 | 292 | $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH); |
| 293 | - foreach($searchDir as $dir){ |
|
| 293 | + foreach ($searchDir as $dir) { |
|
| 294 | 294 | $filePath = $dir . $appLang . DS . $file; |
| 295 | - if (file_exists($filePath)){ |
|
| 295 | + if (file_exists($filePath)) { |
|
| 296 | 296 | $languageFilePath = $filePath; |
| 297 | 297 | //already found no need continue |
| 298 | 298 | break; |
@@ -329,19 +329,19 @@ discard block |
||
| 329 | 329 | * 'class' => 'class_name' |
| 330 | 330 | * ) |
| 331 | 331 | */ |
| 332 | - protected static function getModuleInfoForModelLibrary($class){ |
|
| 332 | + protected static function getModuleInfoForModelLibrary($class) { |
|
| 333 | 333 | $module = null; |
| 334 | 334 | $obj = & get_instance(); |
| 335 | - if (strpos($class, '/') !== false){ |
|
| 335 | + if (strpos($class, '/') !== false) { |
|
| 336 | 336 | $path = explode('/', $class); |
| 337 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
| 337 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
| 338 | 338 | $module = $path[0]; |
| 339 | 339 | $class = ucfirst($path[1]); |
| 340 | 340 | } |
| 341 | - } else{ |
|
| 341 | + } else { |
|
| 342 | 342 | $class = ucfirst($class); |
| 343 | 343 | } |
| 344 | - if (! $module && !empty($obj->moduleName)){ |
|
| 344 | + if (!$module && !empty($obj->moduleName)) { |
|
| 345 | 345 | $module = $obj->moduleName; |
| 346 | 346 | } |
| 347 | 347 | return array( |
@@ -451,15 +451,15 @@ discard block |
||
| 451 | 451 | * @param string $class the class name to determine the instance |
| 452 | 452 | * @return string the instance name |
| 453 | 453 | */ |
| 454 | - protected static function getModelLibraryInstanceName($class){ |
|
| 454 | + protected static function getModelLibraryInstanceName($class) { |
|
| 455 | 455 | //for module |
| 456 | 456 | $instance = null; |
| 457 | - if (strpos($class, '/') !== false){ |
|
| 457 | + if (strpos($class, '/') !== false) { |
|
| 458 | 458 | $path = explode('/', $class); |
| 459 | - if (isset($path[1])){ |
|
| 459 | + if (isset($path[1])) { |
|
| 460 | 460 | $instance = strtolower($path[1]); |
| 461 | 461 | } |
| 462 | - } else{ |
|
| 462 | + } else { |
|
| 463 | 463 | $instance = strtolower($class); |
| 464 | 464 | } |
| 465 | 465 | return $instance; |
@@ -478,10 +478,10 @@ discard block |
||
| 478 | 478 | $module = $moduleInfo['module']; |
| 479 | 479 | $class = $moduleInfo['class']; |
| 480 | 480 | $moduleLibraryPath = Module::findLibraryFullPath($class, $module); |
| 481 | - if ($moduleLibraryPath){ |
|
| 482 | - $logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it'); |
|
| 481 | + if ($moduleLibraryPath) { |
|
| 482 | + $logger->info('Found library [' . $class . '] from module [' . $module . '], the file path is [' . $moduleLibraryPath . '] we will used it'); |
|
| 483 | 483 | $libraryFilePath = $moduleLibraryPath; |
| 484 | - } else{ |
|
| 484 | + } else { |
|
| 485 | 485 | $logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
| 486 | 486 | } |
| 487 | 487 | return $libraryFilePath; |
@@ -495,20 +495,20 @@ discard block |
||
| 495 | 495 | * @param array $params the parameter to use |
| 496 | 496 | * @return void |
| 497 | 497 | */ |
| 498 | - protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()){ |
|
| 499 | - if ($libraryFilePath){ |
|
| 498 | + protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()) { |
|
| 499 | + if ($libraryFilePath) { |
|
| 500 | 500 | $logger = static::getLogger(); |
| 501 | 501 | require_once $libraryFilePath; |
| 502 | - if (class_exists($class)){ |
|
| 502 | + if (class_exists($class)) { |
|
| 503 | 503 | $c = $params ? new $class($params) : new $class(); |
| 504 | 504 | $obj = & get_instance(); |
| 505 | 505 | $obj->{$instance} = $c; |
| 506 | 506 | static::$loaded[$instance] = $class; |
| 507 | 507 | $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
| 508 | - } else{ |
|
| 509 | - show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class); |
|
| 508 | + } else { |
|
| 509 | + show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class); |
|
| 510 | 510 | } |
| 511 | - } else{ |
|
| 511 | + } else { |
|
| 512 | 512 | show_error('Unable to find library class [' . $class . ']'); |
| 513 | 513 | } |
| 514 | 514 | } |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | } |
| 535 | 535 | static::$loaded['lang_' . $language] = $languageFilePath; |
| 536 | 536 | $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
| 537 | - } else{ |
|
| 537 | + } else { |
|
| 538 | 538 | show_error('Unable to find language [' . $language . ']'); |
| 539 | 539 | } |
| 540 | 540 | } |
@@ -242,8 +242,7 @@ discard block |
||
| 242 | 242 | //if the application is running in CLI mode use the first argument |
| 243 | 243 | else if (IS_CLI && isset($_SERVER['argv'][1])) { |
| 244 | 244 | $routeUri = $_SERVER['argv'][1]; |
| 245 | - } |
|
| 246 | - else if (isset($_SERVER['REQUEST_URI'])) { |
|
| 245 | + } else if (isset($_SERVER['REQUEST_URI'])) { |
|
| 247 | 246 | $routeUri = $_SERVER['REQUEST_URI']; |
| 248 | 247 | } |
| 249 | 248 | $this->logger->debug('Check if URL suffix is enabled in the configuration'); |
@@ -339,15 +338,13 @@ discard block |
||
| 339 | 338 | if (!class_exists($controller, false)) { |
| 340 | 339 | $e404 = true; |
| 341 | 340 | $this->logger->warning('The controller file [' . $classFilePath . '] exists but does not contain the class [' . $controller . ']'); |
| 342 | - } |
|
| 343 | - else { |
|
| 341 | + } else { |
|
| 344 | 342 | $controllerInstance = new $controller(); |
| 345 | 343 | $controllerMethod = $this->getMethod(); |
| 346 | 344 | if (!method_exists($controllerInstance, $controllerMethod)) { |
| 347 | 345 | $e404 = true; |
| 348 | 346 | $this->logger->warning('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']'); |
| 349 | - } |
|
| 350 | - else { |
|
| 347 | + } else { |
|
| 351 | 348 | $this->logger->info('Routing data is set correctly now GO!'); |
| 352 | 349 | call_user_func_array(array($controllerInstance, $controllerMethod), $this->args); |
| 353 | 350 | //render the final page to user |
@@ -355,8 +352,7 @@ discard block |
||
| 355 | 352 | get_instance()->response->renderFinalPage(); |
| 356 | 353 | } |
| 357 | 354 | } |
| 358 | - } |
|
| 359 | - else { |
|
| 355 | + } else { |
|
| 360 | 356 | $this->logger->info('The controller file path [' . $classFilePath . '] does not exist'); |
| 361 | 357 | $e404 = true; |
| 362 | 358 | } |
@@ -462,8 +458,7 @@ discard block |
||
| 462 | 458 | $this->logger->info('The current request use the module [' . $moduleControllerMethod[0] . ']'); |
| 463 | 459 | $this->module = $moduleControllerMethod[0]; |
| 464 | 460 | $moduleControllerMethod = explode('@', $moduleControllerMethod[1]); |
| 465 | - } |
|
| 466 | - else { |
|
| 461 | + } else { |
|
| 467 | 462 | $this->logger->info('The current request does not use the module'); |
| 468 | 463 | $moduleControllerMethod = explode('@', $this->callback[$index]); |
| 469 | 464 | } |
@@ -519,8 +514,7 @@ discard block |
||
| 519 | 514 | } |
| 520 | 515 | //args |
| 521 | 516 | $this->args = $segment; |
| 522 | - } |
|
| 523 | - else { |
|
| 517 | + } else { |
|
| 524 | 518 | $this->logger->info('The application contains a loaded module will check if the current request is found in the module list'); |
| 525 | 519 | if (in_array($segment[0], $modules)) { |
| 526 | 520 | $this->logger->info('Found, the current request use the module [' . $segment[0] . ']'); |
@@ -534,8 +528,7 @@ discard block |
||
| 534 | 528 | if (!$path) { |
| 535 | 529 | $this->logger->info('The controller [' . $this->controller . '] not found in the module, may be will use the module [' . $this->module . '] as controller'); |
| 536 | 530 | $this->controller = $this->module; |
| 537 | - } |
|
| 538 | - else { |
|
| 531 | + } else { |
|
| 539 | 532 | $this->controllerPath = $path; |
| 540 | 533 | array_shift($segment); |
| 541 | 534 | } |
@@ -547,8 +540,7 @@ discard block |
||
| 547 | 540 | } |
| 548 | 541 | //the remaining is for args |
| 549 | 542 | $this->args = $segment; |
| 550 | - } |
|
| 551 | - else { |
|
| 543 | + } else { |
|
| 552 | 544 | $this->logger->info('The current request information is not found in the module list'); |
| 553 | 545 | //controller |
| 554 | 546 | if (isset($segment[0])) { |
@@ -82,8 +82,7 @@ discard block |
||
| 82 | 82 | // Unlinking when the file was expired |
| 83 | 83 | unlink($filePath); |
| 84 | 84 | return false; |
| 85 | - } |
|
| 86 | - else { |
|
| 85 | + } else { |
|
| 87 | 86 | $this->logger->info('The cache not yet expire, now return the cache data for key [' . $key . '], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']'); |
| 88 | 87 | return $data['data']; |
| 89 | 88 | } |
@@ -120,8 +119,7 @@ discard block |
||
| 120 | 119 | $this->logger->error('Can not write cache data into file [' . $filePath . '] for the key [' . $key . '], return false'); |
| 121 | 120 | fclose($handle); |
| 122 | 121 | return false; |
| 123 | - } |
|
| 124 | - else { |
|
| 122 | + } else { |
|
| 125 | 123 | $this->logger->info('Cache data saved into file [' . $filePath . '] for the key [' . $key . ']'); |
| 126 | 124 | fclose($handle); |
| 127 | 125 | chmod($filePath, 0640); |
@@ -143,8 +141,7 @@ discard block |
||
| 143 | 141 | if (!file_exists($filePath)) { |
| 144 | 142 | $this->logger->info('This cache file does not exists skipping'); |
| 145 | 143 | return false; |
| 146 | - } |
|
| 147 | - else { |
|
| 144 | + } else { |
|
| 148 | 145 | $this->logger->info('Found cache file [' . $filePath . '] remove it'); |
| 149 | 146 | unlink($filePath); |
| 150 | 147 | return true; |
@@ -197,8 +194,7 @@ discard block |
||
| 197 | 194 | $list = glob(CACHE_PATH . '*.cache'); |
| 198 | 195 | if (!$list) { |
| 199 | 196 | $this->logger->info('No cache files were found skipping'); |
| 200 | - } |
|
| 201 | - else { |
|
| 197 | + } else { |
|
| 202 | 198 | $this->logger->info('Found [' . count($list) . '] cache files to remove if expired'); |
| 203 | 199 | foreach ($list as $file) { |
| 204 | 200 | $this->logger->debug('Processing the cache file [' . $file . ']'); |
@@ -206,12 +202,10 @@ discard block |
||
| 206 | 202 | $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
| 207 | 203 | if (!$data) { |
| 208 | 204 | $this->logger->warning('Can not unserialize the cache data for file [' . $file . ']'); |
| 209 | - } |
|
| 210 | - else if (time() > $data['expire']) { |
|
| 205 | + } else if (time() > $data['expire']) { |
|
| 211 | 206 | $this->logger->info('The cache data for file [' . $file . '] already expired remove it'); |
| 212 | 207 | unlink($file); |
| 213 | - } |
|
| 214 | - else { |
|
| 208 | + } else { |
|
| 215 | 209 | $this->logger->info('The cache data for file [' . $file . '] not yet expired skip it'); |
| 216 | 210 | } |
| 217 | 211 | } |
@@ -226,8 +220,7 @@ discard block |
||
| 226 | 220 | $list = glob(CACHE_PATH . '*.cache'); |
| 227 | 221 | if (!$list) { |
| 228 | 222 | $this->logger->info('No cache files were found skipping'); |
| 229 | - } |
|
| 230 | - else { |
|
| 223 | + } else { |
|
| 231 | 224 | $this->logger->info('Found [' . count($list) . '] cache files to remove'); |
| 232 | 225 | foreach ($list as $file) { |
| 233 | 226 | $this->logger->debug('Processing the cache file [' . $file . ']'); |
@@ -254,8 +247,7 @@ discard block |
||
| 254 | 247 | |
| 255 | 248 | $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE'); |
| 256 | 249 | $this->compressCacheData = false; |
| 257 | - } |
|
| 258 | - else { |
|
| 250 | + } else { |
|
| 259 | 251 | $this->compressCacheData = $status; |
| 260 | 252 | } |
| 261 | 253 | return $this; |
@@ -47,8 +47,7 @@ discard block |
||
| 47 | 47 | if ($success === false) { |
| 48 | 48 | $this->logger->info('No cache found for the key [' . $key . '], return false'); |
| 49 | 49 | return false; |
| 50 | - } |
|
| 51 | - else { |
|
| 50 | + } else { |
|
| 52 | 51 | $cacheInfo = $this->_getCacheInfo($key); |
| 53 | 52 | $expire = time(); |
| 54 | 53 | if ($cacheInfo) { |
@@ -74,8 +73,7 @@ discard block |
||
| 74 | 73 | if ($result === false) { |
| 75 | 74 | $this->logger->error('Can not write cache data for the key [' . $key . '], return false'); |
| 76 | 75 | return false; |
| 77 | - } |
|
| 78 | - else { |
|
| 76 | + } else { |
|
| 79 | 77 | $this->logger->info('Cache data saved for the key [' . $key . ']'); |
| 80 | 78 | return true; |
| 81 | 79 | } |
@@ -94,8 +92,7 @@ discard block |
||
| 94 | 92 | if ($cacheInfo === false) { |
| 95 | 93 | $this->logger->info('This cache data does not exists skipping'); |
| 96 | 94 | return false; |
| 97 | - } |
|
| 98 | - else { |
|
| 95 | + } else { |
|
| 99 | 96 | $this->logger->info('Found cache data for the key [' . $key . '] remove it'); |
| 100 | 97 | return apc_delete($key) === true; |
| 101 | 98 | } |
@@ -119,8 +116,7 @@ discard block |
||
| 119 | 116 | 'ttl' => $cacheInfos['ttl'] |
| 120 | 117 | ); |
| 121 | 118 | return $data; |
| 122 | - } |
|
| 123 | - else { |
|
| 119 | + } else { |
|
| 124 | 120 | $this->logger->info('This cache does not exists skipping'); |
| 125 | 121 | return false; |
| 126 | 122 | } |
@@ -144,8 +140,7 @@ discard block |
||
| 144 | 140 | if (empty($cacheInfos['cache_list'])) { |
| 145 | 141 | $this->logger->info('No cache data were found skipping'); |
| 146 | 142 | return false; |
| 147 | - } |
|
| 148 | - else { |
|
| 143 | + } else { |
|
| 149 | 144 | $this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove'); |
| 150 | 145 | return apc_clear_cache('user'); |
| 151 | 146 | } |
@@ -44,25 +44,25 @@ |
||
| 44 | 44 | * @param string $path the link path or full URL |
| 45 | 45 | * @return string the full link URL |
| 46 | 46 | */ |
| 47 | - public static function site_url($path = ''){ |
|
| 48 | - if(is_url($path)){ |
|
| 47 | + public static function site_url($path = '') { |
|
| 48 | + if (is_url($path)) { |
|
| 49 | 49 | return $path; |
| 50 | 50 | } |
| 51 | 51 | $path = rtrim($path, '/'); |
| 52 | 52 | $baseUrl = get_config('base_url'); |
| 53 | 53 | $frontController = get_config('front_controller'); |
| 54 | 54 | $url = $baseUrl; |
| 55 | - if($frontController){ |
|
| 55 | + if ($frontController) { |
|
| 56 | 56 | $url .= $frontController . '/'; |
| 57 | 57 | } |
| 58 | - if(($suffix = get_config('url_suffix')) && $path){ |
|
| 59 | - if(strpos($path, '?') !== false){ |
|
| 58 | + if (($suffix = get_config('url_suffix')) && $path) { |
|
| 59 | + if (strpos($path, '?') !== false) { |
|
| 60 | 60 | $query = explode('?', $path); |
| 61 | 61 | $query[0] = str_ireplace($suffix, '', $query[0]); |
| 62 | 62 | $query[0] = rtrim($query[0], '/'); |
| 63 | 63 | $query[0] .= $suffix; |
| 64 | 64 | $path = implode('?', $query); |
| 65 | - } else{ |
|
| 65 | + } else { |
|
| 66 | 66 | $path .= $suffix; |
| 67 | 67 | } |
| 68 | 68 | } |
@@ -78,14 +78,14 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | //if the language exists in cookie use it |
| 80 | 80 | $cfgKey = get_config('language_cookie_name'); |
| 81 | - $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']'); |
|
| 81 | + $this->logger->debug('Getting current language from cookie [' . $cfgKey . ']'); |
|
| 82 | 82 | $objCookie = & class_loader('Cookie'); |
| 83 | 83 | $cookieLang = $objCookie->get($cfgKey); |
| 84 | - if($cookieLang && $this->isValid($cookieLang)){ |
|
| 84 | + if ($cookieLang && $this->isValid($cookieLang)) { |
|
| 85 | 85 | $this->current = $cookieLang; |
| 86 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']'); |
|
| 87 | - } else{ |
|
| 88 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
|
| 86 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is valid so we will set the language using the cookie value [' . $cookieLang . ']'); |
|
| 87 | + } else { |
|
| 88 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is not set, use the default value [' . $this->getDefault() . ']'); |
|
| 89 | 89 | $this->current = $this->getDefault(); |
| 90 | 90 | } |
| 91 | 91 | } |
@@ -166,13 +166,13 @@ discard block |
||
| 166 | 166 | * @param string $name the short language name like "en", "fr". |
| 167 | 167 | * @param string $description the human readable description of this language |
| 168 | 168 | */ |
| 169 | - public function addLang($name, $description){ |
|
| 170 | - if(isset($this->availables[$name])){ |
|
| 169 | + public function addLang($name, $description) { |
|
| 170 | + if (isset($this->availables[$name])) { |
|
| 171 | 171 | return; //already added cost in performance |
| 172 | 172 | } |
| 173 | - if($this->isValid($name)){ |
|
| 173 | + if ($this->isValid($name)) { |
|
| 174 | 174 | $this->availables[$name] = $description; |
| 175 | - } else{ |
|
| 175 | + } else { |
|
| 176 | 176 | show_error('The language [' . $name . '] is not valid or does not exists.'); |
| 177 | 177 | } |
| 178 | 178 | } |
@@ -65,15 +65,15 @@ discard block |
||
| 65 | 65 | * @param mixed $default the default value to use if can not find the session flash item in the list |
| 66 | 66 | * @return mixed the session flash value if exist or the default value |
| 67 | 67 | */ |
| 68 | - public static function getFlash($item, $default = null){ |
|
| 68 | + public static function getFlash($item, $default = null) { |
|
| 69 | 69 | $logger = self::getLogger(); |
| 70 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 70 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
| 71 | 71 | $return = array_key_exists($key, $_SESSION) ? |
| 72 | 72 | ($_SESSION[$key]) : $default; |
| 73 | - if(array_key_exists($key, $_SESSION)){ |
|
| 73 | + if (array_key_exists($key, $_SESSION)) { |
|
| 74 | 74 | unset($_SESSION[$key]); |
| 75 | - } else{ |
|
| 76 | - $logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']'); |
|
| 75 | + } else { |
|
| 76 | + $logger->warning('Cannot find session flash item [' . $key . '] using the default value [' . $default . ']'); |
|
| 77 | 77 | } |
| 78 | 78 | return $return; |
| 79 | 79 | } |
@@ -102,13 +102,13 @@ discard block |
||
| 102 | 102 | * Clear the session item in the list |
| 103 | 103 | * @param string $item the session item name to be deleted |
| 104 | 104 | */ |
| 105 | - public static function clear($item){ |
|
| 105 | + public static function clear($item) { |
|
| 106 | 106 | $logger = self::getLogger(); |
| 107 | - if(array_key_exists($item, $_SESSION)){ |
|
| 108 | - $logger->info('Deleting of session for item ['.$item.' ]'); |
|
| 107 | + if (array_key_exists($item, $_SESSION)) { |
|
| 108 | + $logger->info('Deleting of session for item [' . $item . ' ]'); |
|
| 109 | 109 | unset($_SESSION[$item]); |
| 110 | - } else{ |
|
| 111 | - $logger->warning('Session item ['.$item.'] to be deleted does not exists'); |
|
| 110 | + } else { |
|
| 111 | + $logger->warning('Session item [' . $item . '] to be deleted does not exists'); |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
@@ -116,14 +116,14 @@ discard block |
||
| 116 | 116 | * Clear the session flash item in the list |
| 117 | 117 | * @param string $item the session flash item name to be deleted |
| 118 | 118 | */ |
| 119 | - public static function clearFlash($item){ |
|
| 119 | + public static function clearFlash($item) { |
|
| 120 | 120 | $logger = self::getLogger(); |
| 121 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 122 | - if(array_key_exists($key, $_SESSION)){ |
|
| 123 | - $logger->info('Delete session flash for item ['.$item.']'); |
|
| 121 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
| 122 | + if (array_key_exists($key, $_SESSION)) { |
|
| 123 | + $logger->info('Delete session flash for item [' . $item . ']'); |
|
| 124 | 124 | unset($_SESSION[$item]); |
| 125 | - } else{ |
|
| 126 | - $logger->warning('Dession flash item ['.$item.'] to be deleted does not exists'); |
|
| 125 | + } else { |
|
| 126 | + $logger->warning('Dession flash item [' . $item . '] to be deleted does not exists'); |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | |