@@ -8,13 +8,13 @@ discard block |
||
| 8 | 8 | <meta name="description" content="A simple PHP framework using HMVC architecture"> |
| 9 | 9 | <meta name="author" content="Tony NGUEREZA"> |
| 10 | 10 | <title>TNH Framework</title> |
| 11 | - <link href="<?php echo Assets::css('bootstrap.min');?>" rel="stylesheet" type = "text/css" > |
|
| 12 | - <link href="<?php echo Assets::css('font-awesome.min');?>" rel="stylesheet" type = "text/css" > |
|
| 13 | - <link href="<?php echo Assets::css('responsive');?>" rel="stylesheet" type = "text/css" > |
|
| 14 | - <link rel="icon" href="<?php echo Assets::img('favicon.ico');?>"> |
|
| 11 | + <link href="<?php echo Assets::css('bootstrap.min'); ?>" rel="stylesheet" type = "text/css" > |
|
| 12 | + <link href="<?php echo Assets::css('font-awesome.min'); ?>" rel="stylesheet" type = "text/css" > |
|
| 13 | + <link href="<?php echo Assets::css('responsive'); ?>" rel="stylesheet" type = "text/css" > |
|
| 14 | + <link rel="icon" href="<?php echo Assets::img('favicon.ico'); ?>"> |
|
| 15 | 15 | <!--[if lt IE 9]> |
| 16 | - <script src="<?php echo Assets::js('html5shiv');?>"></script> |
|
| 17 | - <script src="<?php echo Assets::js('respond.min');?>"></script> |
|
| 16 | + <script src="<?php echo Assets::js('html5shiv'); ?>"></script> |
|
| 17 | + <script src="<?php echo Assets::js('respond.min'); ?>"></script> |
|
| 18 | 18 | <![endif]--> |
| 19 | 19 | <style type = "text/css"> |
| 20 | 20 | |
@@ -28,15 +28,15 @@ discard block |
||
| 28 | 28 | <div class = "col-md-offset-2 col-md-8 col-md-offset-2"> |
| 29 | 29 | <div class = "panel panel-primary"> |
| 30 | 30 | <div class = "panel-heading"> |
| 31 | - <h2>Welcome on <?php echo TNH_NAME;?> v<?php echo TNH_VERSION;?></h2> |
|
| 31 | + <h2>Welcome on <?php echo TNH_NAME; ?> v<?php echo TNH_VERSION; ?></h2> |
|
| 32 | 32 | </div> |
| 33 | 33 | <div class = "panel-body"> |
| 34 | - <img src = "<?php echo Assets::img('logo.png');?>" class = "img-responsive" style = "float:left;" /> |
|
| 34 | + <img src = "<?php echo Assets::img('logo.png'); ?>" class = "img-responsive" style = "float:left;" /> |
|
| 35 | 35 | <h3> |
| 36 | 36 | A simple PHP framework using HMVC architecture |
| 37 | 37 | </h3> |
| 38 | 38 | <br /> |
| 39 | - <p><?php echo Html::a('https://github.com/tnhfw/tnh-fw', 'Framework on Github', array('class' => 'btn btn-default', 'target' => '_blank'));?></p> |
|
| 39 | + <p><?php echo Html::a('https://github.com/tnhfw/tnh-fw', 'Framework on Github', array('class' => 'btn btn-default', 'target' => '_blank')); ?></p> |
|
| 40 | 40 | </div> |
| 41 | 41 | </div> |
| 42 | 42 | <div class = "panel panel-primary"> |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | <h2>Server information</h2> |
| 45 | 45 | </div> |
| 46 | 46 | <div class = "panel-body"> |
| 47 | - <h4>Running on : <b><?php echo php_uname();?></b></h4> |
|
| 48 | - <h4>PHP server SAPI : <b><?php echo php_sapi_name();?></b></h4> |
|
| 49 | - <h4>PHP Version : <b><?php echo phpversion();?></b></h4> |
|
| 50 | - <h4>PHP Loaded extensions : (<?php echo count(get_loaded_extensions());?> extensions)</h4> |
|
| 47 | + <h4>Running on : <b><?php echo php_uname(); ?></b></h4> |
|
| 48 | + <h4>PHP server SAPI : <b><?php echo php_sapi_name(); ?></b></h4> |
|
| 49 | + <h4>PHP Version : <b><?php echo phpversion(); ?></b></h4> |
|
| 50 | + <h4>PHP Loaded extensions : (<?php echo count(get_loaded_extensions()); ?> extensions)</h4> |
|
| 51 | 51 | <table class = "table table-striped table-condensed table-bordered table-responsive"> |
| 52 | 52 | <tr> |
| 53 | 53 | <th>Name</th> |
@@ -55,10 +55,10 @@ discard block |
||
| 55 | 55 | </tr> |
| 56 | 56 | <?php foreach (get_loaded_extensions() as $e):?> |
| 57 | 57 | <tr> |
| 58 | - <td><?php echo $e;?></td> |
|
| 59 | - <td><?php echo phpversion($e);?></td> |
|
| 58 | + <td><?php echo $e; ?></td> |
|
| 59 | + <td><?php echo phpversion($e); ?></td> |
|
| 60 | 60 | </tr> |
| 61 | - <?php endforeach;?> |
|
| 61 | + <?php endforeach; ?> |
|
| 62 | 62 | </table> |
| 63 | 63 | </div> |
| 64 | 64 | </div> |
@@ -67,30 +67,30 @@ discard block |
||
| 67 | 67 | <h2>Framework information</h2> |
| 68 | 68 | </div> |
| 69 | 69 | <div class = "panel-body"> |
| 70 | - <h4>Version : <b><?php echo TNH_VERSION;?></b></h4> |
|
| 71 | - <h4>Required PHP version : <b>PHP >= <?php echo TNH_REQUIRED_PHP_MIN_VERSION;?>, PHP <= <?php echo TNH_REQUIRED_PHP_MAX_VERSION;?></b></h4> |
|
| 72 | - <h4>Build date : <b><?php echo TNH_RELEASE_DATE;?></b></h4> |
|
| 73 | - <h4>Author : <b><?php echo TNH_AUTHOR;?></b></h4> |
|
| 74 | - <h4>Author E-mail : <b><?php echo TNH_AUTHOR_EMAIL;?></b></h4> |
|
| 75 | - <h4>Loaded files : (<?php echo count(get_included_files());?> files)</h4> |
|
| 70 | + <h4>Version : <b><?php echo TNH_VERSION; ?></b></h4> |
|
| 71 | + <h4>Required PHP version : <b>PHP >= <?php echo TNH_REQUIRED_PHP_MIN_VERSION; ?>, PHP <= <?php echo TNH_REQUIRED_PHP_MAX_VERSION; ?></b></h4> |
|
| 72 | + <h4>Build date : <b><?php echo TNH_RELEASE_DATE; ?></b></h4> |
|
| 73 | + <h4>Author : <b><?php echo TNH_AUTHOR; ?></b></h4> |
|
| 74 | + <h4>Author E-mail : <b><?php echo TNH_AUTHOR_EMAIL; ?></b></h4> |
|
| 75 | + <h4>Loaded files : (<?php echo count(get_included_files()); ?> files)</h4> |
|
| 76 | 76 | <table class = "table table-striped table-condensed table-bordered table-responsive"> |
| 77 | 77 | <tr> |
| 78 | 78 | <th>Path</th> |
| 79 | 79 | <th>File</th> |
| 80 | 80 | </tr> |
| 81 | - <?php foreach(get_included_files() as $file):?> |
|
| 81 | + <?php foreach (get_included_files() as $file):?> |
|
| 82 | 82 | <tr> |
| 83 | - <td><?php echo $file;?></td> |
|
| 84 | - <td><?php echo basename($file);?></td> |
|
| 83 | + <td><?php echo $file; ?></td> |
|
| 84 | + <td><?php echo basename($file); ?></td> |
|
| 85 | 85 | </tr> |
| 86 | - <?php endforeach;?> |
|
| 86 | + <?php endforeach; ?> |
|
| 87 | 87 | </table> |
| 88 | 88 | </div> |
| 89 | 89 | </div> |
| 90 | 90 | </div> |
| 91 | 91 | </div> |
| 92 | 92 | </div> |
| 93 | - <script src="<?php echo Assets::js('jquery');?>"></script> |
|
| 94 | - <script src="<?php echo Assets::js('bootstrap.min');?>"></script> |
|
| 93 | + <script src="<?php echo Assets::js('jquery'); ?>"></script> |
|
| 94 | + <script src="<?php echo Assets::js('bootstrap.min'); ?>"></script> |
|
| 95 | 95 | </body> |
| 96 | 96 | </html> |
@@ -243,7 +243,7 @@ |
||
| 243 | 243 | if (version_compare(PHP_VERSION, '5.3', '>=')) { |
| 244 | 244 | error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); |
| 245 | 245 | } |
| 246 | - else{ |
|
| 246 | + else { |
|
| 247 | 247 | error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
| 248 | 248 | } |
| 249 | 249 | break; |
@@ -242,8 +242,7 @@ |
||
| 242 | 242 | ini_set('display_errors', 0); |
| 243 | 243 | if (version_compare(PHP_VERSION, '5.3', '>=')) { |
| 244 | 244 | error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); |
| 245 | - } |
|
| 246 | - else{ |
|
| 245 | + } else{ |
|
| 247 | 246 | error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
| 248 | 247 | } |
| 249 | 248 | break; |
@@ -78,8 +78,7 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){ |
| 80 | 80 | show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment'); |
| 81 | - } |
|
| 82 | - else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
| 81 | + } else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
| 83 | 82 | show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment'); |
| 84 | 83 | } |
| 85 | 84 | $LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue'); |
@@ -104,8 +103,7 @@ discard block |
||
| 104 | 103 | if(file_exists(VENDOR_PATH . 'autoload.php')){ |
| 105 | 104 | $LOGGER->info('The composer autoload file exists include it'); |
| 106 | 105 | require_once VENDOR_PATH . 'autoload.php'; |
| 107 | - } |
|
| 108 | - else{ |
|
| 106 | + } else{ |
|
| 109 | 107 | $LOGGER->info('The composer autoload file does not exist skipping'); |
| 110 | 108 | } |
| 111 | 109 | |
@@ -176,8 +174,7 @@ discard block |
||
| 176 | 174 | //first check if the cache handler is the system driver |
| 177 | 175 | if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){ |
| 178 | 176 | $CACHE =& class_loader($cacheHandler, 'classes/cache'); |
| 179 | - } |
|
| 180 | - else{ |
|
| 177 | + } else{ |
|
| 181 | 178 | //it's not a system driver use user library |
| 182 | 179 | $CACHE =& class_loader($cacheHandler); |
| 183 | 180 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | |
| 43 | 43 | //if the application is running in CLI mode $_SESSION global variable is not available |
| 44 | - if(IS_CLI){ |
|
| 44 | + if (IS_CLI) { |
|
| 45 | 45 | $_SESSION = array(); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -60,14 +60,14 @@ discard block |
||
| 60 | 60 | /** |
| 61 | 61 | * The Benchmark class |
| 62 | 62 | */ |
| 63 | - $BENCHMARK =& class_loader('Benchmark'); |
|
| 63 | + $BENCHMARK = & class_loader('Benchmark'); |
|
| 64 | 64 | |
| 65 | 65 | $BENCHMARK->mark('APP_EXECUTION_START'); |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * instance of the Log class |
| 69 | 69 | */ |
| 70 | - $LOGGER =& class_loader('Log', 'classes'); |
|
| 70 | + $LOGGER = & class_loader('Log', 'classes'); |
|
| 71 | 71 | |
| 72 | 72 | $LOGGER->setLogger('ApplicationBootstrap'); |
| 73 | 73 | |
@@ -76,10 +76,10 @@ discard block |
||
| 76 | 76 | /** |
| 77 | 77 | * Verification of the PHP environment: minimum and maximum version |
| 78 | 78 | */ |
| 79 | - if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){ |
|
| 79 | + if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')) { |
|
| 80 | 80 | show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment'); |
| 81 | 81 | } |
| 82 | - else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
| 82 | + else if (version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')) { |
|
| 83 | 83 | show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment'); |
| 84 | 84 | } |
| 85 | 85 | $LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue'); |
@@ -101,11 +101,11 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | //if user have some composer packages |
| 103 | 103 | $LOGGER->debug('Check for composer autoload'); |
| 104 | - if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 104 | + if (file_exists(VENDOR_PATH . 'autoload.php')) { |
|
| 105 | 105 | $LOGGER->info('The composer autoload file exists include it'); |
| 106 | 106 | require_once VENDOR_PATH . 'autoload.php'; |
| 107 | 107 | } |
| 108 | - else{ |
|
| 108 | + else { |
|
| 109 | 109 | $LOGGER->info('The composer autoload file does not exist skipping'); |
| 110 | 110 | } |
| 111 | 111 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * Load configurations and using the |
| 122 | 122 | * static method "init()" to initialize the Config class . |
| 123 | 123 | */ |
| 124 | - $CONFIG =& class_loader('Config', 'classes'); |
|
| 124 | + $CONFIG = & class_loader('Config', 'classes'); |
|
| 125 | 125 | $CONFIG->init(); |
| 126 | 126 | $BENCHMARK->mark('CONFIG_INIT_END'); |
| 127 | 127 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | * Load modules and using the |
| 131 | 131 | * static method "init()" to initialize the Module class. |
| 132 | 132 | */ |
| 133 | - $MODULE =& class_loader('Module', 'classes'); |
|
| 133 | + $MODULE = & class_loader('Module', 'classes'); |
|
| 134 | 134 | $MODULE->init(); |
| 135 | 135 | $BENCHMARK->mark('MODULE_INIT_END'); |
| 136 | 136 | |
@@ -149,34 +149,34 @@ discard block |
||
| 149 | 149 | /** |
| 150 | 150 | * Loading Security class |
| 151 | 151 | */ |
| 152 | - $SECURITY =& class_loader('Security', 'classes'); |
|
| 152 | + $SECURITY = & class_loader('Security', 'classes'); |
|
| 153 | 153 | $SECURITY->checkWhiteListIpAccess(); |
| 154 | 154 | |
| 155 | 155 | /** |
| 156 | 156 | * Loading Url class |
| 157 | 157 | */ |
| 158 | - $URL =& class_loader('Url', 'classes'); |
|
| 158 | + $URL = & class_loader('Url', 'classes'); |
|
| 159 | 159 | |
| 160 | - if(get_config('cache_enable', false)){ |
|
| 160 | + if (get_config('cache_enable', false)) { |
|
| 161 | 161 | /** |
| 162 | 162 | * Load Cache interface file |
| 163 | 163 | */ |
| 164 | 164 | require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php'; |
| 165 | 165 | $cacheHandler = get_config('cache_handler'); |
| 166 | - if(! $cacheHandler){ |
|
| 166 | + if (!$cacheHandler) { |
|
| 167 | 167 | show_error('The cache feature is enabled in the configuration but the cache handler class is not set.'); |
| 168 | 168 | } |
| 169 | 169 | $CACHE = null; |
| 170 | 170 | //first check if the cache handler is the system driver |
| 171 | - if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){ |
|
| 172 | - $CACHE =& class_loader($cacheHandler, 'classes/cache'); |
|
| 171 | + if (file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')) { |
|
| 172 | + $CACHE = & class_loader($cacheHandler, 'classes/cache'); |
|
| 173 | 173 | } |
| 174 | - else{ |
|
| 174 | + else { |
|
| 175 | 175 | //it's not a system driver use user library |
| 176 | - $CACHE =& class_loader($cacheHandler); |
|
| 176 | + $CACHE = & class_loader($cacheHandler); |
|
| 177 | 177 | } |
| 178 | 178 | //check if the page already cached |
| 179 | - if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){ |
|
| 179 | + if (!empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get') { |
|
| 180 | 180 | $RESPONSE = & class_loader('Response', 'classes'); |
| 181 | 181 | $RESPONSE->renderFinalPageFromCache($CACHE); |
| 182 | 182 | } |
@@ -66,15 +66,13 @@ discard block |
||
| 66 | 66 | //check if the server is running under IPv6 |
| 67 | 67 | if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){ |
| 68 | 68 | $baseUrl = '['.$_SERVER['SERVER_ADDR'].']'; |
| 69 | - } |
|
| 70 | - else{ |
|
| 69 | + } else{ |
|
| 71 | 70 | $baseUrl = $_SERVER['SERVER_ADDR']; |
| 72 | 71 | } |
| 73 | 72 | $port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && ! is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https()) ) ? ':' . $_SERVER['SERVER_PORT'] : ''); |
| 74 | 73 | $baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port |
| 75 | 74 | . substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))); |
| 76 | - } |
|
| 77 | - else{ |
|
| 75 | + } else{ |
|
| 78 | 76 | $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
| 79 | 77 | $baseUrl = 'http://localhost/'; |
| 80 | 78 | } |
@@ -139,8 +137,7 @@ discard block |
||
| 139 | 137 | $logger->info('Delete config item ['.$item.']'); |
| 140 | 138 | unset(static::$config[$item]); |
| 141 | 139 | return true; |
| 142 | - } |
|
| 143 | - else{ |
|
| 140 | + } else{ |
|
| 144 | 141 | $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
| 145 | 142 | return false; |
| 146 | 143 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - class Config{ |
|
| 27 | + class Config { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The list of loaded configuration |
@@ -42,9 +42,9 @@ discard block |
||
| 42 | 42 | * The signleton of the logger |
| 43 | 43 | * @return Object the Log instance |
| 44 | 44 | */ |
| 45 | - private static function getLogger(){ |
|
| 46 | - if(static::$logger == null){ |
|
| 47 | - $logger[0] =& class_loader('Log', 'classes'); |
|
| 45 | + private static function getLogger() { |
|
| 46 | + if (static::$logger == null) { |
|
| 47 | + $logger[0] = & class_loader('Log', 'classes'); |
|
| 48 | 48 | $logger[0]->setLogger('Library::Config'); |
| 49 | 49 | static::$logger = $logger[0]; |
| 50 | 50 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @param Log $logger the log object |
| 57 | 57 | * @return Log the log instance |
| 58 | 58 | */ |
| 59 | - public static function setLogger($logger){ |
|
| 59 | + public static function setLogger($logger) { |
|
| 60 | 60 | static::$logger = $logger; |
| 61 | 61 | return static::$logger; |
| 62 | 62 | } |
@@ -64,35 +64,35 @@ discard block |
||
| 64 | 64 | /** |
| 65 | 65 | * Initialize the configuration by loading all the configuration from config file |
| 66 | 66 | */ |
| 67 | - public static function init(){ |
|
| 67 | + public static function init() { |
|
| 68 | 68 | $logger = static::getLogger(); |
| 69 | 69 | $logger->debug('Initialization of the configuration'); |
| 70 | 70 | static::$config = & load_configurations(); |
| 71 | - if(! static::$config['base_url'] || ! is_url(static::$config['base_url'])){ |
|
| 72 | - if(ENVIRONMENT == 'production'){ |
|
| 71 | + if (!static::$config['base_url'] || !is_url(static::$config['base_url'])) { |
|
| 72 | + if (ENVIRONMENT == 'production') { |
|
| 73 | 73 | $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time'); |
| 74 | 74 | } |
| 75 | 75 | $baseUrl = null; |
| 76 | - if (isset($_SERVER['SERVER_ADDR'])){ |
|
| 76 | + if (isset($_SERVER['SERVER_ADDR'])) { |
|
| 77 | 77 | //check if the server is running under IPv6 |
| 78 | - if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){ |
|
| 79 | - $baseUrl = '['.$_SERVER['SERVER_ADDR'].']'; |
|
| 78 | + if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) { |
|
| 79 | + $baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']'; |
|
| 80 | 80 | } |
| 81 | - else{ |
|
| 81 | + else { |
|
| 82 | 82 | $baseUrl = $_SERVER['SERVER_ADDR']; |
| 83 | 83 | } |
| 84 | - $port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && ! is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https()) ) ? ':' . $_SERVER['SERVER_PORT'] : ''); |
|
| 85 | - $baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port |
|
| 84 | + $port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && !is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https())) ? ':' . $_SERVER['SERVER_PORT'] : ''); |
|
| 85 | + $baseUrl = (is_https() ? 'https' : 'http') . '://' . $baseUrl . $port |
|
| 86 | 86 | . substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))); |
| 87 | 87 | } |
| 88 | - else{ |
|
| 88 | + else { |
|
| 89 | 89 | $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
| 90 | 90 | $baseUrl = 'http://localhost/'; |
| 91 | 91 | } |
| 92 | 92 | self::set('base_url', $baseUrl); |
| 93 | 93 | } |
| 94 | - static::$config['base_url'] = rtrim(static::$config['base_url'], '/') .'/'; |
|
| 95 | - if(ENVIRONMENT == 'production' && in_array(strtolower(static::$config['log_level']), array('debug', 'info','all'))){ |
|
| 94 | + static::$config['base_url'] = rtrim(static::$config['base_url'], '/') . '/'; |
|
| 95 | + if (ENVIRONMENT == 'production' && in_array(strtolower(static::$config['log_level']), array('debug', 'info', 'all'))) { |
|
| 96 | 96 | $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance'); |
| 97 | 97 | } |
| 98 | 98 | $logger->info('Configuration initialized successfully'); |
@@ -105,12 +105,12 @@ discard block |
||
| 105 | 105 | * @param mixed $default the default value to use if can not find the config item in the list |
| 106 | 106 | * @return mixed the config value if exist or the default value |
| 107 | 107 | */ |
| 108 | - public static function get($item, $default = null){ |
|
| 108 | + public static function get($item, $default = null) { |
|
| 109 | 109 | $logger = static::getLogger(); |
| 110 | - if(array_key_exists($item, static::$config)){ |
|
| 110 | + if (array_key_exists($item, static::$config)) { |
|
| 111 | 111 | return static::$config[$item]; |
| 112 | 112 | } |
| 113 | - $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']'); |
|
| 113 | + $logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']'); |
|
| 114 | 114 | return $default; |
| 115 | 115 | } |
| 116 | 116 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @param string $item the config item name to set |
| 120 | 120 | * @param mixed $value the config item value |
| 121 | 121 | */ |
| 122 | - public static function set($item, $value){ |
|
| 122 | + public static function set($item, $value) { |
|
| 123 | 123 | static::$config[$item] = $value; |
| 124 | 124 | } |
| 125 | 125 | |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * Get all the configuration values |
| 128 | 128 | * @return array the config values |
| 129 | 129 | */ |
| 130 | - public static function getAll(){ |
|
| 130 | + public static function getAll() { |
|
| 131 | 131 | return static::$config; |
| 132 | 132 | } |
| 133 | 133 | |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * Set the configuration values bu merged with the existing configuration |
| 136 | 136 | * @param array $config the config values to add in the configuration list |
| 137 | 137 | */ |
| 138 | - public static function setAll(array $config = array()){ |
|
| 138 | + public static function setAll(array $config = array()) { |
|
| 139 | 139 | static::$config = array_merge(static::$config, $config); |
| 140 | 140 | } |
| 141 | 141 | |
@@ -144,15 +144,15 @@ discard block |
||
| 144 | 144 | * @param string $item the config item name to be deleted |
| 145 | 145 | * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
| 146 | 146 | */ |
| 147 | - public static function delete($item){ |
|
| 147 | + public static function delete($item) { |
|
| 148 | 148 | $logger = static::getLogger(); |
| 149 | - if(array_key_exists($item, static::$config)){ |
|
| 150 | - $logger->info('Delete config item ['.$item.']'); |
|
| 149 | + if (array_key_exists($item, static::$config)) { |
|
| 150 | + $logger->info('Delete config item [' . $item . ']'); |
|
| 151 | 151 | unset(static::$config[$item]); |
| 152 | 152 | return true; |
| 153 | 153 | } |
| 154 | - else{ |
|
| 155 | - $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
|
| 154 | + else { |
|
| 155 | + $logger->warning('Config item [' . $item . '] to be deleted does not exists'); |
|
| 156 | 156 | return false; |
| 157 | 157 | } |
| 158 | 158 | } |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * Load the configuration file. This an alias to Loader::config() |
| 162 | 162 | * @param string $config the config name to be loaded |
| 163 | 163 | */ |
| 164 | - public static function load($config){ |
|
| 164 | + public static function load($config) { |
|
| 165 | 165 | Loader::config($config); |
| 166 | 166 | } |
| 167 | 167 | } |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - interface CacheInterface{ |
|
| 27 | + interface CacheInterface { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * This is used to get the cache data using the key |
@@ -25,15 +25,15 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class Url{ |
|
| 28 | + class Url { |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Return the link using base_url config without front controller "index.php" |
| 32 | 32 | * @param string $path the link path or full URL |
| 33 | 33 | * @return string the full link URL |
| 34 | 34 | */ |
| 35 | - public static function base_url($path = ''){ |
|
| 36 | - if(is_url($path)){ |
|
| 35 | + public static function base_url($path = '') { |
|
| 36 | + if (is_url($path)) { |
|
| 37 | 37 | return $path; |
| 38 | 38 | } |
| 39 | 39 | return get_config('base_url') . $path; |
@@ -44,26 +44,26 @@ discard block |
||
| 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 | 65 | } |
| 66 | - else{ |
|
| 66 | + else { |
|
| 67 | 67 | $path .= $suffix; |
| 68 | 68 | } |
| 69 | 69 | } |
@@ -74,10 +74,10 @@ discard block |
||
| 74 | 74 | * Return the current site URL |
| 75 | 75 | * @return string |
| 76 | 76 | */ |
| 77 | - public static function current(){ |
|
| 77 | + public static function current() { |
|
| 78 | 78 | $current = '/'; |
| 79 | 79 | $requestUri = get_instance()->request->requestUri(); |
| 80 | - if($requestUri){ |
|
| 80 | + if ($requestUri) { |
|
| 81 | 81 | $current = $requestUri; |
| 82 | 82 | } |
| 83 | 83 | return static::domain() . $current; |
@@ -90,18 +90,18 @@ discard block |
||
| 90 | 90 | * @param boolean $lowercase whether to set the final text to lowe case or not |
| 91 | 91 | * @return string the friendly generated text |
| 92 | 92 | */ |
| 93 | - public static function title($str = null, $separator = '-', $lowercase = true){ |
|
| 93 | + public static function title($str = null, $separator = '-', $lowercase = true) { |
|
| 94 | 94 | $str = trim($str); |
| 95 | - $from = array('ç','À','Á','Â','Ã','Ä','Å','à','á','â','ã','ä','å','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','È','É','Ê','Ë','è','é','ê','ë','Ç','ç','Ì','Í','Î','Ï','ì','í','î','ï','Ù','Ú','Û','Ü','ù','ú','û','ü','ÿ','Ñ','ñ'); |
|
| 96 | - $to = array('c','a','a','a','a','a','a','a','a','a','a','a','a','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','i','i','i','i','i','i','i','i','u','u','u','u','u','u','u','u','y','n','n'); |
|
| 95 | + $from = array('ç', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'à', 'á', 'â', 'ã', 'ä', 'å', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'È', 'É', 'Ê', 'Ë', 'è', 'é', 'ê', 'ë', 'Ç', 'ç', 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï', 'Ù', 'Ú', 'Û', 'Ü', 'ù', 'ú', 'û', 'ü', 'ÿ', 'Ñ', 'ñ'); |
|
| 96 | + $to = array('c', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'y', 'n', 'n'); |
|
| 97 | 97 | $str = str_replace($from, $to, $str); |
| 98 | 98 | $str = preg_replace('#([^a-z0-9]+)#i', $separator, $str); |
| 99 | 99 | $str = str_replace('--', $separator, $str); |
| 100 | 100 | //if after process we get something like one-two-three-, need truncate the last separator "-" |
| 101 | - if(substr($str, -1) == $separator){ |
|
| 101 | + if (substr($str, -1) == $separator) { |
|
| 102 | 102 | $str = substr($str, 0, -1); |
| 103 | 103 | } |
| 104 | - if($lowercase){ |
|
| 104 | + if ($lowercase) { |
|
| 105 | 105 | $str = strtolower($str); |
| 106 | 106 | } |
| 107 | 107 | return $str; |
@@ -111,36 +111,36 @@ discard block |
||
| 111 | 111 | * Get the current application domain with protocol |
| 112 | 112 | * @return string the domain name |
| 113 | 113 | */ |
| 114 | - public static function domain(){ |
|
| 114 | + public static function domain() { |
|
| 115 | 115 | $obj = & get_instance(); |
| 116 | 116 | $domain = 'localhost'; |
| 117 | 117 | $port = $obj->request->server('SERVER_PORT'); |
| 118 | 118 | $protocol = is_https() ? 'https' : 'http'; |
| 119 | 119 | |
| 120 | - if($obj->request->server('HTTP_HOST')){ |
|
| 120 | + if ($obj->request->server('HTTP_HOST')) { |
|
| 121 | 121 | $domain = $obj->request->server('HTTP_HOST'); |
| 122 | 122 | } |
| 123 | - else if($obj->request->server('SERVER_NAME')){ |
|
| 123 | + else if ($obj->request->server('SERVER_NAME')) { |
|
| 124 | 124 | $domain = $obj->request->server('SERVER_NAME'); |
| 125 | 125 | } |
| 126 | - else if($obj->request->server('SERVER_ADDR')){ |
|
| 126 | + else if ($obj->request->server('SERVER_ADDR')) { |
|
| 127 | 127 | $domain = $obj->request->server('SERVER_ADDR'); |
| 128 | 128 | } |
| 129 | - if($port && (is_https() && $port != 443 || !is_https() && $port != 80)){ |
|
| 129 | + if ($port && (is_https() && $port != 443 || !is_https() && $port != 80)) { |
|
| 130 | 130 | //some server use SSL but the port doesn't equal 443 sometime is 80 if is the case put the port at this end |
| 131 | 131 | //of the domain like https://my.domain.com:787 |
| 132 | - if(is_https() && $port != 80){ |
|
| 133 | - $domain .= ':'.$port; |
|
| 132 | + if (is_https() && $port != 80) { |
|
| 133 | + $domain .= ':' . $port; |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | - return $protocol.'://'.$domain; |
|
| 136 | + return $protocol . '://' . $domain; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
| 140 | 140 | * Get the current request query string |
| 141 | 141 | * @return string |
| 142 | 142 | */ |
| 143 | - public static function queryString(){ |
|
| 143 | + public static function queryString() { |
|
| 144 | 144 | return get_instance()->request->server('QUERY_STRING'); |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | \ No newline at end of file |
@@ -62,8 +62,7 @@ discard block |
||
| 62 | 62 | $query[0] = rtrim($query[0], '/'); |
| 63 | 63 | $query[0] .= $suffix; |
| 64 | 64 | $path = implode('?', $query); |
| 65 | - } |
|
| 66 | - else{ |
|
| 65 | + } else{ |
|
| 67 | 66 | $path .= $suffix; |
| 68 | 67 | } |
| 69 | 68 | } |
@@ -119,11 +118,9 @@ discard block |
||
| 119 | 118 | |
| 120 | 119 | if($obj->request->server('HTTP_HOST')){ |
| 121 | 120 | $domain = $obj->request->server('HTTP_HOST'); |
| 122 | - } |
|
| 123 | - else if($obj->request->server('SERVER_NAME')){ |
|
| 121 | + } else if($obj->request->server('SERVER_NAME')){ |
|
| 124 | 122 | $domain = $obj->request->server('SERVER_NAME'); |
| 125 | - } |
|
| 126 | - else if($obj->request->server('SERVER_ADDR')){ |
|
| 123 | + } else if($obj->request->server('SERVER_ADDR')){ |
|
| 127 | 124 | $domain = $obj->request->server('SERVER_ADDR'); |
| 128 | 125 | } |
| 129 | 126 | if($port && (is_https() && $port != 443 || !is_https() && $port != 80)){ |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | - class Session{ |
|
| 26 | + class Session { |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * The session flash key to use |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | * Get the logger singleton instance |
| 42 | 42 | * @return Log the logger instance |
| 43 | 43 | */ |
| 44 | - private static function getLogger(){ |
|
| 45 | - if(static::$logger == null){ |
|
| 46 | - static::$logger[0] =& class_loader('Log', 'classes'); |
|
| 44 | + private static function getLogger() { |
|
| 45 | + if (static::$logger == null) { |
|
| 46 | + static::$logger[0] = & class_loader('Log', 'classes'); |
|
| 47 | 47 | static::$logger[0]->setLogger('Library::Session'); |
| 48 | 48 | } |
| 49 | 49 | return static::$logger[0]; |
@@ -55,14 +55,14 @@ discard block |
||
| 55 | 55 | * @param mixed $default the default value to use if can not find the session item in the list |
| 56 | 56 | * @return mixed the session value if exist or the default value |
| 57 | 57 | */ |
| 58 | - public static function get($item, $default = null){ |
|
| 58 | + public static function get($item, $default = null) { |
|
| 59 | 59 | $logger = static::getLogger(); |
| 60 | - $logger->debug('Getting session data for item [' .$item. '] ...'); |
|
| 61 | - if(array_key_exists($item, $_SESSION)){ |
|
| 60 | + $logger->debug('Getting session data for item [' . $item . '] ...'); |
|
| 61 | + if (array_key_exists($item, $_SESSION)) { |
|
| 62 | 62 | $logger->info('Found session data for item [' . $item . '] the vaue is : [' . stringfy_vars($_SESSION[$item]) . ']'); |
| 63 | 63 | return $_SESSION[$item]; |
| 64 | 64 | } |
| 65 | - $logger->warning('Cannot find session item [' . $item . '] using the default value ['. $default . ']'); |
|
| 65 | + $logger->warning('Cannot find session item [' . $item . '] using the default value [' . $default . ']'); |
|
| 66 | 66 | return $default; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * @param string $item the session item name to set |
| 72 | 72 | * @param mixed $value the session item value |
| 73 | 73 | */ |
| 74 | - public static function set($item, $value){ |
|
| 74 | + public static function set($item, $value) { |
|
| 75 | 75 | $logger = static::getLogger(); |
| 76 | 76 | $logger->debug('Setting session data for item [' . $item . '], value [' . stringfy_vars($value) . ']'); |
| 77 | 77 | $_SESSION[$item] = $value; |
@@ -83,16 +83,16 @@ discard block |
||
| 83 | 83 | * @param mixed $default the default value to use if can not find the session flash item in the list |
| 84 | 84 | * @return mixed the session flash value if exist or the default value |
| 85 | 85 | */ |
| 86 | - public static function getFlash($item, $default = null){ |
|
| 86 | + public static function getFlash($item, $default = null) { |
|
| 87 | 87 | $logger = static::getLogger(); |
| 88 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 88 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
| 89 | 89 | $return = array_key_exists($key, $_SESSION) ? |
| 90 | 90 | ($_SESSION[$key]) : $default; |
| 91 | - if(array_key_exists($key, $_SESSION)){ |
|
| 91 | + if (array_key_exists($key, $_SESSION)) { |
|
| 92 | 92 | unset($_SESSION[$key]); |
| 93 | 93 | } |
| 94 | - else{ |
|
| 95 | - $logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']'); |
|
| 94 | + else { |
|
| 95 | + $logger->warning('Cannot find session flash item [' . $key . '] using the default value [' . $default . ']'); |
|
| 96 | 96 | } |
| 97 | 97 | return $return; |
| 98 | 98 | } |
@@ -102,8 +102,8 @@ discard block |
||
| 102 | 102 | * @param string $item the session flash item name |
| 103 | 103 | * @return boolean |
| 104 | 104 | */ |
| 105 | - public static function hasFlash($item){ |
|
| 106 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 105 | + public static function hasFlash($item) { |
|
| 106 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
| 107 | 107 | return array_key_exists($key, $_SESSION); |
| 108 | 108 | } |
| 109 | 109 | |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | * @param string $item the session flash item name to set |
| 113 | 113 | * @param mixed $value the session flash item value |
| 114 | 114 | */ |
| 115 | - public static function setFlash($item, $value){ |
|
| 116 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 115 | + public static function setFlash($item, $value) { |
|
| 116 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
| 117 | 117 | $_SESSION[$key] = $value; |
| 118 | 118 | } |
| 119 | 119 | |
@@ -121,14 +121,14 @@ discard block |
||
| 121 | 121 | * Clear the session item in the list |
| 122 | 122 | * @param string $item the session item name to be deleted |
| 123 | 123 | */ |
| 124 | - public static function clear($item){ |
|
| 124 | + public static function clear($item) { |
|
| 125 | 125 | $logger = static::getLogger(); |
| 126 | - if(array_key_exists($item, $_SESSION)){ |
|
| 127 | - $logger->info('Deleting of session for item ['.$item.' ]'); |
|
| 126 | + if (array_key_exists($item, $_SESSION)) { |
|
| 127 | + $logger->info('Deleting of session for item [' . $item . ' ]'); |
|
| 128 | 128 | unset($_SESSION[$item]); |
| 129 | 129 | } |
| 130 | - else{ |
|
| 131 | - $logger->warning('Session item ['.$item.'] to be deleted does not exists'); |
|
| 130 | + else { |
|
| 131 | + $logger->warning('Session item [' . $item . '] to be deleted does not exists'); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
@@ -136,15 +136,15 @@ discard block |
||
| 136 | 136 | * Clear the session flash item in the list |
| 137 | 137 | * @param string $item the session flash item name to be deleted |
| 138 | 138 | */ |
| 139 | - public static function clearFlash($item){ |
|
| 139 | + public static function clearFlash($item) { |
|
| 140 | 140 | $logger = static::getLogger(); |
| 141 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 142 | - if(array_key_exists($key, $_SESSION)){ |
|
| 143 | - $logger->info('Delete session flash for item ['.$item.']'); |
|
| 141 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
| 142 | + if (array_key_exists($key, $_SESSION)) { |
|
| 143 | + $logger->info('Delete session flash for item [' . $item . ']'); |
|
| 144 | 144 | unset($_SESSION[$item]); |
| 145 | 145 | } |
| 146 | - else{ |
|
| 147 | - $logger->warning('Dession flash item ['.$item.'] to be deleted does not exists'); |
|
| 146 | + else { |
|
| 147 | + $logger->warning('Dession flash item [' . $item . '] to be deleted does not exists'); |
|
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
@@ -153,14 +153,14 @@ discard block |
||
| 153 | 153 | * @param string $item the session item name |
| 154 | 154 | * @return boolean |
| 155 | 155 | */ |
| 156 | - public static function exists($item){ |
|
| 156 | + public static function exists($item) { |
|
| 157 | 157 | return array_key_exists($item, $_SESSION); |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
| 161 | 161 | * Destroy all session data values |
| 162 | 162 | */ |
| 163 | - public static function clearAll(){ |
|
| 163 | + public static function clearAll() { |
|
| 164 | 164 | session_unset(); |
| 165 | 165 | session_destroy(); |
| 166 | 166 | } |
@@ -90,8 +90,7 @@ discard block |
||
| 90 | 90 | ($_SESSION[$key]) : $default; |
| 91 | 91 | if(array_key_exists($key, $_SESSION)){ |
| 92 | 92 | unset($_SESSION[$key]); |
| 93 | - } |
|
| 94 | - else{ |
|
| 93 | + } else{ |
|
| 95 | 94 | $logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']'); |
| 96 | 95 | } |
| 97 | 96 | return $return; |
@@ -126,8 +125,7 @@ discard block |
||
| 126 | 125 | if(array_key_exists($item, $_SESSION)){ |
| 127 | 126 | $logger->info('Deleting of session for item ['.$item.' ]'); |
| 128 | 127 | unset($_SESSION[$item]); |
| 129 | - } |
|
| 130 | - else{ |
|
| 128 | + } else{ |
|
| 131 | 129 | $logger->warning('Session item ['.$item.'] to be deleted does not exists'); |
| 132 | 130 | } |
| 133 | 131 | } |
@@ -142,8 +140,7 @@ discard block |
||
| 142 | 140 | if(array_key_exists($key, $_SESSION)){ |
| 143 | 141 | $logger->info('Delete session flash for item ['.$item.']'); |
| 144 | 142 | unset($_SESSION[$item]); |
| 145 | - } |
|
| 146 | - else{ |
|
| 143 | + } else{ |
|
| 147 | 144 | $logger->warning('Dession flash item ['.$item.'] to be deleted does not exists'); |
| 148 | 145 | } |
| 149 | 146 | } |
@@ -92,39 +92,39 @@ discard block |
||
| 92 | 92 | /** |
| 93 | 93 | * Construct the new Router instance |
| 94 | 94 | */ |
| 95 | - public function __construct(){ |
|
| 96 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 95 | + public function __construct() { |
|
| 96 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 97 | 97 | $this->logger->setLogger('Library::Router'); |
| 98 | 98 | $routesPath = CONFIG_PATH . 'routes.php'; |
| 99 | 99 | $this->logger->debug('Loading of routes configuration file --> ' . $routesPath . ' ...'); |
| 100 | - if(file_exists($routesPath)){ |
|
| 101 | - $this->logger->info('Found routes configuration file --> ' . $routesPath. ' now load it'); |
|
| 100 | + if (file_exists($routesPath)) { |
|
| 101 | + $this->logger->info('Found routes configuration file --> ' . $routesPath . ' now load it'); |
|
| 102 | 102 | require_once $routesPath; |
| 103 | - if(! empty($route) && is_array($route)){ |
|
| 103 | + if (!empty($route) && is_array($route)) { |
|
| 104 | 104 | $this->routes = $route; |
| 105 | 105 | unset($route); |
| 106 | 106 | } |
| 107 | - else{ |
|
| 107 | + else { |
|
| 108 | 108 | show_error('No routing configuration found in [' . $routesPath . ']'); |
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | - else{ |
|
| 111 | + else { |
|
| 112 | 112 | show_error('Unable to find the routes configuration file [' . $routesPath . ']'); |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | //loading routes for module |
| 116 | 116 | $this->logger->debug('Loading of modules routes ... '); |
| 117 | 117 | $modulesRoutes = Module::getModulesRoutes(); |
| 118 | - if($modulesRoutes && is_array($modulesRoutes)){ |
|
| 118 | + if ($modulesRoutes && is_array($modulesRoutes)) { |
|
| 119 | 119 | $this->routes = array_merge($this->routes, $modulesRoutes); |
| 120 | 120 | $this->logger->info('Routes for all modules loaded successfully'); |
| 121 | 121 | } |
| 122 | - else{ |
|
| 122 | + else { |
|
| 123 | 123 | $this->logger->info('No routes found for all modules skipping.'); |
| 124 | 124 | } |
| 125 | 125 | $this->logger->info('The routes configuration are listed below: ' . stringfy_vars($this->routes)); |
| 126 | 126 | |
| 127 | - foreach($this->routes as $pattern => $callback){ |
|
| 127 | + foreach ($this->routes as $pattern => $callback) { |
|
| 128 | 128 | $this->add($pattern, $callback); |
| 129 | 129 | } |
| 130 | 130 | |
@@ -132,14 +132,14 @@ discard block |
||
| 132 | 132 | $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; |
| 133 | 133 | $this->logger->debug('Check if URL suffix is enabled in the configuration'); |
| 134 | 134 | //remove url suffix from the request URI |
| 135 | - if($suffix = get_config('url_suffix')){ |
|
| 136 | - $this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']' ); |
|
| 135 | + if ($suffix = get_config('url_suffix')) { |
|
| 136 | + $this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']'); |
|
| 137 | 137 | $uri = str_ireplace($suffix, '', $uri); |
| 138 | 138 | } |
| 139 | - else{ |
|
| 139 | + else { |
|
| 140 | 140 | $this->logger->info('URL suffix is not enabled in the configuration'); |
| 141 | 141 | } |
| 142 | - if(strpos($uri, '?') !== false){ |
|
| 142 | + if (strpos($uri, '?') !== false) { |
|
| 143 | 143 | $uri = substr($uri, 0, strpos($uri, '?')); |
| 144 | 144 | } |
| 145 | 145 | $uri = trim($uri, $this->uriTrim); |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | public function add($uri, $callback) { |
| 156 | 156 | $uri = trim($uri, $this->uriTrim); |
| 157 | - if(in_array($uri, $this->pattern)){ |
|
| 157 | + if (in_array($uri, $this->pattern)) { |
|
| 158 | 158 | $this->logger->warning('The route [' . $uri . '] already added, may be adding again can have route conflict'); |
| 159 | 159 | } |
| 160 | 160 | $this->pattern[] = $uri; |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * Get the module name |
| 166 | 166 | * @return string |
| 167 | 167 | */ |
| 168 | - public function getModule(){ |
|
| 168 | + public function getModule() { |
|
| 169 | 169 | return $this->module; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | * Get the controller name |
| 174 | 174 | * @return string |
| 175 | 175 | */ |
| 176 | - public function getController(){ |
|
| 176 | + public function getController() { |
|
| 177 | 177 | return $this->controller; |
| 178 | 178 | } |
| 179 | 179 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * Get the controller file path |
| 182 | 182 | * @return string |
| 183 | 183 | */ |
| 184 | - public function getControllerPath(){ |
|
| 184 | + public function getControllerPath() { |
|
| 185 | 185 | return $this->controllerPath; |
| 186 | 186 | } |
| 187 | 187 | |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | * Get the controller method |
| 190 | 190 | * @return string |
| 191 | 191 | */ |
| 192 | - public function getMethod(){ |
|
| 192 | + public function getMethod() { |
|
| 193 | 193 | return $this->method; |
| 194 | 194 | } |
| 195 | 195 | |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | * Get the request arguments |
| 198 | 198 | * @return array |
| 199 | 199 | */ |
| 200 | - public function getArgs(){ |
|
| 200 | + public function getArgs() { |
|
| 201 | 201 | return $this->args; |
| 202 | 202 | } |
| 203 | 203 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * Get the URL segments array |
| 206 | 206 | * @return array |
| 207 | 207 | */ |
| 208 | - public function getSegments(){ |
|
| 208 | + public function getSegments() { |
|
| 209 | 209 | return $this->segments; |
| 210 | 210 | } |
| 211 | 211 | |
@@ -214,27 +214,27 @@ discard block |
||
| 214 | 214 | * otherwise send 404 error. |
| 215 | 215 | */ |
| 216 | 216 | public function run() { |
| 217 | - $benchmark =& class_loader('Benchmark'); |
|
| 217 | + $benchmark = & class_loader('Benchmark'); |
|
| 218 | 218 | $benchmark->mark('ROUTING_PROCESS_START'); |
| 219 | 219 | $this->logger->debug('Routing process start ...'); |
| 220 | 220 | $segment = $this->segments; |
| 221 | 221 | $baseUrl = get_config('base_url'); |
| 222 | 222 | //check if the app is not in DOCUMENT_ROOT |
| 223 | - if(isset($segment[0]) && stripos($baseUrl, $segment[0]) != false){ |
|
| 223 | + if (isset($segment[0]) && stripos($baseUrl, $segment[0]) != false) { |
|
| 224 | 224 | array_shift($segment); |
| 225 | 225 | $this->segments = $segment; |
| 226 | 226 | } |
| 227 | 227 | $this->logger->debug('Check if the request URI contains the front controller'); |
| 228 | - if(isset($segment[0]) && $segment[0] == SELF){ |
|
| 228 | + if (isset($segment[0]) && $segment[0] == SELF) { |
|
| 229 | 229 | $this->logger->info('The request URI contains the front controller'); |
| 230 | 230 | array_shift($segment); |
| 231 | 231 | $this->segments = $segment; |
| 232 | 232 | } |
| 233 | - else{ |
|
| 233 | + else { |
|
| 234 | 234 | $this->logger->info('The request URI does not contain the front controller'); |
| 235 | 235 | } |
| 236 | 236 | $uri = implode('/', $segment); |
| 237 | - $this->logger->info('The final Request URI is [' . $uri . ']' ); |
|
| 237 | + $this->logger->info('The final Request URI is [' . $uri . ']'); |
|
| 238 | 238 | //generic routes |
| 239 | 239 | $pattern = array(':num', ':alpha', ':alnum', ':any'); |
| 240 | 240 | $replace = array('[0-9]+', '[a-zA-Z]+', '[a-zA-Z0-9]+', '.*'); |
@@ -248,20 +248,20 @@ discard block |
||
| 248 | 248 | array_shift($args); |
| 249 | 249 | //check if this contains an module |
| 250 | 250 | $moduleControllerMethod = explode('#', $this->callback[$index]); |
| 251 | - if(is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2){ |
|
| 252 | - $this->logger->info('The current request use the module [' .$moduleControllerMethod[0]. ']'); |
|
| 251 | + if (is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2) { |
|
| 252 | + $this->logger->info('The current request use the module [' . $moduleControllerMethod[0] . ']'); |
|
| 253 | 253 | $this->module = $moduleControllerMethod[0]; |
| 254 | 254 | $moduleControllerMethod = explode('@', $moduleControllerMethod[1]); |
| 255 | 255 | } |
| 256 | - else{ |
|
| 256 | + else { |
|
| 257 | 257 | $this->logger->info('The current request does not use the module'); |
| 258 | 258 | $moduleControllerMethod = explode('@', $this->callback[$index]); |
| 259 | 259 | } |
| 260 | - if(is_array($moduleControllerMethod)){ |
|
| 261 | - if(isset($moduleControllerMethod[0])){ |
|
| 260 | + if (is_array($moduleControllerMethod)) { |
|
| 261 | + if (isset($moduleControllerMethod[0])) { |
|
| 262 | 262 | $this->controller = $moduleControllerMethod[0]; |
| 263 | 263 | } |
| 264 | - if(isset($moduleControllerMethod[1])){ |
|
| 264 | + if (isset($moduleControllerMethod[1])) { |
|
| 265 | 265 | $this->method = $moduleControllerMethod[1]; |
| 266 | 266 | } |
| 267 | 267 | $this->args = $args; |
@@ -271,73 +271,73 @@ discard block |
||
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | //first if the controller is not set and the module is set use the module name as the controller |
| 274 | - if(! $this->getController() && $this->getModule()){ |
|
| 274 | + if (!$this->getController() && $this->getModule()) { |
|
| 275 | 275 | $this->logger->info('After loop in predefined routes configuration, the module name is set but the controller is not set, so we will use module as the controller'); |
| 276 | 276 | $this->controller = $this->getModule(); |
| 277 | 277 | } |
| 278 | 278 | //if can not determine the module/controller/method via the defined routes configuration we will use |
| 279 | 279 | //the URL like http://domain.com/module/controller/method/arg1/arg2 |
| 280 | - if(! $this->getController()){ |
|
| 280 | + if (!$this->getController()) { |
|
| 281 | 281 | $this->logger->info('Cannot determine the routing information using the predefined routes configuration, will use the request URI parameters'); |
| 282 | 282 | $nbSegment = count($segment); |
| 283 | 283 | //if segment is null so means no need to perform |
| 284 | - if($nbSegment > 0){ |
|
| 284 | + if ($nbSegment > 0) { |
|
| 285 | 285 | //get the module list |
| 286 | 286 | $modules = Module::getModuleList(); |
| 287 | 287 | //first check if no module |
| 288 | - if(! $modules){ |
|
| 288 | + if (!$modules) { |
|
| 289 | 289 | $this->logger->info('No module was loaded will skip the module checking'); |
| 290 | 290 | //the application don't use module |
| 291 | 291 | //controller |
| 292 | - if(isset($segment[0])){ |
|
| 292 | + if (isset($segment[0])) { |
|
| 293 | 293 | $this->controller = $segment[0]; |
| 294 | 294 | array_shift($segment); |
| 295 | 295 | } |
| 296 | 296 | //method |
| 297 | - if(isset($segment[0])){ |
|
| 297 | + if (isset($segment[0])) { |
|
| 298 | 298 | $this->method = $segment[0]; |
| 299 | 299 | array_shift($segment); |
| 300 | 300 | } |
| 301 | 301 | //args |
| 302 | 302 | $this->args = $segment; |
| 303 | 303 | } |
| 304 | - else{ |
|
| 304 | + else { |
|
| 305 | 305 | $this->logger->info('The application contains a loaded module will check if the current request is found in the module list'); |
| 306 | - if(in_array($segment[0], $modules)){ |
|
| 306 | + if (in_array($segment[0], $modules)) { |
|
| 307 | 307 | $this->logger->info('Found, the current request use the module [' . $segment[0] . ']'); |
| 308 | 308 | $this->module = $segment[0]; |
| 309 | 309 | array_shift($segment); |
| 310 | 310 | //check if the second arg is the controller from module |
| 311 | - if(isset($segment[0])){ |
|
| 311 | + if (isset($segment[0])) { |
|
| 312 | 312 | $this->controller = $segment[0]; |
| 313 | 313 | //check if the request use the same module name and controller |
| 314 | 314 | $path = Module::findControllerFullPath(ucfirst($this->getController()), $this->getModule()); |
| 315 | - if(! $path){ |
|
| 315 | + if (!$path) { |
|
| 316 | 316 | $this->logger->info('The controller [' . $this->getController() . '] not found in the module, may be will use the module [' . $this->getModule() . '] as controller'); |
| 317 | 317 | $this->controller = $this->getModule(); |
| 318 | 318 | } |
| 319 | - else{ |
|
| 319 | + else { |
|
| 320 | 320 | $this->controllerPath = $path; |
| 321 | 321 | array_shift($segment); |
| 322 | 322 | } |
| 323 | 323 | } |
| 324 | 324 | //check for method |
| 325 | - if(isset($segment[0])){ |
|
| 325 | + if (isset($segment[0])) { |
|
| 326 | 326 | $this->method = $segment[0]; |
| 327 | 327 | array_shift($segment); |
| 328 | 328 | } |
| 329 | 329 | //the remaining is for args |
| 330 | 330 | $this->args = $segment; |
| 331 | 331 | } |
| 332 | - else{ |
|
| 332 | + else { |
|
| 333 | 333 | $this->logger->info('The current request information is not found in the module list'); |
| 334 | 334 | //controller |
| 335 | - if(isset($segment[0])){ |
|
| 335 | + if (isset($segment[0])) { |
|
| 336 | 336 | $this->controller = $segment[0]; |
| 337 | 337 | array_shift($segment); |
| 338 | 338 | } |
| 339 | 339 | //method |
| 340 | - if(isset($segment[0])){ |
|
| 340 | + if (isset($segment[0])) { |
|
| 341 | 341 | $this->method = $segment[0]; |
| 342 | 342 | array_shift($segment); |
| 343 | 343 | } |
@@ -347,18 +347,18 @@ discard block |
||
| 347 | 347 | } |
| 348 | 348 | } |
| 349 | 349 | } |
| 350 | - if(! $this->getController() && $this->getModule()){ |
|
| 350 | + if (!$this->getController() && $this->getModule()) { |
|
| 351 | 351 | $this->logger->info('After using the request URI the module name is set but the controller is not set so we will use module as the controller'); |
| 352 | 352 | $this->controller = $this->getModule(); |
| 353 | 353 | } |
| 354 | 354 | //did we set the controller, so set the controller path |
| 355 | - if($this->getController() && ! $this->getControllerPath()){ |
|
| 355 | + if ($this->getController() && !$this->getControllerPath()) { |
|
| 356 | 356 | $this->logger->debug('Setting the file path for the controller [' . $this->getController() . ']'); |
| 357 | 357 | //if it is the module controller |
| 358 | - if($this->getModule()){ |
|
| 358 | + if ($this->getModule()) { |
|
| 359 | 359 | $this->controllerPath = Module::findControllerFullPath(ucfirst($this->getController()), $this->getModule()); |
| 360 | 360 | } |
| 361 | - else{ |
|
| 361 | + else { |
|
| 362 | 362 | $this->controllerPath = APPS_CONTROLLER_PATH . ucfirst($this->getController()) . '.php'; |
| 363 | 363 | } |
| 364 | 364 | } |
@@ -368,20 +368,20 @@ discard block |
||
| 368 | 368 | $this->logger->debug('Loading controller [' . $controller . '], the file path is [' . $classFilePath . ']...'); |
| 369 | 369 | $benchmark->mark('ROUTING_PROCESS_END'); |
| 370 | 370 | $e404 = false; |
| 371 | - if(file_exists($classFilePath)){ |
|
| 371 | + if (file_exists($classFilePath)) { |
|
| 372 | 372 | require_once $classFilePath; |
| 373 | - if(! class_exists($controller, false)){ |
|
| 373 | + if (!class_exists($controller, false)) { |
|
| 374 | 374 | $e404 = true; |
| 375 | - $this->logger->info('The controller file [' .$classFilePath. '] exists but does not contain the class [' . $controller . ']'); |
|
| 375 | + $this->logger->info('The controller file [' . $classFilePath . '] exists but does not contain the class [' . $controller . ']'); |
|
| 376 | 376 | } |
| 377 | - else{ |
|
| 377 | + else { |
|
| 378 | 378 | $controllerInstance = new $controller(); |
| 379 | 379 | $controllerMethod = $this->getMethod(); |
| 380 | - if(! method_exists($controllerInstance, $controllerMethod)){ |
|
| 380 | + if (!method_exists($controllerInstance, $controllerMethod)) { |
|
| 381 | 381 | $e404 = true; |
| 382 | 382 | $this->logger->info('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']'); |
| 383 | 383 | } |
| 384 | - else{ |
|
| 384 | + else { |
|
| 385 | 385 | $this->logger->info('Routing data is set correctly now GO!'); |
| 386 | 386 | call_user_func_array(array($controllerInstance, $controllerMethod), $this->getArgs()); |
| 387 | 387 | $obj = & get_instance(); |
@@ -391,12 +391,12 @@ discard block |
||
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | 393 | } |
| 394 | - else{ |
|
| 394 | + else { |
|
| 395 | 395 | $this->logger->info('The controller file path [' . $classFilePath . '] does not exist'); |
| 396 | 396 | $e404 = true; |
| 397 | 397 | } |
| 398 | - if($e404){ |
|
| 399 | - $response =& class_loader('Response', 'classes'); |
|
| 398 | + if ($e404) { |
|
| 399 | + $response = & class_loader('Response', 'classes'); |
|
| 400 | 400 | $response->send404(); |
| 401 | 401 | } |
| 402 | 402 | } |
@@ -103,12 +103,10 @@ discard block |
||
| 103 | 103 | if(! empty($route) && is_array($route)){ |
| 104 | 104 | $this->routes = $route; |
| 105 | 105 | unset($route); |
| 106 | - } |
|
| 107 | - else{ |
|
| 106 | + } else{ |
|
| 108 | 107 | show_error('No routing configuration found in [' . $routesPath . ']'); |
| 109 | 108 | } |
| 110 | - } |
|
| 111 | - else{ |
|
| 109 | + } else{ |
|
| 112 | 110 | show_error('Unable to find the routes configuration file [' . $routesPath . ']'); |
| 113 | 111 | } |
| 114 | 112 | |
@@ -118,8 +116,7 @@ discard block |
||
| 118 | 116 | if($modulesRoutes && is_array($modulesRoutes)){ |
| 119 | 117 | $this->routes = array_merge($this->routes, $modulesRoutes); |
| 120 | 118 | $this->logger->info('Routes for all modules loaded successfully'); |
| 121 | - } |
|
| 122 | - else{ |
|
| 119 | + } else{ |
|
| 123 | 120 | $this->logger->info('No routes found for all modules skipping.'); |
| 124 | 121 | } |
| 125 | 122 | $this->logger->info('The routes configuration are listed below: ' . stringfy_vars($this->routes)); |
@@ -135,8 +132,7 @@ discard block |
||
| 135 | 132 | if($suffix = get_config('url_suffix')){ |
| 136 | 133 | $this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']' ); |
| 137 | 134 | $uri = str_ireplace($suffix, '', $uri); |
| 138 | - } |
|
| 139 | - else{ |
|
| 135 | + } else{ |
|
| 140 | 136 | $this->logger->info('URL suffix is not enabled in the configuration'); |
| 141 | 137 | } |
| 142 | 138 | if(strpos($uri, '?') !== false){ |
@@ -229,8 +225,7 @@ discard block |
||
| 229 | 225 | $this->logger->info('The request URI contains the front controller'); |
| 230 | 226 | array_shift($segment); |
| 231 | 227 | $this->segments = $segment; |
| 232 | - } |
|
| 233 | - else{ |
|
| 228 | + } else{ |
|
| 234 | 229 | $this->logger->info('The request URI does not contain the front controller'); |
| 235 | 230 | } |
| 236 | 231 | $uri = implode('/', $segment); |
@@ -252,8 +247,7 @@ discard block |
||
| 252 | 247 | $this->logger->info('The current request use the module [' .$moduleControllerMethod[0]. ']'); |
| 253 | 248 | $this->module = $moduleControllerMethod[0]; |
| 254 | 249 | $moduleControllerMethod = explode('@', $moduleControllerMethod[1]); |
| 255 | - } |
|
| 256 | - else{ |
|
| 250 | + } else{ |
|
| 257 | 251 | $this->logger->info('The current request does not use the module'); |
| 258 | 252 | $moduleControllerMethod = explode('@', $this->callback[$index]); |
| 259 | 253 | } |
@@ -300,8 +294,7 @@ discard block |
||
| 300 | 294 | } |
| 301 | 295 | //args |
| 302 | 296 | $this->args = $segment; |
| 303 | - } |
|
| 304 | - else{ |
|
| 297 | + } else{ |
|
| 305 | 298 | $this->logger->info('The application contains a loaded module will check if the current request is found in the module list'); |
| 306 | 299 | if(in_array($segment[0], $modules)){ |
| 307 | 300 | $this->logger->info('Found, the current request use the module [' . $segment[0] . ']'); |
@@ -315,8 +308,7 @@ discard block |
||
| 315 | 308 | if(! $path){ |
| 316 | 309 | $this->logger->info('The controller [' . $this->getController() . '] not found in the module, may be will use the module [' . $this->getModule() . '] as controller'); |
| 317 | 310 | $this->controller = $this->getModule(); |
| 318 | - } |
|
| 319 | - else{ |
|
| 311 | + } else{ |
|
| 320 | 312 | $this->controllerPath = $path; |
| 321 | 313 | array_shift($segment); |
| 322 | 314 | } |
@@ -328,8 +320,7 @@ discard block |
||
| 328 | 320 | } |
| 329 | 321 | //the remaining is for args |
| 330 | 322 | $this->args = $segment; |
| 331 | - } |
|
| 332 | - else{ |
|
| 323 | + } else{ |
|
| 333 | 324 | $this->logger->info('The current request information is not found in the module list'); |
| 334 | 325 | //controller |
| 335 | 326 | if(isset($segment[0])){ |
@@ -357,8 +348,7 @@ discard block |
||
| 357 | 348 | //if it is the module controller |
| 358 | 349 | if($this->getModule()){ |
| 359 | 350 | $this->controllerPath = Module::findControllerFullPath(ucfirst($this->getController()), $this->getModule()); |
| 360 | - } |
|
| 361 | - else{ |
|
| 351 | + } else{ |
|
| 362 | 352 | $this->controllerPath = APPS_CONTROLLER_PATH . ucfirst($this->getController()) . '.php'; |
| 363 | 353 | } |
| 364 | 354 | } |
@@ -373,15 +363,13 @@ discard block |
||
| 373 | 363 | if(! class_exists($controller, false)){ |
| 374 | 364 | $e404 = true; |
| 375 | 365 | $this->logger->info('The controller file [' .$classFilePath. '] exists but does not contain the class [' . $controller . ']'); |
| 376 | - } |
|
| 377 | - else{ |
|
| 366 | + } else{ |
|
| 378 | 367 | $controllerInstance = new $controller(); |
| 379 | 368 | $controllerMethod = $this->getMethod(); |
| 380 | 369 | if(! method_exists($controllerInstance, $controllerMethod)){ |
| 381 | 370 | $e404 = true; |
| 382 | 371 | $this->logger->info('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']'); |
| 383 | - } |
|
| 384 | - else{ |
|
| 372 | + } else{ |
|
| 385 | 373 | $this->logger->info('Routing data is set correctly now GO!'); |
| 386 | 374 | call_user_func_array(array($controllerInstance, $controllerMethod), $this->getArgs()); |
| 387 | 375 | $obj = & get_instance(); |
@@ -390,8 +378,7 @@ discard block |
||
| 390 | 378 | $obj->response->renderFinalPage(); |
| 391 | 379 | } |
| 392 | 380 | } |
| 393 | - } |
|
| 394 | - else{ |
|
| 381 | + } else{ |
|
| 395 | 382 | $this->logger->info('The controller file path [' . $classFilePath . '] does not exist'); |
| 396 | 383 | $e404 = true; |
| 397 | 384 | } |
@@ -82,8 +82,7 @@ discard block |
||
| 82 | 82 | if($cookieLang && $this->isValid($cookieLang)){ |
| 83 | 83 | $this->current = $cookieLang; |
| 84 | 84 | $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']'); |
| 85 | - } |
|
| 86 | - else{ |
|
| 85 | + } else{ |
|
| 87 | 86 | $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
| 88 | 87 | $this->current = $this->getDefault(); |
| 89 | 88 | } |
@@ -171,8 +170,7 @@ discard block |
||
| 171 | 170 | } |
| 172 | 171 | if($this->isValid($name)){ |
| 173 | 172 | $this->availables[$name] = $description; |
| 174 | - } |
|
| 175 | - else{ |
|
| 173 | + } else{ |
|
| 176 | 174 | show_error('The language [' . $name . '] is not valid or does not exists.'); |
| 177 | 175 | } |
| 178 | 176 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * For application languages management |
| 29 | 29 | */ |
| 30 | - class Lang{ |
|
| 30 | + class Lang { |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * The supported available language for this application. |
@@ -67,8 +67,8 @@ discard block |
||
| 67 | 67 | /** |
| 68 | 68 | * Construct new Lang instance |
| 69 | 69 | */ |
| 70 | - public function __construct(){ |
|
| 71 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 70 | + public function __construct() { |
|
| 71 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 72 | 72 | $this->logger->setLogger('Library::Lang'); |
| 73 | 73 | |
| 74 | 74 | $this->default = get_config('default_language', 'en'); |
@@ -76,8 +76,8 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | //add the supported languages ('key', 'display name') |
| 78 | 78 | $languages = get_config('languages', null); |
| 79 | - if(! empty($languages)){ |
|
| 80 | - foreach($languages as $key => $displayName){ |
|
| 79 | + if (!empty($languages)) { |
|
| 80 | + foreach ($languages as $key => $displayName) { |
|
| 81 | 81 | $this->addLang($key, $displayName); |
| 82 | 82 | } |
| 83 | 83 | } |
@@ -87,15 +87,15 @@ discard block |
||
| 87 | 87 | $language = null; |
| 88 | 88 | //if the language exists in cookie use it |
| 89 | 89 | $cfgKey = get_config('language_cookie_name'); |
| 90 | - $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']'); |
|
| 90 | + $this->logger->debug('Getting current language from cookie [' . $cfgKey . ']'); |
|
| 91 | 91 | $objCookie = & class_loader('Cookie'); |
| 92 | 92 | $cookieLang = $objCookie->get($cfgKey); |
| 93 | - if($cookieLang && $this->isValid($cookieLang)){ |
|
| 93 | + if ($cookieLang && $this->isValid($cookieLang)) { |
|
| 94 | 94 | $this->current = $cookieLang; |
| 95 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']'); |
|
| 95 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is valid so we will set the language using the cookie value [' . $cookieLang . ']'); |
|
| 96 | 96 | } |
| 97 | - else{ |
|
| 98 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
|
| 97 | + else { |
|
| 98 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is not set, use the default value [' . $this->getDefault() . ']'); |
|
| 99 | 99 | $this->current = $this->getDefault(); |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * |
| 106 | 106 | * @return array the language message list |
| 107 | 107 | */ |
| 108 | - public function getAll(){ |
|
| 108 | + public function getAll() { |
|
| 109 | 109 | return $this->languages; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * @param string $key the language key to identify |
| 116 | 116 | * @param string $value the language message value |
| 117 | 117 | */ |
| 118 | - public function set($key, $value){ |
|
| 118 | + public function set($key, $value) { |
|
| 119 | 119 | $this->languages[$key] = $value; |
| 120 | 120 | } |
| 121 | 121 | |
@@ -127,11 +127,11 @@ discard block |
||
| 127 | 127 | * |
| 128 | 128 | * @return string the language message value |
| 129 | 129 | */ |
| 130 | - public function get($key, $default = 'LANGUAGE_ERROR'){ |
|
| 131 | - if(isset($this->languages[$key])){ |
|
| 130 | + public function get($key, $default = 'LANGUAGE_ERROR') { |
|
| 131 | + if (isset($this->languages[$key])) { |
|
| 132 | 132 | return $this->languages[$key]; |
| 133 | 133 | } |
| 134 | - $this->logger->warning('Language key [' .$key. '] does not exist use the default value [' .$default. ']'); |
|
| 134 | + $this->logger->warning('Language key [' . $key . '] does not exist use the default value [' . $default . ']'); |
|
| 135 | 135 | return $default; |
| 136 | 136 | } |
| 137 | 137 | |
@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | * |
| 143 | 143 | * @return boolean true if the language directory exists, false or not |
| 144 | 144 | */ |
| 145 | - public function isValid($language){ |
|
| 145 | + public function isValid($language) { |
|
| 146 | 146 | $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH); |
| 147 | - foreach($searchDir as $dir){ |
|
| 148 | - if(file_exists($dir . $language) && is_dir($dir . $language)){ |
|
| 147 | + foreach ($searchDir as $dir) { |
|
| 148 | + if (file_exists($dir . $language) && is_dir($dir . $language)) { |
|
| 149 | 149 | return true; |
| 150 | 150 | } |
| 151 | 151 | } |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @return string the default language |
| 159 | 159 | */ |
| 160 | - public function getDefault(){ |
|
| 160 | + public function getDefault() { |
|
| 161 | 161 | return $this->default; |
| 162 | 162 | } |
| 163 | 163 | |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * |
| 167 | 167 | * @return string the current language |
| 168 | 168 | */ |
| 169 | - public function getCurrent(){ |
|
| 169 | + public function getCurrent() { |
|
| 170 | 170 | return $this->current; |
| 171 | 171 | } |
| 172 | 172 | |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | * @param string $name the short language name like "en", "fr". |
| 177 | 177 | * @param string $description the human readable description of this language |
| 178 | 178 | */ |
| 179 | - public function addLang($name, $description){ |
|
| 180 | - if(isset($this->availables[$name])){ |
|
| 179 | + public function addLang($name, $description) { |
|
| 180 | + if (isset($this->availables[$name])) { |
|
| 181 | 181 | return; //already added cost in performance |
| 182 | 182 | } |
| 183 | - if($this->isValid($name)){ |
|
| 183 | + if ($this->isValid($name)) { |
|
| 184 | 184 | $this->availables[$name] = $description; |
| 185 | 185 | } |
| 186 | - else{ |
|
| 186 | + else { |
|
| 187 | 187 | show_error('The language [' . $name . '] is not valid or does not exists.'); |
| 188 | 188 | } |
| 189 | 189 | } |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | * |
| 194 | 194 | * @return array the list of the application language |
| 195 | 195 | */ |
| 196 | - public function getSupported(){ |
|
| 196 | + public function getSupported() { |
|
| 197 | 197 | return $this->availables; |
| 198 | 198 | } |
| 199 | 199 | |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * |
| 203 | 203 | * @param array $langs the languages array of the messages to be added |
| 204 | 204 | */ |
| 205 | - public function addLangMessages(array $langs){ |
|
| 205 | + public function addLangMessages(array $langs) { |
|
| 206 | 206 | foreach ($langs as $key => $value) { |
| 207 | 207 | $this->set($key, $value); |
| 208 | 208 | } |