@@ -24,20 +24,20 @@ |
||
24 | 24 | } |
25 | 25 | |
26 | 26 | |
27 | - public function testFunctionGetConfigKeyNotExist(){ |
|
27 | + public function testFunctionGetConfigKeyNotExist() { |
|
28 | 28 | $key = 'foo'; |
29 | 29 | $cfg = get_config($key); |
30 | 30 | $this->assertNull($cfg); |
31 | 31 | } |
32 | 32 | |
33 | - public function testFunctionGetConfigKeyNotExistUsingDefaultValue(){ |
|
33 | + public function testFunctionGetConfigKeyNotExistUsingDefaultValue() { |
|
34 | 34 | $key = 'foo'; |
35 | 35 | $expected = 'bar'; |
36 | 36 | $cfg = get_config($key, $expected); |
37 | 37 | $this->assertEquals($cfg, $expected); |
38 | 38 | } |
39 | 39 | |
40 | - public function testFunctionGetConfigAfterSet(){ |
|
40 | + public function testFunctionGetConfigAfterSet() { |
|
41 | 41 | $key = 'foo'; |
42 | 42 | $expected = 'bar'; |
43 | 43 | $c = new Config(); |
@@ -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 ApcCache implements CacheInterface{ |
|
27 | + class ApcCache implements CacheInterface { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The logger instance |
@@ -33,19 +33,19 @@ discard block |
||
33 | 33 | private $logger; |
34 | 34 | |
35 | 35 | |
36 | - public function __construct(Log $logger = null){ |
|
37 | - if(! $this->isSupported()){ |
|
36 | + public function __construct(Log $logger = null) { |
|
37 | + if (!$this->isSupported()) { |
|
38 | 38 | show_error('The cache for APC[u] driver is not available. Check if APC[u] extension is loaded and enabled.'); |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * instance of the Log class |
43 | 43 | */ |
44 | - if(is_object($logger)){ |
|
44 | + if (is_object($logger)) { |
|
45 | 45 | $this->logger = $logger; |
46 | 46 | } |
47 | - else{ |
|
48 | - $this->logger =& class_loader('Log', 'classes'); |
|
47 | + else { |
|
48 | + $this->logger = & class_loader('Log', 'classes'); |
|
49 | 49 | $this->logger->setLogger('Library::ApcCache'); |
50 | 50 | } |
51 | 51 | } |
@@ -55,21 +55,21 @@ discard block |
||
55 | 55 | * @param string $key the key to identify the cache data |
56 | 56 | * @return mixed the cache data if exists else return false |
57 | 57 | */ |
58 | - public function get($key){ |
|
59 | - $this->logger->debug('Getting cache data for key ['. $key .']'); |
|
58 | + public function get($key) { |
|
59 | + $this->logger->debug('Getting cache data for key [' . $key . ']'); |
|
60 | 60 | $success = false; |
61 | 61 | $data = apc_fetch($key, $success); |
62 | - if($success === false){ |
|
63 | - $this->logger->info('No cache found for the key ['. $key .'], return false'); |
|
62 | + if ($success === false) { |
|
63 | + $this->logger->info('No cache found for the key [' . $key . '], return false'); |
|
64 | 64 | return false; |
65 | 65 | } |
66 | - else{ |
|
66 | + else { |
|
67 | 67 | $cacheInfo = $this->_getCacheInfo($key); |
68 | 68 | $expire = time(); |
69 | - if($cacheInfo){ |
|
69 | + if ($cacheInfo) { |
|
70 | 70 | $expire = $cacheInfo['creation_time'] + $cacheInfo['ttl']; |
71 | 71 | } |
72 | - $this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
72 | + $this->logger->info('The cache not yet expire, now return the cache data for key [' . $key . '], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
73 | 73 | return $data; |
74 | 74 | } |
75 | 75 | } |
@@ -82,16 +82,16 @@ discard block |
||
82 | 82 | * @param integer $ttl the cache life time |
83 | 83 | * @return boolean true if success otherwise will return false |
84 | 84 | */ |
85 | - public function set($key, $data, $ttl = 0){ |
|
85 | + public function set($key, $data, $ttl = 0) { |
|
86 | 86 | $expire = time() + $ttl; |
87 | - $this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
87 | + $this->logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
88 | 88 | $result = apc_store($key, $data, $ttl); |
89 | - if($result === false){ |
|
90 | - $this->logger->error('Can not write cache data for the key ['. $key .'], return false'); |
|
89 | + if ($result === false) { |
|
90 | + $this->logger->error('Can not write cache data for the key [' . $key . '], return false'); |
|
91 | 91 | return false; |
92 | 92 | } |
93 | - else{ |
|
94 | - $this->logger->info('Cache data saved for the key ['. $key .']'); |
|
93 | + else { |
|
94 | + $this->logger->info('Cache data saved for the key [' . $key . ']'); |
|
95 | 95 | return true; |
96 | 96 | } |
97 | 97 | } |
@@ -103,15 +103,15 @@ discard block |
||
103 | 103 | * @return boolean true if the cache is deleted, false if can't delete |
104 | 104 | * the cache or the cache with the given key not exist |
105 | 105 | */ |
106 | - public function delete($key){ |
|
107 | - $this->logger->debug('Deleting of cache data for key [' .$key. ']'); |
|
106 | + public function delete($key) { |
|
107 | + $this->logger->debug('Deleting of cache data for key [' . $key . ']'); |
|
108 | 108 | $cacheInfo = $this->_getCacheInfo($key); |
109 | - if($cacheInfo === false){ |
|
109 | + if ($cacheInfo === false) { |
|
110 | 110 | $this->logger->info('This cache data does not exists skipping'); |
111 | 111 | return false; |
112 | 112 | } |
113 | - else{ |
|
114 | - $this->logger->info('Found cache data for the key [' .$key. '] remove it'); |
|
113 | + else { |
|
114 | + $this->logger->info('Found cache data for the key [' . $key . '] remove it'); |
|
115 | 115 | return apc_delete($key) === true; |
116 | 116 | } |
117 | 117 | } |
@@ -124,10 +124,10 @@ discard block |
||
124 | 124 | * 'expire' => expiration time of the cache (Unix timestamp), |
125 | 125 | * 'ttl' => the time to live of the cache in second |
126 | 126 | */ |
127 | - public function getInfo($key){ |
|
128 | - $this->logger->debug('Getting of cache info for key [' .$key. ']'); |
|
127 | + public function getInfo($key) { |
|
128 | + $this->logger->debug('Getting of cache info for key [' . $key . ']'); |
|
129 | 129 | $cacheInfos = $this->_getCacheInfo($key); |
130 | - if($cacheInfos){ |
|
130 | + if ($cacheInfos) { |
|
131 | 131 | $data = array( |
132 | 132 | 'mtime' => $cacheInfos['creation_time'], |
133 | 133 | 'expire' => $cacheInfos['creation_time'] + $cacheInfos['ttl'], |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | ); |
136 | 136 | return $data; |
137 | 137 | } |
138 | - else{ |
|
138 | + else { |
|
139 | 139 | $this->logger->info('This cache does not exists skipping'); |
140 | 140 | return false; |
141 | 141 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | /** |
146 | 146 | * Used to delete expired cache data |
147 | 147 | */ |
148 | - public function deleteExpiredCache(){ |
|
148 | + public function deleteExpiredCache() { |
|
149 | 149 | //for APC[u] is done automatically |
150 | 150 | return true; |
151 | 151 | } |
@@ -153,14 +153,14 @@ discard block |
||
153 | 153 | /** |
154 | 154 | * Remove all cache data |
155 | 155 | */ |
156 | - public function clean(){ |
|
156 | + public function clean() { |
|
157 | 157 | $this->logger->debug('Deleting of all cache data'); |
158 | 158 | $cacheInfos = apc_cache_info('user'); |
159 | - if(empty($cacheInfos['cache_list'])){ |
|
159 | + if (empty($cacheInfos['cache_list'])) { |
|
160 | 160 | $this->logger->info('No cache data were found skipping'); |
161 | 161 | return false; |
162 | 162 | } |
163 | - else{ |
|
163 | + else { |
|
164 | 164 | $this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove'); |
165 | 165 | return apc_clear_cache('user'); |
166 | 166 | } |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * |
173 | 173 | * @return bool |
174 | 174 | */ |
175 | - public function isSupported(){ |
|
175 | + public function isSupported() { |
|
176 | 176 | return (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled'); |
177 | 177 | } |
178 | 178 | |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * Return the Log instance |
181 | 181 | * @return Log |
182 | 182 | */ |
183 | - public function getLogger(){ |
|
183 | + public function getLogger() { |
|
184 | 184 | return $this->logger; |
185 | 185 | } |
186 | 186 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * Set the log instance |
189 | 189 | * @param Log $logger the log object |
190 | 190 | */ |
191 | - public function setLogger(Log $logger){ |
|
191 | + public function setLogger(Log $logger) { |
|
192 | 192 | $this->logger = $logger; |
193 | 193 | return $this; |
194 | 194 | } |
@@ -199,12 +199,12 @@ discard block |
||
199 | 199 | * @param string $key the cache key to get the cache information |
200 | 200 | * @return boolean|array |
201 | 201 | */ |
202 | - private function _getCacheInfo($key){ |
|
202 | + private function _getCacheInfo($key) { |
|
203 | 203 | $caches = apc_cache_info('user'); |
204 | - if(! empty($caches['cache_list'])){ |
|
204 | + if (!empty($caches['cache_list'])) { |
|
205 | 205 | $cacheLists = $caches['cache_list']; |
206 | - foreach ($cacheLists as $c){ |
|
207 | - if(isset($c['info']) && $c['info'] === $key){ |
|
206 | + foreach ($cacheLists as $c) { |
|
207 | + if (isset($c['info']) && $c['info'] === $key) { |
|
208 | 208 | return $c; |
209 | 209 | } |
210 | 210 | } |
@@ -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 Cookie{ |
|
27 | + class Cookie { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The logger instance |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | * The signleton of the logger |
37 | 37 | * @return Object the Log instance |
38 | 38 | */ |
39 | - private static function getLogger(){ |
|
40 | - if(self::$logger == null){ |
|
41 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
39 | + private static function getLogger() { |
|
40 | + if (self::$logger == null) { |
|
41 | + self::$logger[0] = & class_loader('Log', 'classes'); |
|
42 | 42 | self::$logger[0]->setLogger('Library::Cookie'); |
43 | 43 | } |
44 | 44 | return self::$logger[0]; |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | * @param mixed $default the default value to use if can not find the cokkie item in the list |
51 | 51 | * @return mixed the cookie value if exist or the default value |
52 | 52 | */ |
53 | - public static function get($item, $default = null){ |
|
53 | + public static function get($item, $default = null) { |
|
54 | 54 | $logger = self::getLogger(); |
55 | - if(array_key_exists($item, $_COOKIE)){ |
|
55 | + if (array_key_exists($item, $_COOKIE)) { |
|
56 | 56 | return $_COOKIE[$item]; |
57 | 57 | } |
58 | 58 | $logger->warning('Cannot find cookie item [' . $item . '], using the default value [' . $default . ']'); |
@@ -69,14 +69,14 @@ discard block |
||
69 | 69 | * @param boolean $secure if this cookie will be available on secure connection or not |
70 | 70 | * @param boolean $httponly if this cookie will be available under HTTP protocol. |
71 | 71 | */ |
72 | - public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false){ |
|
73 | - if(headers_sent()){ |
|
72 | + public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false) { |
|
73 | + if (headers_sent()) { |
|
74 | 74 | show_error('There exists a cookie that we wanted to create that we couldn\'t |
75 | 75 | because headers was already sent. Make sure to do this first |
76 | 76 | before outputing anything.'); |
77 | 77 | } |
78 | 78 | $timestamp = $expire; |
79 | - if($expire){ |
|
79 | + if ($expire) { |
|
80 | 80 | $timestamp = time() + $expire; |
81 | 81 | } |
82 | 82 | setcookie($name, $value, $timestamp, $path, $domain, $secure, $httponly); |
@@ -87,15 +87,15 @@ discard block |
||
87 | 87 | * @param string $item the cookie item name to be cleared |
88 | 88 | * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
89 | 89 | */ |
90 | - public static function delete($item){ |
|
90 | + public static function delete($item) { |
|
91 | 91 | $logger = self::getLogger(); |
92 | - if(array_key_exists($item, $_COOKIE)){ |
|
93 | - $logger->info('Delete cookie item ['.$item.']'); |
|
92 | + if (array_key_exists($item, $_COOKIE)) { |
|
93 | + $logger->info('Delete cookie item [' . $item . ']'); |
|
94 | 94 | unset($_COOKIE[$item]); |
95 | 95 | return true; |
96 | 96 | } |
97 | - else{ |
|
98 | - $logger->warning('Cookie item ['.$item.'] to be deleted does not exists'); |
|
97 | + else { |
|
98 | + $logger->warning('Cookie item [' . $item . '] to be deleted does not exists'); |
|
99 | 99 | return false; |
100 | 100 | } |
101 | 101 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @param string $item the cookie item name |
106 | 106 | * @return boolean true if the cookie item is set, false or not |
107 | 107 | */ |
108 | - public static function exists($item){ |
|
108 | + public static function exists($item) { |
|
109 | 109 | return array_key_exists($item, $_COOKIE); |
110 | 110 | } |
111 | 111 |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * Class for Benchmark |
29 | 29 | */ |
30 | - class Benchmark{ |
|
30 | + class Benchmark { |
|
31 | 31 | /** |
32 | 32 | * The markers for excution time |
33 | 33 | * @var array |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * This method is used to mark one point for benchmark (execution time and memory usage) |
45 | 45 | * @param string $name the marker name |
46 | 46 | */ |
47 | - public function mark($name){ |
|
47 | + public function mark($name) { |
|
48 | 48 | //Marker for execution time |
49 | 49 | $this->markersTime[$name] = microtime(true); |
50 | 50 | //Marker for memory usage |
@@ -58,12 +58,12 @@ discard block |
||
58 | 58 | * @param integer $decimalCount the number of decimal |
59 | 59 | * @return string the total execution time |
60 | 60 | */ |
61 | - public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
62 | - if(! $startMarkerName || !isset($this->markersTime[$startMarkerName])){ |
|
61 | + public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6) { |
|
62 | + if (!$startMarkerName || !isset($this->markersTime[$startMarkerName])) { |
|
63 | 63 | return 0; |
64 | 64 | } |
65 | 65 | |
66 | - if(! isset($this->markersTime[$endMarkerName])){ |
|
66 | + if (!isset($this->markersTime[$endMarkerName])) { |
|
67 | 67 | $this->markersTime[$endMarkerName] = microtime(true); |
68 | 68 | } |
69 | 69 | return number_format($this->markersTime[$endMarkerName] - $this->markersTime[$startMarkerName], $decimalCount); |
@@ -76,12 +76,12 @@ discard block |
||
76 | 76 | * @param integer $decimalCount the number of decimal |
77 | 77 | * @return string the total memory usage |
78 | 78 | */ |
79 | - public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
80 | - if(! $startMarkerName || !isset($this->markersMemory[$startMarkerName])){ |
|
79 | + public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6) { |
|
80 | + if (!$startMarkerName || !isset($this->markersMemory[$startMarkerName])) { |
|
81 | 81 | return 0; |
82 | 82 | } |
83 | 83 | |
84 | - if(! isset($this->markersMemory[$endMarkerName])){ |
|
84 | + if (!isset($this->markersMemory[$endMarkerName])) { |
|
85 | 85 | $this->markersMemory[$endMarkerName] = microtime(true); |
86 | 86 | } |
87 | 87 | return number_format($this->markersMemory[$endMarkerName] - $this->markersMemory[$startMarkerName], $decimalCount); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function __construct() |
88 | 88 | { |
89 | - $this->logger =& class_loader('Log', 'classes'); |
|
89 | + $this->logger = & class_loader('Log', 'classes'); |
|
90 | 90 | $this->logger->setLogger('Library::Email'); |
91 | 91 | $this->reset(); |
92 | 92 | } |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | public function setTos(array $emails) |
149 | 149 | { |
150 | 150 | foreach ($emails as $name => $email) { |
151 | - if(is_numeric($name)){ |
|
151 | + if (is_numeric($name)) { |
|
152 | 152 | $this->setTo($email); |
153 | 153 | } |
154 | - else{ |
|
154 | + else { |
|
155 | 155 | $this->setTo($email, $name); |
156 | 156 | } |
157 | 157 | } |
@@ -281,8 +281,8 @@ discard block |
||
281 | 281 | */ |
282 | 282 | public function addAttachment($path, $filename = null, $data = null) |
283 | 283 | { |
284 | - if(! file_exists($path)){ |
|
285 | - show_error('The file [' .$path. '] does not exists.'); |
|
284 | + if (!file_exists($path)) { |
|
285 | + show_error('The file [' . $path . '] does not exists.'); |
|
286 | 286 | } |
287 | 287 | $filename = empty($filename) ? basename($path) : $filename; |
288 | 288 | $filename = $this->encodeUtf8($this->filterOther((string) $filename)); |
@@ -304,13 +304,13 @@ discard block |
||
304 | 304 | */ |
305 | 305 | public function getAttachmentData($path) |
306 | 306 | { |
307 | - if(! file_exists($path)){ |
|
308 | - show_error('The file [' .$path. '] does not exists.'); |
|
307 | + if (!file_exists($path)) { |
|
308 | + show_error('The file [' . $path . '] does not exists.'); |
|
309 | 309 | } |
310 | 310 | $filesize = filesize($path); |
311 | 311 | $handle = fopen($path, "r"); |
312 | 312 | $attachment = null; |
313 | - if(is_resource($handle)){ |
|
313 | + if (is_resource($handle)) { |
|
314 | 314 | $attachment = fread($handle, $filesize); |
315 | 315 | fclose($handle); |
316 | 316 | } |
@@ -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 | } |
@@ -85,15 +85,15 @@ discard block |
||
85 | 85 | |
86 | 86 | //if the language exists in cookie use it |
87 | 87 | $cfgKey = get_config('language_cookie_name'); |
88 | - $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']'); |
|
88 | + $this->logger->debug('Getting current language from cookie [' . $cfgKey . ']'); |
|
89 | 89 | $objCookie = & class_loader('Cookie'); |
90 | 90 | $cookieLang = $objCookie->get($cfgKey); |
91 | - if($cookieLang && $this->isValid($cookieLang)){ |
|
91 | + if ($cookieLang && $this->isValid($cookieLang)) { |
|
92 | 92 | $this->current = $cookieLang; |
93 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']'); |
|
93 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is valid so we will set the language using the cookie value [' . $cookieLang . ']'); |
|
94 | 94 | } |
95 | - else{ |
|
96 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
|
95 | + else { |
|
96 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is not set, use the default value [' . $this->getDefault() . ']'); |
|
97 | 97 | $this->current = $this->getDefault(); |
98 | 98 | } |
99 | 99 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @return array the language message list |
105 | 105 | */ |
106 | - public function getAll(){ |
|
106 | + public function getAll() { |
|
107 | 107 | return $this->languages; |
108 | 108 | } |
109 | 109 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * @param string $key the language key to identify |
114 | 114 | * @param string $value the language message value |
115 | 115 | */ |
116 | - public function set($key, $value){ |
|
116 | + public function set($key, $value) { |
|
117 | 117 | $this->languages[$key] = $value; |
118 | 118 | } |
119 | 119 | |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @return string the language message value |
127 | 127 | */ |
128 | - public function get($key, $default = 'LANGUAGE_ERROR'){ |
|
129 | - if(isset($this->languages[$key])){ |
|
128 | + public function get($key, $default = 'LANGUAGE_ERROR') { |
|
129 | + if (isset($this->languages[$key])) { |
|
130 | 130 | return $this->languages[$key]; |
131 | 131 | } |
132 | - $this->logger->warning('Language key [' .$key. '] does not exist use the default value [' .$default. ']'); |
|
132 | + $this->logger->warning('Language key [' . $key . '] does not exist use the default value [' . $default . ']'); |
|
133 | 133 | return $default; |
134 | 134 | } |
135 | 135 | |
@@ -140,10 +140,10 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return boolean true if the language directory exists, false or not |
142 | 142 | */ |
143 | - public function isValid($language){ |
|
143 | + public function isValid($language) { |
|
144 | 144 | $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH); |
145 | - foreach($searchDir as $dir){ |
|
146 | - if(file_exists($dir . $language) && is_dir($dir . $language)){ |
|
145 | + foreach ($searchDir as $dir) { |
|
146 | + if (file_exists($dir . $language) && is_dir($dir . $language)) { |
|
147 | 147 | return true; |
148 | 148 | } |
149 | 149 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return string the default language |
157 | 157 | */ |
158 | - public function getDefault(){ |
|
158 | + public function getDefault() { |
|
159 | 159 | return $this->default; |
160 | 160 | } |
161 | 161 | |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * |
165 | 165 | * @return string the current language |
166 | 166 | */ |
167 | - public function getCurrent(){ |
|
167 | + public function getCurrent() { |
|
168 | 168 | return $this->current; |
169 | 169 | } |
170 | 170 | |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | * @param string $name the short language name like "en", "fr". |
175 | 175 | * @param string $description the human readable description of this language |
176 | 176 | */ |
177 | - public function addLang($name, $description){ |
|
178 | - if(isset($this->availables[$name])){ |
|
177 | + public function addLang($name, $description) { |
|
178 | + if (isset($this->availables[$name])) { |
|
179 | 179 | return; //already added cost in performance |
180 | 180 | } |
181 | - if($this->isValid($name)){ |
|
181 | + if ($this->isValid($name)) { |
|
182 | 182 | $this->availables[$name] = $description; |
183 | 183 | } |
184 | - else{ |
|
184 | + else { |
|
185 | 185 | show_error('The language [' . $name . '] is not valid or does not exists.'); |
186 | 186 | } |
187 | 187 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * |
192 | 192 | * @return array the list of the application language |
193 | 193 | */ |
194 | - public function getSupported(){ |
|
194 | + public function getSupported() { |
|
195 | 195 | return $this->availables; |
196 | 196 | } |
197 | 197 | |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * |
201 | 201 | * @param array $langs the languages array of the messages to be added |
202 | 202 | */ |
203 | - public function addLangMessages(array $langs){ |
|
203 | + public function addLangMessages(array $langs) { |
|
204 | 204 | foreach ($langs as $key => $value) { |
205 | 205 | $this->set($key, $value); |
206 | 206 | } |
@@ -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(self::$logger == null){ |
|
46 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
44 | + private static function getLogger() { |
|
45 | + if (self::$logger == null) { |
|
46 | + self::$logger[0] = & class_loader('Log', 'classes'); |
|
47 | 47 | self::$logger[0]->setLogger('Library::Session'); |
48 | 48 | } |
49 | 49 | return self::$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 = self::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 = self::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 = self::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 = self::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 = self::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 | } |
@@ -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 Request{ |
|
27 | + class Request { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The value for the super global $_GET |
@@ -90,21 +90,21 @@ discard block |
||
90 | 90 | /** |
91 | 91 | * Construct new request instance |
92 | 92 | */ |
93 | - public function __construct(){ |
|
93 | + public function __construct() { |
|
94 | 94 | $this->get = $_GET; |
95 | 95 | $this->post = $_POST; |
96 | 96 | $this->server = $_SERVER; |
97 | 97 | $this->query = $_REQUEST; |
98 | 98 | $this->cookie = $_COOKIE; |
99 | 99 | $this->file = $_FILES; |
100 | - $this->session =& class_loader('Session', 'classes'); |
|
100 | + $this->session = & class_loader('Session', 'classes'); |
|
101 | 101 | $this->method = $this->server('REQUEST_METHOD'); |
102 | 102 | $this->requestUri = $this->server('REQUEST_URI'); |
103 | 103 | $this->header = array(); |
104 | - if(function_exists('apache_request_headers')){ |
|
104 | + if (function_exists('apache_request_headers')) { |
|
105 | 105 | $this->header = apache_request_headers(); |
106 | 106 | } |
107 | - else if(function_exists('getallheaders')){ |
|
107 | + else if (function_exists('getallheaders')) { |
|
108 | 108 | $this->header = getallheaders(); |
109 | 109 | } |
110 | 110 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * Get the request method |
114 | 114 | * @return string |
115 | 115 | */ |
116 | - public function method(){ |
|
116 | + public function method() { |
|
117 | 117 | return $this->method; |
118 | 118 | } |
119 | 119 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * Get the request URI |
122 | 122 | * @return string |
123 | 123 | */ |
124 | - public function requestUri(){ |
|
124 | + public function requestUri() { |
|
125 | 125 | return $this->requestUri; |
126 | 126 | } |
127 | 127 | |
@@ -131,13 +131,13 @@ discard block |
||
131 | 131 | * @param boolean $xss if need apply some XSS attack rule on the value |
132 | 132 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
133 | 133 | */ |
134 | - public function query($key = null, $xss = true){ |
|
135 | - if(empty($key)){ |
|
134 | + public function query($key = null, $xss = true) { |
|
135 | + if (empty($key)) { |
|
136 | 136 | //return all |
137 | 137 | return $xss ? clean_input($this->query) : $this->query; |
138 | 138 | } |
139 | 139 | $query = array_key_exists($key, $this->query) ? $this->query[$key] : null; |
140 | - if($xss){ |
|
140 | + if ($xss) { |
|
141 | 141 | $query = clean_input($query); |
142 | 142 | } |
143 | 143 | return $query; |
@@ -149,13 +149,13 @@ discard block |
||
149 | 149 | * @param boolean $xss if need apply some XSS attack rule on the value |
150 | 150 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
151 | 151 | */ |
152 | - public function get($key = null, $xss = true){ |
|
153 | - if(empty($key)){ |
|
152 | + public function get($key = null, $xss = true) { |
|
153 | + if (empty($key)) { |
|
154 | 154 | //return all |
155 | 155 | return $xss ? clean_input($this->get) : $this->get; |
156 | 156 | } |
157 | 157 | $get = array_key_exists($key, $this->get) ? $this->get[$key] : null; |
158 | - if($xss){ |
|
158 | + if ($xss) { |
|
159 | 159 | $get = clean_input($get); |
160 | 160 | } |
161 | 161 | return $get; |
@@ -167,13 +167,13 @@ discard block |
||
167 | 167 | * @param boolean $xss if need apply some XSS attack rule on the value |
168 | 168 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
169 | 169 | */ |
170 | - public function post($key = null, $xss = true){ |
|
171 | - if(empty($key)){ |
|
170 | + public function post($key = null, $xss = true) { |
|
171 | + if (empty($key)) { |
|
172 | 172 | //return all |
173 | 173 | return $xss ? clean_input($this->post) : $this->post; |
174 | 174 | } |
175 | 175 | $post = array_key_exists($key, $this->post) ? $this->post[$key] : null; |
176 | - if($xss){ |
|
176 | + if ($xss) { |
|
177 | 177 | $post = clean_input($post); |
178 | 178 | } |
179 | 179 | return $post; |
@@ -185,13 +185,13 @@ discard block |
||
185 | 185 | * @param boolean $xss if need apply some XSS attack rule on the value |
186 | 186 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
187 | 187 | */ |
188 | - public function server($key = null, $xss = true){ |
|
189 | - if(empty($key)){ |
|
188 | + public function server($key = null, $xss = true) { |
|
189 | + if (empty($key)) { |
|
190 | 190 | //return all |
191 | 191 | return $xss ? clean_input($this->server) : $this->server; |
192 | 192 | } |
193 | 193 | $server = array_key_exists($key, $this->server) ? $this->server[$key] : null; |
194 | - if($xss){ |
|
194 | + if ($xss) { |
|
195 | 195 | $server = clean_input($server); |
196 | 196 | } |
197 | 197 | return $server; |
@@ -203,13 +203,13 @@ discard block |
||
203 | 203 | * @param boolean $xss if need apply some XSS attack rule on the value |
204 | 204 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
205 | 205 | */ |
206 | - public function cookie($key = null, $xss = true){ |
|
207 | - if(empty($key)){ |
|
206 | + public function cookie($key = null, $xss = true) { |
|
207 | + if (empty($key)) { |
|
208 | 208 | //return all |
209 | 209 | return $xss ? clean_input($this->cookie) : $this->cookie; |
210 | 210 | } |
211 | 211 | $cookie = array_key_exists($key, $this->cookie) ? $this->cookie[$key] : null; |
212 | - if($xss){ |
|
212 | + if ($xss) { |
|
213 | 213 | $cookie = clean_input($cookie); |
214 | 214 | } |
215 | 215 | return $cookie; |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @param string $key the item key to be fetched |
221 | 221 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
222 | 222 | */ |
223 | - public function file($key){ |
|
223 | + public function file($key) { |
|
224 | 224 | $file = array_key_exists($key, $this->file) ? $this->file[$key] : null; |
225 | 225 | return $file; |
226 | 226 | } |
@@ -231,9 +231,9 @@ discard block |
||
231 | 231 | * @param boolean $xss if need apply some XSS attack rule on the value |
232 | 232 | * @return array|mixed the item value if the key exists or null if the key does not exists |
233 | 233 | */ |
234 | - public function session($key, $xss = true){ |
|
234 | + public function session($key, $xss = true) { |
|
235 | 235 | $session = $this->session->get($key); |
236 | - if($xss){ |
|
236 | + if ($xss) { |
|
237 | 237 | $session = clean_input($session); |
238 | 238 | } |
239 | 239 | return $session; |
@@ -245,9 +245,9 @@ discard block |
||
245 | 245 | * @param boolean $xss if need apply some XSS attack rule on the value |
246 | 246 | * @return mixed the item value if the key exists or null if the key does not exists |
247 | 247 | */ |
248 | - public function header($key, $xss = true){ |
|
248 | + public function header($key, $xss = true) { |
|
249 | 249 | $header = array_key_exists($key, $this->header) ? $this->header[$key] : null; |
250 | - if($xss){ |
|
250 | + if ($xss) { |
|
251 | 251 | $header = clean_input($header); |
252 | 252 | } |
253 | 253 | return $header; |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * This class represent the event detail to dispatch to correspond listener |
29 | 29 | */ |
30 | - class EventInfo{ |
|
30 | + class EventInfo { |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * The event name |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public $stop; |
56 | 56 | |
57 | - public function __construct($name, $payload = array(), $returnBack = false, $stop = false){ |
|
57 | + public function __construct($name, $payload = array(), $returnBack = false, $stop = false) { |
|
58 | 58 | $this->name = $name; |
59 | 59 | $this->payload = $payload; |
60 | 60 | $this->returnBack = $returnBack; |