Test Failed
Push — 1.0.0-dev ( aa6afc...324983 )
by nguereza
04:25
created
classes/views/home.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -8,13 +8,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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>
Please login to merge, or discard this patch.
index.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -243,7 +243,7 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
core/classes/cache/CacheInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
core/classes/Url.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -25,15 +25,15 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
core/classes/Session.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 		}
Please login to merge, or discard this patch.
core/classes/Router.php 1 patch
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -92,39 +92,39 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 		}
Please login to merge, or discard this patch.
core/classes/Security.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class Security{
27
+	class Security {
28 28
 		
29 29
 		/**
30 30
 		 * The logger instance
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 		 * Get the logger singleton instance
37 37
 		 * @return Log the logger instance
38 38
 		 */
39
-		private static function getLogger(){
40
-			if(static::$logger == null){
41
-				static::$logger[0] =& class_loader('Log', 'classes');
39
+		private static function getLogger() {
40
+			if (static::$logger == null) {
41
+				static::$logger[0] = & class_loader('Log', 'classes');
42 42
 				static::$logger[0]->setLogger('Library::Security');
43 43
 			}
44 44
 			return static::$logger[0];
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 		 * This method is used to generate the CSRF token
50 50
 		 * @return string the generated CSRF token
51 51
 		 */
52
-		public static function generateCSRF(){
52
+		public static function generateCSRF() {
53 53
 			$logger = static::getLogger();
54 54
 			$logger->debug('Generation of CSRF ...');
55 55
 			
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
 			$expire = get_config('csrf_expire', 60);
58 58
 			$keyExpire = 'csrf_expire';
59 59
 			$currentTime = time();
60
-			if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){
60
+			if (Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime) {
61 61
 				$logger->info('The CSRF token not yet expire just return it');
62 62
 				return Session::get($key);
63 63
 			}
64
-			else{
64
+			else {
65 65
 				$newTime = $currentTime + $expire;
66 66
 				$token = sha1(uniqid()) . sha1(uniqid());
67
-				$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']');
67
+				$logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . '], token [' . $token . ']');
68 68
 				Session::set($keyExpire, $newTime);
69 69
 				Session::set($key, $token);
70 70
 				return Session::get($key);
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		 * This method is used to check the CSRF if is valid, not yet expire, etc.
76 76
 		 * @return boolean true if valid, false if not valid
77 77
 		 */
78
-		public static function validateCSRF(){
78
+		public static function validateCSRF() {
79 79
 			$logger = static::getLogger();
80 80
 			$logger->debug('Validation of CSRF ...');
81 81
 				
@@ -83,23 +83,23 @@  discard block
 block discarded – undo
83 83
 			$expire = get_config('csrf_expire', 60);
84 84
 			$keyExpire = 'csrf_expire';
85 85
 			$currentTime = time();
86
-			$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. ']');
87
-			if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){
86
+			$logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . ']');
87
+			if (!Session::exists($key) || Session::get($keyExpire) <= $currentTime) {
88 88
 				$logger->warning('The CSRF session data is not valide');
89 89
 				return false;
90 90
 			}
91
-			else{
91
+			else {
92 92
 				//perform form data
93 93
 				//need use request->query() for best retrieve
94 94
 				//super instance
95 95
 				$obj = & get_instance();
96 96
 				$token = $obj->request->query($key);
97
-				if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){
98
-					$logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job');
97
+				if (!$token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime) {
98
+					$logger->warning('The CSRF data [' . $token . '] is not valide may be attacker do his job');
99 99
 					return false;
100 100
 				}
101
-				else{
102
-					$logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue');
101
+				else {
102
+					$logger->info('The CSRF data [' . $token . '] is valide the form data is safe continue');
103 103
 					//remove the token from session
104 104
 					Session::clear($key);
105 105
 					Session::clear($keyExpire);
@@ -111,24 +111,24 @@  discard block
 block discarded – undo
111 111
 		/**
112 112
 		 * This method is used to check the whitelist IP address access
113 113
 		 */
114
-		 public static function checkWhiteListIpAccess(){
114
+		 public static function checkWhiteListIpAccess() {
115 115
 			$logger = static::getLogger();
116 116
 			$logger->debug('Validation of the IP address access ...');
117 117
 			$logger->debug('Check if whitelist IP access is enabled in the configuration ...');
118 118
 			$isEnable = get_config('white_list_ip_enable', false);
119
-			if($isEnable){
119
+			if ($isEnable) {
120 120
 				$logger->info('Whitelist IP access is enabled in the configuration');
121 121
 				$list = get_config('white_list_ip_addresses', array());
122
-				if(! empty($list)){
122
+				if (!empty($list)) {
123 123
 					//Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing
124 124
 					require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
125 125
 					$ip = get_ip();
126
-					if(count($list) == 1 && $list[0] == '*' || in_array($ip, $list)){
126
+					if (count($list) == 1 && $list[0] == '*' || in_array($ip, $list)) {
127 127
 						$logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP');
128 128
 						//wildcard to access all ip address
129 129
 						return;
130 130
 					}
131
-					else{
131
+					else {
132 132
 						// go through all whitelisted ips
133 133
 						foreach ($list as $ipaddr) {
134 134
 							// find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*")
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 					}
155 155
 				}
156 156
 			}
157
-			else{
157
+			else {
158 158
 				$logger->info('Whitelist IP access is not enabled in the configuration, ignore checking');
159 159
 			}
160 160
 		 }
Please login to merge, or discard this patch.
core/classes/EventDispatcher.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * also to dispatch the event
30 30
 	 */
31 31
 	
32
-	class EventDispatcher{
32
+	class EventDispatcher {
33 33
 		
34 34
 		/**
35 35
 		 * The list of the registered listeners
@@ -44,8 +44,8 @@  discard block
 block discarded – undo
44 44
 		 */
45 45
 		private $logger;
46 46
 
47
-		public function __construct(){
48
-			$this->logger =& class_loader('Log', 'classes');
47
+		public function __construct() {
48
+			$this->logger = & class_loader('Log', 'classes');
49 49
 			$this->logger->setLogger('Library::EventDispatcher');
50 50
 		}
51 51
 
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
 		 * @param string   $eventName the name of the event to register for
55 55
 		 * @param callable $listener  the function or class method to receive the event information after dispatch
56 56
 		 */
57
-		public function addListener($eventName, callable $listener){
58
-			$this->logger->debug('Adding new Event Listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
59
-			if(! isset($this->listeners[$eventName])){
57
+		public function addListener($eventName, callable $listener) {
58
+			$this->logger->debug('Adding new Event Listener for the event name [' . $eventName . '], listener [' . stringfy_vars($listener) . ']');
59
+			if (!isset($this->listeners[$eventName])) {
60 60
 				$this->logger->info('This event does not have the registered event listener before, adding new one');
61 61
 				$this->listeners[$eventName] = array();
62 62
 			}
63
-			else{
63
+			else {
64 64
 				$this->logger->info('This event already have the registered listener, add this listener to the list');
65 65
 			}
66 66
 			$this->listeners[$eventName][] = $listener;
@@ -71,19 +71,19 @@  discard block
 block discarded – undo
71 71
 		 * @param  string   $eventName the event name
72 72
 		 * @param  callable $listener  the listener callback
73 73
 		 */
74
-		public function removeListener($eventName, callable $listener){
75
-			$this->logger->debug('Removing of the Event Listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
76
-			if(isset($this->listeners[$eventName])){
74
+		public function removeListener($eventName, callable $listener) {
75
+			$this->logger->debug('Removing of the Event Listener, the event name [' . $eventName . '], listener [' . stringfy_vars($listener) . ']');
76
+			if (isset($this->listeners[$eventName])) {
77 77
 				$this->logger->info('This event have the listeners, check if this listener exists');
78
-				if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){
79
-					$this->logger->info('Found the listener at index [' .$index. '] remove it');
78
+				if (false !== $index = array_search($listener, $this->listeners[$eventName], true)) {
79
+					$this->logger->info('Found the listener at index [' . $index . '] remove it');
80 80
 					unset($this->listeners[$eventName][$index]);
81 81
 				}
82
-				else{
82
+				else {
83 83
 					$this->logger->info('Cannot found this listener in the event listener list');
84 84
 				}
85 85
 			}
86
-			else{
86
+			else {
87 87
 				$this->logger->info('This event does not have this listener ignore remove');
88 88
 			}
89 89
 		}
@@ -93,13 +93,13 @@  discard block
 block discarded – undo
93 93
 		 * remove all listeners for this event
94 94
 		 * @param  string $eventName the event name
95 95
 		 */
96
-		public function removeAllListener($eventName = null){
97
-			$this->logger->debug('Removing of all Event Listener, the event name [' .$eventName. ']');
98
-			if($eventName != null && isset($this->listeners[$eventName])){
96
+		public function removeAllListener($eventName = null) {
97
+			$this->logger->debug('Removing of all Event Listener, the event name [' . $eventName . ']');
98
+			if ($eventName != null && isset($this->listeners[$eventName])) {
99 99
 				$this->logger->info('The Event name is set of exist in the listener just remove all Event Listener for this event');
100 100
 				unset($this->listeners[$eventName]);
101 101
 			}
102
-			else{
102
+			else {
103 103
 				$this->logger->info('The Event name is not set or does not exist in the listener, so remove all Event Listener');
104 104
 				$this->listeners = array();
105 105
 			}
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 		 * @param string $eventName the event name
111 111
 		 * @return array the listeners for this event or empty array if this event does not contain any listener
112 112
 		 */
113
-		public function getListeners($eventName){
113
+		public function getListeners($eventName) {
114 114
 			return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array();
115 115
 		}
116 116
 		
@@ -119,21 +119,21 @@  discard block
 block discarded – undo
119 119
 		 * @param  mixed|Event $event  the event information
120 120
 		 * @return void|Event if event need return, will return the final Event object.
121 121
 		 */	
122
-		public function dispatch($event){
123
-			if(! $event || !$event instanceof Event){
122
+		public function dispatch($event) {
123
+			if (!$event || !$event instanceof Event) {
124 124
 				$this->logger->info('The event is not set or is not an instance of "Event" create the default "Event" object to use instead of.');
125 125
 				$event = new Event((string) $event);
126 126
 			}			
127
-			$this->logger->debug('Dispatch to the Event Listener, the event [' .stringfy_vars($event). ']');
128
-			if(isset($event->stop) && $event->stop){
127
+			$this->logger->debug('Dispatch to the Event Listener, the event [' . stringfy_vars($event) . ']');
128
+			if (isset($event->stop) && $event->stop) {
129 129
 				$this->logger->info('This event need stopped, no need call any listener');
130 130
 				return;
131 131
 			}
132
-			if($event->returnBack){
132
+			if ($event->returnBack) {
133 133
 				$this->logger->info('This event need return back, return the result for future use');
134 134
 				return $this->dispatchToListerners($event);
135 135
 			}
136
-			else{
136
+			else {
137 137
 				$this->logger->info('This event no need return back the result, just dispatch it');
138 138
 				$this->dispatchToListerners($event);
139 139
 			}
@@ -144,38 +144,38 @@  discard block
 block discarded – undo
144 144
 		 * @param  Event $event  the event information
145 145
 		 * @return void|Event if event need return, will return the final Event instance.
146 146
 		 */	
147
-		private function dispatchToListerners(Event $event){
147
+		private function dispatchToListerners(Event $event) {
148 148
 			$eBackup = $event;
149 149
 			$list = $this->getListeners($event->name);
150
-			if(empty($list)){
151
-				$this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.');
152
-				if($event->returnBack){
150
+			if (empty($list)) {
151
+				$this->logger->info('No event listener is registered for the event [' . $event->name . '] skipping.');
152
+				if ($event->returnBack) {
153 153
 					return $event;
154 154
 				}
155 155
 				return;
156 156
 			}
157
-			else{
158
-				$this->logger->info('Found the registered Event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list));
157
+			else {
158
+				$this->logger->info('Found the registered Event listener for the event [' . $event->name . '] the list are: ' . stringfy_vars($list));
159 159
 			}
160
-			foreach($list as $listener){
161
-				if($eBackup->returnBack){
160
+			foreach ($list as $listener) {
161
+				if ($eBackup->returnBack) {
162 162
 					$returnedEvent = call_user_func_array($listener, array($event));
163
-					if($returnedEvent instanceof Event){
163
+					if ($returnedEvent instanceof Event) {
164 164
 						$event = $returnedEvent;
165 165
 					}
166
-					else{
167
-						show_error('This event [' .$event->name. '] need you return the event object after processing');
166
+					else {
167
+						show_error('This event [' . $event->name . '] need you return the event object after processing');
168 168
 					}
169 169
 				}
170
-				else{
170
+				else {
171 171
 					call_user_func_array($listener, array($event));
172 172
 				}
173
-				if($event->stop){
173
+				if ($event->stop) {
174 174
 					break;
175 175
 				}
176 176
 			}
177 177
 			//only test for original event may be during the flow some listeners change this parameter
178
-			if($eBackup->returnBack){
178
+			if ($eBackup->returnBack) {
179 179
 				return $event;
180 180
 			}
181 181
 		}
Please login to merge, or discard this patch.
core/classes/Response.php 1 patch
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class Response{
27
+	class Response {
28 28
 
29 29
 		/**
30 30
 		 * The list of request header to send with response
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
 		/**
66 66
 		 * Construct new response instance
67 67
 		 */
68
-		public function __construct(){
69
-			$this->_currentUrl =  (! empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '' )
70
-					. (! empty($_SERVER['QUERY_STRING']) ? ('?' . $_SERVER['QUERY_STRING']) : '' );
68
+		public function __construct() {
69
+			$this->_currentUrl = (!empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '')
70
+					. (!empty($_SERVER['QUERY_STRING']) ? ('?' . $_SERVER['QUERY_STRING']) : '');
71 71
 					
72 72
 			$this->_currentUrlCacheKey = md5($this->_currentUrl);
73 73
 			
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
 		 * Get the logger singleton instance
83 83
 		 * @return Log the logger instance
84 84
 		 */
85
-		private static function getLogger(){
86
-			if(static::$logger == null){
87
-				static::$logger[0] =& class_loader('Log', 'classes');
85
+		private static function getLogger() {
86
+			if (static::$logger == null) {
87
+				static::$logger[0] = & class_loader('Log', 'classes');
88 88
 				static::$logger[0]->setLogger('Library::Response');
89 89
 			}
90 90
 			return static::$logger[0];
@@ -95,12 +95,12 @@  discard block
 block discarded – undo
95 95
 		 * @param  integer $httpCode the HTTP status code
96 96
 		 * @param  array   $headers   the additional headers to add to the existing headers list
97 97
 		 */
98
-		public static function sendHeaders($httpCode = 200, array $headers = array()){
98
+		public static function sendHeaders($httpCode = 200, array $headers = array()) {
99 99
 			set_http_status_header($httpCode);
100 100
 			static::setHeaders($headers);
101
-			if(! headers_sent()){
102
-				foreach(static::getHeaders() as $key => $value){
103
-					header($key .': '.$value);
101
+			if (!headers_sent()) {
102
+				foreach (static::getHeaders() as $key => $value) {
103
+					header($key . ': ' . $value);
104 104
 				}
105 105
 			}
106 106
 		}
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 		 * Get the list of the headers
110 110
 		 * @return array the headers list
111 111
 		 */
112
-		public static function getHeaders(){
112
+		public static function getHeaders() {
113 113
 			return static::$headers;
114 114
 		}
115 115
 
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 		 * @param  string $name the header name
119 119
 		 * @return string       the header value
120 120
 		 */
121
-		public static function getHeader($name){
121
+		public static function getHeader($name) {
122 122
 			return array_key_exists($name, static::$headers) ? static::$headers[$name] : null;
123 123
 		}
124 124
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 		 * @param string $name  the header name
129 129
 		 * @param string $value the header value to be set
130 130
 		 */
131
-		public static function setHeader($name, $value){
131
+		public static function setHeader($name, $value) {
132 132
 			static::$headers[$name] = $value;
133 133
 		}
134 134
 
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 		 * @param array $headers the list of the headers to set. 
138 138
 		 * Note: this will merge with the existing headers
139 139
 		 */
140
-		public static function setHeaders(array $headers){
140
+		public static function setHeaders(array $headers) {
141 141
 			static::$headers = array_merge(static::getHeaders(), $headers);
142 142
 		}
143 143
 		
@@ -145,17 +145,17 @@  discard block
 block discarded – undo
145 145
 		 * Redirect user in the specified page
146 146
 		 * @param  string $path the URL or URI to be redirect to
147 147
 		 */
148
-		public static function redirect($path = ''){
148
+		public static function redirect($path = '') {
149 149
 			$logger = static::getLogger();
150 150
 			$url = Url::site_url($path);
151
-			$logger->info('Redirect to URL [' .$url. ']');
152
-			if(! headers_sent()){
153
-				header('Location: '.$url);
151
+			$logger->info('Redirect to URL [' . $url . ']');
152
+			if (!headers_sent()) {
153
+				header('Location: ' . $url);
154 154
 				exit;
155 155
 			}
156
-			else{
156
+			else {
157 157
 				echo '<script>
158
-						location.href = "'.$url.'";
158
+						location.href = "'.$url . '";
159 159
 					</script>';
160 160
 			}
161 161
 		}
@@ -168,10 +168,10 @@  discard block
 block discarded – undo
168 168
 		 * @return void|string          if $return is true will return the view content otherwise
169 169
 		 * will display the view content.
170 170
 		 */
171
-		public function render($view, $data = array(), $return = false){
171
+		public function render($view, $data = array(), $return = false) {
172 172
 			$logger = static::getLogger();
173 173
 			//convert data to an array
174
-			$data = ! is_array($data) ? (array) $data : $data;
174
+			$data = !is_array($data) ? (array) $data : $data;
175 175
 			$view = str_ireplace('.php', '', $view);
176 176
 			$view = trim($view, '/\\');
177 177
 			$viewFile = $view . '.php';
@@ -180,42 +180,42 @@  discard block
 block discarded – undo
180 180
 			//super instance
181 181
 			$obj = & get_instance();
182 182
 			
183
-			if(Module::hasModule()){
183
+			if (Module::hasModule()) {
184 184
 				//check in module first
185 185
 				$logger->debug('Checking the view [' . $view . '] from module list ...');
186 186
 				$mod = null;
187 187
 				//check if the request class contains module name
188
-				if(strpos($view, '/') !== false){
188
+				if (strpos($view, '/') !== false) {
189 189
 					$viewPath = explode('/', $view);
190
-					if(isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())){
190
+					if (isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())) {
191 191
 						$mod = $viewPath[0];
192 192
 						array_shift($viewPath);
193 193
 						$view = implode('/', $viewPath);
194 194
 						$viewFile = $view . '.php';
195 195
 					}
196 196
 				}
197
-				if(! $mod && !empty($obj->moduleName)){
197
+				if (!$mod && !empty($obj->moduleName)) {
198 198
 					$mod = $obj->moduleName;
199 199
 				}
200
-				if($mod){
200
+				if ($mod) {
201 201
 					$moduleViewPath = Module::findViewFullPath($view, $mod);
202
-					if($moduleViewPath){
202
+					if ($moduleViewPath) {
203 203
 						$path = $moduleViewPath;
204
-						$logger->info('Found view [' . $view . '] in module [' .$mod. '], the file path is [' .$moduleViewPath. '] we will used it');
204
+						$logger->info('Found view [' . $view . '] in module [' . $mod . '], the file path is [' . $moduleViewPath . '] we will used it');
205 205
 					}
206
-					else{
207
-						$logger->info('Cannot find view [' . $view . '] in module [' .$mod. '] using the default location');
206
+					else {
207
+						$logger->info('Cannot find view [' . $view . '] in module [' . $mod . '] using the default location');
208 208
 					}
209 209
 				}
210
-				else{
210
+				else {
211 211
 					$logger->info('The current request does not use module using the default location.');
212 212
 				}
213 213
 			}
214 214
 			$logger->info('The view file path to be loaded is [' . $path . ']');
215 215
 			$found = false;
216
-			if(file_exists($path)){
217
-				foreach(get_object_vars($obj) as $key => $value){
218
-					if(! isset($this->{$key})){
216
+			if (file_exists($path)) {
217
+				foreach (get_object_vars($obj) as $key => $value) {
218
+					if (!isset($this->{$key})) {
219 219
 						$this->{$key} = & $obj->{$key};
220 220
 					}
221 221
 				}
@@ -224,39 +224,39 @@  discard block
 block discarded – undo
224 224
 				//need use require() instead of require_once because can load this view many time
225 225
 				require $path;
226 226
 				$content = ob_get_clean();
227
-				if($return){
227
+				if ($return) {
228 228
 					return $content;
229 229
 				}
230 230
 				$this->_pageRender .= $content;
231 231
 				$found = true;
232 232
 			}
233
-			if(! $found){
234
-				show_error('Unable to find view [' .$view . ']');
233
+			if (!$found) {
234
+				show_error('Unable to find view [' . $view . ']');
235 235
 			}
236 236
 		}
237 237
 		
238 238
 		/**
239 239
 		* Send the final page output to user
240 240
 		*/
241
-		public function renderFinalPage(){
241
+		public function renderFinalPage() {
242 242
 			$logger = static::getLogger();
243 243
 			$obj = & get_instance();
244 244
 			$cachePageStatus = get_config('cache_enable', false) && !empty($obj->view_cache_enable);
245 245
 			$dispatcher = $obj->eventdispatcher;
246 246
 			$content = $this->_pageRender;
247
-			if(! $content){
247
+			if (!$content) {
248 248
 				$logger->warning('The final view content is empty.');
249 249
 				return;
250 250
 			}
251 251
 			//dispatch
252 252
 			$event = $dispatcher->dispatch(new Event('FINAL_VIEW_READY', $content, true));
253
-			$content = ! empty($event->payload) ? $event->payload : null;
254
-			if(empty($content)){
253
+			$content = !empty($event->payload) ? $event->payload : null;
254
+			if (empty($content)) {
255 255
 				$logger->warning('The view content is empty after dispatch to Event Listeners.');
256 256
 			}
257 257
 			
258 258
 			//check whether need save the page into cache.
259
-			if($cachePageStatus){
259
+			if ($cachePageStatus) {
260 260
 				//current page URL
261 261
 				$url = $this->_currentUrl;
262 262
 				//Cache view Time to live in second
@@ -271,14 +271,14 @@  discard block
 block discarded – undo
271 271
 				
272 272
 				//get the cache information to prepare header to send to browser
273 273
 				$cacheInfo = $cacheInstance->getInfo($cacheKey);
274
-				if($cacheInfo){
274
+				if ($cacheInfo) {
275 275
 					$lastModified = $cacheInfo['mtime'];
276 276
 					$expire = $cacheInfo['expire'];
277 277
 					$maxAge = $expire - time();
278 278
 					static::setHeader('Pragma', 'public');
279 279
 					static::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public');
280
-					static::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT');
281
-					static::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT');	
280
+					static::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT');
281
+					static::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');	
282 282
 				}
283 283
 			}
284 284
 			
@@ -289,10 +289,10 @@  discard block
 block discarded – undo
289 289
 			$content = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsedTime, $memoryUsage), $content);
290 290
 			
291 291
 			//compress the output if is available
292
-			if (static::$_canCompressOutput){
292
+			if (static::$_canCompressOutput) {
293 293
 				ob_start('ob_gzhandler');
294 294
 			}
295
-			else{
295
+			else {
296 296
 				ob_start();
297 297
 			}
298 298
 			static::sendHeaders(200);
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 		/**
304 304
 		* Send the final page output to user if is cached
305 305
 		*/
306
-		public function renderFinalPageFromCache(&$cache){
306
+		public function renderFinalPageFromCache(&$cache) {
307 307
 			$logger = static::getLogger();
308 308
 			$url = $this->_currentUrl;					
309 309
 			//the current page cache key for identification
@@ -312,25 +312,25 @@  discard block
 block discarded – undo
312 312
 			$logger->debug('Checking if the page content for the URL [' . $url . '] is cached ...');
313 313
 			//get the cache information to prepare header to send to browser
314 314
 			$cacheInfo = $cache->getInfo($pageCacheKey);
315
-			if($cacheInfo){
315
+			if ($cacheInfo) {
316 316
 				$lastModified = $cacheInfo['mtime'];
317 317
 				$expire = $cacheInfo['expire'];
318 318
 				$maxAge = $expire - $_SERVER['REQUEST_TIME'];
319 319
 				static::setHeader('Pragma', 'public');
320 320
 				static::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public');
321
-				static::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT');
322
-				static::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT');
323
-				if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
321
+				static::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT');
322
+				static::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');
323
+				if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
324 324
 					$logger->info('The cache page content is not yet expire for the URL [' . $url . '] send 304 header to browser');
325 325
 					static::sendHeaders(304);
326 326
 					exit;
327 327
 				}
328
-				else{
328
+				else {
329 329
 					$logger->info('The cache page content is expired or the browser don\'t send the HTTP_IF_MODIFIED_SINCE header for the URL [' . $url . '] send cache headers to tell the browser');
330 330
 					static::sendHeaders(200);
331 331
 					//get the cache content
332 332
 					$content = $cache->get($pageCacheKey);
333
-					if($content){
333
+					if ($content) {
334 334
 						$logger->info('The page content for the URL [' . $url . '] already cached just display it');
335 335
 						//load benchmark class
336 336
 						$benchmark = & class_loader('Benchmark');
@@ -343,17 +343,17 @@  discard block
 block discarded – undo
343 343
 						
344 344
 						///display the final output
345 345
 						//compress the output if is available
346
-						if (static::$_canCompressOutput){
346
+						if (static::$_canCompressOutput) {
347 347
 							ob_start('ob_gzhandler');
348 348
 						}
349
-						else{
349
+						else {
350 350
 							ob_start();
351 351
 						}
352 352
 						echo $content;
353 353
 						@ob_end_flush();
354 354
 						exit;
355 355
 					}
356
-					else{
356
+					else {
357 357
 						$logger->info('The page cache content for the URL [' . $url . '] is not valid may be already expired');
358 358
 						$cache->delete($pageCacheKey);
359 359
 					}
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 		* Get the final page to be rendered
366 366
 		* @return string
367 367
 		*/
368
-		public function getFinalPageRendered(){
368
+		public function getFinalPageRendered() {
369 369
 			return $this->_pageRender;
370 370
 		}
371 371
 
@@ -373,14 +373,14 @@  discard block
 block discarded – undo
373 373
 		 * Send the HTTP 404 error if can not found the 
374 374
 		 * routing information for the current request
375 375
 		 */
376
-		public static function send404(){
376
+		public static function send404() {
377 377
 			/********* for logs **************/
378 378
 			//can't use $obj = & get_instance()  here because the global super object will be available until
379 379
 			//the main controller is loaded even for Loader::library('xxxx');
380 380
 			$logger = static::getLogger();
381
-			$request =& class_loader('Request', 'classes');
382
-			$userAgent =& class_loader('Browser');
383
-			$browser = $userAgent->getPlatform().', '.$userAgent->getBrowser().' '.$userAgent->getVersion();
381
+			$request = & class_loader('Request', 'classes');
382
+			$userAgent = & class_loader('Browser');
383
+			$browser = $userAgent->getPlatform() . ', ' . $userAgent->getBrowser() . ' ' . $userAgent->getVersion();
384 384
 			
385 385
 			//here can't use Loader::functions just include the helper manually
386 386
 			require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
@@ -390,12 +390,12 @@  discard block
 block discarded – undo
390 390
 			$logger->error($str);
391 391
 			/***********************************/
392 392
 			$path = CORE_VIEWS_PATH . '404.php';
393
-			if(file_exists($path)){
393
+			if (file_exists($path)) {
394 394
 				//compress the output if is available
395
-				if (static::$_canCompressOutput){
395
+				if (static::$_canCompressOutput) {
396 396
 					ob_start('ob_gzhandler');
397 397
 				}
398
-				else{
398
+				else {
399 399
 					ob_start();
400 400
 				}
401 401
 				require_once $path;
@@ -403,8 +403,8 @@  discard block
 block discarded – undo
403 403
 				static::sendHeaders(404);
404 404
 				echo $output;
405 405
 			}
406
-			else{
407
-				show_error('The 404 view [' .$path. '] does not exist');
406
+			else {
407
+				show_error('The 404 view [' . $path . '] does not exist');
408 408
 			}
409 409
 		}
410 410
 
@@ -412,14 +412,14 @@  discard block
 block discarded – undo
412 412
 		 * Display the error to user
413 413
 		 * @param  array  $data the error information
414 414
 		 */
415
-		public static function sendError(array $data = array()){
415
+		public static function sendError(array $data = array()) {
416 416
 			$path = CORE_VIEWS_PATH . 'errors.php';
417
-			if(file_exists($path)){
417
+			if (file_exists($path)) {
418 418
 				//compress the output if exists
419
-				if (static::$_canCompressOutput){
419
+				if (static::$_canCompressOutput) {
420 420
 					ob_start('ob_gzhandler');
421 421
 				}
422
-				else{
422
+				else {
423 423
 					ob_start();
424 424
 				}
425 425
 				extract($data);
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 				static::sendHeaders(503);
429 429
 				echo $output;
430 430
 			}
431
-			else{
431
+			else {
432 432
 				//can't use show_error() at this time because some dependencies not yet loaded and to prevent loop
433 433
 				set_http_status_header(503);
434 434
 				echo 'The error view [' . $path . '] does not exist';
Please login to merge, or discard this patch.