@@ -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); |
| 116 | 116 | } |
| 117 | 117 | return false; |
@@ -125,10 +125,10 @@ discard block |
||
| 125 | 125 | * 'expire' => expiration time of the cache (Unix timestamp), |
| 126 | 126 | * 'ttl' => the time to live of the cache in second |
| 127 | 127 | */ |
| 128 | - public function getInfo($key){ |
|
| 129 | - $this->logger->debug('Getting of cache info for key [' .$key. ']'); |
|
| 128 | + public function getInfo($key) { |
|
| 129 | + $this->logger->debug('Getting of cache info for key [' . $key . ']'); |
|
| 130 | 130 | $cacheInfos = $this->_getCacheInfo($key); |
| 131 | - if($cacheInfos){ |
|
| 131 | + if ($cacheInfos) { |
|
| 132 | 132 | $data = array( |
| 133 | 133 | 'mtime' => $cacheInfos['creation_time'], |
| 134 | 134 | 'expire' => $cacheInfos['creation_time'] + $cacheInfos['ttl'], |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | ); |
| 137 | 137 | return $data; |
| 138 | 138 | } |
| 139 | - else{ |
|
| 139 | + else { |
|
| 140 | 140 | $this->logger->info('This cache does not exists skipping'); |
| 141 | 141 | return false; |
| 142 | 142 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | /** |
| 147 | 147 | * Used to delete expired cache data |
| 148 | 148 | */ |
| 149 | - public function deleteExpiredCache(){ |
|
| 149 | + public function deleteExpiredCache() { |
|
| 150 | 150 | //for APC[u] is done automatically |
| 151 | 151 | return true; |
| 152 | 152 | } |
@@ -154,14 +154,14 @@ discard block |
||
| 154 | 154 | /** |
| 155 | 155 | * Remove all cache data |
| 156 | 156 | */ |
| 157 | - public function clean(){ |
|
| 157 | + public function clean() { |
|
| 158 | 158 | $this->logger->debug('Deleting of all cache data'); |
| 159 | 159 | $cacheInfos = apc_cache_info('user'); |
| 160 | - if(empty($cacheInfos['cache_list'])){ |
|
| 160 | + if (empty($cacheInfos['cache_list'])) { |
|
| 161 | 161 | $this->logger->info('No cache data were found skipping'); |
| 162 | 162 | return false; |
| 163 | 163 | } |
| 164 | - else{ |
|
| 164 | + else { |
|
| 165 | 165 | $this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove'); |
| 166 | 166 | return apc_clear_cache('user'); |
| 167 | 167 | } |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | * |
| 174 | 174 | * @return bool |
| 175 | 175 | */ |
| 176 | - public function isSupported(){ |
|
| 176 | + public function isSupported() { |
|
| 177 | 177 | return (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled'); |
| 178 | 178 | } |
| 179 | 179 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * Return the Log instance |
| 182 | 182 | * @return Log |
| 183 | 183 | */ |
| 184 | - public function getLogger(){ |
|
| 184 | + public function getLogger() { |
|
| 185 | 185 | return $this->logger; |
| 186 | 186 | } |
| 187 | 187 | |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | * Set the log instance |
| 190 | 190 | * @param Log $logger the log object |
| 191 | 191 | */ |
| 192 | - public function setLogger(Log $logger){ |
|
| 192 | + public function setLogger(Log $logger) { |
|
| 193 | 193 | $this->logger = $logger; |
| 194 | 194 | return $this; |
| 195 | 195 | } |
@@ -200,12 +200,12 @@ discard block |
||
| 200 | 200 | * @param string $key the cache key to get the cache information |
| 201 | 201 | * @return array |
| 202 | 202 | */ |
| 203 | - private function _getCacheInfo($key){ |
|
| 203 | + private function _getCacheInfo($key) { |
|
| 204 | 204 | $caches = apc_cache_info('user'); |
| 205 | - if(! empty($caches['cache_list'])){ |
|
| 205 | + if (!empty($caches['cache_list'])) { |
|
| 206 | 206 | $cacheLists = $caches['cache_list']; |
| 207 | - foreach ($cacheLists as $c){ |
|
| 208 | - if(isset($c['info']) && $c['info'] === $key){ |
|
| 207 | + foreach ($cacheLists as $c) { |
|
| 208 | + if (isset($c['info']) && $c['info'] === $key) { |
|
| 209 | 209 | return $c; |
| 210 | 210 | } |
| 211 | 211 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * For application languages management |
| 29 | 29 | */ |
| 30 | - class Lang{ |
|
| 30 | + class Lang { |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * The supported available language for this application. |
@@ -67,8 +67,8 @@ discard block |
||
| 67 | 67 | /** |
| 68 | 68 | * Construct new Lang instance |
| 69 | 69 | */ |
| 70 | - public function __construct(){ |
|
| 71 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 70 | + public function __construct() { |
|
| 71 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 72 | 72 | $this->logger->setLogger('Library::Lang'); |
| 73 | 73 | |
| 74 | 74 | $this->default = get_config('default_language', 'en'); |
@@ -76,8 +76,8 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | //add the supported languages ('key', 'display name') |
| 78 | 78 | $languages = get_config('languages', null); |
| 79 | - if(! empty($languages)){ |
|
| 80 | - foreach($languages as $key => $displayName){ |
|
| 79 | + if (!empty($languages)) { |
|
| 80 | + foreach ($languages as $key => $displayName) { |
|
| 81 | 81 | $this->addLang($key, $displayName); |
| 82 | 82 | } |
| 83 | 83 | } |
@@ -87,15 +87,15 @@ discard block |
||
| 87 | 87 | $language = null; |
| 88 | 88 | //if the language exists in cookie use it |
| 89 | 89 | $cfgKey = get_config('language_cookie_name'); |
| 90 | - $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']'); |
|
| 90 | + $this->logger->debug('Getting current language from cookie [' . $cfgKey . ']'); |
|
| 91 | 91 | $objCookie = & class_loader('Cookie'); |
| 92 | 92 | $cookieLang = $objCookie->get($cfgKey); |
| 93 | - if($cookieLang && $this->isValid($cookieLang)){ |
|
| 93 | + if ($cookieLang && $this->isValid($cookieLang)) { |
|
| 94 | 94 | $this->current = $cookieLang; |
| 95 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']'); |
|
| 95 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is valid so we will set the language using the cookie value [' . $cookieLang . ']'); |
|
| 96 | 96 | } |
| 97 | - else{ |
|
| 98 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
|
| 97 | + else { |
|
| 98 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is not set, use the default value [' . $this->getDefault() . ']'); |
|
| 99 | 99 | $this->current = $this->getDefault(); |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * |
| 106 | 106 | * @return array the language message list |
| 107 | 107 | */ |
| 108 | - public function getAll(){ |
|
| 108 | + public function getAll() { |
|
| 109 | 109 | return $this->languages; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * @param string $key the language key to identify |
| 116 | 116 | * @param string $value the language message value |
| 117 | 117 | */ |
| 118 | - public function set($key, $value){ |
|
| 118 | + public function set($key, $value) { |
|
| 119 | 119 | $this->languages[$key] = $value; |
| 120 | 120 | } |
| 121 | 121 | |
@@ -127,11 +127,11 @@ discard block |
||
| 127 | 127 | * |
| 128 | 128 | * @return string the language message value |
| 129 | 129 | */ |
| 130 | - public function get($key, $default = 'LANGUAGE_ERROR'){ |
|
| 131 | - if(isset($this->languages[$key])){ |
|
| 130 | + public function get($key, $default = 'LANGUAGE_ERROR') { |
|
| 131 | + if (isset($this->languages[$key])) { |
|
| 132 | 132 | return $this->languages[$key]; |
| 133 | 133 | } |
| 134 | - $this->logger->warning('Language key [' .$key. '] does not exist use the default value [' .$default. ']'); |
|
| 134 | + $this->logger->warning('Language key [' . $key . '] does not exist use the default value [' . $default . ']'); |
|
| 135 | 135 | return $default; |
| 136 | 136 | } |
| 137 | 137 | |
@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | * |
| 143 | 143 | * @return boolean true if the language directory exists, false or not |
| 144 | 144 | */ |
| 145 | - public function isValid($language){ |
|
| 145 | + public function isValid($language) { |
|
| 146 | 146 | $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH); |
| 147 | - foreach($searchDir as $dir){ |
|
| 148 | - if(file_exists($dir . $language) && is_dir($dir . $language)){ |
|
| 147 | + foreach ($searchDir as $dir) { |
|
| 148 | + if (file_exists($dir . $language) && is_dir($dir . $language)) { |
|
| 149 | 149 | return true; |
| 150 | 150 | } |
| 151 | 151 | } |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @return string the default language |
| 159 | 159 | */ |
| 160 | - public function getDefault(){ |
|
| 160 | + public function getDefault() { |
|
| 161 | 161 | return $this->default; |
| 162 | 162 | } |
| 163 | 163 | |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * |
| 167 | 167 | * @return string the current language |
| 168 | 168 | */ |
| 169 | - public function getCurrent(){ |
|
| 169 | + public function getCurrent() { |
|
| 170 | 170 | return $this->current; |
| 171 | 171 | } |
| 172 | 172 | |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | * @param string $name the short language name like "en", "fr". |
| 177 | 177 | * @param string $description the human readable description of this language |
| 178 | 178 | */ |
| 179 | - public function addLang($name, $description){ |
|
| 180 | - if(isset($this->availables[$name])){ |
|
| 179 | + public function addLang($name, $description) { |
|
| 180 | + if (isset($this->availables[$name])) { |
|
| 181 | 181 | return; //already added cost in performance |
| 182 | 182 | } |
| 183 | - if($this->isValid($name)){ |
|
| 183 | + if ($this->isValid($name)) { |
|
| 184 | 184 | $this->availables[$name] = $description; |
| 185 | 185 | } |
| 186 | - else{ |
|
| 186 | + else { |
|
| 187 | 187 | show_error('The language [' . $name . '] is not valid or does not exists.'); |
| 188 | 188 | } |
| 189 | 189 | } |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | * |
| 194 | 194 | * @return array the list of the application language |
| 195 | 195 | */ |
| 196 | - public function getSupported(){ |
|
| 196 | + public function getSupported() { |
|
| 197 | 197 | return $this->availables; |
| 198 | 198 | } |
| 199 | 199 | |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * |
| 203 | 203 | * @param array $langs the languages array of the messages to be added |
| 204 | 204 | */ |
| 205 | - public function addLangMessages(array $langs){ |
|
| 205 | + public function addLangMessages(array $langs) { |
|
| 206 | 206 | foreach ($langs as $key => $value) { |
| 207 | 207 | $this->set($key, $value); |
| 208 | 208 | } |
@@ -23,158 +23,158 @@ 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 Database{ |
|
| 26 | + class Database { |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * The PDO instance |
| 30 | 30 | * @var object |
| 31 | 31 | */ |
| 32 | - private $pdo = null; |
|
| 32 | + private $pdo = null; |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * The database name used for the application |
| 36 | 36 | * @var string |
| 37 | 37 | */ |
| 38 | - private $databaseName = null; |
|
| 38 | + private $databaseName = null; |
|
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * The SQL SELECT statment |
| 42 | 42 | * @var string |
| 43 | 43 | */ |
| 44 | - private $select = '*'; |
|
| 44 | + private $select = '*'; |
|
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * The SQL FROM statment |
| 48 | 48 | * @var string |
| 49 | 49 | */ |
| 50 | - private $from = null; |
|
| 50 | + private $from = null; |
|
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * The SQL WHERE statment |
| 54 | 54 | * @var string |
| 55 | 55 | */ |
| 56 | - private $where = null; |
|
| 56 | + private $where = null; |
|
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * The SQL LIMIT statment |
| 60 | 60 | * @var string |
| 61 | 61 | */ |
| 62 | - private $limit = null; |
|
| 62 | + private $limit = null; |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * The SQL JOIN statment |
| 66 | 66 | * @var string |
| 67 | 67 | */ |
| 68 | - private $join = null; |
|
| 68 | + private $join = null; |
|
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * The SQL ORDER BY statment |
| 72 | 72 | * @var string |
| 73 | 73 | */ |
| 74 | - private $orderBy = null; |
|
| 74 | + private $orderBy = null; |
|
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | 77 | * The SQL GROUP BY statment |
| 78 | 78 | * @var string |
| 79 | 79 | */ |
| 80 | - private $groupBy = null; |
|
| 80 | + private $groupBy = null; |
|
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * The SQL HAVING statment |
| 84 | 84 | * @var string |
| 85 | 85 | */ |
| 86 | - private $having = null; |
|
| 86 | + private $having = null; |
|
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * The number of rows returned by the last query |
| 90 | 90 | * @var int |
| 91 | 91 | */ |
| 92 | - private $numRows = 0; |
|
| 92 | + private $numRows = 0; |
|
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | 95 | * The last insert id for the primary key column that have auto increment or sequence |
| 96 | 96 | * @var mixed |
| 97 | 97 | */ |
| 98 | - private $insertId = null; |
|
| 98 | + private $insertId = null; |
|
| 99 | 99 | |
| 100 | 100 | /** |
| 101 | 101 | * The full SQL query statment after build for each command |
| 102 | 102 | * @var string |
| 103 | 103 | */ |
| 104 | - private $query = null; |
|
| 104 | + private $query = null; |
|
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | 107 | * The error returned for the last query |
| 108 | 108 | * @var string |
| 109 | 109 | */ |
| 110 | - private $error = null; |
|
| 110 | + private $error = null; |
|
| 111 | 111 | |
| 112 | 112 | /** |
| 113 | 113 | * The result returned for the last query |
| 114 | 114 | * @var mixed |
| 115 | 115 | */ |
| 116 | - private $result = array(); |
|
| 116 | + private $result = array(); |
|
| 117 | 117 | |
| 118 | 118 | /** |
| 119 | 119 | * The prefix used in each database table |
| 120 | 120 | * @var string |
| 121 | 121 | */ |
| 122 | - private $prefix = null; |
|
| 122 | + private $prefix = null; |
|
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * The list of SQL valid operators |
| 126 | 126 | * @var array |
| 127 | 127 | */ |
| 128 | - private $operatorList = array('=','!=','<','>','<=','>=','<>'); |
|
| 128 | + private $operatorList = array('=', '!=', '<', '>', '<=', '>=', '<>'); |
|
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | 131 | * The cache default time to live in second. 0 means no need to use the cache feature |
| 132 | 132 | * @var int |
| 133 | 133 | */ |
| 134 | - private $cacheTtl = 0; |
|
| 134 | + private $cacheTtl = 0; |
|
| 135 | 135 | |
| 136 | 136 | /** |
| 137 | 137 | * The cache current time to live. 0 means no need to use the cache feature |
| 138 | 138 | * @var int |
| 139 | 139 | */ |
| 140 | - private $temporaryCacheTtl = 0; |
|
| 140 | + private $temporaryCacheTtl = 0; |
|
| 141 | 141 | |
| 142 | 142 | /** |
| 143 | 143 | * The number of executed query for the current request |
| 144 | 144 | * @var int |
| 145 | 145 | */ |
| 146 | - private $queryCount = 0; |
|
| 146 | + private $queryCount = 0; |
|
| 147 | 147 | |
| 148 | 148 | /** |
| 149 | 149 | * The default data to be used in the statments query INSERT, UPDATE |
| 150 | 150 | * @var array |
| 151 | 151 | */ |
| 152 | - private $data = array(); |
|
| 152 | + private $data = array(); |
|
| 153 | 153 | |
| 154 | 154 | /** |
| 155 | 155 | * The database configuration |
| 156 | 156 | * @var array |
| 157 | 157 | */ |
| 158 | - private $config = array(); |
|
| 158 | + private $config = array(); |
|
| 159 | 159 | |
| 160 | 160 | /** |
| 161 | 161 | * The logger instance |
| 162 | 162 | * @var Log |
| 163 | 163 | */ |
| 164 | - private $logger = null; |
|
| 164 | + private $logger = null; |
|
| 165 | 165 | |
| 166 | 166 | |
| 167 | 167 | /** |
| 168 | 168 | * The cache instance |
| 169 | 169 | * @var CacheInterface |
| 170 | 170 | */ |
| 171 | - private $cacheInstance = null; |
|
| 171 | + private $cacheInstance = null; |
|
| 172 | 172 | |
| 173 | 173 | /** |
| 174 | 174 | * The benchmark instance |
| 175 | 175 | * @var Benchmark |
| 176 | 176 | */ |
| 177 | - private $benchmarkInstance = null; |
|
| 177 | + private $benchmarkInstance = null; |
|
| 178 | 178 | |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -182,25 +182,25 @@ discard block |
||
| 182 | 182 | * @param array $overwriteConfig the config to overwrite with the config set in database.php |
| 183 | 183 | * @param object $logger the log instance |
| 184 | 184 | */ |
| 185 | - public function __construct($overwriteConfig = array(), Log $logger = null){ |
|
| 185 | + public function __construct($overwriteConfig = array(), Log $logger = null) { |
|
| 186 | 186 | /** |
| 187 | 187 | * instance of the Log class |
| 188 | 188 | */ |
| 189 | - if(is_object($logger)){ |
|
| 189 | + if (is_object($logger)) { |
|
| 190 | 190 | $this->logger = $logger; |
| 191 | 191 | } |
| 192 | - else{ |
|
| 193 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 192 | + else { |
|
| 193 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 194 | 194 | $this->logger->setLogger('Library::Database'); |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | $db = array(); |
| 198 | - if(file_exists(CONFIG_PATH . 'database.php')){ |
|
| 198 | + if (file_exists(CONFIG_PATH . 'database.php')) { |
|
| 199 | 199 | //here don't use require_once because somewhere user can create database instance directly |
| 200 | 200 | require CONFIG_PATH . 'database.php'; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - if(! empty($overwriteConfig)){ |
|
| 203 | + if (!empty($overwriteConfig)) { |
|
| 204 | 204 | $db = array_merge($db, $overwriteConfig); |
| 205 | 205 | } |
| 206 | 206 | $config['driver'] = isset($db['driver']) ? $db['driver'] : 'mysql'; |
@@ -212,11 +212,11 @@ discard block |
||
| 212 | 212 | $config['collation'] = isset($db['collation']) ? $db['collation'] : 'utf8_general_ci'; |
| 213 | 213 | $config['prefix'] = isset($db['prefix']) ? $db['prefix'] : ''; |
| 214 | 214 | $port = ''; |
| 215 | - if(strstr($config['hostname'], ':')){ |
|
| 215 | + if (strstr($config['hostname'], ':')) { |
|
| 216 | 216 | $p = explode(':', $config['hostname']); |
| 217 | 217 | $port = isset($p[1]) ? $p[1] : ''; |
| 218 | 218 | } |
| 219 | - $config['port'] = $port; |
|
| 219 | + $config['port'] = $port; |
|
| 220 | 220 | |
| 221 | 221 | $this->setDatabaseConfiguration($config); |
| 222 | 222 | |
@@ -227,20 +227,20 @@ discard block |
||
| 227 | 227 | * This is used to connect to database |
| 228 | 228 | * @return bool |
| 229 | 229 | */ |
| 230 | - public function connect(){ |
|
| 230 | + public function connect() { |
|
| 231 | 231 | $config = $this->getDatabaseConfiguration(); |
| 232 | - if(! empty($config)){ |
|
| 233 | - try{ |
|
| 232 | + if (!empty($config)) { |
|
| 233 | + try { |
|
| 234 | 234 | $dsn = ''; |
| 235 | - if($config['driver'] == 'mysql' || $config['driver'] == '' || $config['driver'] == 'pgsql'){ |
|
| 235 | + if ($config['driver'] == 'mysql' || $config['driver'] == '' || $config['driver'] == 'pgsql') { |
|
| 236 | 236 | $dsn = $config['driver'] . ':host=' . $config['hostname'] . ';' |
| 237 | 237 | . (($config['port']) != '' ? 'port=' . $config['port'] . ';' : '') |
| 238 | 238 | . 'dbname=' . $config['database']; |
| 239 | 239 | } |
| 240 | - else if ($config['driver'] == 'sqlite'){ |
|
| 240 | + else if ($config['driver'] == 'sqlite') { |
|
| 241 | 241 | $dsn = 'sqlite:' . $config['database']; |
| 242 | 242 | } |
| 243 | - else if($config['driver'] == 'oracle'){ |
|
| 243 | + else if ($config['driver'] == 'oracle') { |
|
| 244 | 244 | $dsn = 'oci:dbname=' . $config['host'] . '/' . $config['database']; |
| 245 | 245 | } |
| 246 | 246 | |
@@ -250,13 +250,13 @@ discard block |
||
| 250 | 250 | $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); |
| 251 | 251 | return true; |
| 252 | 252 | } |
| 253 | - catch (PDOException $e){ |
|
| 253 | + catch (PDOException $e) { |
|
| 254 | 254 | $this->logger->fatal($e->getMessage()); |
| 255 | 255 | show_error('Cannot connect to Database.'); |
| 256 | 256 | return false; |
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | - else{ |
|
| 259 | + else { |
|
| 260 | 260 | show_error('Database configuration is not set.'); |
| 261 | 261 | return false; |
| 262 | 262 | } |
@@ -267,15 +267,15 @@ discard block |
||
| 267 | 267 | * @param string|array $table the table name or array of table list |
| 268 | 268 | * @return object the current Database instance |
| 269 | 269 | */ |
| 270 | - public function from($table){ |
|
| 271 | - if(is_array($table)){ |
|
| 270 | + public function from($table) { |
|
| 271 | + if (is_array($table)) { |
|
| 272 | 272 | $froms = ''; |
| 273 | - foreach($table as $key){ |
|
| 273 | + foreach ($table as $key) { |
|
| 274 | 274 | $froms .= $this->prefix . $key . ', '; |
| 275 | 275 | } |
| 276 | 276 | $this->from = rtrim($froms, ', '); |
| 277 | 277 | } |
| 278 | - else{ |
|
| 278 | + else { |
|
| 279 | 279 | $this->from = $this->prefix . $table; |
| 280 | 280 | } |
| 281 | 281 | return $this; |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | * @param string|array $fields the field name or array of field list |
| 287 | 287 | * @return object the current Database instance |
| 288 | 288 | */ |
| 289 | - public function select($fields){ |
|
| 289 | + public function select($fields) { |
|
| 290 | 290 | $select = (is_array($fields) ? implode(', ', $fields) : $fields); |
| 291 | 291 | $this->select = ($this->select == '*' ? $select : $this->select . ', ' . $select); |
| 292 | 292 | return $this; |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | * @param string $field the field name to distinct |
| 298 | 298 | * @return object the current Database instance |
| 299 | 299 | */ |
| 300 | - public function distinct($field){ |
|
| 300 | + public function distinct($field) { |
|
| 301 | 301 | $distinct = ' DISTINCT ' . $field; |
| 302 | 302 | $this->select = ($this->select == '*' ? $distinct : $this->select . ', ' . $distinct); |
| 303 | 303 | |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | * @param string $name if is not null represent the alias used for this field in the result |
| 311 | 311 | * @return object the current Database instance |
| 312 | 312 | */ |
| 313 | - public function max($field, $name = null){ |
|
| 313 | + public function max($field, $name = null) { |
|
| 314 | 314 | $func = 'MAX(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
| 315 | 315 | $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
| 316 | 316 | return $this; |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | * @param string $name if is not null represent the alias used for this field in the result |
| 323 | 323 | * @return object the current Database instance |
| 324 | 324 | */ |
| 325 | - public function min($field, $name = null){ |
|
| 325 | + public function min($field, $name = null) { |
|
| 326 | 326 | $func = 'MIN(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
| 327 | 327 | $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
| 328 | 328 | return $this; |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | * @param string $name if is not null represent the alias used for this field in the result |
| 335 | 335 | * @return object the current Database instance |
| 336 | 336 | */ |
| 337 | - public function sum($field, $name = null){ |
|
| 337 | + public function sum($field, $name = null) { |
|
| 338 | 338 | $func = 'SUM(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
| 339 | 339 | $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
| 340 | 340 | return $this; |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | * @param string $name if is not null represent the alias used for this field in the result |
| 347 | 347 | * @return object the current Database instance |
| 348 | 348 | */ |
| 349 | - public function count($field = '*', $name = null){ |
|
| 349 | + public function count($field = '*', $name = null) { |
|
| 350 | 350 | $func = 'COUNT(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
| 351 | 351 | $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
| 352 | 352 | return $this; |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | * @param string $name if is not null represent the alias used for this field in the result |
| 359 | 359 | * @return object the current Database instance |
| 360 | 360 | */ |
| 361 | - public function avg($field, $name = null){ |
|
| 361 | + public function avg($field, $name = null) { |
|
| 362 | 362 | $func = 'AVG(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
| 363 | 363 | $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
| 364 | 364 | return $this; |
@@ -373,16 +373,16 @@ discard block |
||
| 373 | 373 | * @param string $type the type of join (INNER, LEFT, RIGHT) |
| 374 | 374 | * @return object the current Database instance |
| 375 | 375 | */ |
| 376 | - public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){ |
|
| 376 | + public function join($table, $field1 = null, $op = null, $field2 = null, $type = '') { |
|
| 377 | 377 | $on = $field1; |
| 378 | 378 | $table = $this->prefix . $table; |
| 379 | - if(! is_null($op)){ |
|
| 380 | - $on = (! in_array($op, $this->operatorList) ? $this->prefix . $field1 . ' = ' . $this->prefix . $op : $this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2); |
|
| 379 | + if (!is_null($op)) { |
|
| 380 | + $on = (!in_array($op, $this->operatorList) ? $this->prefix . $field1 . ' = ' . $this->prefix . $op : $this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2); |
|
| 381 | 381 | } |
| 382 | - if (is_null($this->join)){ |
|
| 382 | + if (is_null($this->join)) { |
|
| 383 | 383 | $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
| 384 | 384 | } |
| 385 | - else{ |
|
| 385 | + else { |
|
| 386 | 386 | $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
| 387 | 387 | } |
| 388 | 388 | return $this; |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | * @see Database::join() |
| 394 | 394 | * @return object the current Database instance |
| 395 | 395 | */ |
| 396 | - public function innerJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 396 | + public function innerJoin($table, $field1, $op = null, $field2 = '') { |
|
| 397 | 397 | return $this->join($table, $field1, $op, $field2, 'INNER '); |
| 398 | 398 | } |
| 399 | 399 | |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | * @see Database::join() |
| 403 | 403 | * @return object the current Database instance |
| 404 | 404 | */ |
| 405 | - public function leftJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 405 | + public function leftJoin($table, $field1, $op = null, $field2 = '') { |
|
| 406 | 406 | return $this->join($table, $field1, $op, $field2, 'LEFT '); |
| 407 | 407 | } |
| 408 | 408 | |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | * @see Database::join() |
| 412 | 412 | * @return object the current Database instance |
| 413 | 413 | */ |
| 414 | - public function rightJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 414 | + public function rightJoin($table, $field1, $op = null, $field2 = '') { |
|
| 415 | 415 | return $this->join($table, $field1, $op, $field2, 'RIGHT '); |
| 416 | 416 | } |
| 417 | 417 | |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | * @see Database::join() |
| 421 | 421 | * @return object the current Database instance |
| 422 | 422 | */ |
| 423 | - public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 423 | + public function fullOuterJoin($table, $field1, $op = null, $field2 = '') { |
|
| 424 | 424 | return $this->join($table, $field1, $op, $field2, 'FULL OUTER '); |
| 425 | 425 | } |
| 426 | 426 | |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | * @see Database::join() |
| 430 | 430 | * @return object the current Database instance |
| 431 | 431 | */ |
| 432 | - public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 432 | + public function leftOuterJoin($table, $field1, $op = null, $field2 = '') { |
|
| 433 | 433 | return $this->join($table, $field1, $op, $field2, 'LEFT OUTER '); |
| 434 | 434 | } |
| 435 | 435 | |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | * @see Database::join() |
| 439 | 439 | * @return object the current Database instance |
| 440 | 440 | */ |
| 441 | - public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 441 | + public function rightOuterJoin($table, $field1, $op = null, $field2 = '') { |
|
| 442 | 442 | return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER '); |
| 443 | 443 | } |
| 444 | 444 | |
@@ -448,18 +448,18 @@ discard block |
||
| 448 | 448 | * @param string $andOr the separator type used 'AND', 'OR', etc. |
| 449 | 449 | * @return object the current Database instance |
| 450 | 450 | */ |
| 451 | - public function whereIsNull($field, $andOr = 'AND'){ |
|
| 452 | - if(is_array($field)){ |
|
| 453 | - foreach($field as $f){ |
|
| 451 | + public function whereIsNull($field, $andOr = 'AND') { |
|
| 452 | + if (is_array($field)) { |
|
| 453 | + foreach ($field as $f) { |
|
| 454 | 454 | $this->whereIsNull($f, $andOr); |
| 455 | 455 | } |
| 456 | 456 | } |
| 457 | - else{ |
|
| 458 | - if (! $this->where){ |
|
| 459 | - $this->where = $field.' IS NULL '; |
|
| 457 | + else { |
|
| 458 | + if (!$this->where) { |
|
| 459 | + $this->where = $field . ' IS NULL '; |
|
| 460 | 460 | } |
| 461 | - else{ |
|
| 462 | - $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NULL '; |
|
| 461 | + else { |
|
| 462 | + $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' IS NULL '; |
|
| 463 | 463 | } |
| 464 | 464 | } |
| 465 | 465 | return $this; |
@@ -471,18 +471,18 @@ discard block |
||
| 471 | 471 | * @param string $andOr the separator type used 'AND', 'OR', etc. |
| 472 | 472 | * @return object the current Database instance |
| 473 | 473 | */ |
| 474 | - public function whereIsNotNull($field, $andOr = 'AND'){ |
|
| 475 | - if(is_array($field)){ |
|
| 476 | - foreach($field as $f){ |
|
| 474 | + public function whereIsNotNull($field, $andOr = 'AND') { |
|
| 475 | + if (is_array($field)) { |
|
| 476 | + foreach ($field as $f) { |
|
| 477 | 477 | $this->whereIsNotNull($f, $andOr); |
| 478 | 478 | } |
| 479 | 479 | } |
| 480 | - else{ |
|
| 481 | - if (! $this->where){ |
|
| 482 | - $this->where = $field.' IS NOT NULL '; |
|
| 480 | + else { |
|
| 481 | + if (!$this->where) { |
|
| 482 | + $this->where = $field . ' IS NOT NULL '; |
|
| 483 | 483 | } |
| 484 | - else{ |
|
| 485 | - $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NOT NULL '; |
|
| 484 | + else { |
|
| 485 | + $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' IS NOT NULL '; |
|
| 486 | 486 | } |
| 487 | 487 | } |
| 488 | 488 | return $this; |
@@ -498,24 +498,24 @@ discard block |
||
| 498 | 498 | * @param boolean $escape whether to escape or not the $val |
| 499 | 499 | * @return object the current Database instance |
| 500 | 500 | */ |
| 501 | - public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){ |
|
| 502 | - if (is_array($where)){ |
|
| 501 | + public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true) { |
|
| 502 | + if (is_array($where)) { |
|
| 503 | 503 | $_where = array(); |
| 504 | - foreach ($where as $column => $data){ |
|
| 505 | - if(is_null($data)){ |
|
| 504 | + foreach ($where as $column => $data) { |
|
| 505 | + if (is_null($data)) { |
|
| 506 | 506 | $data = ''; |
| 507 | 507 | } |
| 508 | 508 | $_where[] = $type . $column . '=' . ($escape ? $this->escape($data) : $data); |
| 509 | 509 | } |
| 510 | - $where = implode(' '.$andOr.' ', $_where); |
|
| 510 | + $where = implode(' ' . $andOr . ' ', $_where); |
|
| 511 | 511 | } |
| 512 | - else{ |
|
| 513 | - if(is_array($op)){ |
|
| 512 | + else { |
|
| 513 | + if (is_array($op)) { |
|
| 514 | 514 | $x = explode('?', $where); |
| 515 | 515 | $w = ''; |
| 516 | - foreach($x as $k => $v){ |
|
| 517 | - if(! empty($v)){ |
|
| 518 | - if(isset($op[$k]) && is_null($op[$k])){ |
|
| 516 | + foreach ($x as $k => $v) { |
|
| 517 | + if (!empty($v)) { |
|
| 518 | + if (isset($op[$k]) && is_null($op[$k])) { |
|
| 519 | 519 | $op[$k] = ''; |
| 520 | 520 | } |
| 521 | 521 | $w .= $type . $v . (isset($op[$k]) ? ($escape ? $this->escape($op[$k]) : $op[$k]) : ''); |
@@ -523,28 +523,28 @@ discard block |
||
| 523 | 523 | } |
| 524 | 524 | $where = $w; |
| 525 | 525 | } |
| 526 | - else if (! in_array((string)$op, $this->operatorList)){ |
|
| 527 | - if(is_null($op)){ |
|
| 526 | + else if (!in_array((string) $op, $this->operatorList)) { |
|
| 527 | + if (is_null($op)) { |
|
| 528 | 528 | $op = ''; |
| 529 | 529 | } |
| 530 | 530 | $where = $type . $where . ' = ' . ($escape ? $this->escape($op) : $op); |
| 531 | 531 | } |
| 532 | - else{ |
|
| 533 | - if(is_null($val)){ |
|
| 532 | + else { |
|
| 533 | + if (is_null($val)) { |
|
| 534 | 534 | $val = ''; |
| 535 | 535 | } |
| 536 | 536 | $where = $type . $where . $op . ($escape ? $this->escape($val) : $val); |
| 537 | 537 | } |
| 538 | 538 | } |
| 539 | - if (is_null($this->where)){ |
|
| 539 | + if (is_null($this->where)) { |
|
| 540 | 540 | $this->where = $where; |
| 541 | 541 | } |
| 542 | - else{ |
|
| 543 | - if(substr($this->where, -1) == '('){ |
|
| 542 | + else { |
|
| 543 | + if (substr($this->where, -1) == '(') { |
|
| 544 | 544 | $this->where = $this->where . ' ' . $where; |
| 545 | 545 | } |
| 546 | - else{ |
|
| 547 | - $this->where = $this->where . ' '.$andOr.' ' . $where; |
|
| 546 | + else { |
|
| 547 | + $this->where = $this->where . ' ' . $andOr . ' ' . $where; |
|
| 548 | 548 | } |
| 549 | 549 | } |
| 550 | 550 | return $this; |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | * @see Database::where() |
| 556 | 556 | * @return object the current Database instance |
| 557 | 557 | */ |
| 558 | - public function orWhere($where, $op = null, $val = null, $escape = true){ |
|
| 558 | + public function orWhere($where, $op = null, $val = null, $escape = true) { |
|
| 559 | 559 | return $this->where($where, $op, $val, '', 'OR', $escape); |
| 560 | 560 | } |
| 561 | 561 | |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | * @see Database::where() |
| 566 | 566 | * @return object the current Database instance |
| 567 | 567 | */ |
| 568 | - public function notWhere($where, $op = null, $val = null, $escape = true){ |
|
| 568 | + public function notWhere($where, $op = null, $val = null, $escape = true) { |
|
| 569 | 569 | return $this->where($where, $op, $val, 'NOT ', 'AND', $escape); |
| 570 | 570 | } |
| 571 | 571 | |
@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | * @see Database::where() |
| 575 | 575 | * @return object the current Database instance |
| 576 | 576 | */ |
| 577 | - public function orNotWhere($where, $op = null, $val = null, $escape = true){ |
|
| 577 | + public function orNotWhere($where, $op = null, $val = null, $escape = true) { |
|
| 578 | 578 | return $this->where($where, $op, $val, 'NOT ', 'OR', $escape); |
| 579 | 579 | } |
| 580 | 580 | |
@@ -584,15 +584,15 @@ discard block |
||
| 584 | 584 | * @param string $andOr the multiple conditions separator (AND, OR, etc.) |
| 585 | 585 | * @return object the current Database instance |
| 586 | 586 | */ |
| 587 | - public function groupStart($type = '', $andOr = ' AND'){ |
|
| 588 | - if (is_null($this->where)){ |
|
| 587 | + public function groupStart($type = '', $andOr = ' AND') { |
|
| 588 | + if (is_null($this->where)) { |
|
| 589 | 589 | $this->where = $type . ' ('; |
| 590 | 590 | } |
| 591 | - else{ |
|
| 592 | - if(substr($this->where, -1) == '('){ |
|
| 591 | + else { |
|
| 592 | + if (substr($this->where, -1) == '(') { |
|
| 593 | 593 | $this->where .= $type . ' ('; |
| 594 | 594 | } |
| 595 | - else{ |
|
| 595 | + else { |
|
| 596 | 596 | $this->where .= $andOr . ' ' . $type . ' ('; |
| 597 | 597 | } |
| 598 | 598 | } |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | * @see Database::groupStart() |
| 605 | 605 | * @return object the current Database instance |
| 606 | 606 | */ |
| 607 | - public function notGroupStart(){ |
|
| 607 | + public function notGroupStart() { |
|
| 608 | 608 | return $this->groupStart('NOT'); |
| 609 | 609 | } |
| 610 | 610 | |
@@ -613,7 +613,7 @@ discard block |
||
| 613 | 613 | * @see Database::groupStart() |
| 614 | 614 | * @return object the current Database instance |
| 615 | 615 | */ |
| 616 | - public function orGroupStart(){ |
|
| 616 | + public function orGroupStart() { |
|
| 617 | 617 | return $this->groupStart('', ' OR'); |
| 618 | 618 | } |
| 619 | 619 | |
@@ -622,7 +622,7 @@ discard block |
||
| 622 | 622 | * @see Database::groupStart() |
| 623 | 623 | * @return object the current Database instance |
| 624 | 624 | */ |
| 625 | - public function orNotGroupStart(){ |
|
| 625 | + public function orNotGroupStart() { |
|
| 626 | 626 | return $this->groupStart('NOT', ' OR'); |
| 627 | 627 | } |
| 628 | 628 | |
@@ -630,7 +630,7 @@ discard block |
||
| 630 | 630 | * Close the parenthesis for the grouped SQL |
| 631 | 631 | * @return object the current Database instance |
| 632 | 632 | */ |
| 633 | - public function groupEnd(){ |
|
| 633 | + public function groupEnd() { |
|
| 634 | 634 | $this->where .= ')'; |
| 635 | 635 | return $this; |
| 636 | 636 | } |
@@ -644,25 +644,25 @@ discard block |
||
| 644 | 644 | * @param boolean $escape whether to escape or not the values |
| 645 | 645 | * @return object the current Database instance |
| 646 | 646 | */ |
| 647 | - public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){ |
|
| 648 | - if (is_array($keys)){ |
|
| 647 | + public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true) { |
|
| 648 | + if (is_array($keys)) { |
|
| 649 | 649 | $_keys = array(); |
| 650 | - foreach ($keys as $k => $v){ |
|
| 651 | - if(is_null($v)){ |
|
| 650 | + foreach ($keys as $k => $v) { |
|
| 651 | + if (is_null($v)) { |
|
| 652 | 652 | $v = ''; |
| 653 | 653 | } |
| 654 | 654 | $_keys[] = (is_numeric($v) ? $v : ($escape ? $this->escape($v) : $v)); |
| 655 | 655 | } |
| 656 | 656 | $keys = implode(', ', $_keys); |
| 657 | - if (is_null($this->where)){ |
|
| 657 | + if (is_null($this->where)) { |
|
| 658 | 658 | $this->where = $field . ' ' . $type . 'IN (' . $keys . ')'; |
| 659 | 659 | } |
| 660 | - else{ |
|
| 661 | - if(substr($this->where, -1) == '('){ |
|
| 662 | - $this->where = $this->where . ' ' . $field . ' '.$type.'IN (' . $keys . ')'; |
|
| 660 | + else { |
|
| 661 | + if (substr($this->where, -1) == '(') { |
|
| 662 | + $this->where = $this->where . ' ' . $field . ' ' . $type . 'IN (' . $keys . ')'; |
|
| 663 | 663 | } |
| 664 | - else{ |
|
| 665 | - $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' '.$type.'IN (' . $keys . ')'; |
|
| 664 | + else { |
|
| 665 | + $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' ' . $type . 'IN (' . $keys . ')'; |
|
| 666 | 666 | } |
| 667 | 667 | } |
| 668 | 668 | } |
@@ -674,7 +674,7 @@ discard block |
||
| 674 | 674 | * @see Database::in() |
| 675 | 675 | * @return object the current Database instance |
| 676 | 676 | */ |
| 677 | - public function notIn($field, array $keys, $escape = true){ |
|
| 677 | + public function notIn($field, array $keys, $escape = true) { |
|
| 678 | 678 | return $this->in($field, $keys, 'NOT ', 'AND', $escape); |
| 679 | 679 | } |
| 680 | 680 | |
@@ -683,7 +683,7 @@ discard block |
||
| 683 | 683 | * @see Database::in() |
| 684 | 684 | * @return object the current Database instance |
| 685 | 685 | */ |
| 686 | - public function orIn($field, array $keys, $escape = true){ |
|
| 686 | + public function orIn($field, array $keys, $escape = true) { |
|
| 687 | 687 | return $this->in($field, $keys, '', 'OR', $escape); |
| 688 | 688 | } |
| 689 | 689 | |
@@ -692,7 +692,7 @@ discard block |
||
| 692 | 692 | * @see Database::in() |
| 693 | 693 | * @return object the current Database instance |
| 694 | 694 | */ |
| 695 | - public function orNotIn($field, array $keys, $escape = true){ |
|
| 695 | + public function orNotIn($field, array $keys, $escape = true) { |
|
| 696 | 696 | return $this->in($field, $keys, 'NOT ', 'OR', $escape); |
| 697 | 697 | } |
| 698 | 698 | |
@@ -706,21 +706,21 @@ discard block |
||
| 706 | 706 | * @param boolean $escape whether to escape or not the values |
| 707 | 707 | * @return object the current Database instance |
| 708 | 708 | */ |
| 709 | - public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){ |
|
| 710 | - if(is_null($value1)){ |
|
| 709 | + public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true) { |
|
| 710 | + if (is_null($value1)) { |
|
| 711 | 711 | $value1 = ''; |
| 712 | 712 | } |
| 713 | - if(is_null($value2)){ |
|
| 713 | + if (is_null($value2)) { |
|
| 714 | 714 | $value2 = ''; |
| 715 | 715 | } |
| 716 | - if (is_null($this->where)){ |
|
| 716 | + if (is_null($this->where)) { |
|
| 717 | 717 | $this->where = $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2); |
| 718 | 718 | } |
| 719 | - else{ |
|
| 720 | - if(substr($this->where, -1) == '('){ |
|
| 719 | + else { |
|
| 720 | + if (substr($this->where, -1) == '(') { |
|
| 721 | 721 | $this->where = $this->where . ' ' . $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2); |
| 722 | 722 | } |
| 723 | - else{ |
|
| 723 | + else { |
|
| 724 | 724 | $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2); |
| 725 | 725 | } |
| 726 | 726 | } |
@@ -732,7 +732,7 @@ discard block |
||
| 732 | 732 | * @see Database::between() |
| 733 | 733 | * @return object the current Database instance |
| 734 | 734 | */ |
| 735 | - public function notBetween($field, $value1, $value2, $escape = true){ |
|
| 735 | + public function notBetween($field, $value1, $value2, $escape = true) { |
|
| 736 | 736 | return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape); |
| 737 | 737 | } |
| 738 | 738 | |
@@ -741,7 +741,7 @@ discard block |
||
| 741 | 741 | * @see Database::between() |
| 742 | 742 | * @return object the current Database instance |
| 743 | 743 | */ |
| 744 | - public function orBetween($field, $value1, $value2, $escape = true){ |
|
| 744 | + public function orBetween($field, $value1, $value2, $escape = true) { |
|
| 745 | 745 | return $this->between($field, $value1, $value2, '', 'OR', $escape); |
| 746 | 746 | } |
| 747 | 747 | |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | * @see Database::between() |
| 751 | 751 | * @return object the current Database instance |
| 752 | 752 | */ |
| 753 | - public function orNotBetween($field, $value1, $value2, $escape = true){ |
|
| 753 | + public function orNotBetween($field, $value1, $value2, $escape = true) { |
|
| 754 | 754 | return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape); |
| 755 | 755 | } |
| 756 | 756 | |
@@ -763,20 +763,20 @@ discard block |
||
| 763 | 763 | * @param boolean $escape whether to escape or not the values |
| 764 | 764 | * @return object the current Database instance |
| 765 | 765 | */ |
| 766 | - public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){ |
|
| 767 | - if(is_null($data)){ |
|
| 766 | + public function like($field, $data, $type = '', $andOr = 'AND', $escape = true) { |
|
| 767 | + if (is_null($data)) { |
|
| 768 | 768 | $data = ''; |
| 769 | 769 | } |
| 770 | 770 | $like = $escape ? $this->escape($data) : $data; |
| 771 | - if (is_null($this->where)){ |
|
| 771 | + if (is_null($this->where)) { |
|
| 772 | 772 | $this->where = $field . ' ' . $type . 'LIKE ' . $like; |
| 773 | 773 | } |
| 774 | - else{ |
|
| 775 | - if(substr($this->where, -1) == '('){ |
|
| 774 | + else { |
|
| 775 | + if (substr($this->where, -1) == '(') { |
|
| 776 | 776 | $this->where = $this->where . ' ' . $field . ' ' . $type . 'LIKE ' . $like; |
| 777 | 777 | } |
| 778 | - else{ |
|
| 779 | - $this->where = $this->where . ' '.$andOr.' ' . $field . ' ' . $type . 'LIKE ' . $like; |
|
| 778 | + else { |
|
| 779 | + $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' ' . $type . 'LIKE ' . $like; |
|
| 780 | 780 | } |
| 781 | 781 | } |
| 782 | 782 | return $this; |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | * @see Database::like() |
| 788 | 788 | * @return object the current Database instance |
| 789 | 789 | */ |
| 790 | - public function orLike($field, $data, $escape = true){ |
|
| 790 | + public function orLike($field, $data, $escape = true) { |
|
| 791 | 791 | return $this->like($field, $data, '', 'OR', $escape); |
| 792 | 792 | } |
| 793 | 793 | |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | * @see Database::like() |
| 797 | 797 | * @return object the current Database instance |
| 798 | 798 | */ |
| 799 | - public function notLike($field, $data, $escape = true){ |
|
| 799 | + public function notLike($field, $data, $escape = true) { |
|
| 800 | 800 | return $this->like($field, $data, 'NOT ', 'AND', $escape); |
| 801 | 801 | } |
| 802 | 802 | |
@@ -805,7 +805,7 @@ discard block |
||
| 805 | 805 | * @see Database::like() |
| 806 | 806 | * @return object the current Database instance |
| 807 | 807 | */ |
| 808 | - public function orNotLike($field, $data, $escape = true){ |
|
| 808 | + public function orNotLike($field, $data, $escape = true) { |
|
| 809 | 809 | return $this->like($field, $data, 'NOT ', 'OR', $escape); |
| 810 | 810 | } |
| 811 | 811 | |
@@ -816,14 +816,14 @@ discard block |
||
| 816 | 816 | * @param int $limitEnd the limit count |
| 817 | 817 | * @return object the current Database instance |
| 818 | 818 | */ |
| 819 | - public function limit($limit, $limitEnd = null){ |
|
| 820 | - if(is_null($limit)){ |
|
| 819 | + public function limit($limit, $limitEnd = null) { |
|
| 820 | + if (is_null($limit)) { |
|
| 821 | 821 | return; |
| 822 | 822 | } |
| 823 | - if (! is_null($limitEnd)){ |
|
| 823 | + if (!is_null($limitEnd)) { |
|
| 824 | 824 | $this->limit = $limit . ', ' . $limitEnd; |
| 825 | 825 | } |
| 826 | - else{ |
|
| 826 | + else { |
|
| 827 | 827 | $this->limit = $limit; |
| 828 | 828 | } |
| 829 | 829 | return $this; |
@@ -835,16 +835,16 @@ discard block |
||
| 835 | 835 | * @param string $orderDir the order direction (ASC or DESC) |
| 836 | 836 | * @return object the current Database instance |
| 837 | 837 | */ |
| 838 | - public function orderBy($orderBy, $orderDir = ' ASC'){ |
|
| 839 | - if (! is_null($orderDir)){ |
|
| 840 | - $this->orderBy = ! $this->orderBy ? ($orderBy . ' ' . strtoupper($orderDir)) : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
|
| 838 | + public function orderBy($orderBy, $orderDir = ' ASC') { |
|
| 839 | + if (!is_null($orderDir)) { |
|
| 840 | + $this->orderBy = !$this->orderBy ? ($orderBy . ' ' . strtoupper($orderDir)) : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
|
| 841 | 841 | } |
| 842 | - else{ |
|
| 843 | - if(stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
|
| 844 | - $this->orderBy = ! $this->orderBy ? $orderBy : $this->orderBy . ', ' . $orderBy; |
|
| 842 | + else { |
|
| 843 | + if (stristr($orderBy, ' ') || $orderBy == 'rand()') { |
|
| 844 | + $this->orderBy = !$this->orderBy ? $orderBy : $this->orderBy . ', ' . $orderBy; |
|
| 845 | 845 | } |
| 846 | - else{ |
|
| 847 | - $this->orderBy = ! $this->orderBy ? ($orderBy . ' ASC') : $this->orderBy . ', ' . ($orderBy . ' ASC'); |
|
| 846 | + else { |
|
| 847 | + $this->orderBy = !$this->orderBy ? ($orderBy . ' ASC') : $this->orderBy . ', ' . ($orderBy . ' ASC'); |
|
| 848 | 848 | } |
| 849 | 849 | } |
| 850 | 850 | return $this; |
@@ -855,11 +855,11 @@ discard block |
||
| 855 | 855 | * @param string|array $field the field name used or array of field list |
| 856 | 856 | * @return object the current Database instance |
| 857 | 857 | */ |
| 858 | - public function groupBy($field){ |
|
| 859 | - if(is_array($field)){ |
|
| 858 | + public function groupBy($field) { |
|
| 859 | + if (is_array($field)) { |
|
| 860 | 860 | $this->groupBy = implode(', ', $field); |
| 861 | 861 | } |
| 862 | - else{ |
|
| 862 | + else { |
|
| 863 | 863 | $this->groupBy = $field; |
| 864 | 864 | } |
| 865 | 865 | return $this; |
@@ -873,13 +873,13 @@ discard block |
||
| 873 | 873 | * @param boolean $escape whether to escape or not the values |
| 874 | 874 | * @return object the current Database instance |
| 875 | 875 | */ |
| 876 | - public function having($field, $op = null, $val = null, $escape = true){ |
|
| 877 | - if(is_array($op)){ |
|
| 876 | + public function having($field, $op = null, $val = null, $escape = true) { |
|
| 877 | + if (is_array($op)) { |
|
| 878 | 878 | $x = explode('?', $field); |
| 879 | 879 | $w = ''; |
| 880 | - foreach($x as $k => $v){ |
|
| 881 | - if(!empty($v)){ |
|
| 882 | - if(isset($op[$k]) && is_null($op[$k])){ |
|
| 880 | + foreach ($x as $k => $v) { |
|
| 881 | + if (!empty($v)) { |
|
| 882 | + if (isset($op[$k]) && is_null($op[$k])) { |
|
| 883 | 883 | $op[$k] = ''; |
| 884 | 884 | } |
| 885 | 885 | $w .= $v . (isset($op[$k]) ? ($escape ? $this->escape($op[$k]) : $op[$k]) : ''); |
@@ -887,14 +887,14 @@ discard block |
||
| 887 | 887 | } |
| 888 | 888 | $this->having = $w; |
| 889 | 889 | } |
| 890 | - else if (! in_array($op, $this->operatorList)){ |
|
| 891 | - if(is_null($op)){ |
|
| 890 | + else if (!in_array($op, $this->operatorList)) { |
|
| 891 | + if (is_null($op)) { |
|
| 892 | 892 | $op = ''; |
| 893 | 893 | } |
| 894 | 894 | $this->having = $field . ' > ' . ($escape ? $this->escape($op) : $op); |
| 895 | 895 | } |
| 896 | - else{ |
|
| 897 | - if(is_null($val)){ |
|
| 896 | + else { |
|
| 897 | + if (is_null($val)) { |
|
| 898 | 898 | $val = ''; |
| 899 | 899 | } |
| 900 | 900 | $this->having = $field . ' ' . $op . ' ' . ($escape ? $this->escape($val) : $val); |
@@ -906,7 +906,7 @@ discard block |
||
| 906 | 906 | * Return the number of rows returned by the current query |
| 907 | 907 | * @return int |
| 908 | 908 | */ |
| 909 | - public function numRows(){ |
|
| 909 | + public function numRows() { |
|
| 910 | 910 | return $this->numRows; |
| 911 | 911 | } |
| 912 | 912 | |
@@ -914,15 +914,15 @@ discard block |
||
| 914 | 914 | * Return the last insert id value |
| 915 | 915 | * @return mixed |
| 916 | 916 | */ |
| 917 | - public function insertId(){ |
|
| 917 | + public function insertId() { |
|
| 918 | 918 | return $this->insertId; |
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | /** |
| 922 | 922 | * Show an error got from the current query (SQL command synthax error, database driver returned error, etc.) |
| 923 | 923 | */ |
| 924 | - public function error(){ |
|
| 925 | - if($this->error){ |
|
| 924 | + public function error() { |
|
| 925 | + if ($this->error) { |
|
| 926 | 926 | show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error'); |
| 927 | 927 | } |
| 928 | 928 | } |
@@ -933,14 +933,14 @@ discard block |
||
| 933 | 933 | * If is string will determine the result type "array" or "object" |
| 934 | 934 | * @return mixed the query SQL string or the record result |
| 935 | 935 | */ |
| 936 | - public function get($returnSQLQueryOrResultType = false){ |
|
| 936 | + public function get($returnSQLQueryOrResultType = false) { |
|
| 937 | 937 | $this->limit = 1; |
| 938 | 938 | $query = $this->getAll(true); |
| 939 | - if($returnSQLQueryOrResultType === true){ |
|
| 939 | + if ($returnSQLQueryOrResultType === true) { |
|
| 940 | 940 | return $query; |
| 941 | 941 | } |
| 942 | - else{ |
|
| 943 | - return $this->query( $query, false, (($returnSQLQueryOrResultType == 'array') ? true : false) ); |
|
| 942 | + else { |
|
| 943 | + return $this->query($query, false, (($returnSQLQueryOrResultType == 'array') ? true : false)); |
|
| 944 | 944 | } |
| 945 | 945 | } |
| 946 | 946 | |
@@ -950,37 +950,37 @@ discard block |
||
| 950 | 950 | * If is string will determine the result type "array" or "object" |
| 951 | 951 | * @return mixed the query SQL string or the record result |
| 952 | 952 | */ |
| 953 | - public function getAll($returnSQLQueryOrResultType = false){ |
|
| 953 | + public function getAll($returnSQLQueryOrResultType = false) { |
|
| 954 | 954 | $query = 'SELECT ' . $this->select . ' FROM ' . $this->from; |
| 955 | - if (! is_null($this->join)){ |
|
| 955 | + if (!is_null($this->join)) { |
|
| 956 | 956 | $query .= $this->join; |
| 957 | 957 | } |
| 958 | 958 | |
| 959 | - if (! is_null($this->where)){ |
|
| 959 | + if (!is_null($this->where)) { |
|
| 960 | 960 | $query .= ' WHERE ' . $this->where; |
| 961 | 961 | } |
| 962 | 962 | |
| 963 | - if (! is_null($this->groupBy)){ |
|
| 963 | + if (!is_null($this->groupBy)) { |
|
| 964 | 964 | $query .= ' GROUP BY ' . $this->groupBy; |
| 965 | 965 | } |
| 966 | 966 | |
| 967 | - if (! is_null($this->having)){ |
|
| 967 | + if (!is_null($this->having)) { |
|
| 968 | 968 | $query .= ' HAVING ' . $this->having; |
| 969 | 969 | } |
| 970 | 970 | |
| 971 | - if (! is_null($this->orderBy)){ |
|
| 971 | + if (!is_null($this->orderBy)) { |
|
| 972 | 972 | $query .= ' ORDER BY ' . $this->orderBy; |
| 973 | 973 | } |
| 974 | 974 | |
| 975 | - if(! is_null($this->limit)){ |
|
| 975 | + if (!is_null($this->limit)) { |
|
| 976 | 976 | $query .= ' LIMIT ' . $this->limit; |
| 977 | 977 | } |
| 978 | 978 | |
| 979 | - if($returnSQLQueryOrResultType === true){ |
|
| 979 | + if ($returnSQLQueryOrResultType === true) { |
|
| 980 | 980 | return $query; |
| 981 | 981 | } |
| 982 | - else{ |
|
| 983 | - return $this->query($query, true, (($returnSQLQueryOrResultType == 'array') ? true : false) ); |
|
| 982 | + else { |
|
| 983 | + return $this->query($query, true, (($returnSQLQueryOrResultType == 'array') ? true : false)); |
|
| 984 | 984 | } |
| 985 | 985 | } |
| 986 | 986 | |
@@ -990,15 +990,15 @@ discard block |
||
| 990 | 990 | * @param boolean $escape whether to escape or not the values |
| 991 | 991 | * @return mixed the insert id of the new record or null |
| 992 | 992 | */ |
| 993 | - public function insert($data = array(), $escape = true){ |
|
| 993 | + public function insert($data = array(), $escape = true) { |
|
| 994 | 994 | $column = array(); |
| 995 | 995 | $val = array(); |
| 996 | - if(! $data && $this->getData()){ |
|
| 996 | + if (!$data && $this->getData()) { |
|
| 997 | 997 | $columns = array_keys($this->getData()); |
| 998 | 998 | $column = implode(',', $columns); |
| 999 | 999 | $val = implode(', ', $this->getData()); |
| 1000 | 1000 | } |
| 1001 | - else{ |
|
| 1001 | + else { |
|
| 1002 | 1002 | $columns = array_keys($data); |
| 1003 | 1003 | $column = implode(',', $columns); |
| 1004 | 1004 | $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data)); |
@@ -1007,14 +1007,14 @@ discard block |
||
| 1007 | 1007 | $query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')'; |
| 1008 | 1008 | $query = $this->query($query); |
| 1009 | 1009 | |
| 1010 | - if ($query){ |
|
| 1011 | - if(! $this->pdo){ |
|
| 1010 | + if ($query) { |
|
| 1011 | + if (!$this->pdo) { |
|
| 1012 | 1012 | $this->connect(); |
| 1013 | 1013 | } |
| 1014 | 1014 | $this->insertId = $this->pdo->lastInsertId(); |
| 1015 | 1015 | return $this->insertId(); |
| 1016 | 1016 | } |
| 1017 | - else{ |
|
| 1017 | + else { |
|
| 1018 | 1018 | return false; |
| 1019 | 1019 | } |
| 1020 | 1020 | } |
@@ -1025,29 +1025,29 @@ discard block |
||
| 1025 | 1025 | * @param boolean $escape whether to escape or not the values |
| 1026 | 1026 | * @return mixed the update status |
| 1027 | 1027 | */ |
| 1028 | - public function update($data = array(), $escape = true){ |
|
| 1028 | + public function update($data = array(), $escape = true) { |
|
| 1029 | 1029 | $query = 'UPDATE ' . $this->from . ' SET '; |
| 1030 | 1030 | $values = array(); |
| 1031 | - if(! $data && $this->getData()){ |
|
| 1032 | - foreach ($this->getData() as $column => $val){ |
|
| 1031 | + if (!$data && $this->getData()) { |
|
| 1032 | + foreach ($this->getData() as $column => $val) { |
|
| 1033 | 1033 | $values[] = $column . ' = ' . $val; |
| 1034 | 1034 | } |
| 1035 | 1035 | } |
| 1036 | - else{ |
|
| 1037 | - foreach ($data as $column => $val){ |
|
| 1036 | + else { |
|
| 1037 | + foreach ($data as $column => $val) { |
|
| 1038 | 1038 | $values[] = $column . '=' . ($escape ? $this->escape($val) : $val); |
| 1039 | 1039 | } |
| 1040 | 1040 | } |
| 1041 | 1041 | $query .= (is_array($data) ? implode(', ', $values) : $data); |
| 1042 | - if (! is_null($this->where)){ |
|
| 1042 | + if (!is_null($this->where)) { |
|
| 1043 | 1043 | $query .= ' WHERE ' . $this->where; |
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | - if (! is_null($this->orderBy)){ |
|
| 1046 | + if (!is_null($this->orderBy)) { |
|
| 1047 | 1047 | $query .= ' ORDER BY ' . $this->orderBy; |
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 1050 | - if (! is_null($this->limit)){ |
|
| 1050 | + if (!is_null($this->limit)) { |
|
| 1051 | 1051 | $query .= ' LIMIT ' . $this->limit; |
| 1052 | 1052 | } |
| 1053 | 1053 | return $this->query($query); |
@@ -1057,22 +1057,22 @@ discard block |
||
| 1057 | 1057 | * Delete the record in database |
| 1058 | 1058 | * @return mixed the delete status |
| 1059 | 1059 | */ |
| 1060 | - public function delete(){ |
|
| 1060 | + public function delete() { |
|
| 1061 | 1061 | $query = 'DELETE FROM ' . $this->from; |
| 1062 | 1062 | |
| 1063 | - if (! is_null($this->where)){ |
|
| 1063 | + if (!is_null($this->where)) { |
|
| 1064 | 1064 | $query .= ' WHERE ' . $this->where; |
| 1065 | 1065 | } |
| 1066 | 1066 | |
| 1067 | - if (! is_null($this->orderBy)){ |
|
| 1067 | + if (!is_null($this->orderBy)) { |
|
| 1068 | 1068 | $query .= ' ORDER BY ' . $this->orderBy; |
| 1069 | 1069 | } |
| 1070 | 1070 | |
| 1071 | - if (! is_null($this->limit)){ |
|
| 1071 | + if (!is_null($this->limit)) { |
|
| 1072 | 1072 | $query .= ' LIMIT ' . $this->limit; |
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | - if($query == 'DELETE FROM ' . $this->from){ |
|
| 1075 | + if ($query == 'DELETE FROM ' . $this->from) { |
|
| 1076 | 1076 | $query = 'TRUNCATE TABLE ' . $this->from; |
| 1077 | 1077 | } |
| 1078 | 1078 | return $this->query($query); |
@@ -1085,13 +1085,13 @@ discard block |
||
| 1085 | 1085 | * @param boolean $array return the result as array |
| 1086 | 1086 | * @return mixed the query result |
| 1087 | 1087 | */ |
| 1088 | - public function query($query, $all = true, $array = false){ |
|
| 1088 | + public function query($query, $all = true, $array = false) { |
|
| 1089 | 1089 | $this->reset(); |
| 1090 | - if(is_array($all)){ |
|
| 1090 | + if (is_array($all)) { |
|
| 1091 | 1091 | $x = explode('?', $query); |
| 1092 | 1092 | $q = ''; |
| 1093 | - foreach($x as $k => $v){ |
|
| 1094 | - if(! empty($v)){ |
|
| 1093 | + foreach ($x as $k => $v) { |
|
| 1094 | + if (!empty($v)) { |
|
| 1095 | 1095 | $q .= $v . (isset($all[$k]) ? $this->escape($all[$k]) : ''); |
| 1096 | 1096 | } |
| 1097 | 1097 | } |
@@ -1100,7 +1100,7 @@ discard block |
||
| 1100 | 1100 | |
| 1101 | 1101 | $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query)); |
| 1102 | 1102 | $sqlSELECTQuery = stristr($this->query, 'SELECT'); |
| 1103 | - $this->logger->info('Execute SQL query ['.$this->query.'], return type: ' . ($array?'ARRAY':'OBJECT') .', return as list: ' . ($all ? 'YES':'NO')); |
|
| 1103 | + $this->logger->info('Execute SQL query [' . $this->query . '], return type: ' . ($array ? 'ARRAY' : 'OBJECT') . ', return as list: ' . ($all ? 'YES' : 'NO')); |
|
| 1104 | 1104 | //cache expire time |
| 1105 | 1105 | $cacheExpire = $this->temporaryCacheTtl; |
| 1106 | 1106 | |
@@ -1122,34 +1122,34 @@ discard block |
||
| 1122 | 1122 | //if can use cache feature for this query |
| 1123 | 1123 | $dbCacheStatus = $cacheEnable && $cacheExpire > 0; |
| 1124 | 1124 | |
| 1125 | - if ($dbCacheStatus && $sqlSELECTQuery){ |
|
| 1125 | + if ($dbCacheStatus && $sqlSELECTQuery) { |
|
| 1126 | 1126 | $this->logger->info('The cache is enabled for this query, try to get result from cache'); |
| 1127 | 1127 | $cacheKey = md5($query . $all . $array); |
| 1128 | - if(is_object($this->cacheInstance)){ |
|
| 1128 | + if (is_object($this->cacheInstance)) { |
|
| 1129 | 1129 | $cacheInstance = $this->cacheInstance; |
| 1130 | 1130 | } |
| 1131 | - else{ |
|
| 1131 | + else { |
|
| 1132 | 1132 | $obj = & get_instance(); |
| 1133 | 1133 | $cacheInstance = $obj->cache; |
| 1134 | 1134 | } |
| 1135 | 1135 | $cacheContent = $cacheInstance->get($cacheKey); |
| 1136 | 1136 | } |
| 1137 | - else{ |
|
| 1137 | + else { |
|
| 1138 | 1138 | $this->logger->info('The cache is not enabled for this query or is not the SELECT query, get the result directly from real database'); |
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | - if(! $this->pdo){ |
|
| 1141 | + if (!$this->pdo) { |
|
| 1142 | 1142 | $this->connect(); |
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | - if (! $cacheContent && $sqlSELECTQuery){ |
|
| 1145 | + if (!$cacheContent && $sqlSELECTQuery) { |
|
| 1146 | 1146 | //for database query execution time |
| 1147 | 1147 | $benchmarkMarkerKey = md5($query . $all . $array); |
| 1148 | 1148 | $bench = null; |
| 1149 | - if(is_object($this->benchmarkInstance)){ |
|
| 1149 | + if (is_object($this->benchmarkInstance)) { |
|
| 1150 | 1150 | $bench = $this->benchmarkInstance; |
| 1151 | 1151 | } |
| 1152 | - else{ |
|
| 1152 | + else { |
|
| 1153 | 1153 | $obj = & get_instance(); |
| 1154 | 1154 | $bench = $obj->benchmark; |
| 1155 | 1155 | } |
@@ -1160,52 +1160,52 @@ discard block |
||
| 1160 | 1160 | //get response time for this query |
| 1161 | 1161 | $responseTime = $bench->elapsedTime('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')'); |
| 1162 | 1162 | //TODO use the configuration value for the high response time currently is 1 second |
| 1163 | - if($responseTime >= 1 ){ |
|
| 1164 | - $this->logger->warning('High response time while processing database query [' .$query. ']. The response time is [' .$responseTime. '] sec.'); |
|
| 1163 | + if ($responseTime >= 1) { |
|
| 1164 | + $this->logger->warning('High response time while processing database query [' . $query . ']. The response time is [' . $responseTime . '] sec.'); |
|
| 1165 | 1165 | } |
| 1166 | - if ($sqlQuery){ |
|
| 1166 | + if ($sqlQuery) { |
|
| 1167 | 1167 | $this->numRows = $sqlQuery->rowCount(); |
| 1168 | - if (($this->numRows > 0)){ |
|
| 1168 | + if (($this->numRows > 0)) { |
|
| 1169 | 1169 | //if need return all result like list of record |
| 1170 | - if ($all){ |
|
| 1170 | + if ($all) { |
|
| 1171 | 1171 | $this->result = ($array == false) ? $sqlQuery->fetchAll(PDO::FETCH_OBJ) : $sqlQuery->fetchAll(PDO::FETCH_ASSOC); |
| 1172 | 1172 | } |
| 1173 | - else{ |
|
| 1173 | + else { |
|
| 1174 | 1174 | $this->result = ($array == false) ? $sqlQuery->fetch(PDO::FETCH_OBJ) : $sqlQuery->fetch(PDO::FETCH_ASSOC); |
| 1175 | 1175 | } |
| 1176 | 1176 | } |
| 1177 | - if ($dbCacheStatus && $sqlSELECTQuery){ |
|
| 1178 | - $this->logger->info('Save the result for query [' .$this->query. '] into cache for future use'); |
|
| 1177 | + if ($dbCacheStatus && $sqlSELECTQuery) { |
|
| 1178 | + $this->logger->info('Save the result for query [' . $this->query . '] into cache for future use'); |
|
| 1179 | 1179 | $cacheInstance->set($cacheKey, $this->result, $cacheExpire); |
| 1180 | 1180 | } |
| 1181 | 1181 | } |
| 1182 | - else{ |
|
| 1182 | + else { |
|
| 1183 | 1183 | $error = $this->pdo->errorInfo(); |
| 1184 | 1184 | $this->error = $error[2]; |
| 1185 | 1185 | $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error)); |
| 1186 | 1186 | $this->error(); |
| 1187 | 1187 | } |
| 1188 | 1188 | } |
| 1189 | - else if ((! $cacheContent && !$sqlSELECTQuery) || ($cacheContent && !$sqlSELECTQuery)){ |
|
| 1189 | + else if ((!$cacheContent && !$sqlSELECTQuery) || ($cacheContent && !$sqlSELECTQuery)) { |
|
| 1190 | 1190 | $queryStr = $this->pdo->query($this->query); |
| 1191 | - if($queryStr){ |
|
| 1191 | + if ($queryStr) { |
|
| 1192 | 1192 | $this->result = $queryStr->rowCount() >= 0; //to test the result for the query like UPDATE, INSERT, DELETE |
| 1193 | 1193 | $this->numRows = $queryStr->rowCount(); |
| 1194 | 1194 | } |
| 1195 | - if (! $this->result){ |
|
| 1195 | + if (!$this->result) { |
|
| 1196 | 1196 | $error = $this->pdo->errorInfo(); |
| 1197 | 1197 | $this->error = $error[2]; |
| 1198 | 1198 | $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error)); |
| 1199 | 1199 | $this->error(); |
| 1200 | 1200 | } |
| 1201 | 1201 | } |
| 1202 | - else{ |
|
| 1203 | - $this->logger->info('The result for query [' .$this->query. '] already cached use it'); |
|
| 1202 | + else { |
|
| 1203 | + $this->logger->info('The result for query [' . $this->query . '] already cached use it'); |
|
| 1204 | 1204 | $this->result = $cacheContent; |
| 1205 | 1205 | $this->numRows = count($this->result); |
| 1206 | 1206 | } |
| 1207 | 1207 | $this->queryCount++; |
| 1208 | - if(! $this->result){ |
|
| 1208 | + if (!$this->result) { |
|
| 1209 | 1209 | $this->logger->info('No result where found for the query [' . $query . ']'); |
| 1210 | 1210 | } |
| 1211 | 1211 | return $this->result; |
@@ -1216,8 +1216,8 @@ discard block |
||
| 1216 | 1216 | * @param integer $ttl the cache time to live in second |
| 1217 | 1217 | * @return object the current Database instance |
| 1218 | 1218 | */ |
| 1219 | - public function setCache($ttl = 0){ |
|
| 1220 | - if($ttl > 0){ |
|
| 1219 | + public function setCache($ttl = 0) { |
|
| 1220 | + if ($ttl > 0) { |
|
| 1221 | 1221 | $this->cacheTtl = $ttl; |
| 1222 | 1222 | $this->temporaryCacheTtl = $ttl; |
| 1223 | 1223 | } |
@@ -1229,8 +1229,8 @@ discard block |
||
| 1229 | 1229 | * @param integer $ttl the cache time to live in second |
| 1230 | 1230 | * @return object the current Database instance |
| 1231 | 1231 | */ |
| 1232 | - public function cached($ttl = 0){ |
|
| 1233 | - if($ttl > 0){ |
|
| 1232 | + public function cached($ttl = 0) { |
|
| 1233 | + if ($ttl > 0) { |
|
| 1234 | 1234 | $this->temporaryCacheTtl = $ttl; |
| 1235 | 1235 | } |
| 1236 | 1236 | return $this; |
@@ -1241,11 +1241,11 @@ discard block |
||
| 1241 | 1241 | * @param mixed $data the data to be escaped |
| 1242 | 1242 | * @return mixed the data after escaped |
| 1243 | 1243 | */ |
| 1244 | - public function escape($data){ |
|
| 1245 | - if(is_null($data)){ |
|
| 1244 | + public function escape($data) { |
|
| 1245 | + if (is_null($data)) { |
|
| 1246 | 1246 | return null; |
| 1247 | 1247 | } |
| 1248 | - if(! $this->pdo){ |
|
| 1248 | + if (!$this->pdo) { |
|
| 1249 | 1249 | $this->connect(); |
| 1250 | 1250 | } |
| 1251 | 1251 | return $this->pdo->quote(trim($data)); |
@@ -1255,7 +1255,7 @@ discard block |
||
| 1255 | 1255 | * Return the number query executed count for the current request |
| 1256 | 1256 | * @return int |
| 1257 | 1257 | */ |
| 1258 | - public function queryCount(){ |
|
| 1258 | + public function queryCount() { |
|
| 1259 | 1259 | return $this->queryCount; |
| 1260 | 1260 | } |
| 1261 | 1261 | |
@@ -1263,7 +1263,7 @@ discard block |
||
| 1263 | 1263 | * Return the current query SQL string |
| 1264 | 1264 | * @return string |
| 1265 | 1265 | */ |
| 1266 | - public function getQuery(){ |
|
| 1266 | + public function getQuery() { |
|
| 1267 | 1267 | return $this->query; |
| 1268 | 1268 | } |
| 1269 | 1269 | |
@@ -1271,7 +1271,7 @@ discard block |
||
| 1271 | 1271 | * Return the application database name |
| 1272 | 1272 | * @return string |
| 1273 | 1273 | */ |
| 1274 | - public function getDatabaseName(){ |
|
| 1274 | + public function getDatabaseName() { |
|
| 1275 | 1275 | return $this->databaseName; |
| 1276 | 1276 | } |
| 1277 | 1277 | |
@@ -1279,7 +1279,7 @@ discard block |
||
| 1279 | 1279 | * Return the database configuration |
| 1280 | 1280 | * @return array |
| 1281 | 1281 | */ |
| 1282 | - public function getDatabaseConfiguration(){ |
|
| 1282 | + public function getDatabaseConfiguration() { |
|
| 1283 | 1283 | return $this->config; |
| 1284 | 1284 | } |
| 1285 | 1285 | |
@@ -1287,7 +1287,7 @@ discard block |
||
| 1287 | 1287 | * set the database configuration |
| 1288 | 1288 | * @param array $config the configuration |
| 1289 | 1289 | */ |
| 1290 | - public function setDatabaseConfiguration(array $config){ |
|
| 1290 | + public function setDatabaseConfiguration(array $config) { |
|
| 1291 | 1291 | $this->config = array_merge($this->config, $config); |
| 1292 | 1292 | $this->prefix = $this->config['prefix']; |
| 1293 | 1293 | $this->databaseName = $this->config['database']; |
@@ -1299,7 +1299,7 @@ discard block |
||
| 1299 | 1299 | * Return the PDO instance |
| 1300 | 1300 | * @return PDO |
| 1301 | 1301 | */ |
| 1302 | - public function getPdo(){ |
|
| 1302 | + public function getPdo() { |
|
| 1303 | 1303 | return $this->pdo; |
| 1304 | 1304 | } |
| 1305 | 1305 | |
@@ -1307,7 +1307,7 @@ discard block |
||
| 1307 | 1307 | * Set the PDO instance |
| 1308 | 1308 | * @param PDO $pdo the pdo object |
| 1309 | 1309 | */ |
| 1310 | - public function setPdo(PDO $pdo){ |
|
| 1310 | + public function setPdo(PDO $pdo) { |
|
| 1311 | 1311 | $this->pdo = $pdo; |
| 1312 | 1312 | return $this; |
| 1313 | 1313 | } |
@@ -1317,7 +1317,7 @@ discard block |
||
| 1317 | 1317 | * Return the Log instance |
| 1318 | 1318 | * @return Log |
| 1319 | 1319 | */ |
| 1320 | - public function getLogger(){ |
|
| 1320 | + public function getLogger() { |
|
| 1321 | 1321 | return $this->logger; |
| 1322 | 1322 | } |
| 1323 | 1323 | |
@@ -1325,7 +1325,7 @@ discard block |
||
| 1325 | 1325 | * Set the log instance |
| 1326 | 1326 | * @param Log $logger the log object |
| 1327 | 1327 | */ |
| 1328 | - public function setLogger($logger){ |
|
| 1328 | + public function setLogger($logger) { |
|
| 1329 | 1329 | $this->logger = $logger; |
| 1330 | 1330 | return $this; |
| 1331 | 1331 | } |
@@ -1334,7 +1334,7 @@ discard block |
||
| 1334 | 1334 | * Return the cache instance |
| 1335 | 1335 | * @return CacheInterface |
| 1336 | 1336 | */ |
| 1337 | - public function getCacheInstance(){ |
|
| 1337 | + public function getCacheInstance() { |
|
| 1338 | 1338 | return $this->cacheInstance; |
| 1339 | 1339 | } |
| 1340 | 1340 | |
@@ -1342,7 +1342,7 @@ discard block |
||
| 1342 | 1342 | * Set the cache instance |
| 1343 | 1343 | * @param CacheInterface $cache the cache object |
| 1344 | 1344 | */ |
| 1345 | - public function setCacheInstance($cache){ |
|
| 1345 | + public function setCacheInstance($cache) { |
|
| 1346 | 1346 | $this->cacheInstance = $cache; |
| 1347 | 1347 | return $this; |
| 1348 | 1348 | } |
@@ -1351,7 +1351,7 @@ discard block |
||
| 1351 | 1351 | * Return the benchmark instance |
| 1352 | 1352 | * @return Benchmark |
| 1353 | 1353 | */ |
| 1354 | - public function getBenchmark(){ |
|
| 1354 | + public function getBenchmark() { |
|
| 1355 | 1355 | return $this->benchmarkInstance; |
| 1356 | 1356 | } |
| 1357 | 1357 | |
@@ -1359,7 +1359,7 @@ discard block |
||
| 1359 | 1359 | * Set the benchmark instance |
| 1360 | 1360 | * @param Benchmark $cache the cache object |
| 1361 | 1361 | */ |
| 1362 | - public function setBenchmark($benchmark){ |
|
| 1362 | + public function setBenchmark($benchmark) { |
|
| 1363 | 1363 | $this->benchmarkInstance = $benchmark; |
| 1364 | 1364 | return $this; |
| 1365 | 1365 | } |
@@ -1368,7 +1368,7 @@ discard block |
||
| 1368 | 1368 | * Return the data to be used for insert, update, etc. |
| 1369 | 1369 | * @return array |
| 1370 | 1370 | */ |
| 1371 | - public function getData(){ |
|
| 1371 | + public function getData() { |
|
| 1372 | 1372 | return $this->data; |
| 1373 | 1373 | } |
| 1374 | 1374 | |
@@ -1379,7 +1379,7 @@ discard block |
||
| 1379 | 1379 | * @param boolean $escape whether to escape or not the $value |
| 1380 | 1380 | * @return object the current Database instance |
| 1381 | 1381 | */ |
| 1382 | - public function setData($key, $value, $escape = true){ |
|
| 1382 | + public function setData($key, $value, $escape = true) { |
|
| 1383 | 1383 | $this->data[$key] = $escape ? $this->escape($value) : $value; |
| 1384 | 1384 | return $this; |
| 1385 | 1385 | } |
@@ -1388,7 +1388,7 @@ discard block |
||
| 1388 | 1388 | /** |
| 1389 | 1389 | * Reset the database class attributs to the initail values before each query. |
| 1390 | 1390 | */ |
| 1391 | - private function reset(){ |
|
| 1391 | + private function reset() { |
|
| 1392 | 1392 | $this->select = '*'; |
| 1393 | 1393 | $this->from = null; |
| 1394 | 1394 | $this->where = null; |
@@ -1408,7 +1408,7 @@ discard block |
||
| 1408 | 1408 | /** |
| 1409 | 1409 | * The class destructor |
| 1410 | 1410 | */ |
| 1411 | - function __destruct(){ |
|
| 1411 | + function __destruct() { |
|
| 1412 | 1412 | $this->pdo = null; |
| 1413 | 1413 | } |
| 1414 | 1414 | |
@@ -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 Controller{ |
|
| 27 | + class Controller { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The name of the module if this controller belong to an module |
@@ -47,32 +47,32 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * Class constructor |
| 49 | 49 | */ |
| 50 | - public function __construct(){ |
|
| 51 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 50 | + public function __construct() { |
|
| 51 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 52 | 52 | $this->logger->setLogger('MainController'); |
| 53 | 53 | self::$instance = & $this; |
| 54 | 54 | |
| 55 | 55 | $this->logger->debug('Adding the loaded classes to the super instance'); |
| 56 | - foreach (class_loaded() as $var => $class){ |
|
| 57 | - $this->$var =& class_loader($class); |
|
| 56 | + foreach (class_loaded() as $var => $class) { |
|
| 57 | + $this->$var = & class_loader($class); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $this->logger->debug('Setting the cache handler instance'); |
| 61 | 61 | //set cache handler instance |
| 62 | - if(get_config('cache_enable', false)){ |
|
| 63 | - if(isset($this->{strtolower(get_config('cache_handler'))})){ |
|
| 62 | + if (get_config('cache_enable', false)) { |
|
| 63 | + if (isset($this->{strtolower(get_config('cache_handler'))})) { |
|
| 64 | 64 | $this->cache = $this->{strtolower(get_config('cache_handler'))}; |
| 65 | 65 | unset($this->{strtolower(get_config('cache_handler'))}); |
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | $this->logger->debug('Loading the required classes into super instance'); |
| 69 | - $this->eventdispatcher =& class_loader('EventDispatcher', 'classes'); |
|
| 70 | - $this->loader =& class_loader('Loader', 'classes'); |
|
| 71 | - $this->lang =& class_loader('Lang', 'classes'); |
|
| 72 | - $this->request =& class_loader('Request', 'classes'); |
|
| 69 | + $this->eventdispatcher = & class_loader('EventDispatcher', 'classes'); |
|
| 70 | + $this->loader = & class_loader('Loader', 'classes'); |
|
| 71 | + $this->lang = & class_loader('Lang', 'classes'); |
|
| 72 | + $this->request = & class_loader('Request', 'classes'); |
|
| 73 | 73 | //dispatch the request instance created event |
| 74 | 74 | $this->eventdispatcher->dispatch('REQUEST_CREATED'); |
| 75 | - $this->response =& class_loader('Response', 'classes', 'classes'); |
|
| 75 | + $this->response = & class_loader('Response', 'classes', 'classes'); |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | 78 | //set session config |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | set_session_config(); |
| 81 | 81 | |
| 82 | 82 | //determine the current module |
| 83 | - if(isset($this->router) && $this->router->getModule()){ |
|
| 83 | + if (isset($this->router) && $this->router->getModule()) { |
|
| 84 | 84 | $this->moduleName = $this->router->getModule(); |
| 85 | 85 | } |
| 86 | 86 | //dispatch the loaded instance of super controller event |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | |
| 43 | 43 | //if the application is running in CLI mode $_SESSION global variable is not available |
| 44 | - if(IS_CLI){ |
|
| 44 | + if (IS_CLI) { |
|
| 45 | 45 | $_SESSION = array(); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -60,14 +60,14 @@ discard block |
||
| 60 | 60 | /** |
| 61 | 61 | * The Benchmark class |
| 62 | 62 | */ |
| 63 | - $BENCHMARK =& class_loader('Benchmark'); |
|
| 63 | + $BENCHMARK = & class_loader('Benchmark'); |
|
| 64 | 64 | |
| 65 | 65 | $BENCHMARK->mark('APP_EXECUTION_START'); |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * instance of the Log class |
| 69 | 69 | */ |
| 70 | - $LOGGER =& class_loader('Log', 'classes'); |
|
| 70 | + $LOGGER = & class_loader('Log', 'classes'); |
|
| 71 | 71 | |
| 72 | 72 | $LOGGER->setLogger('ApplicationBootstrap'); |
| 73 | 73 | |
@@ -76,10 +76,10 @@ discard block |
||
| 76 | 76 | /** |
| 77 | 77 | * Verification of the PHP environment: minimum and maximum version |
| 78 | 78 | */ |
| 79 | - if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){ |
|
| 79 | + if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')) { |
|
| 80 | 80 | show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment'); |
| 81 | 81 | } |
| 82 | - else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
| 82 | + else if (version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')) { |
|
| 83 | 83 | show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment'); |
| 84 | 84 | } |
| 85 | 85 | $LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue'); |
@@ -101,11 +101,11 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | //if user have some composer packages |
| 103 | 103 | $LOGGER->debug('Check for composer autoload'); |
| 104 | - if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 104 | + if (file_exists(VENDOR_PATH . 'autoload.php')) { |
|
| 105 | 105 | $LOGGER->info('The composer autoload file exists include it'); |
| 106 | 106 | require_once VENDOR_PATH . 'autoload.php'; |
| 107 | 107 | } |
| 108 | - else{ |
|
| 108 | + else { |
|
| 109 | 109 | $LOGGER->info('The composer autoload file does not exist skipping'); |
| 110 | 110 | } |
| 111 | 111 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * Load configurations and using the |
| 122 | 122 | * static method "init()" to initialize the Config class . |
| 123 | 123 | */ |
| 124 | - $CONFIG =& class_loader('Config', 'classes'); |
|
| 124 | + $CONFIG = & class_loader('Config', 'classes'); |
|
| 125 | 125 | $CONFIG->init(); |
| 126 | 126 | $BENCHMARK->mark('CONFIG_INIT_END'); |
| 127 | 127 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | * Load modules and using the |
| 131 | 131 | * static method "init()" to initialize the Module class. |
| 132 | 132 | */ |
| 133 | - $MODULE =& class_loader('Module', 'classes'); |
|
| 133 | + $MODULE = & class_loader('Module', 'classes'); |
|
| 134 | 134 | $MODULE->init(); |
| 135 | 135 | $BENCHMARK->mark('MODULE_INIT_END'); |
| 136 | 136 | |
@@ -149,34 +149,34 @@ discard block |
||
| 149 | 149 | /** |
| 150 | 150 | * Loading Security class |
| 151 | 151 | */ |
| 152 | - $SECURITY =& class_loader('Security', 'classes'); |
|
| 152 | + $SECURITY = & class_loader('Security', 'classes'); |
|
| 153 | 153 | $SECURITY->checkWhiteListIpAccess(); |
| 154 | 154 | |
| 155 | 155 | /** |
| 156 | 156 | * Loading Url class |
| 157 | 157 | */ |
| 158 | - $URL =& class_loader('Url', 'classes'); |
|
| 158 | + $URL = & class_loader('Url', 'classes'); |
|
| 159 | 159 | |
| 160 | - if(get_config('cache_enable', false)){ |
|
| 160 | + if (get_config('cache_enable', false)) { |
|
| 161 | 161 | /** |
| 162 | 162 | * Load Cache interface file |
| 163 | 163 | */ |
| 164 | 164 | require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php'; |
| 165 | 165 | $cacheHandler = get_config('cache_handler'); |
| 166 | - if(! $cacheHandler){ |
|
| 166 | + if (!$cacheHandler) { |
|
| 167 | 167 | show_error('The cache feature is enabled in the configuration but the cache handler class is not set.'); |
| 168 | 168 | } |
| 169 | 169 | $CACHE = null; |
| 170 | 170 | //first check if the cache handler is the system driver |
| 171 | - if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){ |
|
| 172 | - $CACHE =& class_loader($cacheHandler, 'classes/cache'); |
|
| 171 | + if (file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')) { |
|
| 172 | + $CACHE = & class_loader($cacheHandler, 'classes/cache'); |
|
| 173 | 173 | } |
| 174 | - else{ |
|
| 174 | + else { |
|
| 175 | 175 | //it's not a system driver use user library |
| 176 | - $CACHE =& class_loader($cacheHandler); |
|
| 176 | + $CACHE = & class_loader($cacheHandler); |
|
| 177 | 177 | } |
| 178 | 178 | //check if the page already cached |
| 179 | - if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){ |
|
| 179 | + if (!empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get') { |
|
| 180 | 180 | $RESPONSE = & class_loader('Response', 'classes'); |
| 181 | 181 | $RESPONSE->renderFinalPageFromCache($CACHE); |
| 182 | 182 | } |