@@ -22,7 +22,7 @@ |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | |
27 | 27 | /** |
28 | 28 | * DB session handler class |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | protected $sessionTableColumns = array(); |
47 | 47 | |
48 | - public function __construct(Database $db = null){ |
|
48 | + public function __construct(Database $db = null) { |
|
49 | 49 | parent::__construct($db); |
50 | 50 | } |
51 | 51 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * Return the session database table columns |
54 | 54 | * @return array |
55 | 55 | */ |
56 | - public function getSessionTableColumns(){ |
|
56 | + public function getSessionTableColumns() { |
|
57 | 57 | return $this->sessionTableColumns; |
58 | 58 | } |
59 | 59 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * Set the session database table columns |
62 | 62 | * @param array $columns the columns definition |
63 | 63 | */ |
64 | - public function setSessionTableColumns(array $columns){ |
|
64 | + public function setSessionTableColumns(array $columns) { |
|
65 | 65 | $this->sessionTableColumns = $columns; |
66 | 66 | return $this; |
67 | 67 | } |
@@ -22,7 +22,7 @@ |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | |
27 | 27 | |
28 | 28 | class Url{ |
@@ -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)){ |
@@ -22,7 +22,7 @@ |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | class Session{ |
27 | 27 | |
28 | 28 | /** |
@@ -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 | } |
@@ -22,23 +22,23 @@ discard block |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | |
27 | 27 | class Router { |
28 | 28 | |
29 | 29 | /** |
30 | - * @var array $pattern: The list of URIs to validate against |
|
31 | - */ |
|
30 | + * @var array $pattern: The list of URIs to validate against |
|
31 | + */ |
|
32 | 32 | private $pattern = array(); |
33 | 33 | |
34 | 34 | /** |
35 | - * @var array $callback: The list of callback to call |
|
36 | - */ |
|
35 | + * @var array $callback: The list of callback to call |
|
36 | + */ |
|
37 | 37 | private $callback = array(); |
38 | 38 | |
39 | 39 | /** |
40 | - * @var string $uriTrim: The char to remove from the URIs |
|
41 | - */ |
|
40 | + * @var string $uriTrim: The char to remove from the URIs |
|
41 | + */ |
|
42 | 42 | protected $uriTrim = '/\^$'; |
43 | 43 | |
44 | 44 | /** |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function __construct(){ |
96 | 96 | $this->logger =& class_loader('Log', 'classes'); |
97 | - $this->logger->setLogger('Library::Router'); |
|
98 | - $routesPath = CONFIG_PATH . 'routes.php'; |
|
99 | - $this->logger->debug('Loading of routes configuration file --> ' . $routesPath . ' ...'); |
|
97 | + $this->logger->setLogger('Library::Router'); |
|
98 | + $routesPath = CONFIG_PATH . 'routes.php'; |
|
99 | + $this->logger->debug('Loading of routes configuration file --> ' . $routesPath . ' ...'); |
|
100 | 100 | if(file_exists($routesPath)){ |
101 | 101 | $this->logger->info('Found routes configuration file --> ' . $routesPath. ' now load it'); |
102 | 102 | require_once $routesPath; |
@@ -147,11 +147,11 @@ discard block |
||
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
150 | - * Add the URI and callback to the list of URIs to validate |
|
151 | - * |
|
152 | - * @param string $uri the request URI |
|
153 | - * @param object $callback the callback function |
|
154 | - */ |
|
150 | + * Add the URI and callback to the list of URIs to validate |
|
151 | + * |
|
152 | + * @param string $uri the request URI |
|
153 | + * @param object $callback the callback function |
|
154 | + */ |
|
155 | 155 | public function add($uri, $callback) { |
156 | 156 | $uri = trim($uri, $this->uriTrim); |
157 | 157 | if(in_array($uri, $this->pattern)){ |
@@ -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 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | |
27 | 27 | /** |
28 | 28 | * For application languages management |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | * Construct new Lang instance |
69 | 69 | */ |
70 | 70 | public function __construct(){ |
71 | - $this->logger =& class_loader('Log', 'classes'); |
|
72 | - $this->logger->setLogger('Library::Lang'); |
|
71 | + $this->logger =& class_loader('Log', 'classes'); |
|
72 | + $this->logger->setLogger('Library::Lang'); |
|
73 | 73 | |
74 | 74 | $this->default = get_config('default_language', 'en'); |
75 | 75 | $this->logger->debug('Setting the supported languages'); |
@@ -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 | } |
@@ -22,7 +22,7 @@ |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | |
27 | 27 | class Security{ |
28 | 28 |
@@ -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 Security{ |
|
27 | + class Security { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The logger instance |
@@ -36,9 +36,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -60,8 +60,7 @@ discard block |
||
60 | 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 | - } |
|
64 | - else{ |
|
63 | + } else{ |
|
65 | 64 | $newTime = $currentTime + $expire; |
66 | 65 | $token = sha1(uniqid()) . sha1(uniqid()); |
67 | 66 | $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']'); |
@@ -87,8 +86,7 @@ discard block |
||
87 | 86 | if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){ |
88 | 87 | $logger->warning('The CSRF session data is not valide'); |
89 | 88 | return false; |
90 | - } |
|
91 | - else{ |
|
89 | + } else{ |
|
92 | 90 | //perform form data |
93 | 91 | //need use request->query() for best retrieve |
94 | 92 | //super instance |
@@ -97,8 +95,7 @@ discard block |
||
97 | 95 | if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){ |
98 | 96 | $logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job'); |
99 | 97 | return false; |
100 | - } |
|
101 | - else{ |
|
98 | + } else{ |
|
102 | 99 | $logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue'); |
103 | 100 | //remove the token from session |
104 | 101 | Session::clear($key); |
@@ -127,8 +124,7 @@ discard block |
||
127 | 124 | $logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP'); |
128 | 125 | //wildcard to access all ip address |
129 | 126 | return; |
130 | - } |
|
131 | - else{ |
|
127 | + } else{ |
|
132 | 128 | // go through all whitelisted ips |
133 | 129 | foreach ($list as $ipaddr) { |
134 | 130 | // find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*") |
@@ -153,8 +149,7 @@ discard block |
||
153 | 149 | show_error('Access to this application is not allowed'); |
154 | 150 | } |
155 | 151 | } |
156 | - } |
|
157 | - else{ |
|
152 | + } else{ |
|
158 | 153 | $logger->info('Whitelist IP access is not enabled in the configuration, ignore checking'); |
159 | 154 | } |
160 | 155 | } |
@@ -22,7 +22,7 @@ |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | |
27 | 27 | /** |
28 | 28 | * This class represent the event dispatcher management, permit to record the listener and |
@@ -29,7 +29,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -59,8 +59,7 @@ discard block |
||
59 | 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 | - } |
|
63 | - else{ |
|
62 | + } else{ |
|
64 | 63 | $this->logger->info('This event already have the registered listener, add this listener to the list'); |
65 | 64 | } |
66 | 65 | $this->listeners[$eventName][] = $listener; |
@@ -78,12 +77,10 @@ discard block |
||
78 | 77 | if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){ |
79 | 78 | $this->logger->info('Found the listener at index [' .$index. '] remove it'); |
80 | 79 | unset($this->listeners[$eventName][$index]); |
81 | - } |
|
82 | - else{ |
|
80 | + } else{ |
|
83 | 81 | $this->logger->info('Cannot found this listener in the event listener list'); |
84 | 82 | } |
85 | - } |
|
86 | - else{ |
|
83 | + } else{ |
|
87 | 84 | $this->logger->info('This event does not have this listener ignore remove'); |
88 | 85 | } |
89 | 86 | } |
@@ -98,8 +95,7 @@ discard block |
||
98 | 95 | if($eventName != null && isset($this->listeners[$eventName])){ |
99 | 96 | $this->logger->info('The Event name is set of exist in the listener just remove all Event Listener for this event'); |
100 | 97 | unset($this->listeners[$eventName]); |
101 | - } |
|
102 | - else{ |
|
98 | + } else{ |
|
103 | 99 | $this->logger->info('The Event name is not set or does not exist in the listener, so remove all Event Listener'); |
104 | 100 | $this->listeners = array(); |
105 | 101 | } |
@@ -132,8 +128,7 @@ discard block |
||
132 | 128 | if($event->returnBack){ |
133 | 129 | $this->logger->info('This event need return back, return the result for future use'); |
134 | 130 | return $this->dispatchToListerners($event); |
135 | - } |
|
136 | - else{ |
|
131 | + } else{ |
|
137 | 132 | $this->logger->info('This event no need return back the result, just dispatch it'); |
138 | 133 | $this->dispatchToListerners($event); |
139 | 134 | } |
@@ -153,8 +148,7 @@ discard block |
||
153 | 148 | return $event; |
154 | 149 | } |
155 | 150 | return; |
156 | - } |
|
157 | - else{ |
|
151 | + } else{ |
|
158 | 152 | $this->logger->info('Found the registered Event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list)); |
159 | 153 | } |
160 | 154 | foreach($list as $listener){ |
@@ -162,12 +156,10 @@ discard block |
||
162 | 156 | $returnedEvent = call_user_func_array($listener, array($event)); |
163 | 157 | if($returnedEvent instanceof Event){ |
164 | 158 | $event = $returnedEvent; |
165 | - } |
|
166 | - else{ |
|
159 | + } else{ |
|
167 | 160 | show_error('This event [' .$event->name. '] need you return the event object after processing'); |
168 | 161 | } |
169 | - } |
|
170 | - else{ |
|
162 | + } else{ |
|
171 | 163 | call_user_func_array($listener, array($event)); |
172 | 164 | } |
173 | 165 | if($event->stop){ |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | |
27 | 27 | class Response{ |
28 | 28 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | private $_currentUrlCacheKey = null; |
58 | 58 | |
59 | 59 | /** |
60 | - * Whether we can compress the output using Gzip |
|
61 | - * @var boolean |
|
62 | - */ |
|
60 | + * Whether we can compress the output using Gzip |
|
61 | + * @var boolean |
|
62 | + */ |
|
63 | 63 | private static $_canCompressOutput = false; |
64 | 64 | |
65 | 65 | /** |
@@ -236,8 +236,8 @@ discard block |
||
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
239 | - * Send the final page output to user |
|
240 | - */ |
|
239 | + * Send the final page output to user |
|
240 | + */ |
|
241 | 241 | public function renderFinalPage(){ |
242 | 242 | $logger = static::getLogger(); |
243 | 243 | $obj = & get_instance(); |
@@ -301,8 +301,8 @@ discard block |
||
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
304 | - * Send the final page output to user if is cached |
|
305 | - */ |
|
304 | + * Send the final page output to user if is cached |
|
305 | + */ |
|
306 | 306 | public function renderFinalPageFromCache(&$cache){ |
307 | 307 | $logger = static::getLogger(); |
308 | 308 | $url = $this->_currentUrl; |
@@ -362,9 +362,9 @@ discard block |
||
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
365 | - * Get the final page to be rendered |
|
366 | - * @return string |
|
367 | - */ |
|
365 | + * Get the final page to be rendered |
|
366 | + * @return string |
|
367 | + */ |
|
368 | 368 | public function getFinalPageRendered(){ |
369 | 369 | return $this->_pageRender; |
370 | 370 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Response{ |
|
27 | + class Response { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The list of request header to send with response |
@@ -65,9 +65,9 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * Construct new response instance |
67 | 67 | */ |
68 | - public function __construct(){ |
|
69 | - $this->_currentUrl = (! empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '' ) |
|
70 | - . (! empty($_SERVER['QUERY_STRING']) ? ('?' . $_SERVER['QUERY_STRING']) : '' ); |
|
68 | + public function __construct() { |
|
69 | + $this->_currentUrl = (!empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '') |
|
70 | + . (!empty($_SERVER['QUERY_STRING']) ? ('?' . $_SERVER['QUERY_STRING']) : ''); |
|
71 | 71 | |
72 | 72 | $this->_currentUrlCacheKey = md5($this->_currentUrl); |
73 | 73 | |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | * Get the logger singleton instance |
83 | 83 | * @return Log the logger instance |
84 | 84 | */ |
85 | - private static function getLogger(){ |
|
86 | - if(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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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'; |
@@ -152,8 +152,7 @@ discard block |
||
152 | 152 | if(! headers_sent()){ |
153 | 153 | header('Location: '.$url); |
154 | 154 | exit; |
155 | - } |
|
156 | - else{ |
|
155 | + } else{ |
|
157 | 156 | echo '<script> |
158 | 157 | location.href = "'.$url.'"; |
159 | 158 | </script>'; |
@@ -202,12 +201,10 @@ discard block |
||
202 | 201 | if($moduleViewPath){ |
203 | 202 | $path = $moduleViewPath; |
204 | 203 | $logger->info('Found view [' . $view . '] in module [' .$mod. '], the file path is [' .$moduleViewPath. '] we will used it'); |
205 | - } |
|
206 | - else{ |
|
204 | + } else{ |
|
207 | 205 | $logger->info('Cannot find view [' . $view . '] in module [' .$mod. '] using the default location'); |
208 | 206 | } |
209 | - } |
|
210 | - else{ |
|
207 | + } else{ |
|
211 | 208 | $logger->info('The current request does not use module using the default location.'); |
212 | 209 | } |
213 | 210 | } |
@@ -291,8 +288,7 @@ discard block |
||
291 | 288 | //compress the output if is available |
292 | 289 | if (static::$_canCompressOutput){ |
293 | 290 | ob_start('ob_gzhandler'); |
294 | - } |
|
295 | - else{ |
|
291 | + } else{ |
|
296 | 292 | ob_start(); |
297 | 293 | } |
298 | 294 | static::sendHeaders(200); |
@@ -324,8 +320,7 @@ discard block |
||
324 | 320 | $logger->info('The cache page content is not yet expire for the URL [' . $url . '] send 304 header to browser'); |
325 | 321 | static::sendHeaders(304); |
326 | 322 | exit; |
327 | - } |
|
328 | - else{ |
|
323 | + } else{ |
|
329 | 324 | $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 | 325 | static::sendHeaders(200); |
331 | 326 | //get the cache content |
@@ -345,15 +340,13 @@ discard block |
||
345 | 340 | //compress the output if is available |
346 | 341 | if (static::$_canCompressOutput){ |
347 | 342 | ob_start('ob_gzhandler'); |
348 | - } |
|
349 | - else{ |
|
343 | + } else{ |
|
350 | 344 | ob_start(); |
351 | 345 | } |
352 | 346 | echo $content; |
353 | 347 | @ob_end_flush(); |
354 | 348 | exit; |
355 | - } |
|
356 | - else{ |
|
349 | + } else{ |
|
357 | 350 | $logger->info('The page cache content for the URL [' . $url . '] is not valid may be already expired'); |
358 | 351 | $cache->delete($pageCacheKey); |
359 | 352 | } |
@@ -394,16 +387,14 @@ discard block |
||
394 | 387 | //compress the output if is available |
395 | 388 | if (static::$_canCompressOutput){ |
396 | 389 | ob_start('ob_gzhandler'); |
397 | - } |
|
398 | - else{ |
|
390 | + } else{ |
|
399 | 391 | ob_start(); |
400 | 392 | } |
401 | 393 | require_once $path; |
402 | 394 | $output = ob_get_clean(); |
403 | 395 | static::sendHeaders(404); |
404 | 396 | echo $output; |
405 | - } |
|
406 | - else{ |
|
397 | + } else{ |
|
407 | 398 | show_error('The 404 view [' .$path. '] does not exist'); |
408 | 399 | } |
409 | 400 | } |
@@ -418,8 +409,7 @@ discard block |
||
418 | 409 | //compress the output if exists |
419 | 410 | if (static::$_canCompressOutput){ |
420 | 411 | ob_start('ob_gzhandler'); |
421 | - } |
|
422 | - else{ |
|
412 | + } else{ |
|
423 | 413 | ob_start(); |
424 | 414 | } |
425 | 415 | extract($data); |
@@ -427,8 +417,7 @@ discard block |
||
427 | 417 | $output = ob_get_clean(); |
428 | 418 | static::sendHeaders(503); |
429 | 419 | echo $output; |
430 | - } |
|
431 | - else{ |
|
420 | + } else{ |
|
432 | 421 | //can't use show_error() at this time because some dependencies not yet loaded and to prevent loop |
433 | 422 | set_http_status_header(503); |
434 | 423 | echo 'The error view [' . $path . '] does not exist'; |
@@ -22,7 +22,7 @@ |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | class Loader{ |
27 | 27 | |
28 | 28 | /** |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * along with this program; if not, write to the Free Software |
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | - class Loader{ |
|
26 | + class Loader { |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * List of loaded resources |
@@ -38,77 +38,77 @@ discard block |
||
38 | 38 | private static $logger; |
39 | 39 | |
40 | 40 | |
41 | - public function __construct(){ |
|
41 | + public function __construct() { |
|
42 | 42 | //add the resources already loaded during application bootstrap |
43 | 43 | //in the list to prevent duplicate or loading the resources again. |
44 | 44 | static::$loaded = class_loaded(); |
45 | 45 | |
46 | 46 | $autoloads = array(); |
47 | 47 | //loading of the resources in autoload.php configuration file |
48 | - if(file_exists(CONFIG_PATH . 'autoload.php')){ |
|
48 | + if (file_exists(CONFIG_PATH . 'autoload.php')) { |
|
49 | 49 | require_once CONFIG_PATH . 'autoload.php'; |
50 | - if(! empty($autoload) && is_array($autoload)){ |
|
50 | + if (!empty($autoload) && is_array($autoload)) { |
|
51 | 51 | $autoloads = $autoload; |
52 | 52 | unset($autoload); |
53 | 53 | } |
54 | 54 | } |
55 | 55 | //loading autoload configuration for modules |
56 | 56 | $modulesAutoloads = Module::getModulesAutoloadConfig(); |
57 | - if($modulesAutoloads && is_array($modulesAutoloads)){ |
|
57 | + if ($modulesAutoloads && is_array($modulesAutoloads)) { |
|
58 | 58 | //libraries autoload |
59 | - if(! empty($modulesAutoloads['libraries']) && is_array($modulesAutoloads['libraries'])){ |
|
59 | + if (!empty($modulesAutoloads['libraries']) && is_array($modulesAutoloads['libraries'])) { |
|
60 | 60 | $autoloads['libraries'] = array_merge($autoloads['libraries'], $modulesAutoloads['libraries']); |
61 | 61 | } |
62 | 62 | //config autoload |
63 | - if(! empty($modulesAutoloads['config']) && is_array($modulesAutoloads['config'])){ |
|
63 | + if (!empty($modulesAutoloads['config']) && is_array($modulesAutoloads['config'])) { |
|
64 | 64 | $autoloads['config'] = array_merge($autoloads['config'], $modulesAutoloads['config']); |
65 | 65 | } |
66 | 66 | //models autoload |
67 | - if(! empty($modulesAutoloads['models']) && is_array($modulesAutoloads['models'])){ |
|
67 | + if (!empty($modulesAutoloads['models']) && is_array($modulesAutoloads['models'])) { |
|
68 | 68 | $autoloads['models'] = array_merge($autoloads['models'], $modulesAutoloads['models']); |
69 | 69 | } |
70 | 70 | //functions autoload |
71 | - if(! empty($modulesAutoloads['functions']) && is_array($modulesAutoloads['functions'])){ |
|
71 | + if (!empty($modulesAutoloads['functions']) && is_array($modulesAutoloads['functions'])) { |
|
72 | 72 | $autoloads['functions'] = array_merge($autoloads['functions'], $modulesAutoloads['functions']); |
73 | 73 | } |
74 | 74 | //languages autoload |
75 | - if(! empty($modulesAutoloads['languages']) && is_array($modulesAutoloads['languages'])){ |
|
75 | + if (!empty($modulesAutoloads['languages']) && is_array($modulesAutoloads['languages'])) { |
|
76 | 76 | $autoloads['languages'] = array_merge($autoloads['languages'], $modulesAutoloads['languages']); |
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
80 | 80 | //config autoload |
81 | - if(! empty($autoloads['config']) && is_array($autoloads['config'])){ |
|
82 | - foreach($autoloads['config'] as $c){ |
|
81 | + if (!empty($autoloads['config']) && is_array($autoloads['config'])) { |
|
82 | + foreach ($autoloads['config'] as $c) { |
|
83 | 83 | $this->config($c); |
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | 87 | //languages autoload |
88 | - if(! empty($autoloads['languages']) && is_array($autoloads['languages'])){ |
|
89 | - foreach($autoloads['languages'] as $language){ |
|
88 | + if (!empty($autoloads['languages']) && is_array($autoloads['languages'])) { |
|
89 | + foreach ($autoloads['languages'] as $language) { |
|
90 | 90 | $this->lang($language); |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | 94 | //libraries autoload |
95 | - if(! empty($autoloads['libraries']) && is_array($autoloads['libraries'])){ |
|
96 | - foreach($autoloads['libraries'] as $library){ |
|
95 | + if (!empty($autoloads['libraries']) && is_array($autoloads['libraries'])) { |
|
96 | + foreach ($autoloads['libraries'] as $library) { |
|
97 | 97 | $this->library($library); |
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
101 | 101 | //models autoload |
102 | - if(! empty($autoloads['models']) && is_array($autoloads['models'])){ |
|
102 | + if (!empty($autoloads['models']) && is_array($autoloads['models'])) { |
|
103 | 103 | require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
104 | - foreach($autoloads['models'] as $model){ |
|
104 | + foreach ($autoloads['models'] as $model) { |
|
105 | 105 | $this->model($model); |
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
109 | 109 | //functions autoload |
110 | - if(! empty($autoloads['functions']) && is_array($autoloads['functions'])){ |
|
111 | - foreach($autoloads['functions'] as $function){ |
|
110 | + if (!empty($autoloads['functions']) && is_array($autoloads['functions'])) { |
|
111 | + foreach ($autoloads['functions'] as $function) { |
|
112 | 112 | $this->functions($function); |
113 | 113 | } |
114 | 114 | } |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | * Get the logger singleton instance |
120 | 120 | * @return Log the logger instance |
121 | 121 | */ |
122 | - private static function getLogger(){ |
|
123 | - if(static::$logger == null){ |
|
124 | - static::$logger[0] =& class_loader('Log', 'classes'); |
|
122 | + private static function getLogger() { |
|
123 | + if (static::$logger == null) { |
|
124 | + static::$logger[0] = & class_loader('Log', 'classes'); |
|
125 | 125 | static::$logger[0]->setLogger('Library::Loader'); |
126 | 126 | } |
127 | 127 | return static::$logger[0]; |
@@ -135,25 +135,25 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @return void |
137 | 137 | */ |
138 | - public static function model($class, $instance = null){ |
|
138 | + public static function model($class, $instance = null) { |
|
139 | 139 | $logger = static::getLogger(); |
140 | 140 | $class = str_ireplace('.php', '', $class); |
141 | 141 | $class = trim($class, '/\\'); |
142 | - $file = ucfirst($class).'.php'; |
|
142 | + $file = ucfirst($class) . '.php'; |
|
143 | 143 | $logger->debug('Loading model [' . $class . '] ...'); |
144 | - if(! $instance){ |
|
144 | + if (!$instance) { |
|
145 | 145 | //for module |
146 | - if(strpos($class, '/') !== false){ |
|
146 | + if (strpos($class, '/') !== false) { |
|
147 | 147 | $path = explode('/', $class); |
148 | - if(isset($path[1])){ |
|
148 | + if (isset($path[1])) { |
|
149 | 149 | $instance = strtolower($path[1]); |
150 | 150 | } |
151 | 151 | } |
152 | - else{ |
|
152 | + else { |
|
153 | 153 | $instance = strtolower($class); |
154 | 154 | } |
155 | 155 | } |
156 | - if(isset(static::$loaded[$instance])){ |
|
156 | + if (isset(static::$loaded[$instance])) { |
|
157 | 157 | $logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance'); |
158 | 158 | return; |
159 | 159 | } |
@@ -163,43 +163,43 @@ discard block |
||
163 | 163 | $searchModuleName = null; |
164 | 164 | $obj = & get_instance(); |
165 | 165 | //check if the request class contains module name |
166 | - if(strpos($class, '/') !== false){ |
|
166 | + if (strpos($class, '/') !== false) { |
|
167 | 167 | $path = explode('/', $class); |
168 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
168 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
169 | 169 | $searchModuleName = $path[0]; |
170 | 170 | $class = ucfirst($path[1]); |
171 | 171 | } |
172 | 172 | } |
173 | - else{ |
|
173 | + else { |
|
174 | 174 | $class = ucfirst($class); |
175 | 175 | } |
176 | 176 | |
177 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
177 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
178 | 178 | $searchModuleName = $obj->moduleName; |
179 | 179 | } |
180 | 180 | $moduleModelFilePath = Module::findModelFullPath($class, $searchModuleName); |
181 | - if($moduleModelFilePath){ |
|
182 | - $logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it'); |
|
181 | + if ($moduleModelFilePath) { |
|
182 | + $logger->info('Found model [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleModelFilePath . '] we will used it'); |
|
183 | 183 | $classFilePath = $moduleModelFilePath; |
184 | 184 | } |
185 | - else{ |
|
185 | + else { |
|
186 | 186 | $logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
187 | 187 | } |
188 | 188 | $logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
189 | - if(file_exists($classFilePath)){ |
|
189 | + if (file_exists($classFilePath)) { |
|
190 | 190 | require_once $classFilePath; |
191 | - if(class_exists($class)){ |
|
191 | + if (class_exists($class)) { |
|
192 | 192 | $c = new $class(); |
193 | 193 | $obj = & get_instance(); |
194 | 194 | $obj->{$instance} = $c; |
195 | 195 | static::$loaded[$instance] = $class; |
196 | 196 | $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
197 | 197 | } |
198 | - else{ |
|
199 | - show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']'); |
|
198 | + else { |
|
199 | + show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']'); |
|
200 | 200 | } |
201 | 201 | } |
202 | - else{ |
|
202 | + else { |
|
203 | 203 | show_error('Unable to find the model [' . $class . ']'); |
204 | 204 | } |
205 | 205 | } |
@@ -214,31 +214,31 @@ discard block |
||
214 | 214 | * |
215 | 215 | * @return void |
216 | 216 | */ |
217 | - public static function library($class, $instance = null, array $params = array()){ |
|
217 | + public static function library($class, $instance = null, array $params = array()) { |
|
218 | 218 | $logger = static::getLogger(); |
219 | 219 | $class = str_ireplace('.php', '', $class); |
220 | 220 | $class = trim($class, '/\\'); |
221 | - $file = ucfirst($class) .'.php'; |
|
221 | + $file = ucfirst($class) . '.php'; |
|
222 | 222 | $logger->debug('Loading library [' . $class . '] ...'); |
223 | - if(! $instance){ |
|
223 | + if (!$instance) { |
|
224 | 224 | //for module |
225 | - if(strpos($class, '/') !== false){ |
|
225 | + if (strpos($class, '/') !== false) { |
|
226 | 226 | $path = explode('/', $class); |
227 | - if(isset($path[1])){ |
|
227 | + if (isset($path[1])) { |
|
228 | 228 | $instance = strtolower($path[1]); |
229 | 229 | } |
230 | 230 | } |
231 | - else{ |
|
231 | + else { |
|
232 | 232 | $instance = strtolower($class); |
233 | 233 | } |
234 | 234 | } |
235 | - if(isset(static::$loaded[$instance])){ |
|
235 | + if (isset(static::$loaded[$instance])) { |
|
236 | 236 | $logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance'); |
237 | 237 | return; |
238 | 238 | } |
239 | 239 | $obj = & get_instance(); |
240 | 240 | //TODO for Database library |
241 | - if(strtolower($class) == 'database'){ |
|
241 | + if (strtolower($class) == 'database') { |
|
242 | 242 | $logger->info('This is the Database library ...'); |
243 | 243 | $dbInstance = & class_loader('Database', 'classes', $params); |
244 | 244 | $obj->{$instance} = $dbInstance; |
@@ -249,45 +249,45 @@ discard block |
||
249 | 249 | $libraryFilePath = null; |
250 | 250 | $isSystem = false; |
251 | 251 | $logger->debug('Check if this is a system library ...'); |
252 | - if(file_exists(CORE_LIBRARY_PATH . $file)){ |
|
252 | + if (file_exists(CORE_LIBRARY_PATH . $file)) { |
|
253 | 253 | $isSystem = true; |
254 | 254 | $libraryFilePath = CORE_LIBRARY_PATH . $file; |
255 | 255 | $class = ucfirst($class); |
256 | 256 | $logger->info('This library is a system library'); |
257 | 257 | } |
258 | - else{ |
|
258 | + else { |
|
259 | 259 | $logger->info('This library is not a system library'); |
260 | 260 | //first check if this library is in the module |
261 | 261 | $logger->debug('Checking library [' . $class . '] from module list ...'); |
262 | 262 | $searchModuleName = null; |
263 | 263 | //check if the request class contains module name |
264 | - if(strpos($class, '/') !== false){ |
|
264 | + if (strpos($class, '/') !== false) { |
|
265 | 265 | $path = explode('/', $class); |
266 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
266 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
267 | 267 | $searchModuleName = $path[0]; |
268 | 268 | $class = ucfirst($path[1]); |
269 | 269 | } |
270 | 270 | } |
271 | - else{ |
|
271 | + else { |
|
272 | 272 | $class = ucfirst($class); |
273 | 273 | } |
274 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
274 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
275 | 275 | $searchModuleName = $obj->moduleName; |
276 | 276 | } |
277 | 277 | $moduleLibraryPath = Module::findLibraryFullPath($class, $searchModuleName); |
278 | - if($moduleLibraryPath){ |
|
279 | - $logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it'); |
|
278 | + if ($moduleLibraryPath) { |
|
279 | + $logger->info('Found library [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLibraryPath . '] we will used it'); |
|
280 | 280 | $libraryFilePath = $moduleLibraryPath; |
281 | 281 | } |
282 | - else{ |
|
282 | + else { |
|
283 | 283 | $logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
284 | 284 | } |
285 | 285 | } |
286 | - if(! $libraryFilePath){ |
|
286 | + if (!$libraryFilePath) { |
|
287 | 287 | $searchDir = array(LIBRARY_PATH); |
288 | - foreach($searchDir as $dir){ |
|
288 | + foreach ($searchDir as $dir) { |
|
289 | 289 | $filePath = $dir . $file; |
290 | - if(file_exists($filePath)){ |
|
290 | + if (file_exists($filePath)) { |
|
291 | 291 | $libraryFilePath = $filePath; |
292 | 292 | //is already found not to continue |
293 | 293 | break; |
@@ -295,20 +295,20 @@ discard block |
||
295 | 295 | } |
296 | 296 | } |
297 | 297 | $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']'); |
298 | - if($libraryFilePath){ |
|
298 | + if ($libraryFilePath) { |
|
299 | 299 | require_once $libraryFilePath; |
300 | - if(class_exists($class)){ |
|
300 | + if (class_exists($class)) { |
|
301 | 301 | $c = $params ? new $class($params) : new $class(); |
302 | 302 | $obj = & get_instance(); |
303 | 303 | $obj->{$instance} = $c; |
304 | 304 | static::$loaded[$instance] = $class; |
305 | 305 | $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
306 | 306 | } |
307 | - else{ |
|
308 | - show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class); |
|
307 | + else { |
|
308 | + show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class); |
|
309 | 309 | } |
310 | 310 | } |
311 | - else{ |
|
311 | + else { |
|
312 | 312 | show_error('Unable to find library class [' . $class . ']'); |
313 | 313 | } |
314 | 314 | } |
@@ -320,14 +320,14 @@ discard block |
||
320 | 320 | * |
321 | 321 | * @return void |
322 | 322 | */ |
323 | - public static function functions($function){ |
|
323 | + public static function functions($function) { |
|
324 | 324 | $logger = static::getLogger(); |
325 | 325 | $function = str_ireplace('.php', '', $function); |
326 | 326 | $function = trim($function, '/\\'); |
327 | 327 | $function = str_ireplace('function_', '', $function); |
328 | - $file = 'function_'.$function.'.php'; |
|
328 | + $file = 'function_' . $function . '.php'; |
|
329 | 329 | $logger->debug('Loading helper [' . $function . '] ...'); |
330 | - if(isset(static::$loaded['function_' . $function])){ |
|
330 | + if (isset(static::$loaded['function_' . $function])) { |
|
331 | 331 | $logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance'); |
332 | 332 | return; |
333 | 333 | } |
@@ -337,30 +337,30 @@ discard block |
||
337 | 337 | $searchModuleName = null; |
338 | 338 | $obj = & get_instance(); |
339 | 339 | //check if the request class contains module name |
340 | - if(strpos($function, '/') !== false){ |
|
340 | + if (strpos($function, '/') !== false) { |
|
341 | 341 | $path = explode('/', $function); |
342 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
342 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
343 | 343 | $searchModuleName = $path[0]; |
344 | 344 | $function = 'function_' . $path[1] . '.php'; |
345 | - $file = $path[0] . DS . 'function_'.$function.'.php'; |
|
345 | + $file = $path[0] . DS . 'function_' . $function . '.php'; |
|
346 | 346 | } |
347 | 347 | } |
348 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
348 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
349 | 349 | $searchModuleName = $obj->moduleName; |
350 | 350 | } |
351 | 351 | $moduleFunctionPath = Module::findFunctionFullPath($function, $searchModuleName); |
352 | - if($moduleFunctionPath){ |
|
353 | - $logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it'); |
|
352 | + if ($moduleFunctionPath) { |
|
353 | + $logger->info('Found helper [' . $function . '] from module [' . $searchModuleName . '], the file path is [' . $moduleFunctionPath . '] we will used it'); |
|
354 | 354 | $functionFilePath = $moduleFunctionPath; |
355 | 355 | } |
356 | - else{ |
|
356 | + else { |
|
357 | 357 | $logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
358 | 358 | } |
359 | - if(! $functionFilePath){ |
|
359 | + if (!$functionFilePath) { |
|
360 | 360 | $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH); |
361 | - foreach($searchDir as $dir){ |
|
361 | + foreach ($searchDir as $dir) { |
|
362 | 362 | $filePath = $dir . $file; |
363 | - if(file_exists($filePath)){ |
|
363 | + if (file_exists($filePath)) { |
|
364 | 364 | $functionFilePath = $filePath; |
365 | 365 | //is already found not to continue |
366 | 366 | break; |
@@ -368,12 +368,12 @@ discard block |
||
368 | 368 | } |
369 | 369 | } |
370 | 370 | $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']'); |
371 | - if($functionFilePath){ |
|
371 | + if ($functionFilePath) { |
|
372 | 372 | require_once $functionFilePath; |
373 | 373 | static::$loaded['function_' . $function] = $functionFilePath; |
374 | 374 | $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
375 | 375 | } |
376 | - else{ |
|
376 | + else { |
|
377 | 377 | show_error('Unable to find helper file [' . $file . ']'); |
378 | 378 | } |
379 | 379 | } |
@@ -385,14 +385,14 @@ discard block |
||
385 | 385 | * |
386 | 386 | * @return void |
387 | 387 | */ |
388 | - public static function config($filename){ |
|
388 | + public static function config($filename) { |
|
389 | 389 | $logger = static::getLogger(); |
390 | 390 | $filename = str_ireplace('.php', '', $filename); |
391 | 391 | $filename = trim($filename, '/\\'); |
392 | 392 | $filename = str_ireplace('config_', '', $filename); |
393 | - $file = 'config_'.$filename.'.php'; |
|
393 | + $file = 'config_' . $filename . '.php'; |
|
394 | 394 | $logger->debug('Loading configuration [' . $filename . '] ...'); |
395 | - if(isset(static::$loaded['config_' . $filename])){ |
|
395 | + if (isset(static::$loaded['config_' . $filename])) { |
|
396 | 396 | $logger->info('Configuration [' . $path . '] already loaded no need to load it again, cost in performance'); |
397 | 397 | return; |
398 | 398 | } |
@@ -402,37 +402,37 @@ discard block |
||
402 | 402 | $searchModuleName = null; |
403 | 403 | $obj = & get_instance(); |
404 | 404 | //check if the request class contains module name |
405 | - if(strpos($filename, '/') !== false){ |
|
405 | + if (strpos($filename, '/') !== false) { |
|
406 | 406 | $path = explode('/', $filename); |
407 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
407 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
408 | 408 | $searchModuleName = $path[0]; |
409 | 409 | $filename = $path[1] . '.php'; |
410 | - $file = $path[0] . DS .$filename; |
|
410 | + $file = $path[0] . DS . $filename; |
|
411 | 411 | } |
412 | 412 | } |
413 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
413 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
414 | 414 | $searchModuleName = $obj->moduleName; |
415 | 415 | } |
416 | 416 | $moduleConfigPath = Module::findConfigFullPath($filename, $searchModuleName); |
417 | - if($moduleConfigPath){ |
|
418 | - $logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it'); |
|
417 | + if ($moduleConfigPath) { |
|
418 | + $logger->info('Found config [' . $filename . '] from module [' . $searchModuleName . '], the file path is [' . $moduleConfigPath . '] we will used it'); |
|
419 | 419 | $configFilePath = $moduleConfigPath; |
420 | 420 | } |
421 | - else{ |
|
421 | + else { |
|
422 | 422 | $logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
423 | 423 | } |
424 | 424 | $logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
425 | - if(file_exists($configFilePath)){ |
|
425 | + if (file_exists($configFilePath)) { |
|
426 | 426 | require_once $configFilePath; |
427 | - if(! empty($config) && is_array($config)){ |
|
427 | + if (!empty($config) && is_array($config)) { |
|
428 | 428 | Config::setAll($config); |
429 | 429 | } |
430 | - else{ |
|
431 | - show_error('No configuration found in ['. $configFilePath . ']'); |
|
430 | + else { |
|
431 | + show_error('No configuration found in [' . $configFilePath . ']'); |
|
432 | 432 | } |
433 | 433 | } |
434 | - else{ |
|
435 | - show_error('Unable to find config file ['. $configFilePath . ']'); |
|
434 | + else { |
|
435 | + show_error('Unable to find config file [' . $configFilePath . ']'); |
|
436 | 436 | } |
437 | 437 | static::$loaded['config_' . $filename] = $configFilePath; |
438 | 438 | $logger->info('Configuration [' . $configFilePath . '] loaded successfully.'); |
@@ -448,14 +448,14 @@ discard block |
||
448 | 448 | * |
449 | 449 | * @return void |
450 | 450 | */ |
451 | - public static function lang($language){ |
|
451 | + public static function lang($language) { |
|
452 | 452 | $logger = static::getLogger(); |
453 | 453 | $language = str_ireplace('.php', '', $language); |
454 | 454 | $language = trim($language, '/\\'); |
455 | 455 | $language = str_ireplace('lang_', '', $language); |
456 | - $file = 'lang_'.$language.'.php'; |
|
456 | + $file = 'lang_' . $language . '.php'; |
|
457 | 457 | $logger->debug('Loading language [' . $language . '] ...'); |
458 | - if(isset(static::$loaded['lang_' . $language])){ |
|
458 | + if (isset(static::$loaded['lang_' . $language])) { |
|
459 | 459 | $logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance'); |
460 | 460 | return; |
461 | 461 | } |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | $cfgKey = get_config('language_cookie_name'); |
466 | 466 | $objCookie = & class_loader('Cookie'); |
467 | 467 | $cookieLang = $objCookie->get($cfgKey); |
468 | - if($cookieLang){ |
|
468 | + if ($cookieLang) { |
|
469 | 469 | $appLang = $cookieLang; |
470 | 470 | } |
471 | 471 | $languageFilePath = null; |
@@ -474,30 +474,30 @@ discard block |
||
474 | 474 | $searchModuleName = null; |
475 | 475 | $obj = & get_instance(); |
476 | 476 | //check if the request class contains module name |
477 | - if(strpos($language, '/') !== false){ |
|
477 | + if (strpos($language, '/') !== false) { |
|
478 | 478 | $path = explode('/', $language); |
479 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
479 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
480 | 480 | $searchModuleName = $path[0]; |
481 | 481 | $language = 'lang_' . $path[1] . '.php'; |
482 | - $file = $path[0] . DS .$language; |
|
482 | + $file = $path[0] . DS . $language; |
|
483 | 483 | } |
484 | 484 | } |
485 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
485 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
486 | 486 | $searchModuleName = $obj->moduleName; |
487 | 487 | } |
488 | 488 | $moduleLanguagePath = Module::findLanguageFullPath($language, $searchModuleName, $appLang); |
489 | - if($moduleLanguagePath){ |
|
490 | - $logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it'); |
|
489 | + if ($moduleLanguagePath) { |
|
490 | + $logger->info('Found language [' . $language . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLanguagePath . '] we will used it'); |
|
491 | 491 | $languageFilePath = $moduleLanguagePath; |
492 | 492 | } |
493 | - else{ |
|
493 | + else { |
|
494 | 494 | $logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
495 | 495 | } |
496 | - if(! $languageFilePath){ |
|
496 | + if (!$languageFilePath) { |
|
497 | 497 | $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH); |
498 | - foreach($searchDir as $dir){ |
|
498 | + foreach ($searchDir as $dir) { |
|
499 | 499 | $filePath = $dir . $appLang . DS . $file; |
500 | - if(file_exists($filePath)){ |
|
500 | + if (file_exists($filePath)) { |
|
501 | 501 | $languageFilePath = $filePath; |
502 | 502 | //is already found not to continue |
503 | 503 | break; |
@@ -505,12 +505,12 @@ discard block |
||
505 | 505 | } |
506 | 506 | } |
507 | 507 | $logger->info('The language file path to be loaded is [' . $languageFilePath . ']'); |
508 | - if($languageFilePath){ |
|
508 | + if ($languageFilePath) { |
|
509 | 509 | require_once $languageFilePath; |
510 | - if(! empty($lang) && is_array($lang)){ |
|
511 | - $logger->info('Language file [' .$languageFilePath. '] contains the valid languages keys add them to language list'); |
|
510 | + if (!empty($lang) && is_array($lang)) { |
|
511 | + $logger->info('Language file [' . $languageFilePath . '] contains the valid languages keys add them to language list'); |
|
512 | 512 | //Note: may be here the class 'Lang' not yet loaded |
513 | - $langObj =& class_loader('Lang', 'classes'); |
|
513 | + $langObj = & class_loader('Lang', 'classes'); |
|
514 | 514 | $langObj->addLangMessages($lang); |
515 | 515 | //free the memory |
516 | 516 | unset($lang); |
@@ -518,7 +518,7 @@ discard block |
||
518 | 518 | static::$loaded['lang_' . $language] = $languageFilePath; |
519 | 519 | $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
520 | 520 | } |
521 | - else{ |
|
521 | + else { |
|
522 | 522 | show_error('Unable to find language file [' . $file . ']'); |
523 | 523 | } |
524 | 524 | } |
@@ -148,8 +148,7 @@ discard block |
||
148 | 148 | if(isset($path[1])){ |
149 | 149 | $instance = strtolower($path[1]); |
150 | 150 | } |
151 | - } |
|
152 | - else{ |
|
151 | + } else{ |
|
153 | 152 | $instance = strtolower($class); |
154 | 153 | } |
155 | 154 | } |
@@ -169,8 +168,7 @@ discard block |
||
169 | 168 | $searchModuleName = $path[0]; |
170 | 169 | $class = ucfirst($path[1]); |
171 | 170 | } |
172 | - } |
|
173 | - else{ |
|
171 | + } else{ |
|
174 | 172 | $class = ucfirst($class); |
175 | 173 | } |
176 | 174 | |
@@ -181,8 +179,7 @@ discard block |
||
181 | 179 | if($moduleModelFilePath){ |
182 | 180 | $logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it'); |
183 | 181 | $classFilePath = $moduleModelFilePath; |
184 | - } |
|
185 | - else{ |
|
182 | + } else{ |
|
186 | 183 | $logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
187 | 184 | } |
188 | 185 | $logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
@@ -194,12 +191,10 @@ discard block |
||
194 | 191 | $obj->{$instance} = $c; |
195 | 192 | static::$loaded[$instance] = $class; |
196 | 193 | $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
197 | - } |
|
198 | - else{ |
|
194 | + } else{ |
|
199 | 195 | show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']'); |
200 | 196 | } |
201 | - } |
|
202 | - else{ |
|
197 | + } else{ |
|
203 | 198 | show_error('Unable to find the model [' . $class . ']'); |
204 | 199 | } |
205 | 200 | } |
@@ -227,8 +222,7 @@ discard block |
||
227 | 222 | if(isset($path[1])){ |
228 | 223 | $instance = strtolower($path[1]); |
229 | 224 | } |
230 | - } |
|
231 | - else{ |
|
225 | + } else{ |
|
232 | 226 | $instance = strtolower($class); |
233 | 227 | } |
234 | 228 | } |
@@ -254,8 +248,7 @@ discard block |
||
254 | 248 | $libraryFilePath = CORE_LIBRARY_PATH . $file; |
255 | 249 | $class = ucfirst($class); |
256 | 250 | $logger->info('This library is a system library'); |
257 | - } |
|
258 | - else{ |
|
251 | + } else{ |
|
259 | 252 | $logger->info('This library is not a system library'); |
260 | 253 | //first check if this library is in the module |
261 | 254 | $logger->debug('Checking library [' . $class . '] from module list ...'); |
@@ -267,8 +260,7 @@ discard block |
||
267 | 260 | $searchModuleName = $path[0]; |
268 | 261 | $class = ucfirst($path[1]); |
269 | 262 | } |
270 | - } |
|
271 | - else{ |
|
263 | + } else{ |
|
272 | 264 | $class = ucfirst($class); |
273 | 265 | } |
274 | 266 | if(! $searchModuleName && !empty($obj->moduleName)){ |
@@ -278,8 +270,7 @@ discard block |
||
278 | 270 | if($moduleLibraryPath){ |
279 | 271 | $logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it'); |
280 | 272 | $libraryFilePath = $moduleLibraryPath; |
281 | - } |
|
282 | - else{ |
|
273 | + } else{ |
|
283 | 274 | $logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
284 | 275 | } |
285 | 276 | } |
@@ -303,12 +294,10 @@ discard block |
||
303 | 294 | $obj->{$instance} = $c; |
304 | 295 | static::$loaded[$instance] = $class; |
305 | 296 | $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
306 | - } |
|
307 | - else{ |
|
297 | + } else{ |
|
308 | 298 | show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class); |
309 | 299 | } |
310 | - } |
|
311 | - else{ |
|
300 | + } else{ |
|
312 | 301 | show_error('Unable to find library class [' . $class . ']'); |
313 | 302 | } |
314 | 303 | } |
@@ -352,8 +341,7 @@ discard block |
||
352 | 341 | if($moduleFunctionPath){ |
353 | 342 | $logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it'); |
354 | 343 | $functionFilePath = $moduleFunctionPath; |
355 | - } |
|
356 | - else{ |
|
344 | + } else{ |
|
357 | 345 | $logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
358 | 346 | } |
359 | 347 | if(! $functionFilePath){ |
@@ -372,8 +360,7 @@ discard block |
||
372 | 360 | require_once $functionFilePath; |
373 | 361 | static::$loaded['function_' . $function] = $functionFilePath; |
374 | 362 | $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
375 | - } |
|
376 | - else{ |
|
363 | + } else{ |
|
377 | 364 | show_error('Unable to find helper file [' . $file . ']'); |
378 | 365 | } |
379 | 366 | } |
@@ -417,8 +404,7 @@ discard block |
||
417 | 404 | if($moduleConfigPath){ |
418 | 405 | $logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it'); |
419 | 406 | $configFilePath = $moduleConfigPath; |
420 | - } |
|
421 | - else{ |
|
407 | + } else{ |
|
422 | 408 | $logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
423 | 409 | } |
424 | 410 | $logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
@@ -426,12 +412,10 @@ discard block |
||
426 | 412 | require_once $configFilePath; |
427 | 413 | if(! empty($config) && is_array($config)){ |
428 | 414 | Config::setAll($config); |
429 | - } |
|
430 | - else{ |
|
415 | + } else{ |
|
431 | 416 | show_error('No configuration found in ['. $configFilePath . ']'); |
432 | 417 | } |
433 | - } |
|
434 | - else{ |
|
418 | + } else{ |
|
435 | 419 | show_error('Unable to find config file ['. $configFilePath . ']'); |
436 | 420 | } |
437 | 421 | static::$loaded['config_' . $filename] = $configFilePath; |
@@ -489,8 +473,7 @@ discard block |
||
489 | 473 | if($moduleLanguagePath){ |
490 | 474 | $logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it'); |
491 | 475 | $languageFilePath = $moduleLanguagePath; |
492 | - } |
|
493 | - else{ |
|
476 | + } else{ |
|
494 | 477 | $logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
495 | 478 | } |
496 | 479 | if(! $languageFilePath){ |
@@ -517,8 +500,7 @@ discard block |
||
517 | 500 | } |
518 | 501 | static::$loaded['lang_' . $language] = $languageFilePath; |
519 | 502 | $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
520 | - } |
|
521 | - else{ |
|
503 | + } else{ |
|
522 | 504 | show_error('Unable to find language file [' . $file . ']'); |
523 | 505 | } |
524 | 506 | } |