@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | - class DBSessionModel extends DBSessionHandlerModel{ |
|
| 2 | + class DBSessionModel extends DBSessionHandlerModel { |
|
| 3 | 3 | |
| 4 | 4 | protected $_table = 'ses'; |
| 5 | 5 | protected $primary_key = 's_id'; |
@@ -14,14 +14,14 @@ discard block |
||
| 14 | 14 | 'skey' => 'test_id' //VARCHAR(255) |
| 15 | 15 | ); |
| 16 | 16 | |
| 17 | - public function deleteByTime($time){ |
|
| 17 | + public function deleteByTime($time) { |
|
| 18 | 18 | $this->_database->from($this->_table) |
| 19 | 19 | ->where('s_time', '<', $time) |
| 20 | 20 | ->delete(); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
| 24 | - public function getKeyValue(){ |
|
| 24 | + public function getKeyValue() { |
|
| 25 | 25 | $user_id = 0; |
| 26 | 26 | return $user_id; |
| 27 | 27 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | /** |
| 61 | 61 | * Custom application path for tests |
| 62 | 62 | */ |
| 63 | - define('APPS_PATH', TESTS_PATH .'hmvc' . DS); |
|
| 63 | + define('APPS_PATH', TESTS_PATH . 'hmvc' . DS); |
|
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * The path to the controller directory of your application. |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
| 197 | 197 | * in HMVC architecture (hierichical, controllers, models, views). |
| 198 | 198 | */ |
| 199 | - define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS); |
|
| 199 | + define('MODULE_PATH', dirname(realpath(__FILE__)) . DS . 'hmvc' . DS . 'modules' . DS); |
|
| 200 | 200 | |
| 201 | 201 | /** |
| 202 | 202 | * The path to the directory of sources external to your application. |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | //Fix to allow test as if application is running in CLI mode $_SESSION global variable is not available |
| 236 | 236 | $_SESSION = array(); |
| 237 | 237 | |
| 238 | - if(! isset($_SERVER['REMOTE_ADDR'])){ |
|
| 238 | + if (!isset($_SERVER['REMOTE_ADDR'])) { |
|
| 239 | 239 | $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; |
| 240 | 240 | } |
| 241 | 241 | |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | require_once 'include/autoloader.php'; |
| 244 | 244 | |
| 245 | 245 | //check for composer autoload file if exists include it |
| 246 | - if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 246 | + if (file_exists(VENDOR_PATH . 'autoload.php')) { |
|
| 247 | 247 | require_once VENDOR_PATH . 'autoload.php'; |
| 248 | 248 | |
| 249 | 249 | //define the class alias for vstream |
@@ -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 FileCache implements CacheInterface{ |
|
| 27 | + class FileCache implements CacheInterface { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Whether to enable compression of the cache data file. |
@@ -39,23 +39,23 @@ discard block |
||
| 39 | 39 | private $logger; |
| 40 | 40 | |
| 41 | 41 | |
| 42 | - public function __construct(Log $logger = null){ |
|
| 43 | - if(! $this->isSupported()){ |
|
| 42 | + public function __construct(Log $logger = null) { |
|
| 43 | + if (!$this->isSupported()) { |
|
| 44 | 44 | show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.'); |
| 45 | 45 | } |
| 46 | 46 | /** |
| 47 | 47 | * instance of the Log class |
| 48 | 48 | */ |
| 49 | - if(is_object($logger)){ |
|
| 49 | + if (is_object($logger)) { |
|
| 50 | 50 | $this->logger = $logger; |
| 51 | 51 | } |
| 52 | - else{ |
|
| 53 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 52 | + else { |
|
| 53 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 54 | 54 | $this->logger->setLogger('Library::FileCache'); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | //if Zlib extension is not loaded set compressCacheData to false |
| 58 | - if(! extension_loaded('zlib')){ |
|
| 58 | + if (!extension_loaded('zlib')) { |
|
| 59 | 59 | $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE'); |
| 60 | 60 | $this->compressCacheData = false; |
| 61 | 61 | } |
@@ -66,17 +66,17 @@ discard block |
||
| 66 | 66 | * @param string $key the key to identify the cache data |
| 67 | 67 | * @return mixed the cache data if exists else return false |
| 68 | 68 | */ |
| 69 | - public function get($key){ |
|
| 70 | - $this->logger->debug('Getting cache data for key ['. $key .']'); |
|
| 69 | + public function get($key) { |
|
| 70 | + $this->logger->debug('Getting cache data for key [' . $key . ']'); |
|
| 71 | 71 | $filePath = $this->getFilePath($key); |
| 72 | - if(! file_exists($filePath)){ |
|
| 73 | - $this->logger->info('No cache file found for the key ['. $key .'], return false'); |
|
| 72 | + if (!file_exists($filePath)) { |
|
| 73 | + $this->logger->info('No cache file found for the key [' . $key . '], return false'); |
|
| 74 | 74 | return false; |
| 75 | 75 | } |
| 76 | - $this->logger->info('The cache file [' .$filePath. '] for the key ['. $key .'] exists, check if the cache data is valid'); |
|
| 77 | - $handle = fopen($filePath,'r'); |
|
| 78 | - if(! is_resource($handle)){ |
|
| 79 | - $this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false'); |
|
| 76 | + $this->logger->info('The cache file [' . $filePath . '] for the key [' . $key . '] exists, check if the cache data is valid'); |
|
| 77 | + $handle = fopen($filePath, 'r'); |
|
| 78 | + if (!is_resource($handle)) { |
|
| 79 | + $this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false'); |
|
| 80 | 80 | return false; |
| 81 | 81 | } |
| 82 | 82 | // Getting a shared lock |
@@ -84,20 +84,20 @@ discard block |
||
| 84 | 84 | $data = file_get_contents($filePath); |
| 85 | 85 | fclose($handle); |
| 86 | 86 | $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
| 87 | - if (! $data) { |
|
| 88 | - $this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false'); |
|
| 87 | + if (!$data) { |
|
| 88 | + $this->logger->error('Can not unserialize the cache data for the key [' . $key . '], return false'); |
|
| 89 | 89 | // If unserializing somehow didn't work out, we'll delete the file |
| 90 | 90 | unlink($filePath); |
| 91 | 91 | return false; |
| 92 | 92 | } |
| 93 | 93 | if (time() > $data['expire']) { |
| 94 | - $this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']'); |
|
| 94 | + $this->logger->info('The cache data for the key [' . $key . '] already expired delete the cache file [' . $filePath . ']'); |
|
| 95 | 95 | // Unlinking when the file was expired |
| 96 | 96 | unlink($filePath); |
| 97 | 97 | return false; |
| 98 | 98 | } |
| 99 | - else{ |
|
| 100 | - $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', $data['expire']) . ']'); |
|
| 99 | + else { |
|
| 100 | + $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', $data['expire']) . ']'); |
|
| 101 | 101 | return $data['data']; |
| 102 | 102 | } |
| 103 | 103 | } |
@@ -110,13 +110,13 @@ discard block |
||
| 110 | 110 | * @param integer $ttl the cache life time |
| 111 | 111 | * @return boolean true if success otherwise will return false |
| 112 | 112 | */ |
| 113 | - public function set($key, $data, $ttl = 0){ |
|
| 113 | + public function set($key, $data, $ttl = 0) { |
|
| 114 | 114 | $expire = time() + $ttl; |
| 115 | - $this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
| 115 | + $this->logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
| 116 | 116 | $filePath = $this->getFilePath($key); |
| 117 | - $handle = fopen($filePath,'w'); |
|
| 118 | - if(! is_resource($handle)){ |
|
| 119 | - $this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false'); |
|
| 117 | + $handle = fopen($filePath, 'w'); |
|
| 118 | + if (!is_resource($handle)) { |
|
| 119 | + $this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false'); |
|
| 120 | 120 | return false; |
| 121 | 121 | } |
| 122 | 122 | flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed |
@@ -129,13 +129,13 @@ discard block |
||
| 129 | 129 | ) |
| 130 | 130 | ); |
| 131 | 131 | $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData); |
| 132 | - if(! $result){ |
|
| 133 | - $this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false'); |
|
| 132 | + if (!$result) { |
|
| 133 | + $this->logger->error('Can not write cache data into file [' . $filePath . '] for the key [' . $key . '], return false'); |
|
| 134 | 134 | fclose($handle); |
| 135 | 135 | return false; |
| 136 | 136 | } |
| 137 | - else{ |
|
| 138 | - $this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']'); |
|
| 137 | + else { |
|
| 138 | + $this->logger->info('Cache data saved into file [' . $filePath . '] for the key [' . $key . ']'); |
|
| 139 | 139 | fclose($handle); |
| 140 | 140 | chmod($filePath, 0640); |
| 141 | 141 | return true; |
@@ -149,16 +149,16 @@ discard block |
||
| 149 | 149 | * @return boolean true if the cache is delete, false if can't delete |
| 150 | 150 | * the cache or the cache with the given key not exist |
| 151 | 151 | */ |
| 152 | - public function delete($key){ |
|
| 153 | - $this->logger->debug('Deleting of cache data for key [' .$key. ']'); |
|
| 152 | + public function delete($key) { |
|
| 153 | + $this->logger->debug('Deleting of cache data for key [' . $key . ']'); |
|
| 154 | 154 | $filePath = $this->getFilePath($key); |
| 155 | - $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']'); |
|
| 156 | - if(! file_exists($filePath)){ |
|
| 155 | + $this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']'); |
|
| 156 | + if (!file_exists($filePath)) { |
|
| 157 | 157 | $this->logger->info('This cache file does not exists skipping'); |
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | - else{ |
|
| 161 | - $this->logger->info('Found cache file [' .$filePath. '] remove it'); |
|
| 160 | + else { |
|
| 161 | + $this->logger->info('Found cache file [' . $filePath . '] remove it'); |
|
| 162 | 162 | unlink($filePath); |
| 163 | 163 | return true; |
| 164 | 164 | } |
@@ -172,25 +172,25 @@ discard block |
||
| 172 | 172 | * 'expire' => expiration time of the cache (Unix timestamp), |
| 173 | 173 | * 'ttl' => the time to live of the cache in second |
| 174 | 174 | */ |
| 175 | - public function getInfo($key){ |
|
| 176 | - $this->logger->debug('Getting of cache info for key [' .$key. ']'); |
|
| 175 | + public function getInfo($key) { |
|
| 176 | + $this->logger->debug('Getting of cache info for key [' . $key . ']'); |
|
| 177 | 177 | $filePath = $this->getFilePath($key); |
| 178 | - $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']'); |
|
| 179 | - if(! file_exists($filePath)){ |
|
| 178 | + $this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']'); |
|
| 179 | + if (!file_exists($filePath)) { |
|
| 180 | 180 | $this->logger->info('This cache file does not exists skipping'); |
| 181 | 181 | return false; |
| 182 | 182 | } |
| 183 | - else{ |
|
| 184 | - $this->logger->info('Found cache file [' .$filePath. '] check the validity'); |
|
| 183 | + else { |
|
| 184 | + $this->logger->info('Found cache file [' . $filePath . '] check the validity'); |
|
| 185 | 185 | $data = file_get_contents($filePath); |
| 186 | 186 | $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
| 187 | - if(! $data){ |
|
| 187 | + if (!$data) { |
|
| 188 | 188 | $this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']'); |
| 189 | 189 | return false; |
| 190 | 190 | } |
| 191 | - else{ |
|
| 191 | + else { |
|
| 192 | 192 | $this->logger->info('This cache data is OK check for expire'); |
| 193 | - if(isset($data['expire']) && $data['expire'] > time()){ |
|
| 193 | + if (isset($data['expire']) && $data['expire'] > time()) { |
|
| 194 | 194 | $this->logger->info('This cache not yet expired return cache informations'); |
| 195 | 195 | $info = array( |
| 196 | 196 | 'mtime' => $data['mtime'], |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | ); |
| 200 | 200 | return $info; |
| 201 | 201 | } |
| 202 | - else{ |
|
| 202 | + else { |
|
| 203 | 203 | $this->logger->info('This cache already expired return false'); |
| 204 | 204 | return false; |
| 205 | 205 | } |
@@ -211,26 +211,26 @@ discard block |
||
| 211 | 211 | /** |
| 212 | 212 | * Used to delete expired cache data |
| 213 | 213 | */ |
| 214 | - public function deleteExpiredCache(){ |
|
| 214 | + public function deleteExpiredCache() { |
|
| 215 | 215 | $this->logger->debug('Deleting of expired cache files'); |
| 216 | 216 | $list = glob(CACHE_PATH . '*.cache'); |
| 217 | - if(! $list){ |
|
| 217 | + if (!$list) { |
|
| 218 | 218 | $this->logger->info('No cache files were found skipping'); |
| 219 | 219 | } |
| 220 | - else{ |
|
| 220 | + else { |
|
| 221 | 221 | $this->logger->info('Found [' . count($list) . '] cache files to remove if expired'); |
| 222 | 222 | foreach ($list as $file) { |
| 223 | 223 | $this->logger->debug('Processing the cache file [' . $file . ']'); |
| 224 | 224 | $data = file_get_contents($file); |
| 225 | 225 | $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
| 226 | - if(! $data){ |
|
| 226 | + if (!$data) { |
|
| 227 | 227 | $this->logger->warning('Can not unserialize the cache data for file [' . $file . ']'); |
| 228 | 228 | } |
| 229 | - else if(time() > $data['expire']){ |
|
| 229 | + else if (time() > $data['expire']) { |
|
| 230 | 230 | $this->logger->info('The cache data for file [' . $file . '] already expired remove it'); |
| 231 | 231 | unlink($file); |
| 232 | 232 | } |
| 233 | - else{ |
|
| 233 | + else { |
|
| 234 | 234 | $this->logger->info('The cache data for file [' . $file . '] not yet expired skip it'); |
| 235 | 235 | } |
| 236 | 236 | } |
@@ -240,13 +240,13 @@ discard block |
||
| 240 | 240 | /** |
| 241 | 241 | * Remove all file from cache folder |
| 242 | 242 | */ |
| 243 | - public function clean(){ |
|
| 243 | + public function clean() { |
|
| 244 | 244 | $this->logger->debug('Deleting of all cache files'); |
| 245 | 245 | $list = glob(CACHE_PATH . '*.cache'); |
| 246 | - if(! $list){ |
|
| 246 | + if (!$list) { |
|
| 247 | 247 | $this->logger->info('No cache files were found skipping'); |
| 248 | 248 | } |
| 249 | - else{ |
|
| 249 | + else { |
|
| 250 | 250 | $this->logger->info('Found [' . count($list) . '] cache files to remove'); |
| 251 | 251 | foreach ($list as $file) { |
| 252 | 252 | $this->logger->debug('Processing the cache file [' . $file . ']'); |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | /** |
| 259 | 259 | * @return boolean |
| 260 | 260 | */ |
| 261 | - public function isCompressCacheData(){ |
|
| 261 | + public function isCompressCacheData() { |
|
| 262 | 262 | return $this->compressCacheData; |
| 263 | 263 | } |
| 264 | 264 | |
@@ -267,14 +267,14 @@ discard block |
||
| 267 | 267 | * |
| 268 | 268 | * @return self |
| 269 | 269 | */ |
| 270 | - public function setCompressCacheData($status = true){ |
|
| 270 | + public function setCompressCacheData($status = true) { |
|
| 271 | 271 | //if Zlib extension is not loaded set compressCacheData to false |
| 272 | - if($status === true && ! extension_loaded('zlib')){ |
|
| 272 | + if ($status === true && !extension_loaded('zlib')) { |
|
| 273 | 273 | |
| 274 | 274 | $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE'); |
| 275 | 275 | $this->compressCacheData = false; |
| 276 | 276 | } |
| 277 | - else{ |
|
| 277 | + else { |
|
| 278 | 278 | $this->compressCacheData = $status; |
| 279 | 279 | } |
| 280 | 280 | return $this; |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * |
| 286 | 286 | * @return bool |
| 287 | 287 | */ |
| 288 | - public function isSupported(){ |
|
| 288 | + public function isSupported() { |
|
| 289 | 289 | return CACHE_PATH && is_dir(CACHE_PATH) && is_writable(CACHE_PATH); |
| 290 | 290 | } |
| 291 | 291 | |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | * Return the Log instance |
| 294 | 294 | * @return Log |
| 295 | 295 | */ |
| 296 | - public function getLogger(){ |
|
| 296 | + public function getLogger() { |
|
| 297 | 297 | return $this->logger; |
| 298 | 298 | } |
| 299 | 299 | |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * Set the log instance |
| 302 | 302 | * @param Log $logger the log object |
| 303 | 303 | */ |
| 304 | - public function setLogger(Log $logger){ |
|
| 304 | + public function setLogger(Log $logger) { |
|
| 305 | 305 | $this->logger = $logger; |
| 306 | 306 | return $this; |
| 307 | 307 | } |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | * @param $key the cache item key |
| 313 | 313 | * @return string the full cache file path for this key |
| 314 | 314 | */ |
| 315 | - private function getFilePath($key){ |
|
| 315 | + private function getFilePath($key) { |
|
| 316 | 316 | return CACHE_PATH . md5($key) . '.cache'; |
| 317 | 317 | } |
| 318 | 318 | } |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | private static $config = null; |
| 15 | 15 | |
| 16 | - public function __construct(){ |
|
| 16 | + public function __construct() { |
|
| 17 | 17 | $this->db = new Database(array( |
| 18 | 18 | 'driver' => 'sqlite', |
| 19 | 19 | 'database' => TESTS_PATH . 'assets/db_tests.db', |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | |
| 51 | 51 | |
| 52 | - public function testUsingSessionConfiguration(){ |
|
| 52 | + public function testUsingSessionConfiguration() { |
|
| 53 | 53 | //using value in the configuration |
| 54 | 54 | static::$config->set('session_save_path', 'DBSessionModel'); |
| 55 | 55 | static::$config->set('session_secret', $this->secret); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | $this->assertEquals($dbsh->decode($encoded), 'foo'); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - public function testWhenDataIsExpired(){ |
|
| 78 | + public function testWhenDataIsExpired() { |
|
| 79 | 79 | $dbsh = new DBSessionHandler($this->model); |
| 80 | 80 | $dbsh->setSessionSecret($this->secret); |
| 81 | 81 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | $this->assertNull($dbsh->read('foo')); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - public function testWhenDataAlreadyExistDoUpdate(){ |
|
| 91 | + public function testWhenDataAlreadyExistDoUpdate() { |
|
| 92 | 92 | $dbsh = new DBSessionHandler($this->model); |
| 93 | 93 | $dbsh->setSessionSecret($this->secret); |
| 94 | 94 | |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | $this->assertEquals($dbsh->read('foo'), '445'); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - public function testUsingCustomModelInstance(){ |
|
| 104 | + public function testUsingCustomModelInstance() { |
|
| 105 | 105 | $dbsh = new DBSessionHandler($this->model); |
| 106 | 106 | $dbsh->setSessionSecret($this->secret); |
| 107 | 107 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | |
| 132 | - public function testUsingCustomLogInstance(){ |
|
| 132 | + public function testUsingCustomLogInstance() { |
|
| 133 | 133 | $dbsh = new DBSessionHandler($this->model, new Log()); |
| 134 | 134 | $dbsh->setSessionSecret($this->secret); |
| 135 | 135 | |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | $this->assertEquals($dbsh->decode($encoded), 'foo'); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - public function testUsingCustomLoaderInstance(){ |
|
| 159 | + public function testUsingCustomLoaderInstance() { |
|
| 160 | 160 | $dbsh = new DBSessionHandler($this->model, null, new Loader()); |
| 161 | 161 | $dbsh->setSessionSecret($this->secret); |
| 162 | 162 | |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | |
| 187 | - public function testWhenModelInsanceIsNotSet(){ |
|
| 187 | + public function testWhenModelInsanceIsNotSet() { |
|
| 188 | 188 | $dbsh = new DBSessionHandler(null, null, new Loader()); |
| 189 | 189 | $dbsh->setSessionSecret($this->secret); |
| 190 | 190 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | $this->assertEquals($dbsh->decode($encoded), 'foo'); |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - public function testWhenModelTableColumnsIsNotSet(){ |
|
| 215 | + public function testWhenModelTableColumnsIsNotSet() { |
|
| 216 | 216 | //session table is empty |
| 217 | 217 | $this->model->setSessionTableColumns(array()); |
| 218 | 218 | $dbsh = new DBSessionHandler($this->model); |
@@ -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 | |
@@ -25,13 +25,13 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class FormValidation{ |
|
| 28 | + class FormValidation { |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * The form validation status |
| 32 | 32 | * @var boolean |
| 33 | 33 | */ |
| 34 | - protected $_success = false; |
|
| 34 | + protected $_success = false; |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * The list of errors messages |
@@ -40,31 +40,31 @@ discard block |
||
| 40 | 40 | protected $_errorsMessages = array(); |
| 41 | 41 | |
| 42 | 42 | // Array of rule sets, fieldName => PIPE seperated ruleString |
| 43 | - protected $_rules = array(); |
|
| 43 | + protected $_rules = array(); |
|
| 44 | 44 | |
| 45 | 45 | // Array of errors, niceName => Error Message |
| 46 | - protected $_errors = array(); |
|
| 46 | + protected $_errors = array(); |
|
| 47 | 47 | |
| 48 | 48 | // Array of post Key => Nice name labels |
| 49 | - protected $_labels = array(); |
|
| 49 | + protected $_labels = array(); |
|
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * The errors delimiters |
| 53 | 53 | * @var array |
| 54 | 54 | */ |
| 55 | - protected $_allErrorsDelimiter = array('<div class="error">', '</div>'); |
|
| 55 | + protected $_allErrorsDelimiter = array('<div class="error">', '</div>'); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * The each error delimiter |
| 59 | 59 | * @var array |
| 60 | 60 | */ |
| 61 | - protected $_eachErrorDelimiter = array('<p class="error">', '</p>'); |
|
| 61 | + protected $_eachErrorDelimiter = array('<p class="error">', '</p>'); |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * Indicated if need force the validation to be failed |
| 65 | 65 | * @var boolean |
| 66 | 66 | */ |
| 67 | - protected $_forceFail = false; |
|
| 67 | + protected $_forceFail = false; |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * The list of the error messages overrides by the original |
@@ -98,13 +98,13 @@ discard block |
||
| 98 | 98 | * @return void |
| 99 | 99 | */ |
| 100 | 100 | public function __construct() { |
| 101 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 101 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 102 | 102 | $this->logger->setLogger('Library::FormValidation'); |
| 103 | 103 | |
| 104 | 104 | //Load form validation language message |
| 105 | 105 | Loader::lang('form_validation'); |
| 106 | 106 | $obj = & get_instance(); |
| 107 | - $this->_errorsMessages = array( |
|
| 107 | + $this->_errorsMessages = array( |
|
| 108 | 108 | 'required' => $obj->lang->get('fv_required'), |
| 109 | 109 | 'min_length' => $obj->lang->get('fv_min_length'), |
| 110 | 110 | 'max_length' => $obj->lang->get('fv_max_length'), |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $this->_success = false; |
| 142 | 142 | $this->_forceFail = false; |
| 143 | 143 | $this->data = array(); |
| 144 | - $this->enableCsrfCheck = false; |
|
| 144 | + $this->enableCsrfCheck = false; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * |
| 151 | 151 | * @return FormValidation Current instance of object. |
| 152 | 152 | */ |
| 153 | - public function setData(array $data){ |
|
| 153 | + public function setData(array $data) { |
|
| 154 | 154 | $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data)); |
| 155 | 155 | $this->data = $data; |
| 156 | 156 | return $this; |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * Get the form validation data |
| 161 | 161 | * @return array the form validation data to be validated |
| 162 | 162 | */ |
| 163 | - public function getData(){ |
|
| 163 | + public function getData() { |
|
| 164 | 164 | return $this->data; |
| 165 | 165 | } |
| 166 | 166 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * |
| 170 | 170 | * @return string the function name |
| 171 | 171 | */ |
| 172 | - protected function _toCallCase($funcName, $prefix='_validate') { |
|
| 172 | + protected function _toCallCase($funcName, $prefix = '_validate') { |
|
| 173 | 173 | $funcName = strtolower($funcName); |
| 174 | 174 | $finalFuncName = $prefix; |
| 175 | 175 | foreach (explode('_', $funcName) as $funcNamePart) { |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | * @return boolean Whether or not the form has been submitted or the data is available for validation. |
| 194 | 194 | */ |
| 195 | 195 | public function canDoValidation() { |
| 196 | - return get_instance()->request->method() === 'POST' || ! empty($this->data); |
|
| 196 | + return get_instance()->request->method() === 'POST' || !empty($this->data); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -215,16 +215,16 @@ discard block |
||
| 215 | 215 | * afterwards. |
| 216 | 216 | */ |
| 217 | 217 | protected function _run() { |
| 218 | - if(get_instance()->request->method() == 'POST' || $this->enableCsrfCheck){ |
|
| 218 | + if (get_instance()->request->method() == 'POST' || $this->enableCsrfCheck) { |
|
| 219 | 219 | $this->logger->debug('Check if CSRF is enabled in configuration'); |
| 220 | 220 | //first check for CSRF |
| 221 | - if( get_config('csrf_enable', false) || $this->enableCsrfCheck){ |
|
| 221 | + if (get_config('csrf_enable', false) || $this->enableCsrfCheck) { |
|
| 222 | 222 | $this->logger->info('Check the CSRF value if is valid'); |
| 223 | - if(! Security::validateCSRF()){ |
|
| 223 | + if (!Security::validateCSRF()) { |
|
| 224 | 224 | show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.'); |
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | - else{ |
|
| 227 | + else { |
|
| 228 | 228 | $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it'); |
| 229 | 229 | } |
| 230 | 230 | } |
@@ -232,10 +232,10 @@ discard block |
||
| 232 | 232 | $this->_forceFail = false; |
| 233 | 233 | |
| 234 | 234 | foreach ($this->getData() as $inputName => $inputVal) { |
| 235 | - if(is_array($this->data[$inputName])){ |
|
| 235 | + if (is_array($this->data[$inputName])) { |
|
| 236 | 236 | $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
| 237 | 237 | } |
| 238 | - else{ |
|
| 238 | + else { |
|
| 239 | 239 | $this->data[$inputName] = trim($this->data[$inputName]); |
| 240 | 240 | } |
| 241 | 241 | |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | public function setRule($inputField, $inputLabel, $ruleSets) { |
| 263 | 263 | $this->_rules[$inputField] = $ruleSets; |
| 264 | 264 | $this->_labels[$inputField] = $inputLabel; |
| 265 | - $this->logger->info('Set the field rule: name [' .$inputField. '], label [' .$inputLabel. '], rules [' .$ruleSets. ']'); |
|
| 265 | + $this->logger->info('Set the field rule: name [' . $inputField . '], label [' . $inputLabel . '], rules [' . $ruleSets . ']'); |
|
| 266 | 266 | return $this; |
| 267 | 267 | } |
| 268 | 268 | |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | } |
| 427 | 427 | $errorOutput .= $errorsEnd; |
| 428 | 428 | echo ($echo) ? $errorOutput : ''; |
| 429 | - return (! $echo) ? $errorOutput : null; |
|
| 429 | + return (!$echo) ? $errorOutput : null; |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | /** |
@@ -451,25 +451,25 @@ discard block |
||
| 451 | 451 | /* |
| 452 | 452 | //////////////// hack for regex rule that can contain "|" |
| 453 | 453 | */ |
| 454 | - if(strpos($ruleString, 'regex') !== false){ |
|
| 454 | + if (strpos($ruleString, 'regex') !== false) { |
|
| 455 | 455 | $regexRule = array(); |
| 456 | 456 | $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#'; |
| 457 | 457 | preg_match($rule, $ruleString, $regexRule); |
| 458 | 458 | $ruleStringTemp = preg_replace($rule, '', $ruleString); |
| 459 | - if(isset($regexRule[0]) && !empty($regexRule[0])){ |
|
| 459 | + if (isset($regexRule[0]) && !empty($regexRule[0])) { |
|
| 460 | 460 | $ruleSets[] = $regexRule[0]; |
| 461 | 461 | } |
| 462 | 462 | $ruleStringRegex = explode('|', $ruleStringTemp); |
| 463 | 463 | foreach ($ruleStringRegex as $rule) { |
| 464 | 464 | $rule = trim($rule); |
| 465 | - if($rule){ |
|
| 465 | + if ($rule) { |
|
| 466 | 466 | $ruleSets[] = $rule; |
| 467 | 467 | } |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | } |
| 471 | 471 | /***********************************/ |
| 472 | - else{ |
|
| 472 | + else { |
|
| 473 | 473 | if (strpos($ruleString, '|') !== FALSE) { |
| 474 | 474 | $ruleSets = explode('|', $ruleString); |
| 475 | 475 | } else { |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | * @return void |
| 502 | 502 | */ |
| 503 | 503 | protected function _validateRule($inputName, $inputVal, $ruleName) { |
| 504 | - $this->logger->debug('Rule validation of field [' .$inputName. '], value [' .$inputVal. '], rule [' .$ruleName. ']'); |
|
| 504 | + $this->logger->debug('Rule validation of field [' . $inputName . '], value [' . $inputVal . '], rule [' . $ruleName . ']'); |
|
| 505 | 505 | // Array to store args |
| 506 | 506 | $ruleArgs = array(); |
| 507 | 507 | |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | $key = $i - 1; |
| 546 | 546 | $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase); |
| 547 | 547 | } |
| 548 | - if (! array_key_exists($inputName, $this->_errors)) { |
|
| 548 | + if (!array_key_exists($inputName, $this->_errors)) { |
|
| 549 | 549 | $this->_errors[$inputName] = $rulePhrase; |
| 550 | 550 | } |
| 551 | 551 | } |
@@ -597,13 +597,13 @@ discard block |
||
| 597 | 597 | */ |
| 598 | 598 | protected function _validateRequired($inputName, $ruleName, array $ruleArgs) { |
| 599 | 599 | $inputVal = $this->post($inputName); |
| 600 | - if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) { |
|
| 600 | + if (array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) { |
|
| 601 | 601 | $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]); |
| 602 | 602 | if ($inputVal == '' && $callbackReturn == true) { |
| 603 | 603 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 604 | 604 | } |
| 605 | 605 | } |
| 606 | - else if($inputVal == '') { |
|
| 606 | + else if ($inputVal == '') { |
|
| 607 | 607 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 608 | 608 | } |
| 609 | 609 | } |
@@ -629,7 +629,7 @@ discard block |
||
| 629 | 629 | protected function _validateCallback($inputName, $ruleName, array $ruleArgs) { |
| 630 | 630 | if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) { |
| 631 | 631 | $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]); |
| 632 | - if(! $result){ |
|
| 632 | + if (!$result) { |
|
| 633 | 633 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
| 634 | 634 | } |
| 635 | 635 | } |
@@ -663,7 +663,7 @@ discard block |
||
| 663 | 663 | continue; |
| 664 | 664 | } |
| 665 | 665 | } |
| 666 | - else{ |
|
| 666 | + else { |
|
| 667 | 667 | if ($inputVal == $doNotEqual) { |
| 668 | 668 | $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual)); |
| 669 | 669 | continue; |
@@ -693,8 +693,8 @@ discard block |
||
| 693 | 693 | */ |
| 694 | 694 | protected function _validateValidEmail($inputName, $ruleName, array $ruleArgs) { |
| 695 | 695 | $inputVal = $this->post($inputName); |
| 696 | - if (! preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) { |
|
| 697 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 696 | + if (!preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) { |
|
| 697 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 698 | 698 | return; |
| 699 | 699 | } |
| 700 | 700 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | protected function _validateExactLength($inputName, $ruleName, array $ruleArgs) { |
| 711 | 711 | $inputVal = $this->post($inputName); |
| 712 | 712 | if (strlen($inputVal) != $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
| 713 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 713 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 714 | 714 | return; |
| 715 | 715 | } |
| 716 | 716 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -726,7 +726,7 @@ discard block |
||
| 726 | 726 | protected function _validateMaxLength($inputName, $ruleName, array $ruleArgs) { |
| 727 | 727 | $inputVal = $this->post($inputName); |
| 728 | 728 | if (strlen($inputVal) > $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
| 729 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 729 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 730 | 730 | return; |
| 731 | 731 | } |
| 732 | 732 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -742,7 +742,7 @@ discard block |
||
| 742 | 742 | protected function _validateMinLength($inputName, $ruleName, array $ruleArgs) { |
| 743 | 743 | $inputVal = $this->post($inputName); |
| 744 | 744 | if (strlen($inputVal) < $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
| 745 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 745 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 746 | 746 | return; |
| 747 | 747 | } |
| 748 | 748 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -758,7 +758,7 @@ discard block |
||
| 758 | 758 | protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) { |
| 759 | 759 | $inputVal = $this->post($inputName); |
| 760 | 760 | if ($inputVal >= $ruleArgs[1]) { |
| 761 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 761 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 762 | 762 | return; |
| 763 | 763 | } |
| 764 | 764 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -774,7 +774,7 @@ discard block |
||
| 774 | 774 | protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) { |
| 775 | 775 | $inputVal = $this->post($inputName); |
| 776 | 776 | if ($inputVal <= $ruleArgs[1]) { |
| 777 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 777 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 778 | 778 | return; |
| 779 | 779 | } |
| 780 | 780 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -789,8 +789,8 @@ discard block |
||
| 789 | 789 | */ |
| 790 | 790 | protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) { |
| 791 | 791 | $inputVal = $this->post($inputName); |
| 792 | - if (! is_numeric($inputVal)) { |
|
| 793 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 792 | + if (!is_numeric($inputVal)) { |
|
| 793 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 794 | 794 | return; |
| 795 | 795 | } |
| 796 | 796 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -806,7 +806,7 @@ discard block |
||
| 806 | 806 | protected function _validateExists($inputName, $ruleName, array $ruleArgs) { |
| 807 | 807 | $inputVal = $this->post($inputName); |
| 808 | 808 | $obj = & get_instance(); |
| 809 | - if(! isset($obj->database)){ |
|
| 809 | + if (!isset($obj->database)) { |
|
| 810 | 810 | return; |
| 811 | 811 | } |
| 812 | 812 | list($table, $column) = explode('.', $ruleArgs[1]); |
@@ -815,7 +815,7 @@ discard block |
||
| 815 | 815 | ->get(); |
| 816 | 816 | $nb = $obj->database->numRows(); |
| 817 | 817 | if ($nb == 0) { |
| 818 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 818 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 819 | 819 | return; |
| 820 | 820 | } |
| 821 | 821 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -831,7 +831,7 @@ discard block |
||
| 831 | 831 | protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) { |
| 832 | 832 | $inputVal = $this->post($inputName); |
| 833 | 833 | $obj = & get_instance(); |
| 834 | - if(! isset($obj->database)){ |
|
| 834 | + if (!isset($obj->database)) { |
|
| 835 | 835 | return; |
| 836 | 836 | } |
| 837 | 837 | list($table, $column) = explode('.', $ruleArgs[1]); |
@@ -840,7 +840,7 @@ discard block |
||
| 840 | 840 | ->get(); |
| 841 | 841 | $nb = $obj->database->numRows(); |
| 842 | 842 | if ($nb != 0) { |
| 843 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 843 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 844 | 844 | return; |
| 845 | 845 | } |
| 846 | 846 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -856,11 +856,11 @@ discard block |
||
| 856 | 856 | protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) { |
| 857 | 857 | $inputVal = $this->post($inputName); |
| 858 | 858 | $obj = & get_instance(); |
| 859 | - if(! isset($obj->database)){ |
|
| 859 | + if (!isset($obj->database)) { |
|
| 860 | 860 | return; |
| 861 | 861 | } |
| 862 | 862 | $data = explode(',', $ruleArgs[1]); |
| 863 | - if(count($data) < 2){ |
|
| 863 | + if (count($data) < 2) { |
|
| 864 | 864 | return; |
| 865 | 865 | } |
| 866 | 866 | list($table, $column) = explode('.', $data[0]); |
@@ -871,7 +871,7 @@ discard block |
||
| 871 | 871 | ->get(); |
| 872 | 872 | $nb = $obj->database->numRows(); |
| 873 | 873 | if ($nb != 0) { |
| 874 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 874 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 875 | 875 | return; |
| 876 | 876 | } |
| 877 | 877 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -888,8 +888,8 @@ discard block |
||
| 888 | 888 | $inputVal = $this->post($inputName); |
| 889 | 889 | $list = explode(',', $ruleArgs[1]); |
| 890 | 890 | $list = array_map('trim', $list); |
| 891 | - if (! in_array($inputVal, $list)) { |
|
| 892 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 891 | + if (!in_array($inputVal, $list)) { |
|
| 892 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 893 | 893 | return; |
| 894 | 894 | } |
| 895 | 895 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -905,8 +905,8 @@ discard block |
||
| 905 | 905 | protected function _validateRegex($inputName, $ruleName, array $ruleArgs) { |
| 906 | 906 | $inputVal = $this->post($inputName); |
| 907 | 907 | $regex = $ruleArgs[1]; |
| 908 | - if (! preg_match($regex, $inputVal)) { |
|
| 909 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 908 | + if (!preg_match($regex, $inputVal)) { |
|
| 909 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 910 | 910 | return; |
| 911 | 911 | } |
| 912 | 912 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @since 1.0.0 |
| 39 | 39 | * @filesource |
| 40 | 40 | */ |
| 41 | - class Assets{ |
|
| 41 | + class Assets { |
|
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * The logger instance |
@@ -50,10 +50,10 @@ discard block |
||
| 50 | 50 | * The signleton of the logger |
| 51 | 51 | * @return Object the Log instance |
| 52 | 52 | */ |
| 53 | - private static function getLogger(){ |
|
| 54 | - if(self::$logger == null){ |
|
| 53 | + private static function getLogger() { |
|
| 54 | + if (self::$logger == null) { |
|
| 55 | 55 | //can't assign reference to static variable |
| 56 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 56 | + self::$logger[0] = & class_loader('Log', 'classes'); |
|
| 57 | 57 | self::$logger[0]->setLogger('Library::Assets'); |
| 58 | 58 | } |
| 59 | 59 | return self::$logger[0]; |
@@ -72,13 +72,13 @@ discard block |
||
| 72 | 72 | * @param $asset the name of the assets file path with the extension. |
| 73 | 73 | * @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist. |
| 74 | 74 | */ |
| 75 | - public static function path($asset){ |
|
| 75 | + public static function path($asset) { |
|
| 76 | 76 | $logger = self::getLogger(); |
| 77 | 77 | $path = ASSETS_PATH . $asset; |
| 78 | 78 | |
| 79 | 79 | $logger->debug('Including the Assets file [' . $path . ']'); |
| 80 | 80 | //Check if the file exists |
| 81 | - if(file_exists($path)){ |
|
| 81 | + if (file_exists($path)) { |
|
| 82 | 82 | $logger->info('Assets file [' . $path . '] included successfully'); |
| 83 | 83 | return Url::base_url($path); |
| 84 | 84 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | * @param $path the name of the css file without the extension. |
| 99 | 99 | * @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist. |
| 100 | 100 | */ |
| 101 | - public static function css($path){ |
|
| 101 | + public static function css($path) { |
|
| 102 | 102 | $logger = self::getLogger(); |
| 103 | 103 | /* |
| 104 | 104 | * if the file name contains the ".css" extension, replace it with |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | $logger->debug('Including the Assets file [' . $path . '] for CSS'); |
| 111 | 111 | //Check if the file exists |
| 112 | - if(file_exists($path)){ |
|
| 112 | + if (file_exists($path)) { |
|
| 113 | 113 | $logger->info('Assets file [' . $path . '] for CSS included successfully'); |
| 114 | 114 | return Url::base_url($path); |
| 115 | 115 | } |
@@ -129,12 +129,12 @@ discard block |
||
| 129 | 129 | * @param $path the name of the javascript file without the extension. |
| 130 | 130 | * @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist. |
| 131 | 131 | */ |
| 132 | - public static function js($path){ |
|
| 132 | + public static function js($path) { |
|
| 133 | 133 | $logger = self::getLogger(); |
| 134 | 134 | $path = str_ireplace('.js', '', $path); |
| 135 | 135 | $path = ASSETS_PATH . 'js/' . $path . '.js'; |
| 136 | 136 | $logger->debug('Including the Assets file [' . $path . '] for javascript'); |
| 137 | - if(file_exists($path)){ |
|
| 137 | + if (file_exists($path)) { |
|
| 138 | 138 | $logger->info('Assets file [' . $path . '] for Javascript included successfully'); |
| 139 | 139 | return Url::base_url($path); |
| 140 | 140 | } |
@@ -154,11 +154,11 @@ discard block |
||
| 154 | 154 | * @param $path the name of the image file with the extension. |
| 155 | 155 | * @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist. |
| 156 | 156 | */ |
| 157 | - public static function img($path){ |
|
| 157 | + public static function img($path) { |
|
| 158 | 158 | $logger = self::getLogger(); |
| 159 | 159 | $path = ASSETS_PATH . 'images/' . $path; |
| 160 | 160 | $logger->debug('Including the Assets file [' . $path . '] for image'); |
| 161 | - if(file_exists($path)){ |
|
| 161 | + if (file_exists($path)) { |
|
| 162 | 162 | $logger->info('Assets file [' . $path . '] for image included successfully'); |
| 163 | 163 | return Url::base_url($path); |
| 164 | 164 | } |