@@ -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 extends BaseStaticClass{ |
|
| 27 | + class Response extends BaseStaticClass { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The list of request header to send with response |
@@ -59,15 +59,15 @@ discard block |
||
| 59 | 59 | /** |
| 60 | 60 | * Construct new response instance |
| 61 | 61 | */ |
| 62 | - public function __construct(){ |
|
| 62 | + public function __construct() { |
|
| 63 | 63 | $currentUrl = ''; |
| 64 | - if (! empty($_SERVER['REQUEST_URI'])){ |
|
| 64 | + if (!empty($_SERVER['REQUEST_URI'])) { |
|
| 65 | 65 | $currentUrl = $_SERVER['REQUEST_URI']; |
| 66 | 66 | } |
| 67 | - if (! empty($_SERVER['QUERY_STRING'])){ |
|
| 67 | + if (!empty($_SERVER['QUERY_STRING'])) { |
|
| 68 | 68 | $currentUrl .= '?' . $_SERVER['QUERY_STRING']; |
| 69 | 69 | } |
| 70 | - $this->_currentUrl = $currentUrl; |
|
| 70 | + $this->_currentUrl = $currentUrl; |
|
| 71 | 71 | |
| 72 | 72 | $this->_currentUrlCacheKey = md5($this->_currentUrl); |
| 73 | 73 | |
@@ -84,12 +84,12 @@ discard block |
||
| 84 | 84 | * @param integer $httpCode the HTTP status code |
| 85 | 85 | * @param array $headers the additional headers to add to the existing headers list |
| 86 | 86 | */ |
| 87 | - public static function sendHeaders($httpCode = 200, array $headers = array()){ |
|
| 87 | + public static function sendHeaders($httpCode = 200, array $headers = array()) { |
|
| 88 | 88 | set_http_status_header($httpCode); |
| 89 | 89 | self::setHeaders($headers); |
| 90 | - if(! headers_sent()){ |
|
| 91 | - foreach(self::getHeaders() as $key => $value){ |
|
| 92 | - header($key .': '.$value); |
|
| 90 | + if (!headers_sent()) { |
|
| 91 | + foreach (self::getHeaders() as $key => $value) { |
|
| 92 | + header($key . ': ' . $value); |
|
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | * Get the list of the headers |
| 99 | 99 | * @return array the headers list |
| 100 | 100 | */ |
| 101 | - public static function getHeaders(){ |
|
| 101 | + public static function getHeaders() { |
|
| 102 | 102 | return self::$headers; |
| 103 | 103 | } |
| 104 | 104 | |
@@ -107,8 +107,8 @@ discard block |
||
| 107 | 107 | * @param string $name the header name |
| 108 | 108 | * @return string|null the header value |
| 109 | 109 | */ |
| 110 | - public static function getHeader($name){ |
|
| 111 | - if(array_key_exists($name, self::$headers)){ |
|
| 110 | + public static function getHeader($name) { |
|
| 111 | + if (array_key_exists($name, self::$headers)) { |
|
| 112 | 112 | return self::$headers[$name]; |
| 113 | 113 | } |
| 114 | 114 | return null; |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * @param string $name the header name |
| 121 | 121 | * @param string $value the header value to be set |
| 122 | 122 | */ |
| 123 | - public static function setHeader($name, $value){ |
|
| 123 | + public static function setHeader($name, $value) { |
|
| 124 | 124 | self::$headers[$name] = $value; |
| 125 | 125 | } |
| 126 | 126 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * @param array $headers the list of the headers to set. |
| 130 | 130 | * Note: this will merge with the existing headers |
| 131 | 131 | */ |
| 132 | - public static function setHeaders(array $headers){ |
|
| 132 | + public static function setHeaders(array $headers) { |
|
| 133 | 133 | self::$headers = array_merge(self::getHeaders(), $headers); |
| 134 | 134 | } |
| 135 | 135 | |
@@ -137,16 +137,16 @@ discard block |
||
| 137 | 137 | * Redirect user to the specified page |
| 138 | 138 | * @param string $path the URL or URI to be redirect to |
| 139 | 139 | */ |
| 140 | - public static function redirect($path = ''){ |
|
| 140 | + public static function redirect($path = '') { |
|
| 141 | 141 | $logger = self::getLogger(); |
| 142 | 142 | $url = Url::site_url($path); |
| 143 | - $logger->info('Redirect to URL [' .$url. ']'); |
|
| 144 | - if(! headers_sent()){ |
|
| 145 | - header('Location: '.$url); |
|
| 143 | + $logger->info('Redirect to URL [' . $url . ']'); |
|
| 144 | + if (!headers_sent()) { |
|
| 145 | + header('Location: ' . $url); |
|
| 146 | 146 | exit; |
| 147 | 147 | } |
| 148 | 148 | echo '<script> |
| 149 | - location.href = "'.$url.'"; |
|
| 149 | + location.href = "'.$url . '"; |
|
| 150 | 150 | </script>'; |
| 151 | 151 | } |
| 152 | 152 | |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * @return void|string if $return is true will return the view content otherwise |
| 159 | 159 | * will display the view content. |
| 160 | 160 | */ |
| 161 | - public function render($view, $data = null, $return = false){ |
|
| 161 | + public function render($view, $data = null, $return = false) { |
|
| 162 | 162 | $logger = self::getLogger(); |
| 163 | 163 | //convert data to an array |
| 164 | 164 | $data = (array) $data; |
@@ -170,22 +170,22 @@ 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'); |
|
| 179 | + $logger->info('Found view [' . $view . '] in module [' . $module . '], the file path is [' . $moduleViewPath . '] we will used it'); |
|
| 180 | 180 | } |
| 181 | - else{ |
|
| 182 | - $logger->info('Cannot find view [' . $view . '] in module [' .$module. '] using the default location'); |
|
| 181 | + else { |
|
| 182 | + $logger->info('Cannot find view [' . $view . '] in module [' . $module . '] using the default location'); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | $logger->info('The view file path to be loaded is [' . $path . ']'); |
| 186 | 186 | |
| 187 | 187 | ///////// |
| 188 | - if($return){ |
|
| 188 | + if ($return) { |
|
| 189 | 189 | return $this->loadView($path, $data, true); |
| 190 | 190 | } |
| 191 | 191 | $this->loadView($path, $data, false); |
@@ -195,36 +195,36 @@ discard block |
||
| 195 | 195 | /** |
| 196 | 196 | * Send the final page output to user |
| 197 | 197 | */ |
| 198 | - public function renderFinalPage(){ |
|
| 198 | + public function renderFinalPage() { |
|
| 199 | 199 | $logger = self::getLogger(); |
| 200 | 200 | $obj = & get_instance(); |
| 201 | 201 | $cachePageStatus = get_config('cache_enable', false) && !empty($obj->view_cache_enable); |
| 202 | 202 | $dispatcher = $obj->eventdispatcher; |
| 203 | 203 | $content = $this->_pageRender; |
| 204 | - if(! $content){ |
|
| 204 | + if (!$content) { |
|
| 205 | 205 | $logger->warning('The final view content is empty.'); |
| 206 | 206 | return; |
| 207 | 207 | } |
| 208 | 208 | //dispatch |
| 209 | 209 | $event = $dispatcher->dispatch(new EventInfo('FINAL_VIEW_READY', $content, true)); |
| 210 | 210 | $content = null; |
| 211 | - if(! empty($event->payload)){ |
|
| 211 | + if (!empty($event->payload)) { |
|
| 212 | 212 | $content = $event->payload; |
| 213 | 213 | } |
| 214 | - if(empty($content)){ |
|
| 214 | + if (empty($content)) { |
|
| 215 | 215 | $logger->warning('The view content is empty after dispatch to event listeners.'); |
| 216 | 216 | } |
| 217 | 217 | //remove unsed space in the content |
| 218 | 218 | $content = preg_replace('~>\s*\n\s*<~', '><', $content); |
| 219 | 219 | //check whether need save the page into cache. |
| 220 | - if($cachePageStatus){ |
|
| 220 | + if ($cachePageStatus) { |
|
| 221 | 221 | $this->savePageContentIntoCache($content); |
| 222 | 222 | } |
| 223 | 223 | $content = $this->replaceElapseTimeAndMemoryUsage($content); |
| 224 | 224 | |
| 225 | 225 | //compress the output if is available |
| 226 | 226 | $type = null; |
| 227 | - if (self::$_canCompressOutput){ |
|
| 227 | + if (self::$_canCompressOutput) { |
|
| 228 | 228 | $type = 'ob_gzhandler'; |
| 229 | 229 | } |
| 230 | 230 | ob_start($type); |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | * |
| 241 | 241 | * @return boolean whether the page content if available or not |
| 242 | 242 | */ |
| 243 | - public function renderFinalPageFromCache(&$cache){ |
|
| 243 | + public function renderFinalPageFromCache(&$cache) { |
|
| 244 | 244 | $logger = self::getLogger(); |
| 245 | 245 | //the current page cache key for identification |
| 246 | 246 | $pageCacheKey = $this->_currentUrlCacheKey; |
@@ -248,9 +248,9 @@ discard block |
||
| 248 | 248 | $logger->debug('Checking if the page content for the URL [' . $this->_currentUrl . '] is cached ...'); |
| 249 | 249 | //get the cache information to prepare header to send to browser |
| 250 | 250 | $cacheInfo = $cache->getInfo($pageCacheKey); |
| 251 | - if($cacheInfo){ |
|
| 251 | + if ($cacheInfo) { |
|
| 252 | 252 | $status = $this->sendCacheNotYetExpireInfoToBrowser($cacheInfo); |
| 253 | - if($status === false){ |
|
| 253 | + if ($status === false) { |
|
| 254 | 254 | return $this->sendCachePageContentToBrowser($cache); |
| 255 | 255 | } |
| 256 | 256 | return true; |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | * Get the final page to be rendered |
| 264 | 264 | * @return string |
| 265 | 265 | */ |
| 266 | - public function getFinalPageRendered(){ |
|
| 266 | + public function getFinalPageRendered() { |
|
| 267 | 267 | return $this->_pageRender; |
| 268 | 268 | } |
| 269 | 269 | |
@@ -271,14 +271,14 @@ discard block |
||
| 271 | 271 | * Send the HTTP 404 error if can not found the |
| 272 | 272 | * routing information for the current request |
| 273 | 273 | */ |
| 274 | - public static function send404(){ |
|
| 274 | + public static function send404() { |
|
| 275 | 275 | /********* for logs **************/ |
| 276 | 276 | //can't use $obj = & get_instance() here because the global super object will be available until |
| 277 | 277 | //the main controller is loaded even for Loader::library('xxxx'); |
| 278 | 278 | $logger = self::getLogger(); |
| 279 | - $request =& class_loader('Request', 'classes'); |
|
| 280 | - $userAgent =& class_loader('Browser'); |
|
| 281 | - $browser = $userAgent->getPlatform().', '.$userAgent->getBrowser().' '.$userAgent->getVersion(); |
|
| 279 | + $request = & class_loader('Request', 'classes'); |
|
| 280 | + $userAgent = & class_loader('Browser'); |
|
| 281 | + $browser = $userAgent->getPlatform() . ', ' . $userAgent->getBrowser() . ' ' . $userAgent->getVersion(); |
|
| 282 | 282 | |
| 283 | 283 | //here can't use Loader::functions just include the helper manually |
| 284 | 284 | require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
@@ -288,10 +288,10 @@ discard block |
||
| 288 | 288 | $logger->error($str); |
| 289 | 289 | /***********************************/ |
| 290 | 290 | $path = CORE_VIEWS_PATH . '404.php'; |
| 291 | - if(file_exists($path)){ |
|
| 291 | + if (file_exists($path)) { |
|
| 292 | 292 | //compress the output if is available |
| 293 | 293 | $type = null; |
| 294 | - if (self::$_canCompressOutput){ |
|
| 294 | + if (self::$_canCompressOutput) { |
|
| 295 | 295 | $type = 'ob_gzhandler'; |
| 296 | 296 | } |
| 297 | 297 | ob_start($type); |
@@ -300,8 +300,8 @@ discard block |
||
| 300 | 300 | self::sendHeaders(404); |
| 301 | 301 | echo $output; |
| 302 | 302 | } |
| 303 | - else{ |
|
| 304 | - show_error('The 404 view [' .$path. '] does not exist'); |
|
| 303 | + else { |
|
| 304 | + show_error('The 404 view [' . $path . '] does not exist'); |
|
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | |
@@ -309,12 +309,12 @@ discard block |
||
| 309 | 309 | * Display the error to user |
| 310 | 310 | * @param array $data the error information |
| 311 | 311 | */ |
| 312 | - public static function sendError(array $data = array()){ |
|
| 312 | + public static function sendError(array $data = array()) { |
|
| 313 | 313 | $path = CORE_VIEWS_PATH . 'errors.php'; |
| 314 | - if(file_exists($path)){ |
|
| 314 | + if (file_exists($path)) { |
|
| 315 | 315 | //compress the output if is available |
| 316 | 316 | $type = null; |
| 317 | - if (self::$_canCompressOutput){ |
|
| 317 | + if (self::$_canCompressOutput) { |
|
| 318 | 318 | $type = 'ob_gzhandler'; |
| 319 | 319 | } |
| 320 | 320 | ob_start($type); |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | self::sendHeaders(503); |
| 325 | 325 | echo $output; |
| 326 | 326 | } |
| 327 | - else{ |
|
| 327 | + else { |
|
| 328 | 328 | //can't use show_error() at this time because some dependencies not yet loaded and to prevent loop |
| 329 | 329 | set_http_status_header(503); |
| 330 | 330 | echo 'The error view [' . $path . '] does not exist'; |
@@ -336,17 +336,17 @@ discard block |
||
| 336 | 336 | * @param array $cacheInfo the cache information |
| 337 | 337 | * @return boolean true if the information is sent otherwise false |
| 338 | 338 | */ |
| 339 | - protected function sendCacheNotYetExpireInfoToBrowser($cacheInfo){ |
|
| 340 | - if(! empty($cacheInfo)){ |
|
| 339 | + protected function sendCacheNotYetExpireInfoToBrowser($cacheInfo) { |
|
| 340 | + if (!empty($cacheInfo)) { |
|
| 341 | 341 | $logger = self::getLogger(); |
| 342 | 342 | $lastModified = $cacheInfo['mtime']; |
| 343 | 343 | $expire = $cacheInfo['expire']; |
| 344 | 344 | $maxAge = $expire - $_SERVER['REQUEST_TIME']; |
| 345 | 345 | self::setHeader('Pragma', 'public'); |
| 346 | 346 | self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public'); |
| 347 | - self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT'); |
|
| 348 | - self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT'); |
|
| 349 | - if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])){ |
|
| 347 | + self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT'); |
|
| 348 | + self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); |
|
| 349 | + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { |
|
| 350 | 350 | $logger->info('The cache page content is not yet expire for the URL [' . $this->_currentUrl . '] send 304 header to browser'); |
| 351 | 351 | self::sendHeaders(304); |
| 352 | 352 | return true; |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | * @return string the page content after replace |
| 362 | 362 | * '{elapsed_time}', '{memory_usage}' |
| 363 | 363 | */ |
| 364 | - protected function replaceElapseTimeAndMemoryUsage($content){ |
|
| 364 | + protected function replaceElapseTimeAndMemoryUsage($content) { |
|
| 365 | 365 | //load benchmark class |
| 366 | 366 | $benchmark = & class_loader('Benchmark'); |
| 367 | 367 | |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | * @param object $cache the cache instance |
| 378 | 378 | * @return boolean the status of the operation |
| 379 | 379 | */ |
| 380 | - protected function sendCachePageContentToBrowser(&$cache){ |
|
| 380 | + protected function sendCachePageContentToBrowser(&$cache) { |
|
| 381 | 381 | $logger = self::getLogger(); |
| 382 | 382 | $logger->info('The cache page content is expired or the browser does not send the HTTP_IF_MODIFIED_SINCE header for the URL [' . $this->_currentUrl . '] send cache headers to tell the browser'); |
| 383 | 383 | self::sendHeaders(200); |
@@ -385,13 +385,13 @@ discard block |
||
| 385 | 385 | $pageCacheKey = $this->_currentUrlCacheKey; |
| 386 | 386 | //get the cache content |
| 387 | 387 | $content = $cache->get($pageCacheKey); |
| 388 | - if($content){ |
|
| 388 | + if ($content) { |
|
| 389 | 389 | $logger->info('The page content for the URL [' . $this->_currentUrl . '] already cached just display it'); |
| 390 | 390 | $content = $this->replaceElapseTimeAndMemoryUsage($content); |
| 391 | 391 | ///display the final output |
| 392 | 392 | //compress the output if is available |
| 393 | 393 | $type = null; |
| 394 | - if (self::$_canCompressOutput){ |
|
| 394 | + if (self::$_canCompressOutput) { |
|
| 395 | 395 | $type = 'ob_gzhandler'; |
| 396 | 396 | } |
| 397 | 397 | ob_start($type); |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | * @param string $content the page content to be saved |
| 410 | 410 | * @return void |
| 411 | 411 | */ |
| 412 | - protected function savePageContentIntoCache($content){ |
|
| 412 | + protected function savePageContentIntoCache($content) { |
|
| 413 | 413 | $obj = & get_instance(); |
| 414 | 414 | $logger = self::getLogger(); |
| 415 | 415 | |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | $url = $this->_currentUrl; |
| 418 | 418 | //Cache view Time to live in second |
| 419 | 419 | $viewCacheTtl = get_config('cache_ttl'); |
| 420 | - if (!empty($obj->view_cache_ttl)){ |
|
| 420 | + if (!empty($obj->view_cache_ttl)) { |
|
| 421 | 421 | $viewCacheTtl = $obj->view_cache_ttl; |
| 422 | 422 | } |
| 423 | 423 | //the cache handler instance |
@@ -429,14 +429,14 @@ discard block |
||
| 429 | 429 | |
| 430 | 430 | //get the cache information to prepare header to send to browser |
| 431 | 431 | $cacheInfo = $cacheInstance->getInfo($cacheKey); |
| 432 | - if($cacheInfo){ |
|
| 432 | + if ($cacheInfo) { |
|
| 433 | 433 | $lastModified = $cacheInfo['mtime']; |
| 434 | 434 | $expire = $cacheInfo['expire']; |
| 435 | 435 | $maxAge = $expire - time(); |
| 436 | 436 | self::setHeader('Pragma', 'public'); |
| 437 | 437 | self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public'); |
| 438 | - self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT'); |
|
| 439 | - self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT'); |
|
| 438 | + self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT'); |
|
| 439 | + self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); |
|
| 440 | 440 | } |
| 441 | 441 | } |
| 442 | 442 | |
@@ -452,21 +452,21 @@ discard block |
||
| 452 | 452 | * 'viewFile' => 'view_file' |
| 453 | 453 | * ) |
| 454 | 454 | */ |
| 455 | - protected function getModuleInfoForView($view){ |
|
| 455 | + protected function getModuleInfoForView($view) { |
|
| 456 | 456 | $module = null; |
| 457 | 457 | $viewFile = null; |
| 458 | 458 | $obj = & get_instance(); |
| 459 | 459 | //check if the request class contains module name |
| 460 | - if(strpos($view, '/') !== false){ |
|
| 460 | + if (strpos($view, '/') !== false) { |
|
| 461 | 461 | $viewPath = explode('/', $view); |
| 462 | - if(isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())){ |
|
| 462 | + if (isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())) { |
|
| 463 | 463 | $module = $viewPath[0]; |
| 464 | 464 | array_shift($viewPath); |
| 465 | 465 | $view = implode('/', $viewPath); |
| 466 | 466 | $viewFile = $view . '.php'; |
| 467 | 467 | } |
| 468 | 468 | } |
| 469 | - if(! $module && !empty($obj->moduleName)){ |
|
| 469 | + if (!$module && !empty($obj->moduleName)) { |
|
| 470 | 470 | $module = $obj->moduleName; |
| 471 | 471 | } |
| 472 | 472 | return array( |
@@ -481,13 +481,13 @@ discard block |
||
| 481 | 481 | * @see Response::render |
| 482 | 482 | * @return void|string |
| 483 | 483 | */ |
| 484 | - protected function loadView($path, array $data = array(), $return = false){ |
|
| 484 | + protected function loadView($path, array $data = array(), $return = false) { |
|
| 485 | 485 | $found = false; |
| 486 | - if(file_exists($path)){ |
|
| 486 | + if (file_exists($path)) { |
|
| 487 | 487 | //super instance |
| 488 | 488 | $obj = & get_instance(); |
| 489 | - foreach(get_object_vars($obj) as $key => $value){ |
|
| 490 | - if(! isset($this->{$key})){ |
|
| 489 | + foreach (get_object_vars($obj) as $key => $value) { |
|
| 490 | + if (!isset($this->{$key})) { |
|
| 491 | 491 | $this->{$key} = & $obj->{$key}; |
| 492 | 492 | } |
| 493 | 493 | } |
@@ -496,15 +496,15 @@ discard block |
||
| 496 | 496 | //need use require() instead of require_once because can load this view many time |
| 497 | 497 | require $path; |
| 498 | 498 | $content = ob_get_clean(); |
| 499 | - if($return){ |
|
| 499 | + if ($return) { |
|
| 500 | 500 | //remove unused html space |
| 501 | 501 | return preg_replace('~>\s*\n\s*<~', '><', $content); |
| 502 | 502 | } |
| 503 | 503 | $this->_pageRender .= $content; |
| 504 | 504 | $found = true; |
| 505 | 505 | } |
| 506 | - if(! $found){ |
|
| 507 | - show_error('Unable to find view [' .$path . ']'); |
|
| 506 | + if (!$found) { |
|
| 507 | + show_error('Unable to find view [' . $path . ']'); |
|
| 508 | 508 | } |
| 509 | 509 | } |
| 510 | 510 | |
@@ -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 BaseStaticClass{ |
|
| 27 | + class BaseStaticClass { |
|
| 28 | 28 | /** |
| 29 | 29 | * The logger instance |
| 30 | 30 | * @var object |
@@ -35,10 +35,10 @@ discard block |
||
| 35 | 35 | * The signleton of the logger |
| 36 | 36 | * @return Object the Log instance |
| 37 | 37 | */ |
| 38 | - public static function getLogger(){ |
|
| 39 | - if(self::$logger == null){ |
|
| 38 | + public static function getLogger() { |
|
| 39 | + if (self::$logger == null) { |
|
| 40 | 40 | $logger = array(); |
| 41 | - $logger[0] =& class_loader('Log', 'classes'); |
|
| 41 | + $logger[0] = & class_loader('Log', 'classes'); |
|
| 42 | 42 | $logger[0]->setLogger('Class::' . get_called_class()); |
| 43 | 43 | self::$logger = $logger[0]; |
| 44 | 44 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * @param object $logger the log object |
| 51 | 51 | * @return object the log instance |
| 52 | 52 | */ |
| 53 | - public static function setLogger($logger){ |
|
| 53 | + public static function setLogger($logger) { |
|
| 54 | 54 | self::$logger = $logger; |
| 55 | 55 | return self::$logger; |
| 56 | 56 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | - class Loader extends BaseStaticClass{ |
|
| 26 | + class Loader extends BaseStaticClass { |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * List of loaded resources |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | public static $loaded = array(); |
| 33 | 33 | |
| 34 | 34 | |
| 35 | - public function __construct(){ |
|
| 35 | + public function __construct() { |
|
| 36 | 36 | //add the resources already loaded during application bootstrap |
| 37 | 37 | //in the list to prevent duplicate or loading the resources again. |
| 38 | 38 | static::$loaded = class_loaded(); |
@@ -50,18 +50,18 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @return void |
| 52 | 52 | */ |
| 53 | - public static function model($class, $instance = null){ |
|
| 53 | + public static function model($class, $instance = null) { |
|
| 54 | 54 | $logger = static::getLogger(); |
| 55 | 55 | $class = str_ireplace('.php', '', $class); |
| 56 | 56 | $class = trim($class, '/\\'); |
| 57 | - $file = ucfirst($class).'.php'; |
|
| 57 | + $file = ucfirst($class) . '.php'; |
|
| 58 | 58 | $logger->debug('Loading model [' . $class . '] ...'); |
| 59 | 59 | //************ |
| 60 | - if (! $instance){ |
|
| 60 | + if (!$instance) { |
|
| 61 | 61 | $instance = self::getModelLibraryInstanceName($class); |
| 62 | 62 | } |
| 63 | 63 | //**************** |
| 64 | - if (isset(static::$loaded[$instance])){ |
|
| 64 | + if (isset(static::$loaded[$instance])) { |
|
| 65 | 65 | $logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance'); |
| 66 | 66 | return; |
| 67 | 67 | } |
@@ -74,28 +74,28 @@ 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 | 80 | } |
| 81 | - else{ |
|
| 81 | + else { |
|
| 82 | 82 | $logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
| 83 | 83 | } |
| 84 | 84 | $logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
| 85 | - if (file_exists($classFilePath)){ |
|
| 85 | + if (file_exists($classFilePath)) { |
|
| 86 | 86 | require_once $classFilePath; |
| 87 | - if (class_exists($class)){ |
|
| 87 | + if (class_exists($class)) { |
|
| 88 | 88 | $c = new $class(); |
| 89 | 89 | $obj = & get_instance(); |
| 90 | 90 | $obj->{$instance} = $c; |
| 91 | 91 | static::$loaded[$instance] = $class; |
| 92 | 92 | $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
| 93 | 93 | } |
| 94 | - else{ |
|
| 95 | - show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']'); |
|
| 94 | + else { |
|
| 95 | + show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']'); |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | - else{ |
|
| 98 | + else { |
|
| 99 | 99 | show_error('Unable to find the model [' . $class . ']'); |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -110,22 +110,22 @@ discard block |
||
| 110 | 110 | * |
| 111 | 111 | * @return void |
| 112 | 112 | */ |
| 113 | - public static function library($class, $instance = null, array $params = array()){ |
|
| 113 | + public static function library($class, $instance = null, array $params = array()) { |
|
| 114 | 114 | $logger = static::getLogger(); |
| 115 | 115 | $class = str_ireplace('.php', '', $class); |
| 116 | 116 | $class = trim($class, '/\\'); |
| 117 | - $file = ucfirst($class) .'.php'; |
|
| 117 | + $file = ucfirst($class) . '.php'; |
|
| 118 | 118 | $logger->debug('Loading library [' . $class . '] ...'); |
| 119 | - if (! $instance){ |
|
| 119 | + if (!$instance) { |
|
| 120 | 120 | $instance = self::getModelLibraryInstanceName($class); |
| 121 | 121 | } |
| 122 | - if (isset(static::$loaded[$instance])){ |
|
| 122 | + if (isset(static::$loaded[$instance])) { |
|
| 123 | 123 | $logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance'); |
| 124 | 124 | return; |
| 125 | 125 | } |
| 126 | 126 | $obj = & get_instance(); |
| 127 | 127 | //Check and load Database library |
| 128 | - if (strtolower($class) == 'database'){ |
|
| 128 | + if (strtolower($class) == 'database') { |
|
| 129 | 129 | $logger->info('This is the Database library ...'); |
| 130 | 130 | $obj->{$instance} = & class_loader('Database', 'classes/database', $params); |
| 131 | 131 | static::$loaded[$instance] = $class; |
@@ -134,18 +134,18 @@ discard block |
||
| 134 | 134 | } |
| 135 | 135 | $libraryFilePath = null; |
| 136 | 136 | $logger->debug('Check if this is a system library ...'); |
| 137 | - if (file_exists(CORE_LIBRARY_PATH . $file)){ |
|
| 137 | + if (file_exists(CORE_LIBRARY_PATH . $file)) { |
|
| 138 | 138 | $libraryFilePath = CORE_LIBRARY_PATH . $file; |
| 139 | 139 | $class = ucfirst($class); |
| 140 | 140 | $logger->info('This library is a system library'); |
| 141 | 141 | } |
| 142 | - else{ |
|
| 142 | + else { |
|
| 143 | 143 | $logger->info('This library is not a system library'); |
| 144 | 144 | //first check if this library is in the module |
| 145 | 145 | $libraryFilePath = self::getLibraryPathUsingModuleInfo($class); |
| 146 | 146 | //*************** |
| 147 | 147 | } |
| 148 | - if (! $libraryFilePath && file_exists(LIBRARY_PATH . $file)){ |
|
| 148 | + if (!$libraryFilePath && file_exists(LIBRARY_PATH . $file)) { |
|
| 149 | 149 | $libraryFilePath = LIBRARY_PATH . $file; |
| 150 | 150 | } |
| 151 | 151 | $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']'); |
@@ -160,14 +160,14 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @return void |
| 162 | 162 | */ |
| 163 | - public static function functions($function){ |
|
| 163 | + public static function functions($function) { |
|
| 164 | 164 | $logger = static::getLogger(); |
| 165 | 165 | $function = str_ireplace('.php', '', $function); |
| 166 | 166 | $function = trim($function, '/\\'); |
| 167 | 167 | $function = str_ireplace('function_', '', $function); |
| 168 | - $file = 'function_'.$function.'.php'; |
|
| 168 | + $file = 'function_' . $function . '.php'; |
|
| 169 | 169 | $logger->debug('Loading helper [' . $function . '] ...'); |
| 170 | - if (isset(static::$loaded['function_' . $function])){ |
|
| 170 | + if (isset(static::$loaded['function_' . $function])) { |
|
| 171 | 171 | $logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance'); |
| 172 | 172 | return; |
| 173 | 173 | } |
@@ -177,22 +177,22 @@ discard block |
||
| 177 | 177 | $moduleInfo = self::getModuleInfoForFunction($function); |
| 178 | 178 | $module = $moduleInfo['module']; |
| 179 | 179 | $function = $moduleInfo['function']; |
| 180 | - if(! empty($moduleInfo['file'])){ |
|
| 180 | + if (!empty($moduleInfo['file'])) { |
|
| 181 | 181 | $file = $moduleInfo['file']; |
| 182 | 182 | } |
| 183 | 183 | $moduleFunctionPath = Module::findFunctionFullPath($function, $module); |
| 184 | - if ($moduleFunctionPath){ |
|
| 185 | - $logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it'); |
|
| 184 | + if ($moduleFunctionPath) { |
|
| 185 | + $logger->info('Found helper [' . $function . '] from module [' . $module . '], the file path is [' . $moduleFunctionPath . '] we will used it'); |
|
| 186 | 186 | $functionFilePath = $moduleFunctionPath; |
| 187 | 187 | } |
| 188 | - else{ |
|
| 188 | + else { |
|
| 189 | 189 | $logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
| 190 | 190 | } |
| 191 | - if (! $functionFilePath){ |
|
| 191 | + if (!$functionFilePath) { |
|
| 192 | 192 | $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH); |
| 193 | - foreach($searchDir as $dir){ |
|
| 193 | + foreach ($searchDir as $dir) { |
|
| 194 | 194 | $filePath = $dir . $file; |
| 195 | - if (file_exists($filePath)){ |
|
| 195 | + if (file_exists($filePath)) { |
|
| 196 | 196 | $functionFilePath = $filePath; |
| 197 | 197 | //is already found not to continue |
| 198 | 198 | break; |
@@ -200,12 +200,12 @@ discard block |
||
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']'); |
| 203 | - if ($functionFilePath){ |
|
| 203 | + if ($functionFilePath) { |
|
| 204 | 204 | require_once $functionFilePath; |
| 205 | 205 | static::$loaded['function_' . $function] = $functionFilePath; |
| 206 | 206 | $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
| 207 | 207 | } |
| 208 | - else{ |
|
| 208 | + else { |
|
| 209 | 209 | show_error('Unable to find helper file [' . $file . ']'); |
| 210 | 210 | } |
| 211 | 211 | } |
@@ -217,14 +217,14 @@ discard block |
||
| 217 | 217 | * |
| 218 | 218 | * @return void |
| 219 | 219 | */ |
| 220 | - public static function config($filename){ |
|
| 220 | + public static function config($filename) { |
|
| 221 | 221 | $logger = static::getLogger(); |
| 222 | 222 | $filename = str_ireplace('.php', '', $filename); |
| 223 | 223 | $filename = trim($filename, '/\\'); |
| 224 | 224 | $filename = str_ireplace('config_', '', $filename); |
| 225 | - $file = 'config_'.$filename.'.php'; |
|
| 225 | + $file = 'config_' . $filename . '.php'; |
|
| 226 | 226 | $logger->debug('Loading configuration [' . $filename . '] ...'); |
| 227 | - if (isset(static::$loaded['config_' . $filename])){ |
|
| 227 | + if (isset(static::$loaded['config_' . $filename])) { |
|
| 228 | 228 | $logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance'); |
| 229 | 229 | return; |
| 230 | 230 | } |
@@ -235,18 +235,18 @@ discard block |
||
| 235 | 235 | $module = $moduleInfo['module']; |
| 236 | 236 | $filename = $moduleInfo['filename']; |
| 237 | 237 | $moduleConfigPath = Module::findConfigFullPath($filename, $module); |
| 238 | - if ($moduleConfigPath){ |
|
| 239 | - $logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it'); |
|
| 238 | + if ($moduleConfigPath) { |
|
| 239 | + $logger->info('Found config [' . $filename . '] from module [' . $module . '], the file path is [' . $moduleConfigPath . '] we will used it'); |
|
| 240 | 240 | $configFilePath = $moduleConfigPath; |
| 241 | 241 | } |
| 242 | - else{ |
|
| 242 | + else { |
|
| 243 | 243 | $logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
| 244 | 244 | } |
| 245 | 245 | $logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
| 246 | 246 | $config = array(); |
| 247 | - if (file_exists($configFilePath)){ |
|
| 247 | + if (file_exists($configFilePath)) { |
|
| 248 | 248 | require_once $configFilePath; |
| 249 | - if (! empty($config) && is_array($config)){ |
|
| 249 | + if (!empty($config) && is_array($config)) { |
|
| 250 | 250 | Config::setAll($config); |
| 251 | 251 | static::$loaded['config_' . $filename] = $configFilePath; |
| 252 | 252 | $logger->info('Configuration [' . $configFilePath . '] loaded successfully.'); |
@@ -254,8 +254,8 @@ discard block |
||
| 254 | 254 | unset($config); |
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | - else{ |
|
| 258 | - show_error('Unable to find config file ['. $configFilePath . ']'); |
|
| 257 | + else { |
|
| 258 | + show_error('Unable to find config file [' . $configFilePath . ']'); |
|
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | |
@@ -267,14 +267,14 @@ discard block |
||
| 267 | 267 | * |
| 268 | 268 | * @return void |
| 269 | 269 | */ |
| 270 | - public static function lang($language){ |
|
| 270 | + public static function lang($language) { |
|
| 271 | 271 | $logger = static::getLogger(); |
| 272 | 272 | $language = str_ireplace('.php', '', $language); |
| 273 | 273 | $language = trim($language, '/\\'); |
| 274 | 274 | $language = str_ireplace('lang_', '', $language); |
| 275 | - $file = 'lang_'.$language.'.php'; |
|
| 275 | + $file = 'lang_' . $language . '.php'; |
|
| 276 | 276 | $logger->debug('Loading language [' . $language . '] ...'); |
| 277 | - if (isset(static::$loaded['lang_' . $language])){ |
|
| 277 | + if (isset(static::$loaded['lang_' . $language])) { |
|
| 278 | 278 | $logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance'); |
| 279 | 279 | return; |
| 280 | 280 | } |
@@ -286,22 +286,22 @@ discard block |
||
| 286 | 286 | $moduleInfo = self::getModuleInfoForLanguage($language); |
| 287 | 287 | $module = $moduleInfo['module']; |
| 288 | 288 | $language = $moduleInfo['language']; |
| 289 | - if(! empty($moduleInfo['file'])){ |
|
| 289 | + if (!empty($moduleInfo['file'])) { |
|
| 290 | 290 | $file = $moduleInfo['file']; |
| 291 | 291 | } |
| 292 | 292 | $moduleLanguagePath = Module::findLanguageFullPath($language, $appLang, $module); |
| 293 | - if ($moduleLanguagePath){ |
|
| 294 | - $logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it'); |
|
| 293 | + if ($moduleLanguagePath) { |
|
| 294 | + $logger->info('Found language [' . $language . '] from module [' . $module . '], the file path is [' . $moduleLanguagePath . '] we will used it'); |
|
| 295 | 295 | $languageFilePath = $moduleLanguagePath; |
| 296 | 296 | } |
| 297 | - else{ |
|
| 297 | + else { |
|
| 298 | 298 | $logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
| 299 | 299 | } |
| 300 | - if (! $languageFilePath){ |
|
| 300 | + if (!$languageFilePath) { |
|
| 301 | 301 | $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH); |
| 302 | - foreach($searchDir as $dir){ |
|
| 302 | + foreach ($searchDir as $dir) { |
|
| 303 | 303 | $filePath = $dir . $appLang . DS . $file; |
| 304 | - if (file_exists($filePath)){ |
|
| 304 | + if (file_exists($filePath)) { |
|
| 305 | 305 | $languageFilePath = $filePath; |
| 306 | 306 | //already found no need continue |
| 307 | 307 | break; |
@@ -317,14 +317,14 @@ discard block |
||
| 317 | 317 | * if can not found will use the default value from configuration |
| 318 | 318 | * @return string the app language like "en", "fr" |
| 319 | 319 | */ |
| 320 | - protected static function getAppLang(){ |
|
| 320 | + protected static function getAppLang() { |
|
| 321 | 321 | //determine the current language |
| 322 | 322 | $appLang = get_config('default_language'); |
| 323 | 323 | //if the language exists in the cookie use it |
| 324 | 324 | $cfgKey = get_config('language_cookie_name'); |
| 325 | 325 | $objCookie = & class_loader('Cookie'); |
| 326 | 326 | $cookieLang = $objCookie->get($cfgKey); |
| 327 | - if ($cookieLang){ |
|
| 327 | + if ($cookieLang) { |
|
| 328 | 328 | $appLang = $cookieLang; |
| 329 | 329 | } |
| 330 | 330 | return $appLang; |
@@ -338,20 +338,20 @@ discard block |
||
| 338 | 338 | * 'class' => 'class_name' |
| 339 | 339 | * ) |
| 340 | 340 | */ |
| 341 | - protected static function getModuleInfoForModelLibrary($class){ |
|
| 341 | + protected static function getModuleInfoForModelLibrary($class) { |
|
| 342 | 342 | $module = null; |
| 343 | 343 | $obj = & get_instance(); |
| 344 | - if (strpos($class, '/') !== false){ |
|
| 344 | + if (strpos($class, '/') !== false) { |
|
| 345 | 345 | $path = explode('/', $class); |
| 346 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
| 346 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
| 347 | 347 | $module = $path[0]; |
| 348 | 348 | $class = ucfirst($path[1]); |
| 349 | 349 | } |
| 350 | 350 | } |
| 351 | - else{ |
|
| 351 | + else { |
|
| 352 | 352 | $class = ucfirst($class); |
| 353 | 353 | } |
| 354 | - if (! $module && !empty($obj->moduleName)){ |
|
| 354 | + if (!$module && !empty($obj->moduleName)) { |
|
| 355 | 355 | $module = $obj->moduleName; |
| 356 | 356 | } |
| 357 | 357 | return array( |
@@ -370,20 +370,20 @@ discard block |
||
| 370 | 370 | * 'file' => 'file' |
| 371 | 371 | * ) |
| 372 | 372 | */ |
| 373 | - protected static function getModuleInfoForFunction($function){ |
|
| 373 | + protected static function getModuleInfoForFunction($function) { |
|
| 374 | 374 | $module = null; |
| 375 | 375 | $file = null; |
| 376 | 376 | $obj = & get_instance(); |
| 377 | 377 | //check if the request class contains module name |
| 378 | - if (strpos($function, '/') !== false){ |
|
| 378 | + if (strpos($function, '/') !== false) { |
|
| 379 | 379 | $path = explode('/', $function); |
| 380 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
| 380 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
| 381 | 381 | $module = $path[0]; |
| 382 | 382 | $function = 'function_' . $path[1]; |
| 383 | - $file = $path[0] . DS . $function.'.php'; |
|
| 383 | + $file = $path[0] . DS . $function . '.php'; |
|
| 384 | 384 | } |
| 385 | 385 | } |
| 386 | - if (! $module && !empty($obj->moduleName)){ |
|
| 386 | + if (!$module && !empty($obj->moduleName)) { |
|
| 387 | 387 | $module = $obj->moduleName; |
| 388 | 388 | } |
| 389 | 389 | return array( |
@@ -403,20 +403,20 @@ discard block |
||
| 403 | 403 | * 'file' => 'file' |
| 404 | 404 | * ) |
| 405 | 405 | */ |
| 406 | - protected static function getModuleInfoForLanguage($language){ |
|
| 406 | + protected static function getModuleInfoForLanguage($language) { |
|
| 407 | 407 | $module = null; |
| 408 | 408 | $file = null; |
| 409 | 409 | $obj = & get_instance(); |
| 410 | 410 | //check if the request class contains module name |
| 411 | - if (strpos($language, '/') !== false){ |
|
| 411 | + if (strpos($language, '/') !== false) { |
|
| 412 | 412 | $path = explode('/', $language); |
| 413 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
| 413 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
| 414 | 414 | $module = $path[0]; |
| 415 | 415 | $language = 'lang_' . $path[1] . '.php'; |
| 416 | - $file = $path[0] . DS .$language; |
|
| 416 | + $file = $path[0] . DS . $language; |
|
| 417 | 417 | } |
| 418 | 418 | } |
| 419 | - if (! $module && !empty($obj->moduleName)){ |
|
| 419 | + if (!$module && !empty($obj->moduleName)) { |
|
| 420 | 420 | $module = $obj->moduleName; |
| 421 | 421 | } |
| 422 | 422 | return array( |
@@ -436,18 +436,18 @@ discard block |
||
| 436 | 436 | * 'filename' => 'filename' |
| 437 | 437 | * ) |
| 438 | 438 | */ |
| 439 | - protected static function getModuleInfoForConfig($filename){ |
|
| 439 | + protected static function getModuleInfoForConfig($filename) { |
|
| 440 | 440 | $module = null; |
| 441 | 441 | $obj = & get_instance(); |
| 442 | 442 | //check if the request class contains module name |
| 443 | - if (strpos($filename, '/') !== false){ |
|
| 443 | + if (strpos($filename, '/') !== false) { |
|
| 444 | 444 | $path = explode('/', $filename); |
| 445 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
| 445 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
| 446 | 446 | $module = $path[0]; |
| 447 | 447 | $filename = $path[1] . '.php'; |
| 448 | 448 | } |
| 449 | 449 | } |
| 450 | - if (! $module && !empty($obj->moduleName)){ |
|
| 450 | + if (!$module && !empty($obj->moduleName)) { |
|
| 451 | 451 | $module = $obj->moduleName; |
| 452 | 452 | } |
| 453 | 453 | return array( |
@@ -461,16 +461,16 @@ discard block |
||
| 461 | 461 | * @param string $class the class name to determine the instance |
| 462 | 462 | * @return string the instance name |
| 463 | 463 | */ |
| 464 | - protected static function getModelLibraryInstanceName($class){ |
|
| 464 | + protected static function getModelLibraryInstanceName($class) { |
|
| 465 | 465 | //for module |
| 466 | 466 | $instance = null; |
| 467 | - if (strpos($class, '/') !== false){ |
|
| 467 | + if (strpos($class, '/') !== false) { |
|
| 468 | 468 | $path = explode('/', $class); |
| 469 | - if (isset($path[1])){ |
|
| 469 | + if (isset($path[1])) { |
|
| 470 | 470 | $instance = strtolower($path[1]); |
| 471 | 471 | } |
| 472 | 472 | } |
| 473 | - else{ |
|
| 473 | + else { |
|
| 474 | 474 | $instance = strtolower($class); |
| 475 | 475 | } |
| 476 | 476 | return $instance; |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | * @param string $class the class name |
| 482 | 482 | * @return string|null the library file path otherwise null will be returned |
| 483 | 483 | */ |
| 484 | - protected static function getLibraryPathUsingModuleInfo($class){ |
|
| 484 | + protected static function getLibraryPathUsingModuleInfo($class) { |
|
| 485 | 485 | $logger = static::getLogger(); |
| 486 | 486 | $libraryFilePath = null; |
| 487 | 487 | $logger->debug('Checking library [' . $class . '] from module list ...'); |
@@ -489,11 +489,11 @@ discard block |
||
| 489 | 489 | $module = $moduleInfo['module']; |
| 490 | 490 | $class = $moduleInfo['class']; |
| 491 | 491 | $moduleLibraryPath = Module::findLibraryFullPath($class, $module); |
| 492 | - if ($moduleLibraryPath){ |
|
| 493 | - $logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it'); |
|
| 492 | + if ($moduleLibraryPath) { |
|
| 493 | + $logger->info('Found library [' . $class . '] from module [' . $module . '], the file path is [' . $moduleLibraryPath . '] we will used it'); |
|
| 494 | 494 | $libraryFilePath = $moduleLibraryPath; |
| 495 | 495 | } |
| 496 | - else{ |
|
| 496 | + else { |
|
| 497 | 497 | $logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
| 498 | 498 | } |
| 499 | 499 | return $libraryFilePath; |
@@ -507,22 +507,22 @@ discard block |
||
| 507 | 507 | * @param array $params the parameter to use |
| 508 | 508 | * @return void |
| 509 | 509 | */ |
| 510 | - protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()){ |
|
| 511 | - if ($libraryFilePath){ |
|
| 510 | + protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()) { |
|
| 511 | + if ($libraryFilePath) { |
|
| 512 | 512 | $logger = static::getLogger(); |
| 513 | 513 | require_once $libraryFilePath; |
| 514 | - if (class_exists($class)){ |
|
| 514 | + if (class_exists($class)) { |
|
| 515 | 515 | $c = $params ? new $class($params) : new $class(); |
| 516 | 516 | $obj = & get_instance(); |
| 517 | 517 | $obj->{$instance} = $c; |
| 518 | 518 | static::$loaded[$instance] = $class; |
| 519 | 519 | $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
| 520 | 520 | } |
| 521 | - else{ |
|
| 522 | - show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class); |
|
| 521 | + else { |
|
| 522 | + show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class); |
|
| 523 | 523 | } |
| 524 | 524 | } |
| 525 | - else{ |
|
| 525 | + else { |
|
| 526 | 526 | show_error('Unable to find library class [' . $class . ']'); |
| 527 | 527 | } |
| 528 | 528 | } |
@@ -533,15 +533,15 @@ discard block |
||
| 533 | 533 | * @param string $language the language name |
| 534 | 534 | * @return void |
| 535 | 535 | */ |
| 536 | - protected static function loadLanguage($languageFilePath, $language){ |
|
| 537 | - if ($languageFilePath){ |
|
| 536 | + protected static function loadLanguage($languageFilePath, $language) { |
|
| 537 | + if ($languageFilePath) { |
|
| 538 | 538 | $logger = static::getLogger(); |
| 539 | 539 | $lang = array(); |
| 540 | 540 | require_once $languageFilePath; |
| 541 | - if (! empty($lang) && is_array($lang)){ |
|
| 542 | - $logger->info('Language file [' .$languageFilePath. '] contains the valid languages keys add them to language list'); |
|
| 541 | + if (!empty($lang) && is_array($lang)) { |
|
| 542 | + $logger->info('Language file [' . $languageFilePath . '] contains the valid languages keys add them to language list'); |
|
| 543 | 543 | //Note: may be here the class 'Lang' not yet loaded |
| 544 | - $langObj =& class_loader('Lang', 'classes'); |
|
| 544 | + $langObj = & class_loader('Lang', 'classes'); |
|
| 545 | 545 | $langObj->addLangMessages($lang); |
| 546 | 546 | //free the memory |
| 547 | 547 | unset($lang); |
@@ -549,7 +549,7 @@ discard block |
||
| 549 | 549 | static::$loaded['lang_' . $language] = $languageFilePath; |
| 550 | 550 | $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
| 551 | 551 | } |
| 552 | - else{ |
|
| 552 | + else { |
|
| 553 | 553 | show_error('Unable to find language [' . $language . ']'); |
| 554 | 554 | } |
| 555 | 555 | } |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | * Get all the autoload using the configuration file |
| 559 | 559 | * @return array |
| 560 | 560 | */ |
| 561 | - private function getResourcesFromAutoloadConfig(){ |
|
| 561 | + private function getResourcesFromAutoloadConfig() { |
|
| 562 | 562 | $autoloads = array(); |
| 563 | 563 | $autoloads['config'] = array(); |
| 564 | 564 | $autoloads['languages'] = array(); |
@@ -566,17 +566,17 @@ discard block |
||
| 566 | 566 | $autoloads['models'] = array(); |
| 567 | 567 | $autoloads['functions'] = array(); |
| 568 | 568 | //loading of the resources from autoload configuration file |
| 569 | - if (file_exists(CONFIG_PATH . 'autoload.php')){ |
|
| 569 | + if (file_exists(CONFIG_PATH . 'autoload.php')) { |
|
| 570 | 570 | $autoload = array(); |
| 571 | 571 | require_once CONFIG_PATH . 'autoload.php'; |
| 572 | - if (! empty($autoload) && is_array($autoload)){ |
|
| 572 | + if (!empty($autoload) && is_array($autoload)) { |
|
| 573 | 573 | $autoloads = array_merge($autoloads, $autoload); |
| 574 | 574 | unset($autoload); |
| 575 | 575 | } |
| 576 | 576 | } |
| 577 | 577 | //loading autoload configuration for modules |
| 578 | 578 | $modulesAutoloads = Module::getModulesAutoloadConfig(); |
| 579 | - if (! empty($modulesAutoloads) && is_array($modulesAutoloads)){ |
|
| 579 | + if (!empty($modulesAutoloads) && is_array($modulesAutoloads)) { |
|
| 580 | 580 | $autoloads = array_merge_recursive($autoloads, $modulesAutoloads); |
| 581 | 581 | } |
| 582 | 582 | return $autoloads; |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | * Load the autoload configuration |
| 587 | 587 | * @return void |
| 588 | 588 | */ |
| 589 | - private function loadResourcesFromAutoloadConfig(){ |
|
| 589 | + private function loadResourcesFromAutoloadConfig() { |
|
| 590 | 590 | $autoloads = array(); |
| 591 | 591 | $autoloads['config'] = array(); |
| 592 | 592 | $autoloads['languages'] = array(); |
@@ -619,7 +619,7 @@ discard block |
||
| 619 | 619 | * @param array $resources the resource to load |
| 620 | 620 | * @return void |
| 621 | 621 | */ |
| 622 | - private function loadAutoloadResourcesArray($method, array $resources){ |
|
| 622 | + private function loadAutoloadResourcesArray($method, array $resources) { |
|
| 623 | 623 | foreach ($resources as $name) { |
| 624 | 624 | $this->{$method}($name); |
| 625 | 625 | } |
@@ -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 Log{ |
|
| 27 | + class Log { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The defined constante for Log level |
@@ -52,14 +52,14 @@ discard block |
||
| 52 | 52 | /** |
| 53 | 53 | * Create new Log instance |
| 54 | 54 | */ |
| 55 | - public function __construct(){ |
|
| 55 | + public function __construct() { |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * Set the logger to identify each message in the log |
| 60 | 60 | * @param string $logger the logger name |
| 61 | 61 | */ |
| 62 | - public function setLogger($logger){ |
|
| 62 | + public function setLogger($logger) { |
|
| 63 | 63 | $this->logger = $logger; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @see Log::writeLog for more detail |
| 69 | 69 | * @param string $message the log message to save |
| 70 | 70 | */ |
| 71 | - public function fatal($message){ |
|
| 71 | + public function fatal($message) { |
|
| 72 | 72 | $this->writeLog($message, self::FATAL); |
| 73 | 73 | } |
| 74 | 74 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * @see Log::writeLog for more detail |
| 78 | 78 | * @param string $message the log message to save |
| 79 | 79 | */ |
| 80 | - public function error($message){ |
|
| 80 | + public function error($message) { |
|
| 81 | 81 | $this->writeLog($message, self::ERROR); |
| 82 | 82 | } |
| 83 | 83 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * @see Log::writeLog for more detail |
| 87 | 87 | * @param string $message the log message to save |
| 88 | 88 | */ |
| 89 | - public function warning($message){ |
|
| 89 | + public function warning($message) { |
|
| 90 | 90 | $this->writeLog($message, self::WARNING); |
| 91 | 91 | } |
| 92 | 92 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @see Log::writeLog for more detail |
| 96 | 96 | * @param string $message the log message to save |
| 97 | 97 | */ |
| 98 | - public function info($message){ |
|
| 98 | + public function info($message) { |
|
| 99 | 99 | $this->writeLog($message, self::INFO); |
| 100 | 100 | } |
| 101 | 101 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @see Log::writeLog for more detail |
| 105 | 105 | * @param string $message the log message to save |
| 106 | 106 | */ |
| 107 | - public function debug($message){ |
|
| 107 | + public function debug($message) { |
|
| 108 | 108 | $this->writeLog($message, self::DEBUG); |
| 109 | 109 | } |
| 110 | 110 | |
@@ -115,31 +115,31 @@ discard block |
||
| 115 | 115 | * @param integer|string $level the log level in integer or string format, if is string will convert into integer |
| 116 | 116 | * to allow check the log level threshold. |
| 117 | 117 | */ |
| 118 | - public function writeLog($message, $level = self::INFO){ |
|
| 118 | + public function writeLog($message, $level = self::INFO) { |
|
| 119 | 119 | $configLogLevel = get_config('log_level'); |
| 120 | - if(! $configLogLevel){ |
|
| 120 | + if (!$configLogLevel) { |
|
| 121 | 121 | //so means no need log just stop here |
| 122 | 122 | return; |
| 123 | 123 | } |
| 124 | 124 | //check config log level |
| 125 | - if(! self::isValidConfigLevel($configLogLevel)){ |
|
| 125 | + if (!self::isValidConfigLevel($configLogLevel)) { |
|
| 126 | 126 | //NOTE: here need put the show_error() "logging" to false to prevent loop |
| 127 | 127 | show_error('Invalid config log level [' . $configLogLevel . '], the value must be one of the following: ' . implode(', ', array_map('strtoupper', self::$validConfigLevel)), $title = 'Log Config Error', $logging = false); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | //check if config log_logger_name and current log can save log data |
| 131 | - if(! $this->canSaveLogDataForLogger()){ |
|
| 131 | + if (!$this->canSaveLogDataForLogger()) { |
|
| 132 | 132 | return; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | //if $level is not an integer |
| 136 | - if(! is_numeric($level)){ |
|
| 136 | + if (!is_numeric($level)) { |
|
| 137 | 137 | $level = self::getLevelValue($level); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | //check if can logging regarding the log level config |
| 141 | 141 | $configLevel = self::getLevelValue($configLogLevel); |
| 142 | - if($configLevel > $level){ |
|
| 142 | + if ($configLevel > $level) { |
|
| 143 | 143 | //can't log |
| 144 | 144 | return; |
| 145 | 145 | } |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | * @param string $message the log message to save |
| 157 | 157 | * @return void |
| 158 | 158 | */ |
| 159 | - protected function saveLogData($path, $level, $message){ |
|
| 159 | + protected function saveLogData($path, $level, $message) { |
|
| 160 | 160 | //may be at this time helper user_agent not yet included |
| 161 | 161 | require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
| 162 | 162 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | $ip = get_ip(); |
| 170 | 170 | |
| 171 | 171 | //if $level is not an integer |
| 172 | - if(! is_numeric($level)){ |
|
| 172 | + if (!is_numeric($level)) { |
|
| 173 | 173 | $level = self::getLevelValue($level); |
| 174 | 174 | } |
| 175 | 175 | |
@@ -179,13 +179,13 @@ discard block |
||
| 179 | 179 | //debug info |
| 180 | 180 | $dtrace = debug_backtrace(); |
| 181 | 181 | $fileInfo = $dtrace[0]; |
| 182 | - if ($dtrace[0]['file'] == __FILE__ || $dtrace[1]['file'] == __FILE__){ |
|
| 182 | + if ($dtrace[0]['file'] == __FILE__ || $dtrace[1]['file'] == __FILE__) { |
|
| 183 | 183 | $fileInfo = $dtrace[2]; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | $str = $logDate . ' [' . str_pad($levelName, 7 /*warning len*/) . '] ' . ' [' . str_pad($ip, 15) . '] ' . $this->logger . ' : ' . $message . ' ' . '[' . $fileInfo['file'] . '::' . $fileInfo['line'] . ']' . "\n"; |
| 187 | 187 | $fp = fopen($path, 'a+'); |
| 188 | - if(is_resource($fp)){ |
|
| 188 | + if (is_resource($fp)) { |
|
| 189 | 189 | flock($fp, LOCK_EX); // exclusive lock, will get released when the file is closed |
| 190 | 190 | fwrite($fp, $str); |
| 191 | 191 | fclose($fp); |
@@ -197,13 +197,13 @@ discard block |
||
| 197 | 197 | * of logger filter |
| 198 | 198 | * @return boolean |
| 199 | 199 | */ |
| 200 | - protected function canSaveLogDataForLogger(){ |
|
| 201 | - if(! empty($this->logger)){ |
|
| 200 | + protected function canSaveLogDataForLogger() { |
|
| 201 | + if (!empty($this->logger)) { |
|
| 202 | 202 | $configLoggersName = get_config('log_logger_name', array()); |
| 203 | 203 | if (!empty($configLoggersName)) { |
| 204 | 204 | //for best comparaison put all string to lowercase |
| 205 | 205 | $configLoggersName = array_map('strtolower', $configLoggersName); |
| 206 | - if(! in_array(strtolower($this->logger), $configLoggersName)){ |
|
| 206 | + if (!in_array(strtolower($this->logger), $configLoggersName)) { |
|
| 207 | 207 | return false; |
| 208 | 208 | } |
| 209 | 209 | } |
@@ -215,19 +215,19 @@ discard block |
||
| 215 | 215 | * Check the file and directory |
| 216 | 216 | * @return string the log file path |
| 217 | 217 | */ |
| 218 | - protected function checkAndSetLogFileDirectory(){ |
|
| 218 | + protected function checkAndSetLogFileDirectory() { |
|
| 219 | 219 | $logSavePath = get_config('log_save_path'); |
| 220 | - if(! $logSavePath){ |
|
| 220 | + if (!$logSavePath) { |
|
| 221 | 221 | $logSavePath = LOGS_PATH; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - if(! is_dir($logSavePath) || !is_writable($logSavePath)){ |
|
| 224 | + if (!is_dir($logSavePath) || !is_writable($logSavePath)) { |
|
| 225 | 225 | //NOTE: here need put the show_error() "logging" to false to prevent loop |
| 226 | 226 | show_error('Error : the log dir does not exists or is not writable', $title = 'Log directory error', $logging = false); |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | $path = $logSavePath . 'logs-' . date('Y-m-d') . '.log'; |
| 230 | - if(! file_exists($path)){ |
|
| 230 | + if (!file_exists($path)) { |
|
| 231 | 231 | touch($path); |
| 232 | 232 | } |
| 233 | 233 | return $path; |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | * |
| 241 | 241 | * @return boolean true if the given log level is valid, false if not |
| 242 | 242 | */ |
| 243 | - protected static function isValidConfigLevel($level){ |
|
| 243 | + protected static function isValidConfigLevel($level) { |
|
| 244 | 244 | $level = strtolower($level); |
| 245 | 245 | return in_array($level, self::$validConfigLevel); |
| 246 | 246 | } |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | * |
| 252 | 252 | * @return int the log level in integer format using the predefined constants |
| 253 | 253 | */ |
| 254 | - protected static function getLevelValue($level){ |
|
| 254 | + protected static function getLevelValue($level) { |
|
| 255 | 255 | $level = strtolower($level); |
| 256 | 256 | $levelMaps = array( |
| 257 | 257 | 'fatal' => self::FATAL, |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | ); |
| 265 | 265 | //the default value is NONE, so means no need test for NONE |
| 266 | 266 | $value = self::NONE; |
| 267 | - if(isset($levelMaps[$level])){ |
|
| 267 | + if (isset($levelMaps[$level])) { |
|
| 268 | 268 | $value = $levelMaps[$level]; |
| 269 | 269 | } |
| 270 | 270 | return $value; |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | * @param integer $level the log level in integer format |
| 276 | 276 | * @return string the log level in string format |
| 277 | 277 | */ |
| 278 | - protected static function getLevelName($level){ |
|
| 278 | + protected static function getLevelName($level) { |
|
| 279 | 279 | $levelMaps = array( |
| 280 | 280 | self::FATAL => 'FATAL', |
| 281 | 281 | self::ERROR => 'ERROR', |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | self::DEBUG => 'DEBUG' |
| 285 | 285 | ); |
| 286 | 286 | $value = ''; |
| 287 | - if(isset($levelMaps[$level])){ |
|
| 287 | + if (isset($levelMaps[$level])) { |
|
| 288 | 288 | $value = $levelMaps[$level]; |
| 289 | 289 | } |
| 290 | 290 | return $value; |