@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - class Security{ |
|
| 27 | + class Security { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The logger instance |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | * Get the logger singleton instance |
| 37 | 37 | * @return Log the logger instance |
| 38 | 38 | */ |
| 39 | - private static function getLogger(){ |
|
| 40 | - if(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::Security'); |
| 43 | 43 | } |
| 44 | 44 | return self::$logger[0]; |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * This method is used to generate the CSRF token |
| 50 | 50 | * @return string the generated CSRF token |
| 51 | 51 | */ |
| 52 | - public static function generateCSRF(){ |
|
| 52 | + public static function generateCSRF() { |
|
| 53 | 53 | $logger = self::getLogger(); |
| 54 | 54 | $logger->debug('Generation of CSRF ...'); |
| 55 | 55 | |
@@ -57,14 +57,14 @@ discard block |
||
| 57 | 57 | $expire = get_config('csrf_expire', 60); |
| 58 | 58 | $keyExpire = 'csrf_expire'; |
| 59 | 59 | $currentTime = time(); |
| 60 | - if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){ |
|
| 60 | + if (Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime) { |
|
| 61 | 61 | $logger->info('The CSRF token not yet expire just return it'); |
| 62 | 62 | return Session::get($key); |
| 63 | 63 | } |
| 64 | - else{ |
|
| 64 | + else { |
|
| 65 | 65 | $newTime = $currentTime + $expire; |
| 66 | 66 | $token = sha1(uniqid()) . sha1(uniqid()); |
| 67 | - $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']'); |
|
| 67 | + $logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . '], token [' . $token . ']'); |
|
| 68 | 68 | Session::set($keyExpire, $newTime); |
| 69 | 69 | Session::set($key, $token); |
| 70 | 70 | return Session::get($key); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * This method is used to check the CSRF if is valid, not yet expire, etc. |
| 76 | 76 | * @return boolean true if valid, false if not valid |
| 77 | 77 | */ |
| 78 | - public static function validateCSRF(){ |
|
| 78 | + public static function validateCSRF() { |
|
| 79 | 79 | $logger = self::getLogger(); |
| 80 | 80 | $logger->debug('Validation of CSRF ...'); |
| 81 | 81 | |
@@ -83,8 +83,8 @@ discard block |
||
| 83 | 83 | $expire = get_config('csrf_expire', 60); |
| 84 | 84 | $keyExpire = 'csrf_expire'; |
| 85 | 85 | $currentTime = time(); |
| 86 | - $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. ']'); |
|
| 87 | - if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){ |
|
| 86 | + $logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . ']'); |
|
| 87 | + if (!Session::exists($key) || Session::get($keyExpire) <= $currentTime) { |
|
| 88 | 88 | $logger->warning('The CSRF session data is not valide'); |
| 89 | 89 | return false; |
| 90 | 90 | } |
@@ -93,11 +93,11 @@ discard block |
||
| 93 | 93 | //super instance |
| 94 | 94 | $obj = & get_instance(); |
| 95 | 95 | $token = $obj->request->query($key); |
| 96 | - if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){ |
|
| 97 | - $logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job'); |
|
| 96 | + if (!$token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime) { |
|
| 97 | + $logger->warning('The CSRF data [' . $token . '] is not valide may be attacker do his job'); |
|
| 98 | 98 | return false; |
| 99 | 99 | } |
| 100 | - $logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue'); |
|
| 100 | + $logger->info('The CSRF data [' . $token . '] is valide the form data is safe continue'); |
|
| 101 | 101 | //remove the token from session |
| 102 | 102 | Session::clear($key); |
| 103 | 103 | Session::clear($keyExpire); |
@@ -107,24 +107,24 @@ discard block |
||
| 107 | 107 | /** |
| 108 | 108 | * This method is used to check the whitelist IP address access |
| 109 | 109 | */ |
| 110 | - public static function checkWhiteListIpAccess(){ |
|
| 110 | + public static function checkWhiteListIpAccess() { |
|
| 111 | 111 | $logger = self::getLogger(); |
| 112 | 112 | $logger->debug('Validation of the IP address access ...'); |
| 113 | 113 | $logger->debug('Check if whitelist IP access is enabled in the configuration ...'); |
| 114 | 114 | $isEnable = get_config('white_list_ip_enable', false); |
| 115 | - if($isEnable){ |
|
| 115 | + if ($isEnable) { |
|
| 116 | 116 | $logger->info('Whitelist IP access is enabled in the configuration'); |
| 117 | 117 | $list = get_config('white_list_ip_addresses', array()); |
| 118 | - if(! empty($list)){ |
|
| 118 | + if (!empty($list)) { |
|
| 119 | 119 | //Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing |
| 120 | 120 | require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
| 121 | 121 | $ip = get_ip(); |
| 122 | - if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){ |
|
| 122 | + if ((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)) { |
|
| 123 | 123 | $logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP'); |
| 124 | 124 | //wildcard to access all ip address |
| 125 | 125 | return; |
| 126 | 126 | } |
| 127 | - else{ |
|
| 127 | + else { |
|
| 128 | 128 | // go through all whitelisted ips |
| 129 | 129 | foreach ($list as $ipaddr) { |
| 130 | 130 | // find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*") |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | - else{ |
|
| 153 | + else { |
|
| 154 | 154 | $logger->info('Whitelist IP access is not enabled in the configuration, ignore checking'); |
| 155 | 155 | } |
| 156 | 156 | } |
@@ -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 |
@@ -97,13 +97,13 @@ discard block |
||
| 97 | 97 | * @return void |
| 98 | 98 | */ |
| 99 | 99 | public function __construct() { |
| 100 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 100 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 101 | 101 | $this->logger->setLogger('Library::FormValidation'); |
| 102 | 102 | |
| 103 | 103 | //Load form validation language message |
| 104 | 104 | Loader::lang('form_validation'); |
| 105 | 105 | $obj = & get_instance(); |
| 106 | - $this->_errorsMessages = array( |
|
| 106 | + $this->_errorsMessages = array( |
|
| 107 | 107 | 'required' => $obj->lang->get('fv_required'), |
| 108 | 108 | 'min_length' => $obj->lang->get('fv_min_length'), |
| 109 | 109 | 'max_length' => $obj->lang->get('fv_max_length'), |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | * Set the database instance |
| 134 | 134 | * @param object $database the database instance |
| 135 | 135 | */ |
| 136 | - public function setDatabase(Database $database){ |
|
| 136 | + public function setDatabase(Database $database) { |
|
| 137 | 137 | $this->databaseInstance = $database; |
| 138 | 138 | return $this; |
| 139 | 139 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * Get the database instance |
| 143 | 143 | * @return object the database instance |
| 144 | 144 | */ |
| 145 | - public function getDatabase(){ |
|
| 145 | + public function getDatabase() { |
|
| 146 | 146 | return $this->databaseInstance; |
| 147 | 147 | } |
| 148 | 148 | |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * |
| 166 | 166 | * @return FormValidation Current instance of object. |
| 167 | 167 | */ |
| 168 | - public function setData(array $data){ |
|
| 168 | + public function setData(array $data) { |
|
| 169 | 169 | $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data)); |
| 170 | 170 | $this->data = $data; |
| 171 | 171 | return $this; |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | * Get the form validation data |
| 176 | 176 | * @return array the form validation data to be validated |
| 177 | 177 | */ |
| 178 | - public function getData(){ |
|
| 178 | + public function getData() { |
|
| 179 | 179 | return $this->data; |
| 180 | 180 | } |
| 181 | 181 | |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * |
| 185 | 185 | * @return string the function name |
| 186 | 186 | */ |
| 187 | - protected function _toCallCase($funcName, $prefix='_validate') { |
|
| 187 | + protected function _toCallCase($funcName, $prefix = '_validate') { |
|
| 188 | 188 | $funcName = strtolower($funcName); |
| 189 | 189 | $finalFuncName = $prefix; |
| 190 | 190 | foreach (explode('_', $funcName) as $funcNamePart) { |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * @return boolean Whether or not the form has been submitted or the data is available for validation. |
| 209 | 209 | */ |
| 210 | 210 | public function canDoValidation() { |
| 211 | - return get_instance()->request->method() === 'POST' || ! empty($this->data); |
|
| 211 | + return get_instance()->request->method() === 'POST' || !empty($this->data); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -228,14 +228,14 @@ discard block |
||
| 228 | 228 | * Validate the CSRF |
| 229 | 229 | * @return void |
| 230 | 230 | */ |
| 231 | - protected function validateCSRF(){ |
|
| 232 | - if(get_instance()->request->method() == 'POST'){ |
|
| 231 | + protected function validateCSRF() { |
|
| 232 | + if (get_instance()->request->method() == 'POST') { |
|
| 233 | 233 | $this->logger->debug('Check if CSRF is enabled in configuration'); |
| 234 | 234 | //first check for CSRF |
| 235 | - if (get_config('csrf_enable', false) && ! Security::validateCSRF()){ |
|
| 235 | + if (get_config('csrf_enable', false) && !Security::validateCSRF()) { |
|
| 236 | 236 | show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.'); |
| 237 | 237 | } |
| 238 | - else{ |
|
| 238 | + else { |
|
| 239 | 239 | $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it'); |
| 240 | 240 | } |
| 241 | 241 | } |
@@ -253,10 +253,10 @@ discard block |
||
| 253 | 253 | $this->_forceFail = false; |
| 254 | 254 | |
| 255 | 255 | foreach ($this->getData() as $inputName => $inputVal) { |
| 256 | - if(is_array($this->data[$inputName])){ |
|
| 256 | + if (is_array($this->data[$inputName])) { |
|
| 257 | 257 | $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
| 258 | 258 | } |
| 259 | - else{ |
|
| 259 | + else { |
|
| 260 | 260 | $this->data[$inputName] = trim($this->data[$inputName]); |
| 261 | 261 | } |
| 262 | 262 | |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | - $this->_success = empty($this->_errors) && $this->_forceFail === false; |
|
| 269 | + $this->_success = empty($this->_errors) && $this->_forceFail === false; |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | public function setRule($inputField, $inputLabel, $ruleSets) { |
| 281 | 281 | $this->_rules[$inputField] = $ruleSets; |
| 282 | 282 | $this->_labels[$inputField] = $inputLabel; |
| 283 | - $this->logger->info('Set the field rule: name [' .$inputField. '], label [' .$inputLabel. '], rules [' .$ruleSets. ']'); |
|
| 283 | + $this->logger->info('Set the field rule: name [' . $inputField . '], label [' . $inputLabel . '], rules [' . $ruleSets . ']'); |
|
| 284 | 284 | return $this; |
| 285 | 285 | } |
| 286 | 286 | |
@@ -444,7 +444,7 @@ discard block |
||
| 444 | 444 | } |
| 445 | 445 | $errorOutput .= $errorsEnd; |
| 446 | 446 | echo ($echo) ? $errorOutput : ''; |
| 447 | - return (! $echo) ? $errorOutput : null; |
|
| 447 | + return (!$echo) ? $errorOutput : null; |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | /** |
@@ -469,25 +469,25 @@ discard block |
||
| 469 | 469 | /* |
| 470 | 470 | //////////////// hack for regex rule that can contain "|" |
| 471 | 471 | */ |
| 472 | - if(strpos($ruleString, 'regex') !== false){ |
|
| 472 | + if (strpos($ruleString, 'regex') !== false) { |
|
| 473 | 473 | $regexRule = array(); |
| 474 | 474 | $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#'; |
| 475 | 475 | preg_match($rule, $ruleString, $regexRule); |
| 476 | 476 | $ruleStringTemp = preg_replace($rule, '', $ruleString); |
| 477 | - if(!empty($regexRule[0])){ |
|
| 477 | + if (!empty($regexRule[0])) { |
|
| 478 | 478 | $ruleSets[] = $regexRule[0]; |
| 479 | 479 | } |
| 480 | 480 | $ruleStringRegex = explode('|', $ruleStringTemp); |
| 481 | 481 | foreach ($ruleStringRegex as $rule) { |
| 482 | 482 | $rule = trim($rule); |
| 483 | - if($rule){ |
|
| 483 | + if ($rule) { |
|
| 484 | 484 | $ruleSets[] = $rule; |
| 485 | 485 | } |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | } |
| 489 | 489 | /***********************************/ |
| 490 | - else{ |
|
| 490 | + else { |
|
| 491 | 491 | if (strpos($ruleString, '|') !== FALSE) { |
| 492 | 492 | $ruleSets = explode('|', $ruleString); |
| 493 | 493 | } else { |
@@ -519,7 +519,7 @@ discard block |
||
| 519 | 519 | * @return void |
| 520 | 520 | */ |
| 521 | 521 | protected function _validateRule($inputName, $inputVal, $ruleName) { |
| 522 | - $this->logger->debug('Rule validation of field [' .$inputName. '], value [' .$inputVal. '], rule [' .$ruleName. ']'); |
|
| 522 | + $this->logger->debug('Rule validation of field [' . $inputName . '], value [' . $inputVal . '], rule [' . $ruleName . ']'); |
|
| 523 | 523 | // Array to store args |
| 524 | 524 | $ruleArgs = array(); |
| 525 | 525 | |
@@ -564,7 +564,7 @@ discard block |
||
| 564 | 564 | $key = $i - 1; |
| 565 | 565 | $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase); |
| 566 | 566 | } |
| 567 | - if (! array_key_exists($inputName, $this->_errors)) { |
|
| 567 | + if (!array_key_exists($inputName, $this->_errors)) { |
|
| 568 | 568 | $this->_errors[$inputName] = $rulePhrase; |
| 569 | 569 | } |
| 570 | 570 | } |
@@ -616,13 +616,13 @@ discard block |
||
| 616 | 616 | */ |
| 617 | 617 | protected function _validateRequired($inputName, $ruleName, array $ruleArgs) { |
| 618 | 618 | $inputVal = $this->post($inputName); |
| 619 | - if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) { |
|
| 619 | + if (array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) { |
|
| 620 | 620 | $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]); |
| 621 | 621 | if ($inputVal == '' && $callbackReturn == true) { |
| 622 | 622 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 623 | 623 | } |
| 624 | 624 | } |
| 625 | - else if($inputVal == '') { |
|
| 625 | + else if ($inputVal == '') { |
|
| 626 | 626 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 627 | 627 | } |
| 628 | 628 | } |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | protected function _validateCallback($inputName, $ruleName, array $ruleArgs) { |
| 649 | 649 | if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) { |
| 650 | 650 | $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]); |
| 651 | - if(! $result){ |
|
| 651 | + if (!$result) { |
|
| 652 | 652 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
| 653 | 653 | } |
| 654 | 654 | } |
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | continue; |
| 683 | 683 | } |
| 684 | 684 | } |
| 685 | - else{ |
|
| 685 | + else { |
|
| 686 | 686 | if ($inputVal == $doNotEqual) { |
| 687 | 687 | $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual)); |
| 688 | 688 | continue; |
@@ -712,8 +712,8 @@ discard block |
||
| 712 | 712 | */ |
| 713 | 713 | protected function _validateValidEmail($inputName, $ruleName, array $ruleArgs) { |
| 714 | 714 | $inputVal = $this->post($inputName); |
| 715 | - 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)) { |
|
| 716 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 715 | + 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)) { |
|
| 716 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 717 | 717 | return; |
| 718 | 718 | } |
| 719 | 719 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
@@ -729,7 +729,7 @@ discard block |
||
| 729 | 729 | protected function _validateExactLength($inputName, $ruleName, array $ruleArgs) { |
| 730 | 730 | $inputVal = $this->post($inputName); |
| 731 | 731 | if (strlen($inputVal) != $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
| 732 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 732 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 733 | 733 | return; |
| 734 | 734 | } |
| 735 | 735 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -745,7 +745,7 @@ discard block |
||
| 745 | 745 | protected function _validateMaxLength($inputName, $ruleName, array $ruleArgs) { |
| 746 | 746 | $inputVal = $this->post($inputName); |
| 747 | 747 | if (strlen($inputVal) > $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
| 748 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 748 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 749 | 749 | return; |
| 750 | 750 | } |
| 751 | 751 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -761,7 +761,7 @@ discard block |
||
| 761 | 761 | protected function _validateMinLength($inputName, $ruleName, array $ruleArgs) { |
| 762 | 762 | $inputVal = $this->post($inputName); |
| 763 | 763 | if (strlen($inputVal) < $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
| 764 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 764 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 765 | 765 | return; |
| 766 | 766 | } |
| 767 | 767 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -777,7 +777,7 @@ discard block |
||
| 777 | 777 | protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) { |
| 778 | 778 | $inputVal = $this->post($inputName); |
| 779 | 779 | if ($inputVal >= $ruleArgs[1]) { |
| 780 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 780 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 781 | 781 | return; |
| 782 | 782 | } |
| 783 | 783 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -793,7 +793,7 @@ discard block |
||
| 793 | 793 | protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) { |
| 794 | 794 | $inputVal = $this->post($inputName); |
| 795 | 795 | if ($inputVal <= $ruleArgs[1]) { |
| 796 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 796 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 797 | 797 | return; |
| 798 | 798 | } |
| 799 | 799 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -808,8 +808,8 @@ discard block |
||
| 808 | 808 | */ |
| 809 | 809 | protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) { |
| 810 | 810 | $inputVal = $this->post($inputName); |
| 811 | - if (! is_numeric($inputVal)) { |
|
| 812 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 811 | + if (!is_numeric($inputVal)) { |
|
| 812 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 813 | 813 | return; |
| 814 | 814 | } |
| 815 | 815 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -824,9 +824,9 @@ discard block |
||
| 824 | 824 | */ |
| 825 | 825 | protected function _validateExists($inputName, $ruleName, array $ruleArgs) { |
| 826 | 826 | $inputVal = $this->post($inputName); |
| 827 | - if (! is_object($this->databaseInstance)){ |
|
| 827 | + if (!is_object($this->databaseInstance)) { |
|
| 828 | 828 | $obj = & get_instance(); |
| 829 | - if(isset($obj->database)){ |
|
| 829 | + if (isset($obj->database)) { |
|
| 830 | 830 | $this->databaseInstance = $obj->database; |
| 831 | 831 | } |
| 832 | 832 | } |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | ->where($column, $inputVal); |
| 836 | 836 | $this->databaseInstance->get(); |
| 837 | 837 | if ($this->databaseInstance->numRows() <= 0) { |
| 838 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 838 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 839 | 839 | return; |
| 840 | 840 | } |
| 841 | 841 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -850,9 +850,9 @@ discard block |
||
| 850 | 850 | */ |
| 851 | 851 | protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) { |
| 852 | 852 | $inputVal = $this->post($inputName); |
| 853 | - if (! is_object($this->databaseInstance)){ |
|
| 853 | + if (!is_object($this->databaseInstance)) { |
|
| 854 | 854 | $obj = & get_instance(); |
| 855 | - if(isset($obj->database)){ |
|
| 855 | + if (isset($obj->database)) { |
|
| 856 | 856 | $this->databaseInstance = $obj->database; |
| 857 | 857 | } |
| 858 | 858 | } |
@@ -861,7 +861,7 @@ discard block |
||
| 861 | 861 | ->where($column, $inputVal); |
| 862 | 862 | $this->databaseInstance->get(); |
| 863 | 863 | if ($this->databaseInstance->numRows() > 0) { |
| 864 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 864 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 865 | 865 | return; |
| 866 | 866 | } |
| 867 | 867 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -876,14 +876,14 @@ discard block |
||
| 876 | 876 | */ |
| 877 | 877 | protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) { |
| 878 | 878 | $inputVal = $this->post($inputName); |
| 879 | - if (! is_object($this->databaseInstance)){ |
|
| 879 | + if (!is_object($this->databaseInstance)) { |
|
| 880 | 880 | $obj = & get_instance(); |
| 881 | - if(isset($obj->database)){ |
|
| 881 | + if (isset($obj->database)) { |
|
| 882 | 882 | $this->databaseInstance = $obj->database; |
| 883 | 883 | } |
| 884 | 884 | } |
| 885 | 885 | $data = explode(',', $ruleArgs[1]); |
| 886 | - if(count($data) < 2){ |
|
| 886 | + if (count($data) < 2) { |
|
| 887 | 887 | return; |
| 888 | 888 | } |
| 889 | 889 | list($table, $column) = explode('.', $data[0]); |
@@ -893,7 +893,7 @@ discard block |
||
| 893 | 893 | ->where($field, '!=', trim($val)); |
| 894 | 894 | $this->databaseInstance->get(); |
| 895 | 895 | if ($this->databaseInstance->numRows() > 0) { |
| 896 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 896 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 897 | 897 | return; |
| 898 | 898 | } |
| 899 | 899 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -910,8 +910,8 @@ discard block |
||
| 910 | 910 | $inputVal = $this->post($inputName); |
| 911 | 911 | $list = explode(',', $ruleArgs[1]); |
| 912 | 912 | $list = array_map('trim', $list); |
| 913 | - if (! in_array($inputVal, $list)) { |
|
| 914 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 913 | + if (!in_array($inputVal, $list)) { |
|
| 914 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 915 | 915 | return; |
| 916 | 916 | } |
| 917 | 917 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -927,8 +927,8 @@ discard block |
||
| 927 | 927 | protected function _validateRegex($inputName, $ruleName, array $ruleArgs) { |
| 928 | 928 | $inputVal = $this->post($inputName); |
| 929 | 929 | $regex = $ruleArgs[1]; |
| 930 | - if (! preg_match($regex, $inputVal)) { |
|
| 931 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 930 | + if (!preg_match($regex, $inputVal)) { |
|
| 931 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 932 | 932 | return; |
| 933 | 933 | } |
| 934 | 934 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -916,27 +916,27 @@ discard block |
||
| 916 | 916 | if (isset($aresult[1])) { |
| 917 | 917 | $this->setBrowser(self::BROWSER_IE); |
| 918 | 918 | $this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1])); |
| 919 | - if(preg_match('#trident/([0-9\.]+);#i', $this->_agent, $aresult)){ |
|
| 920 | - if($aresult[1] == '3.1'){ |
|
| 919 | + if (preg_match('#trident/([0-9\.]+);#i', $this->_agent, $aresult)) { |
|
| 920 | + if ($aresult[1] == '3.1') { |
|
| 921 | 921 | $this->setVersion('7.0'); |
| 922 | 922 | } |
| 923 | - else if($aresult[1] == '4.0'){ |
|
| 923 | + else if ($aresult[1] == '4.0') { |
|
| 924 | 924 | $this->setVersion('8.0'); |
| 925 | 925 | } |
| 926 | - else if($aresult[1] == '5.0'){ |
|
| 926 | + else if ($aresult[1] == '5.0') { |
|
| 927 | 927 | $this->setVersion('9.0'); |
| 928 | 928 | } |
| 929 | - else if($aresult[1] == '6.0'){ |
|
| 929 | + else if ($aresult[1] == '6.0') { |
|
| 930 | 930 | $this->setVersion('10.0'); |
| 931 | 931 | } |
| 932 | - else if($aresult[1] == '7.0'){ |
|
| 932 | + else if ($aresult[1] == '7.0') { |
|
| 933 | 933 | $this->setVersion('11.0'); |
| 934 | 934 | } |
| 935 | - else if($aresult[1] == '8.0'){ |
|
| 935 | + else if ($aresult[1] == '8.0') { |
|
| 936 | 936 | $this->setVersion('11.0'); |
| 937 | 937 | } |
| 938 | 938 | } |
| 939 | - if(stripos($this->_agent, 'IEMobile') !== false) { |
|
| 939 | + if (stripos($this->_agent, 'IEMobile') !== false) { |
|
| 940 | 940 | $this->setBrowser(self::BROWSER_POCKET_IE); |
| 941 | 941 | $this->setMobile(true); |
| 942 | 942 | } |
@@ -1676,7 +1676,7 @@ discard block |
||
| 1676 | 1676 | 'mac' => self::PLATFORM_APPLE, |
| 1677 | 1677 | 'android' => self::PLATFORM_ANDROID, |
| 1678 | 1678 | 'Silk' => self::PLATFORM_FIRE_OS, |
| 1679 | - 'linux_smarttv' => self::PLATFORM_LINUX .'/'.self::PLATFORM_SMART_TV, |
|
| 1679 | + 'linux_smarttv' => self::PLATFORM_LINUX . '/' . self::PLATFORM_SMART_TV, |
|
| 1680 | 1680 | 'linux' => self::PLATFORM_LINUX, |
| 1681 | 1681 | 'Nokia' => self::PLATFORM_NOKIA, |
| 1682 | 1682 | 'BlackBerry' => self::PLATFORM_BLACKBERRY, |
@@ -1700,9 +1700,9 @@ discard block |
||
| 1700 | 1700 | ); |
| 1701 | 1701 | |
| 1702 | 1702 | foreach ($platformMaps as $name => $value) { |
| 1703 | - if($name == 'linux_smarttv' |
|
| 1703 | + if ($name == 'linux_smarttv' |
|
| 1704 | 1704 | && stripos($this->_agent, 'linux') !== false |
| 1705 | - && stripos($this->_agent, 'SMART-TV') !== false ){ |
|
| 1705 | + && stripos($this->_agent, 'SMART-TV') !== false) { |
|
| 1706 | 1706 | $this->_platform = $value; |
| 1707 | 1707 | break; |
| 1708 | 1708 | } elseif (stripos($this->_agent, $name) !== false) { |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @filesource |
| 40 | 40 | */ |
| 41 | 41 | |
| 42 | - if(! function_exists('get_random_string')){ |
|
| 42 | + if (!function_exists('get_random_string')) { |
|
| 43 | 43 | /** |
| 44 | 44 | * Generate a random string |
| 45 | 45 | * @param string $type the type of generation. It can take the values: "alpha" for alphabetic characters, |
@@ -49,21 +49,21 @@ discard block |
||
| 49 | 49 | * @param boolean $lower if we return the generated string in lowercase (true). By default it's false. |
| 50 | 50 | * @return string the generated string. |
| 51 | 51 | */ |
| 52 | - function get_random_string($type = 'alnum', $length = 10, $lower = false){ |
|
| 52 | + function get_random_string($type = 'alnum', $length = 10, $lower = false) { |
|
| 53 | 53 | $chars = array( |
| 54 | 54 | 'alpha' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', |
| 55 | 55 | 'alnum' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', |
| 56 | 56 | 'num' => '1234567890' |
| 57 | 57 | ); |
| 58 | 58 | $str = null; |
| 59 | - if(isset($chars[$type])){ |
|
| 59 | + if (isset($chars[$type])) { |
|
| 60 | 60 | $str = $chars[$type]; |
| 61 | 61 | } |
| 62 | 62 | $random = null; |
| 63 | - for($i = 0; $i < $length; $i++){ |
|
| 63 | + for ($i = 0; $i < $length; $i++) { |
|
| 64 | 64 | $random .= $str[mt_rand() % strlen($str)]; |
| 65 | 65 | } |
| 66 | - if($lower){ |
|
| 66 | + if ($lower) { |
|
| 67 | 67 | $random = strtolower($random); |
| 68 | 68 | } |
| 69 | 69 | return $random; |
@@ -23,94 +23,94 @@ 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 DatabaseQueryBuilder{ |
|
| 26 | + class DatabaseQueryBuilder { |
|
| 27 | 27 | /** |
| 28 | 28 | * The SQL SELECT statment |
| 29 | 29 | * @var string |
| 30 | 30 | */ |
| 31 | - private $select = '*'; |
|
| 31 | + private $select = '*'; |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * The SQL FROM statment |
| 35 | 35 | * @var string |
| 36 | 36 | */ |
| 37 | - private $from = null; |
|
| 37 | + private $from = null; |
|
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * The SQL WHERE statment |
| 41 | 41 | * @var string |
| 42 | 42 | */ |
| 43 | - private $where = null; |
|
| 43 | + private $where = null; |
|
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | 46 | * The SQL LIMIT statment |
| 47 | 47 | * @var string |
| 48 | 48 | */ |
| 49 | - private $limit = null; |
|
| 49 | + private $limit = null; |
|
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * The SQL JOIN statment |
| 53 | 53 | * @var string |
| 54 | 54 | */ |
| 55 | - private $join = null; |
|
| 55 | + private $join = null; |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * The SQL ORDER BY statment |
| 59 | 59 | * @var string |
| 60 | 60 | */ |
| 61 | - private $orderBy = null; |
|
| 61 | + private $orderBy = null; |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * The SQL GROUP BY statment |
| 65 | 65 | * @var string |
| 66 | 66 | */ |
| 67 | - private $groupBy = null; |
|
| 67 | + private $groupBy = null; |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * The SQL HAVING statment |
| 71 | 71 | * @var string |
| 72 | 72 | */ |
| 73 | - private $having = null; |
|
| 73 | + private $having = null; |
|
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | 76 | * The full SQL query statment after build for each command |
| 77 | 77 | * @var string |
| 78 | 78 | */ |
| 79 | - private $query = null; |
|
| 79 | + private $query = null; |
|
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * The list of SQL valid operators |
| 83 | 83 | * @var array |
| 84 | 84 | */ |
| 85 | - private $operatorList = array('=','!=','<','>','<=','>=','<>'); |
|
| 85 | + private $operatorList = array('=', '!=', '<', '>', '<=', '>=', '<>'); |
|
| 86 | 86 | |
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * The prefix used in each database table |
| 90 | 90 | * @var string |
| 91 | 91 | */ |
| 92 | - private $prefix = null; |
|
| 92 | + private $prefix = null; |
|
| 93 | 93 | |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * The PDO instance |
| 97 | 97 | * @var object |
| 98 | 98 | */ |
| 99 | - private $pdo = null; |
|
| 99 | + private $pdo = null; |
|
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * The database driver name used |
| 103 | 103 | * @var string |
| 104 | 104 | */ |
| 105 | - private $driver = null; |
|
| 105 | + private $driver = null; |
|
| 106 | 106 | |
| 107 | 107 | |
| 108 | 108 | /** |
| 109 | 109 | * Construct new DatabaseQueryBuilder |
| 110 | 110 | * @param object $pdo the PDO object |
| 111 | 111 | */ |
| 112 | - public function __construct(PDO $pdo = null){ |
|
| 113 | - if (is_object($pdo)){ |
|
| 112 | + public function __construct(PDO $pdo = null) { |
|
| 113 | + if (is_object($pdo)) { |
|
| 114 | 114 | $this->setPdo($pdo); |
| 115 | 115 | } |
| 116 | 116 | } |
@@ -120,10 +120,10 @@ discard block |
||
| 120 | 120 | * @param string|array $table the table name or array of table list |
| 121 | 121 | * @return object the current DatabaseQueryBuilder instance |
| 122 | 122 | */ |
| 123 | - public function from($table){ |
|
| 124 | - if (is_array($table)){ |
|
| 123 | + public function from($table) { |
|
| 124 | + if (is_array($table)) { |
|
| 125 | 125 | $froms = ''; |
| 126 | - foreach($table as $key){ |
|
| 126 | + foreach ($table as $key) { |
|
| 127 | 127 | $froms .= $this->getPrefix() . $key . ', '; |
| 128 | 128 | } |
| 129 | 129 | $this->from = rtrim($froms, ', '); |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @param string|array $fields the field name or array of field list |
| 139 | 139 | * @return object the current DatabaseQueryBuilder instance |
| 140 | 140 | */ |
| 141 | - public function select($fields){ |
|
| 141 | + public function select($fields) { |
|
| 142 | 142 | $select = (is_array($fields) ? implode(', ', $fields) : $fields); |
| 143 | 143 | $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select); |
| 144 | 144 | return $this; |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * @param string $field the field name to distinct |
| 150 | 150 | * @return object the current DatabaseQueryBuilder instance |
| 151 | 151 | */ |
| 152 | - public function distinct($field){ |
|
| 152 | + public function distinct($field) { |
|
| 153 | 153 | $distinct = ' DISTINCT ' . $field; |
| 154 | 154 | $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct); |
| 155 | 155 | return $this; |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * @param string $name if is not null represent the alias used for this field in the result |
| 162 | 162 | * @return object the current DatabaseQueryBuilder instance |
| 163 | 163 | */ |
| 164 | - public function count($field = '*', $name = null){ |
|
| 164 | + public function count($field = '*', $name = null) { |
|
| 165 | 165 | return $this->select_min_max_sum_count_avg('COUNT', $field, $name); |
| 166 | 166 | } |
| 167 | 167 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | * @param string $name if is not null represent the alias used for this field in the result |
| 172 | 172 | * @return object the current DatabaseQueryBuilder instance |
| 173 | 173 | */ |
| 174 | - public function min($field, $name = null){ |
|
| 174 | + public function min($field, $name = null) { |
|
| 175 | 175 | return $this->select_min_max_sum_count_avg('MIN', $field, $name); |
| 176 | 176 | } |
| 177 | 177 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @param string $name if is not null represent the alias used for this field in the result |
| 182 | 182 | * @return object the current DatabaseQueryBuilder instance |
| 183 | 183 | */ |
| 184 | - public function max($field, $name = null){ |
|
| 184 | + public function max($field, $name = null) { |
|
| 185 | 185 | return $this->select_min_max_sum_count_avg('MAX', $field, $name); |
| 186 | 186 | } |
| 187 | 187 | |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | * @param string $name if is not null represent the alias used for this field in the result |
| 192 | 192 | * @return object the current DatabaseQueryBuilder instance |
| 193 | 193 | */ |
| 194 | - public function sum($field, $name = null){ |
|
| 194 | + public function sum($field, $name = null) { |
|
| 195 | 195 | return $this->select_min_max_sum_count_avg('SUM', $field, $name); |
| 196 | 196 | } |
| 197 | 197 | |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @param string $name if is not null represent the alias used for this field in the result |
| 202 | 202 | * @return object the current DatabaseQueryBuilder instance |
| 203 | 203 | */ |
| 204 | - public function avg($field, $name = null){ |
|
| 204 | + public function avg($field, $name = null) { |
|
| 205 | 205 | return $this->select_min_max_sum_count_avg('AVG', $field, $name); |
| 206 | 206 | } |
| 207 | 207 | |
@@ -215,18 +215,18 @@ discard block |
||
| 215 | 215 | * @param string $type the type of join (INNER, LEFT, RIGHT) |
| 216 | 216 | * @return object the current DatabaseQueryBuilder instance |
| 217 | 217 | */ |
| 218 | - public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){ |
|
| 218 | + public function join($table, $field1 = null, $op = null, $field2 = null, $type = '') { |
|
| 219 | 219 | $on = $field1; |
| 220 | 220 | $table = $this->getPrefix() . $table; |
| 221 | - if (! is_null($op)){ |
|
| 222 | - $on = (! in_array($op, $this->operatorList) |
|
| 221 | + if (!is_null($op)) { |
|
| 222 | + $on = (!in_array($op, $this->operatorList) |
|
| 223 | 223 | ? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) |
| 224 | 224 | : ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2)); |
| 225 | 225 | } |
| 226 | - if (empty($this->join)){ |
|
| 226 | + if (empty($this->join)) { |
|
| 227 | 227 | $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
| 228 | 228 | } |
| 229 | - else{ |
|
| 229 | + else { |
|
| 230 | 230 | $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
| 231 | 231 | } |
| 232 | 232 | return $this; |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | * @see DatabaseQueryBuilder::join() |
| 238 | 238 | * @return object the current DatabaseQueryBuilder instance |
| 239 | 239 | */ |
| 240 | - public function innerJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 240 | + public function innerJoin($table, $field1, $op = null, $field2 = '') { |
|
| 241 | 241 | return $this->join($table, $field1, $op, $field2, 'INNER '); |
| 242 | 242 | } |
| 243 | 243 | |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | * @see DatabaseQueryBuilder::join() |
| 247 | 247 | * @return object the current DatabaseQueryBuilder instance |
| 248 | 248 | */ |
| 249 | - public function leftJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 249 | + public function leftJoin($table, $field1, $op = null, $field2 = '') { |
|
| 250 | 250 | return $this->join($table, $field1, $op, $field2, 'LEFT '); |
| 251 | 251 | } |
| 252 | 252 | |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | * @see DatabaseQueryBuilder::join() |
| 256 | 256 | * @return object the current DatabaseQueryBuilder instance |
| 257 | 257 | */ |
| 258 | - public function rightJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 258 | + public function rightJoin($table, $field1, $op = null, $field2 = '') { |
|
| 259 | 259 | return $this->join($table, $field1, $op, $field2, 'RIGHT '); |
| 260 | 260 | } |
| 261 | 261 | |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | * @see DatabaseQueryBuilder::join() |
| 265 | 265 | * @return object the current DatabaseQueryBuilder instance |
| 266 | 266 | */ |
| 267 | - public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 267 | + public function fullOuterJoin($table, $field1, $op = null, $field2 = '') { |
|
| 268 | 268 | return $this->join($table, $field1, $op, $field2, 'FULL OUTER '); |
| 269 | 269 | } |
| 270 | 270 | |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | * @see DatabaseQueryBuilder::join() |
| 274 | 274 | * @return object the current DatabaseQueryBuilder instance |
| 275 | 275 | */ |
| 276 | - public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 276 | + public function leftOuterJoin($table, $field1, $op = null, $field2 = '') { |
|
| 277 | 277 | return $this->join($table, $field1, $op, $field2, 'LEFT OUTER '); |
| 278 | 278 | } |
| 279 | 279 | |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * @see DatabaseQueryBuilder::join() |
| 283 | 283 | * @return object the current DatabaseQueryBuilder instance |
| 284 | 284 | */ |
| 285 | - public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 285 | + public function rightOuterJoin($table, $field1, $op = null, $field2 = '') { |
|
| 286 | 286 | return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER '); |
| 287 | 287 | } |
| 288 | 288 | |
@@ -292,13 +292,13 @@ discard block |
||
| 292 | 292 | * @param string $andOr the separator type used 'AND', 'OR', etc. |
| 293 | 293 | * @return object the current DatabaseQueryBuilder instance |
| 294 | 294 | */ |
| 295 | - public function whereIsNull($field, $andOr = 'AND'){ |
|
| 296 | - if (is_array($field)){ |
|
| 297 | - foreach($field as $f){ |
|
| 295 | + public function whereIsNull($field, $andOr = 'AND') { |
|
| 296 | + if (is_array($field)) { |
|
| 297 | + foreach ($field as $f) { |
|
| 298 | 298 | $this->whereIsNull($f, $andOr); |
| 299 | 299 | } |
| 300 | 300 | } else { |
| 301 | - $this->setWhereStr($field.' IS NULL ', $andOr); |
|
| 301 | + $this->setWhereStr($field . ' IS NULL ', $andOr); |
|
| 302 | 302 | } |
| 303 | 303 | return $this; |
| 304 | 304 | } |
@@ -309,13 +309,13 @@ discard block |
||
| 309 | 309 | * @param string $andOr the separator type used 'AND', 'OR', etc. |
| 310 | 310 | * @return object the current DatabaseQueryBuilder instance |
| 311 | 311 | */ |
| 312 | - public function whereIsNotNull($field, $andOr = 'AND'){ |
|
| 313 | - if (is_array($field)){ |
|
| 314 | - foreach($field as $f){ |
|
| 312 | + public function whereIsNotNull($field, $andOr = 'AND') { |
|
| 313 | + if (is_array($field)) { |
|
| 314 | + foreach ($field as $f) { |
|
| 315 | 315 | $this->whereIsNotNull($f, $andOr); |
| 316 | 316 | } |
| 317 | 317 | } else { |
| 318 | - $this->setWhereStr($field.' IS NOT NULL ', $andOr); |
|
| 318 | + $this->setWhereStr($field . ' IS NOT NULL ', $andOr); |
|
| 319 | 319 | } |
| 320 | 320 | return $this; |
| 321 | 321 | } |
@@ -330,13 +330,13 @@ discard block |
||
| 330 | 330 | * @param boolean $escape whether to escape or not the $val |
| 331 | 331 | * @return object the current DatabaseQueryBuilder instance |
| 332 | 332 | */ |
| 333 | - public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){ |
|
| 333 | + public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true) { |
|
| 334 | 334 | $whereStr = ''; |
| 335 | - if (is_array($where)){ |
|
| 335 | + if (is_array($where)) { |
|
| 336 | 336 | $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape); |
| 337 | 337 | } |
| 338 | - else{ |
|
| 339 | - if (is_array($op)){ |
|
| 338 | + else { |
|
| 339 | + if (is_array($op)) { |
|
| 340 | 340 | $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape); |
| 341 | 341 | } else { |
| 342 | 342 | $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape); |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | * @see DatabaseQueryBuilder::where() |
| 352 | 352 | * @return object the current DatabaseQueryBuilder instance |
| 353 | 353 | */ |
| 354 | - public function orWhere($where, $op = null, $val = null, $escape = true){ |
|
| 354 | + public function orWhere($where, $op = null, $val = null, $escape = true) { |
|
| 355 | 355 | return $this->where($where, $op, $val, '', 'OR', $escape); |
| 356 | 356 | } |
| 357 | 357 | |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | * @see DatabaseQueryBuilder::where() |
| 362 | 362 | * @return object the current DatabaseQueryBuilder instance |
| 363 | 363 | */ |
| 364 | - public function notWhere($where, $op = null, $val = null, $escape = true){ |
|
| 364 | + public function notWhere($where, $op = null, $val = null, $escape = true) { |
|
| 365 | 365 | return $this->where($where, $op, $val, 'NOT ', 'AND', $escape); |
| 366 | 366 | } |
| 367 | 367 | |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | * @see DatabaseQueryBuilder::where() |
| 371 | 371 | * @return object the current DatabaseQueryBuilder instance |
| 372 | 372 | */ |
| 373 | - public function orNotWhere($where, $op = null, $val = null, $escape = true){ |
|
| 373 | + public function orNotWhere($where, $op = null, $val = null, $escape = true) { |
|
| 374 | 374 | return $this->where($where, $op, $val, 'NOT ', 'OR', $escape); |
| 375 | 375 | } |
| 376 | 376 | |
@@ -380,11 +380,11 @@ discard block |
||
| 380 | 380 | * @param string $andOr the multiple conditions separator (AND, OR, etc.) |
| 381 | 381 | * @return object the current DatabaseQueryBuilder instance |
| 382 | 382 | */ |
| 383 | - public function groupStart($type = '', $andOr = ' AND'){ |
|
| 384 | - if (empty($this->where)){ |
|
| 383 | + public function groupStart($type = '', $andOr = ' AND') { |
|
| 384 | + if (empty($this->where)) { |
|
| 385 | 385 | $this->where = $type . ' ('; |
| 386 | 386 | } else { |
| 387 | - if (substr(trim($this->where), -1) == '('){ |
|
| 387 | + if (substr(trim($this->where), -1) == '(') { |
|
| 388 | 388 | $this->where .= $type . ' ('; |
| 389 | 389 | } else { |
| 390 | 390 | $this->where .= $andOr . ' ' . $type . ' ('; |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | * @see DatabaseQueryBuilder::groupStart() |
| 399 | 399 | * @return object the current DatabaseQueryBuilder instance |
| 400 | 400 | */ |
| 401 | - public function notGroupStart(){ |
|
| 401 | + public function notGroupStart() { |
|
| 402 | 402 | return $this->groupStart('NOT'); |
| 403 | 403 | } |
| 404 | 404 | |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | * @see DatabaseQueryBuilder::groupStart() |
| 408 | 408 | * @return object the current DatabaseQueryBuilder instance |
| 409 | 409 | */ |
| 410 | - public function orGroupStart(){ |
|
| 410 | + public function orGroupStart() { |
|
| 411 | 411 | return $this->groupStart('', ' OR'); |
| 412 | 412 | } |
| 413 | 413 | |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | * @see DatabaseQueryBuilder::groupStart() |
| 417 | 417 | * @return object the current DatabaseQueryBuilder instance |
| 418 | 418 | */ |
| 419 | - public function orNotGroupStart(){ |
|
| 419 | + public function orNotGroupStart() { |
|
| 420 | 420 | return $this->groupStart('NOT', ' OR'); |
| 421 | 421 | } |
| 422 | 422 | |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | * Close the parenthesis for the grouped SQL |
| 425 | 425 | * @return object the current DatabaseQueryBuilder instance |
| 426 | 426 | */ |
| 427 | - public function groupEnd(){ |
|
| 427 | + public function groupEnd() { |
|
| 428 | 428 | $this->where .= ')'; |
| 429 | 429 | return $this; |
| 430 | 430 | } |
@@ -438,10 +438,10 @@ discard block |
||
| 438 | 438 | * @param boolean $escape whether to escape or not the values |
| 439 | 439 | * @return object the current DatabaseQueryBuilder instance |
| 440 | 440 | */ |
| 441 | - public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){ |
|
| 441 | + public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true) { |
|
| 442 | 442 | $_keys = array(); |
| 443 | - foreach ($keys as $k => $v){ |
|
| 444 | - if (is_null($v)){ |
|
| 443 | + foreach ($keys as $k => $v) { |
|
| 444 | + if (is_null($v)) { |
|
| 445 | 445 | $v = ''; |
| 446 | 446 | } |
| 447 | 447 | $_keys[] = (is_numeric($v) ? $v : $this->escape($v, $escape)); |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | * @see DatabaseQueryBuilder::in() |
| 458 | 458 | * @return object the current DatabaseQueryBuilder instance |
| 459 | 459 | */ |
| 460 | - public function notIn($field, array $keys, $escape = true){ |
|
| 460 | + public function notIn($field, array $keys, $escape = true) { |
|
| 461 | 461 | return $this->in($field, $keys, 'NOT ', 'AND', $escape); |
| 462 | 462 | } |
| 463 | 463 | |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | * @see DatabaseQueryBuilder::in() |
| 467 | 467 | * @return object the current DatabaseQueryBuilder instance |
| 468 | 468 | */ |
| 469 | - public function orIn($field, array $keys, $escape = true){ |
|
| 469 | + public function orIn($field, array $keys, $escape = true) { |
|
| 470 | 470 | return $this->in($field, $keys, '', 'OR', $escape); |
| 471 | 471 | } |
| 472 | 472 | |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | * @see DatabaseQueryBuilder::in() |
| 476 | 476 | * @return object the current DatabaseQueryBuilder instance |
| 477 | 477 | */ |
| 478 | - public function orNotIn($field, array $keys, $escape = true){ |
|
| 478 | + public function orNotIn($field, array $keys, $escape = true) { |
|
| 479 | 479 | return $this->in($field, $keys, 'NOT ', 'OR', $escape); |
| 480 | 480 | } |
| 481 | 481 | |
@@ -489,11 +489,11 @@ discard block |
||
| 489 | 489 | * @param boolean $escape whether to escape or not the values |
| 490 | 490 | * @return object the current DatabaseQueryBuilder instance |
| 491 | 491 | */ |
| 492 | - public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){ |
|
| 493 | - if (is_null($value1)){ |
|
| 492 | + public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true) { |
|
| 493 | + if (is_null($value1)) { |
|
| 494 | 494 | $value1 = ''; |
| 495 | 495 | } |
| 496 | - if (is_null($value2)){ |
|
| 496 | + if (is_null($value2)) { |
|
| 497 | 497 | $value2 = ''; |
| 498 | 498 | } |
| 499 | 499 | $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape); |
@@ -506,7 +506,7 @@ discard block |
||
| 506 | 506 | * @see DatabaseQueryBuilder::between() |
| 507 | 507 | * @return object the current DatabaseQueryBuilder instance |
| 508 | 508 | */ |
| 509 | - public function notBetween($field, $value1, $value2, $escape = true){ |
|
| 509 | + public function notBetween($field, $value1, $value2, $escape = true) { |
|
| 510 | 510 | return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape); |
| 511 | 511 | } |
| 512 | 512 | |
@@ -515,7 +515,7 @@ discard block |
||
| 515 | 515 | * @see DatabaseQueryBuilder::between() |
| 516 | 516 | * @return object the current DatabaseQueryBuilder instance |
| 517 | 517 | */ |
| 518 | - public function orBetween($field, $value1, $value2, $escape = true){ |
|
| 518 | + public function orBetween($field, $value1, $value2, $escape = true) { |
|
| 519 | 519 | return $this->between($field, $value1, $value2, '', 'OR', $escape); |
| 520 | 520 | } |
| 521 | 521 | |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | * @see DatabaseQueryBuilder::between() |
| 525 | 525 | * @return object the current DatabaseQueryBuilder instance |
| 526 | 526 | */ |
| 527 | - public function orNotBetween($field, $value1, $value2, $escape = true){ |
|
| 527 | + public function orNotBetween($field, $value1, $value2, $escape = true) { |
|
| 528 | 528 | return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape); |
| 529 | 529 | } |
| 530 | 530 | |
@@ -537,8 +537,8 @@ discard block |
||
| 537 | 537 | * @param boolean $escape whether to escape or not the values |
| 538 | 538 | * @return object the current DatabaseQueryBuilder instance |
| 539 | 539 | */ |
| 540 | - public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){ |
|
| 541 | - if (empty($data)){ |
|
| 540 | + public function like($field, $data, $type = '', $andOr = 'AND', $escape = true) { |
|
| 541 | + if (empty($data)) { |
|
| 542 | 542 | $data = ''; |
| 543 | 543 | } |
| 544 | 544 | $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr); |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | * @see DatabaseQueryBuilder::like() |
| 551 | 551 | * @return object the current DatabaseQueryBuilder instance |
| 552 | 552 | */ |
| 553 | - public function orLike($field, $data, $escape = true){ |
|
| 553 | + public function orLike($field, $data, $escape = true) { |
|
| 554 | 554 | return $this->like($field, $data, '', 'OR', $escape); |
| 555 | 555 | } |
| 556 | 556 | |
@@ -559,7 +559,7 @@ discard block |
||
| 559 | 559 | * @see DatabaseQueryBuilder::like() |
| 560 | 560 | * @return object the current DatabaseQueryBuilder instance |
| 561 | 561 | */ |
| 562 | - public function notLike($field, $data, $escape = true){ |
|
| 562 | + public function notLike($field, $data, $escape = true) { |
|
| 563 | 563 | return $this->like($field, $data, 'NOT ', 'AND', $escape); |
| 564 | 564 | } |
| 565 | 565 | |
@@ -568,7 +568,7 @@ discard block |
||
| 568 | 568 | * @see DatabaseQueryBuilder::like() |
| 569 | 569 | * @return object the current DatabaseQueryBuilder instance |
| 570 | 570 | */ |
| 571 | - public function orNotLike($field, $data, $escape = true){ |
|
| 571 | + public function orNotLike($field, $data, $escape = true) { |
|
| 572 | 572 | return $this->like($field, $data, 'NOT ', 'OR', $escape); |
| 573 | 573 | } |
| 574 | 574 | |
@@ -579,14 +579,14 @@ discard block |
||
| 579 | 579 | * @param int $limitEnd the limit count |
| 580 | 580 | * @return object the current DatabaseQueryBuilder instance |
| 581 | 581 | */ |
| 582 | - public function limit($limit, $limitEnd = null){ |
|
| 583 | - if (empty($limit)){ |
|
| 582 | + public function limit($limit, $limitEnd = null) { |
|
| 583 | + if (empty($limit)) { |
|
| 584 | 584 | $limit = 0; |
| 585 | 585 | } |
| 586 | - if (! is_null($limitEnd)){ |
|
| 586 | + if (!is_null($limitEnd)) { |
|
| 587 | 587 | $this->limit = $limit . ', ' . $limitEnd; |
| 588 | 588 | } |
| 589 | - else{ |
|
| 589 | + else { |
|
| 590 | 590 | $this->limit = $limit; |
| 591 | 591 | } |
| 592 | 592 | return $this; |
@@ -598,11 +598,11 @@ discard block |
||
| 598 | 598 | * @param string $orderDir the order direction (ASC or DESC) |
| 599 | 599 | * @return object the current DatabaseQueryBuilder instance |
| 600 | 600 | */ |
| 601 | - public function orderBy($orderBy, $orderDir = ' ASC'){ |
|
| 602 | - if (stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
|
| 601 | + public function orderBy($orderBy, $orderDir = ' ASC') { |
|
| 602 | + if (stristr($orderBy, ' ') || $orderBy == 'rand()') { |
|
| 603 | 603 | $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy; |
| 604 | 604 | } |
| 605 | - else{ |
|
| 605 | + else { |
|
| 606 | 606 | $this->orderBy = empty($this->orderBy) |
| 607 | 607 | ? ($orderBy . ' ' . strtoupper($orderDir)) |
| 608 | 608 | : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
@@ -615,11 +615,11 @@ discard block |
||
| 615 | 615 | * @param string|array $field the field name used or array of field list |
| 616 | 616 | * @return object the current DatabaseQueryBuilder instance |
| 617 | 617 | */ |
| 618 | - public function groupBy($field){ |
|
| 619 | - if (is_array($field)){ |
|
| 618 | + public function groupBy($field) { |
|
| 619 | + if (is_array($field)) { |
|
| 620 | 620 | $this->groupBy = implode(', ', $field); |
| 621 | 621 | } |
| 622 | - else{ |
|
| 622 | + else { |
|
| 623 | 623 | $this->groupBy = $field; |
| 624 | 624 | } |
| 625 | 625 | return $this; |
@@ -633,18 +633,18 @@ discard block |
||
| 633 | 633 | * @param boolean $escape whether to escape or not the values |
| 634 | 634 | * @return object the current DatabaseQueryBuilder instance |
| 635 | 635 | */ |
| 636 | - public function having($field, $op = null, $val = null, $escape = true){ |
|
| 637 | - if (is_array($op)){ |
|
| 636 | + public function having($field, $op = null, $val = null, $escape = true) { |
|
| 637 | + if (is_array($op)) { |
|
| 638 | 638 | $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape); |
| 639 | 639 | } |
| 640 | - else if (! in_array($op, $this->operatorList)){ |
|
| 641 | - if (is_null($op)){ |
|
| 640 | + else if (!in_array($op, $this->operatorList)) { |
|
| 641 | + if (is_null($op)) { |
|
| 642 | 642 | $op = ''; |
| 643 | 643 | } |
| 644 | 644 | $this->having = $field . ' > ' . ($this->escape($op, $escape)); |
| 645 | 645 | } |
| 646 | - else{ |
|
| 647 | - if (is_null($val)){ |
|
| 646 | + else { |
|
| 647 | + if (is_null($val)) { |
|
| 648 | 648 | $val = ''; |
| 649 | 649 | } |
| 650 | 650 | $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape)); |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | * @param boolean $escape whether to escape or not the values |
| 659 | 659 | * @return object the current DatabaseQueryBuilder instance |
| 660 | 660 | */ |
| 661 | - public function insert($data = array(), $escape = true){ |
|
| 661 | + public function insert($data = array(), $escape = true) { |
|
| 662 | 662 | $columns = array_keys($data); |
| 663 | 663 | $column = implode(', ', $columns); |
| 664 | 664 | $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data)); |
@@ -673,22 +673,22 @@ discard block |
||
| 673 | 673 | * @param boolean $escape whether to escape or not the values |
| 674 | 674 | * @return object the current DatabaseQueryBuilder instance |
| 675 | 675 | */ |
| 676 | - public function update($data = array(), $escape = true){ |
|
| 676 | + public function update($data = array(), $escape = true) { |
|
| 677 | 677 | $query = 'UPDATE ' . $this->from . ' SET '; |
| 678 | 678 | $values = array(); |
| 679 | - foreach ($data as $column => $val){ |
|
| 679 | + foreach ($data as $column => $val) { |
|
| 680 | 680 | $values[] = $column . ' = ' . ($this->escape($val, $escape)); |
| 681 | 681 | } |
| 682 | 682 | $query .= implode(', ', $values); |
| 683 | - if (! empty($this->where)){ |
|
| 683 | + if (!empty($this->where)) { |
|
| 684 | 684 | $query .= ' WHERE ' . $this->where; |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | - if (! empty($this->orderBy)){ |
|
| 687 | + if (!empty($this->orderBy)) { |
|
| 688 | 688 | $query .= ' ORDER BY ' . $this->orderBy; |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - if (! empty($this->limit)){ |
|
| 691 | + if (!empty($this->limit)) { |
|
| 692 | 692 | $query .= ' LIMIT ' . $this->limit; |
| 693 | 693 | } |
| 694 | 694 | $this->query = $query; |
@@ -699,22 +699,22 @@ discard block |
||
| 699 | 699 | * Delete the record in database |
| 700 | 700 | * @return object the current DatabaseQueryBuilder instance |
| 701 | 701 | */ |
| 702 | - public function delete(){ |
|
| 702 | + public function delete() { |
|
| 703 | 703 | $query = 'DELETE FROM ' . $this->from; |
| 704 | 704 | $isTruncate = $query; |
| 705 | - if (! empty($this->where)){ |
|
| 705 | + if (!empty($this->where)) { |
|
| 706 | 706 | $query .= ' WHERE ' . $this->where; |
| 707 | 707 | } |
| 708 | 708 | |
| 709 | - if (! empty($this->orderBy)){ |
|
| 709 | + if (!empty($this->orderBy)) { |
|
| 710 | 710 | $query .= ' ORDER BY ' . $this->orderBy; |
| 711 | 711 | } |
| 712 | 712 | |
| 713 | - if (! empty($this->limit)){ |
|
| 713 | + if (!empty($this->limit)) { |
|
| 714 | 714 | $query .= ' LIMIT ' . $this->limit; |
| 715 | 715 | } |
| 716 | 716 | |
| 717 | - if ($isTruncate == $query && $this->driver != 'sqlite'){ |
|
| 717 | + if ($isTruncate == $query && $this->driver != 'sqlite') { |
|
| 718 | 718 | $query = 'TRUNCATE TABLE ' . $this->from; |
| 719 | 719 | } |
| 720 | 720 | $this->query = $query; |
@@ -727,9 +727,9 @@ discard block |
||
| 727 | 727 | * @param boolean $escaped whether we can do escape of not |
| 728 | 728 | * @return mixed the data after escaped or the same data if not |
| 729 | 729 | */ |
| 730 | - public function escape($data, $escaped = true){ |
|
| 730 | + public function escape($data, $escaped = true) { |
|
| 731 | 731 | $data = trim($data); |
| 732 | - if($escaped){ |
|
| 732 | + if ($escaped) { |
|
| 733 | 733 | return $this->pdo->quote($data); |
| 734 | 734 | } |
| 735 | 735 | return $data; |
@@ -740,31 +740,31 @@ discard block |
||
| 740 | 740 | * Return the current SQL query string |
| 741 | 741 | * @return string |
| 742 | 742 | */ |
| 743 | - public function getQuery(){ |
|
| 743 | + public function getQuery() { |
|
| 744 | 744 | //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now |
| 745 | - if(empty($this->query)){ |
|
| 745 | + if (empty($this->query)) { |
|
| 746 | 746 | $query = 'SELECT ' . $this->select . ' FROM ' . $this->from; |
| 747 | - if (! empty($this->join)){ |
|
| 747 | + if (!empty($this->join)) { |
|
| 748 | 748 | $query .= $this->join; |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | - if (! empty($this->where)){ |
|
| 751 | + if (!empty($this->where)) { |
|
| 752 | 752 | $query .= ' WHERE ' . $this->where; |
| 753 | 753 | } |
| 754 | 754 | |
| 755 | - if (! empty($this->groupBy)){ |
|
| 755 | + if (!empty($this->groupBy)) { |
|
| 756 | 756 | $query .= ' GROUP BY ' . $this->groupBy; |
| 757 | 757 | } |
| 758 | 758 | |
| 759 | - if (! empty($this->having)){ |
|
| 759 | + if (!empty($this->having)) { |
|
| 760 | 760 | $query .= ' HAVING ' . $this->having; |
| 761 | 761 | } |
| 762 | 762 | |
| 763 | - if (! empty($this->orderBy)){ |
|
| 763 | + if (!empty($this->orderBy)) { |
|
| 764 | 764 | $query .= ' ORDER BY ' . $this->orderBy; |
| 765 | 765 | } |
| 766 | 766 | |
| 767 | - if (! empty($this->limit)){ |
|
| 767 | + if (!empty($this->limit)) { |
|
| 768 | 768 | $query .= ' LIMIT ' . $this->limit; |
| 769 | 769 | } |
| 770 | 770 | $this->query = $query; |
@@ -777,7 +777,7 @@ discard block |
||
| 777 | 777 | * Return the PDO instance |
| 778 | 778 | * @return object |
| 779 | 779 | */ |
| 780 | - public function getPdo(){ |
|
| 780 | + public function getPdo() { |
|
| 781 | 781 | return $this->pdo; |
| 782 | 782 | } |
| 783 | 783 | |
@@ -786,7 +786,7 @@ discard block |
||
| 786 | 786 | * @param PDO $pdo the pdo object |
| 787 | 787 | * @return object DatabaseQueryBuilder |
| 788 | 788 | */ |
| 789 | - public function setPdo(PDO $pdo = null){ |
|
| 789 | + public function setPdo(PDO $pdo = null) { |
|
| 790 | 790 | $this->pdo = $pdo; |
| 791 | 791 | return $this; |
| 792 | 792 | } |
@@ -795,7 +795,7 @@ discard block |
||
| 795 | 795 | * Return the database table prefix |
| 796 | 796 | * @return string |
| 797 | 797 | */ |
| 798 | - public function getPrefix(){ |
|
| 798 | + public function getPrefix() { |
|
| 799 | 799 | return $this->prefix; |
| 800 | 800 | } |
| 801 | 801 | |
@@ -804,7 +804,7 @@ discard block |
||
| 804 | 804 | * @param string $prefix the new prefix |
| 805 | 805 | * @return object DatabaseQueryBuilder |
| 806 | 806 | */ |
| 807 | - public function setPrefix($prefix){ |
|
| 807 | + public function setPrefix($prefix) { |
|
| 808 | 808 | $this->prefix = $prefix; |
| 809 | 809 | return $this; |
| 810 | 810 | } |
@@ -813,7 +813,7 @@ discard block |
||
| 813 | 813 | * Return the database driver |
| 814 | 814 | * @return string |
| 815 | 815 | */ |
| 816 | - public function getDriver(){ |
|
| 816 | + public function getDriver() { |
|
| 817 | 817 | return $this->driver; |
| 818 | 818 | } |
| 819 | 819 | |
@@ -822,7 +822,7 @@ discard block |
||
| 822 | 822 | * @param string $driver the new driver |
| 823 | 823 | * @return object DatabaseQueryBuilder |
| 824 | 824 | */ |
| 825 | - public function setDriver($driver){ |
|
| 825 | + public function setDriver($driver) { |
|
| 826 | 826 | $this->driver = $driver; |
| 827 | 827 | return $this; |
| 828 | 828 | } |
@@ -831,7 +831,7 @@ discard block |
||
| 831 | 831 | * Reset the DatabaseQueryBuilder class attributs to the initial values before each query. |
| 832 | 832 | * @return object the current DatabaseQueryBuilder instance |
| 833 | 833 | */ |
| 834 | - public function reset(){ |
|
| 834 | + public function reset() { |
|
| 835 | 835 | $this->select = '*'; |
| 836 | 836 | $this->from = null; |
| 837 | 837 | $this->where = null; |
@@ -850,12 +850,12 @@ discard block |
||
| 850 | 850 | * |
| 851 | 851 | * @return string |
| 852 | 852 | */ |
| 853 | - protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true){ |
|
| 853 | + protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true) { |
|
| 854 | 854 | $x = explode('?', $field); |
| 855 | 855 | $w = ''; |
| 856 | - foreach($x as $k => $v){ |
|
| 857 | - if (!empty($v)){ |
|
| 858 | - if (! isset($op[$k])){ |
|
| 856 | + foreach ($x as $k => $v) { |
|
| 857 | + if (!empty($v)) { |
|
| 858 | + if (!isset($op[$k])) { |
|
| 859 | 859 | $op[$k] = ''; |
| 860 | 860 | } |
| 861 | 861 | $w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : ''); |
@@ -871,15 +871,15 @@ discard block |
||
| 871 | 871 | * |
| 872 | 872 | * @return string |
| 873 | 873 | */ |
| 874 | - protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){ |
|
| 874 | + protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true) { |
|
| 875 | 875 | $_where = array(); |
| 876 | - foreach ($where as $column => $data){ |
|
| 877 | - if (is_null($data)){ |
|
| 876 | + foreach ($where as $column => $data) { |
|
| 877 | + if (is_null($data)) { |
|
| 878 | 878 | $data = ''; |
| 879 | 879 | } |
| 880 | 880 | $_where[] = $type . $column . ' = ' . ($this->escape($data, $escape)); |
| 881 | 881 | } |
| 882 | - $where = implode(' '.$andOr.' ', $_where); |
|
| 882 | + $where = implode(' ' . $andOr . ' ', $_where); |
|
| 883 | 883 | return $where; |
| 884 | 884 | } |
| 885 | 885 | |
@@ -889,12 +889,12 @@ discard block |
||
| 889 | 889 | * |
| 890 | 890 | * @return string |
| 891 | 891 | */ |
| 892 | - protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){ |
|
| 892 | + protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true) { |
|
| 893 | 893 | $x = explode('?', $where); |
| 894 | 894 | $w = ''; |
| 895 | - foreach($x as $k => $v){ |
|
| 896 | - if (! empty($v)){ |
|
| 897 | - if (isset($op[$k]) && is_null($op[$k])){ |
|
| 895 | + foreach ($x as $k => $v) { |
|
| 896 | + if (!empty($v)) { |
|
| 897 | + if (isset($op[$k]) && is_null($op[$k])) { |
|
| 898 | 898 | $op[$k] = ''; |
| 899 | 899 | } |
| 900 | 900 | $w .= $type . $v . (isset($op[$k]) ? ($this->escape($op[$k], $escape)) : ''); |
@@ -909,15 +909,15 @@ discard block |
||
| 909 | 909 | * |
| 910 | 910 | * @return string |
| 911 | 911 | */ |
| 912 | - protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){ |
|
| 912 | + protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true) { |
|
| 913 | 913 | $w = ''; |
| 914 | - if (! in_array((string)$op, $this->operatorList)){ |
|
| 915 | - if (is_null($op)){ |
|
| 914 | + if (!in_array((string) $op, $this->operatorList)) { |
|
| 915 | + if (is_null($op)) { |
|
| 916 | 916 | $op = ''; |
| 917 | 917 | } |
| 918 | 918 | $w = $type . $where . ' = ' . ($this->escape($op, $escape)); |
| 919 | 919 | } else { |
| 920 | - if (is_null($val)){ |
|
| 920 | + if (is_null($val)) { |
|
| 921 | 921 | $val = ''; |
| 922 | 922 | } |
| 923 | 923 | $w = $type . $where . $op . ($this->escape($val, $escape)); |
@@ -930,14 +930,14 @@ discard block |
||
| 930 | 930 | * @param string $whereStr the WHERE clause string |
| 931 | 931 | * @param string $andOr the separator type used 'AND', 'OR', etc. |
| 932 | 932 | */ |
| 933 | - protected function setWhereStr($whereStr, $andOr = 'AND'){ |
|
| 934 | - if (empty($this->where)){ |
|
| 933 | + protected function setWhereStr($whereStr, $andOr = 'AND') { |
|
| 934 | + if (empty($this->where)) { |
|
| 935 | 935 | $this->where = $whereStr; |
| 936 | 936 | } else { |
| 937 | - if (substr(trim($this->where), -1) == '('){ |
|
| 937 | + if (substr(trim($this->where), -1) == '(') { |
|
| 938 | 938 | $this->where = $this->where . ' ' . $whereStr; |
| 939 | 939 | } else { |
| 940 | - $this->where = $this->where . ' '.$andOr.' ' . $whereStr; |
|
| 940 | + $this->where = $this->where . ' ' . $andOr . ' ' . $whereStr; |
|
| 941 | 941 | } |
| 942 | 942 | } |
| 943 | 943 | } |
@@ -953,7 +953,7 @@ discard block |
||
| 953 | 953 | * @see DatabaseQueryBuilder::avg |
| 954 | 954 | * @return object |
| 955 | 955 | */ |
| 956 | - protected function select_min_max_sum_count_avg($clause, $field, $name = null){ |
|
| 956 | + protected function select_min_max_sum_count_avg($clause, $field, $name = null) { |
|
| 957 | 957 | $clause = strtoupper($clause); |
| 958 | 958 | $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
| 959 | 959 | $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
@@ -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 |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * Class constructor |
| 49 | 49 | * @param object $logger the Log instance to use if is null will create one |
| 50 | 50 | */ |
| 51 | - public function __construct(Log $logger = null){ |
|
| 51 | + public function __construct(Log $logger = null) { |
|
| 52 | 52 | //setting the Log instance |
| 53 | 53 | $this->setLoggerFromParamOrCreateNewInstance($logger); |
| 54 | 54 | |
@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | //Load the resources loaded during the application bootstrap |
| 59 | 59 | $this->logger->debug('Adding the loaded classes to the super instance'); |
| 60 | - foreach (class_loaded() as $var => $class){ |
|
| 61 | - $this->$var =& class_loader($class); |
|
| 60 | + foreach (class_loaded() as $var => $class) { |
|
| 61 | + $this->$var = & class_loader($class); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | //set module using the router |
@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | /** |
| 91 | 91 | * This method is used to set the module name |
| 92 | 92 | */ |
| 93 | - protected function setModuleNameFromRouter(){ |
|
| 93 | + protected function setModuleNameFromRouter() { |
|
| 94 | 94 | //set the module using the router instance |
| 95 | - if(isset($this->router) && $this->router->getModule()){ |
|
| 95 | + if (isset($this->router) && $this->router->getModule()) { |
|
| 96 | 96 | $this->moduleName = $this->router->getModule(); |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -101,13 +101,13 @@ discard block |
||
| 101 | 101 | * Set the cache using the argument otherwise will use the configuration |
| 102 | 102 | * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured |
| 103 | 103 | */ |
| 104 | - protected function setCacheFromParamOrConfig(CacheInterface $cache = null){ |
|
| 104 | + protected function setCacheFromParamOrConfig(CacheInterface $cache = null) { |
|
| 105 | 105 | $this->logger->debug('Setting the cache handler instance'); |
| 106 | 106 | //set cache handler instance |
| 107 | - if(get_config('cache_enable', false)){ |
|
| 108 | - if ($cache !== null){ |
|
| 107 | + if (get_config('cache_enable', false)) { |
|
| 108 | + if ($cache !== null) { |
|
| 109 | 109 | $this->cache = $cache; |
| 110 | - } else if (isset($this->{strtolower(get_config('cache_handler'))})){ |
|
| 110 | + } else if (isset($this->{strtolower(get_config('cache_handler'))})) { |
|
| 111 | 111 | $this->cache = $this->{strtolower(get_config('cache_handler'))}; |
| 112 | 112 | unset($this->{strtolower(get_config('cache_handler'))}); |
| 113 | 113 | } |
@@ -118,12 +118,12 @@ discard block |
||
| 118 | 118 | * Set the Log instance using argument or create new instance |
| 119 | 119 | * @param object $logger the Log instance if not null |
| 120 | 120 | */ |
| 121 | - protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
|
| 122 | - if($logger !== null){ |
|
| 121 | + protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) { |
|
| 122 | + if ($logger !== null) { |
|
| 123 | 123 | $this->logger = $logger; |
| 124 | 124 | } |
| 125 | - else{ |
|
| 126 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 125 | + else { |
|
| 126 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 127 | 127 | $this->logger->setLogger('MainController'); |
| 128 | 128 | } |
| 129 | 129 | } |
@@ -132,15 +132,15 @@ discard block |
||
| 132 | 132 | * This method is used to load the required resources for framework to work |
| 133 | 133 | * @return void |
| 134 | 134 | */ |
| 135 | - private function loadRequiredResources(){ |
|
| 135 | + private function loadRequiredResources() { |
|
| 136 | 136 | $this->logger->debug('Loading the required classes into super instance'); |
| 137 | - $this->eventdispatcher =& class_loader('EventDispatcher', 'classes'); |
|
| 138 | - $this->loader =& class_loader('Loader', 'classes'); |
|
| 139 | - $this->lang =& class_loader('Lang', 'classes'); |
|
| 140 | - $this->request =& class_loader('Request', 'classes'); |
|
| 137 | + $this->eventdispatcher = & class_loader('EventDispatcher', 'classes'); |
|
| 138 | + $this->loader = & class_loader('Loader', 'classes'); |
|
| 139 | + $this->lang = & class_loader('Lang', 'classes'); |
|
| 140 | + $this->request = & class_loader('Request', 'classes'); |
|
| 141 | 141 | //dispatch the request instance created event |
| 142 | 142 | $this->eventdispatcher->dispatch('REQUEST_CREATED'); |
| 143 | - $this->response =& class_loader('Response', 'classes', 'classes'); |
|
| 143 | + $this->response = & class_loader('Response', 'classes', 'classes'); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | } |
@@ -23,98 +23,98 @@ 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 number of rows returned by the last query |
| 42 | 42 | * @var int |
| 43 | 43 | */ |
| 44 | - private $numRows = 0; |
|
| 44 | + private $numRows = 0; |
|
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * The last insert id for the primary key column that have auto increment or sequence |
| 48 | 48 | * @var mixed |
| 49 | 49 | */ |
| 50 | - private $insertId = null; |
|
| 50 | + private $insertId = null; |
|
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * The full SQL query statment after build for each command |
| 54 | 54 | * @var string |
| 55 | 55 | */ |
| 56 | - private $query = null; |
|
| 56 | + private $query = null; |
|
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * The result returned for the last query |
| 60 | 60 | * @var mixed |
| 61 | 61 | */ |
| 62 | - private $result = array(); |
|
| 62 | + private $result = array(); |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * The cache default time to live in second. 0 means no need to use the cache feature |
| 66 | 66 | * @var int |
| 67 | 67 | */ |
| 68 | - private $cacheTtl = 0; |
|
| 68 | + private $cacheTtl = 0; |
|
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * The cache current time to live. 0 means no need to use the cache feature |
| 72 | 72 | * @var int |
| 73 | 73 | */ |
| 74 | - private $temporaryCacheTtl = 0; |
|
| 74 | + private $temporaryCacheTtl = 0; |
|
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | 77 | * The number of executed query for the current request |
| 78 | 78 | * @var int |
| 79 | 79 | */ |
| 80 | - private $queryCount = 0; |
|
| 80 | + private $queryCount = 0; |
|
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * The default data to be used in the statments query INSERT, UPDATE |
| 84 | 84 | * @var array |
| 85 | 85 | */ |
| 86 | - private $data = array(); |
|
| 86 | + private $data = array(); |
|
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * The database configuration |
| 90 | 90 | * @var array |
| 91 | 91 | */ |
| 92 | - private $config = array(); |
|
| 92 | + private $config = array(); |
|
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | 95 | * The logger instance |
| 96 | 96 | * @var object |
| 97 | 97 | */ |
| 98 | - private $logger = null; |
|
| 98 | + private $logger = null; |
|
| 99 | 99 | |
| 100 | 100 | /** |
| 101 | 101 | * The cache instance |
| 102 | 102 | * @var object |
| 103 | 103 | */ |
| 104 | - private $cacheInstance = null; |
|
| 104 | + private $cacheInstance = null; |
|
| 105 | 105 | |
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | 108 | * The DatabaseQueryBuilder instance |
| 109 | 109 | * @var object |
| 110 | 110 | */ |
| 111 | - private $queryBuilder = null; |
|
| 111 | + private $queryBuilder = null; |
|
| 112 | 112 | |
| 113 | 113 | /** |
| 114 | 114 | * The DatabaseQueryRunner instance |
| 115 | 115 | * @var object |
| 116 | 116 | */ |
| 117 | - private $queryRunner = null; |
|
| 117 | + private $queryRunner = null; |
|
| 118 | 118 | |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @param array $overwriteConfig the config to overwrite with the config set in database.php |
| 123 | 123 | * @param boolean $autoConnect whether to connect to database automatically |
| 124 | 124 | */ |
| 125 | - public function __construct($overwriteConfig = array(), $autoConnect = true){ |
|
| 125 | + public function __construct($overwriteConfig = array(), $autoConnect = true) { |
|
| 126 | 126 | //Set Log instance to use |
| 127 | 127 | $this->setLoggerFromParamOrCreate(null); |
| 128 | 128 | |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | * This is used to connect to database |
| 144 | 144 | * @return bool |
| 145 | 145 | */ |
| 146 | - public function connect(){ |
|
| 146 | + public function connect() { |
|
| 147 | 147 | $config = $this->getDatabaseConfiguration(); |
| 148 | - if (! empty($config)){ |
|
| 149 | - try{ |
|
| 148 | + if (!empty($config)) { |
|
| 149 | + try { |
|
| 150 | 150 | $this->pdo = new PDO($this->getDsnValueFromConfig(), $config['username'], $config['password']); |
| 151 | 151 | $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'"); |
| 152 | 152 | $this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'"); |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | |
| 158 | 158 | return is_object($this->pdo); |
| 159 | 159 | } |
| 160 | - catch (PDOException $e){ |
|
| 160 | + catch (PDOException $e) { |
|
| 161 | 161 | $this->logger->fatal($e->getMessage()); |
| 162 | 162 | show_error('Cannot connect to Database.'); |
| 163 | 163 | return false; |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | * Return the number of rows returned by the current query |
| 172 | 172 | * @return int |
| 173 | 173 | */ |
| 174 | - public function numRows(){ |
|
| 174 | + public function numRows() { |
|
| 175 | 175 | return $this->numRows; |
| 176 | 176 | } |
| 177 | 177 | |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | * Return the last insert id value |
| 180 | 180 | * @return mixed |
| 181 | 181 | */ |
| 182 | - public function insertId(){ |
|
| 182 | + public function insertId() { |
|
| 183 | 183 | return $this->insertId; |
| 184 | 184 | } |
| 185 | 185 | |
@@ -190,10 +190,10 @@ discard block |
||
| 190 | 190 | * If is string will determine the result type "array" or "object" |
| 191 | 191 | * @return mixed the query SQL string or the record result |
| 192 | 192 | */ |
| 193 | - public function get($returnSQLQueryOrResultType = false){ |
|
| 193 | + public function get($returnSQLQueryOrResultType = false) { |
|
| 194 | 194 | $this->queryBuilder->limit(1); |
| 195 | 195 | $query = $this->getAll(true); |
| 196 | - if ($returnSQLQueryOrResultType === true){ |
|
| 196 | + if ($returnSQLQueryOrResultType === true) { |
|
| 197 | 197 | return $query; |
| 198 | 198 | } else { |
| 199 | 199 | return $this->query($query, false, $returnSQLQueryOrResultType == 'array'); |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | * If is string will determine the result type "array" or "object" |
| 207 | 207 | * @return mixed the query SQL string or the record result |
| 208 | 208 | */ |
| 209 | - public function getAll($returnSQLQueryOrResultType = false){ |
|
| 209 | + public function getAll($returnSQLQueryOrResultType = false) { |
|
| 210 | 210 | $query = $this->queryBuilder->getQuery(); |
| 211 | - if ($returnSQLQueryOrResultType === true){ |
|
| 211 | + if ($returnSQLQueryOrResultType === true) { |
|
| 212 | 212 | return $query; |
| 213 | 213 | } |
| 214 | 214 | return $this->query($query, true, $returnSQLQueryOrResultType == 'array'); |
@@ -220,18 +220,18 @@ discard block |
||
| 220 | 220 | * @param boolean $escape whether to escape or not the values |
| 221 | 221 | * @return mixed the insert id of the new record or null |
| 222 | 222 | */ |
| 223 | - public function insert($data = array(), $escape = true){ |
|
| 224 | - if (empty($data) && ! empty($this->data)){ |
|
| 223 | + public function insert($data = array(), $escape = true) { |
|
| 224 | + if (empty($data) && !empty($this->data)) { |
|
| 225 | 225 | //as when using $this->setData() may be the data already escaped |
| 226 | 226 | $escape = false; |
| 227 | 227 | $data = $this->data; |
| 228 | 228 | } |
| 229 | 229 | $query = $this->queryBuilder->insert($data, $escape)->getQuery(); |
| 230 | 230 | $result = $this->query($query); |
| 231 | - if ($result){ |
|
| 231 | + if ($result) { |
|
| 232 | 232 | $this->insertId = $this->pdo->lastInsertId(); |
| 233 | 233 | //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned |
| 234 | - return ! ($this->insertId) ? true : $this->insertId; |
|
| 234 | + return !($this->insertId) ? true : $this->insertId; |
|
| 235 | 235 | } |
| 236 | 236 | return false; |
| 237 | 237 | } |
@@ -242,8 +242,8 @@ discard block |
||
| 242 | 242 | * @param boolean $escape whether to escape or not the values |
| 243 | 243 | * @return mixed the update status |
| 244 | 244 | */ |
| 245 | - public function update($data = array(), $escape = true){ |
|
| 246 | - if (empty($data) && ! empty($this->data)){ |
|
| 245 | + public function update($data = array(), $escape = true) { |
|
| 246 | + if (empty($data) && !empty($this->data)) { |
|
| 247 | 247 | //as when using $this->setData() may be the data already escaped |
| 248 | 248 | $escape = false; |
| 249 | 249 | $data = $this->data; |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | * Delete the record in database |
| 257 | 257 | * @return mixed the delete status |
| 258 | 258 | */ |
| 259 | - public function delete(){ |
|
| 259 | + public function delete() { |
|
| 260 | 260 | $query = $this->queryBuilder->delete()->getQuery(); |
| 261 | 261 | return $this->query($query); |
| 262 | 262 | } |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | * @param integer $ttl the cache time to live in second |
| 267 | 267 | * @return object the current Database instance |
| 268 | 268 | */ |
| 269 | - public function setCache($ttl = 0){ |
|
| 269 | + public function setCache($ttl = 0) { |
|
| 270 | 270 | $this->cacheTtl = $ttl; |
| 271 | 271 | $this->temporaryCacheTtl = $ttl; |
| 272 | 272 | return $this; |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | * @param integer $ttl the cache time to live in second |
| 278 | 278 | * @return object the current Database instance |
| 279 | 279 | */ |
| 280 | - public function cached($ttl = 0){ |
|
| 280 | + public function cached($ttl = 0) { |
|
| 281 | 281 | $this->temporaryCacheTtl = $ttl; |
| 282 | 282 | return $this; |
| 283 | 283 | } |
@@ -289,9 +289,9 @@ discard block |
||
| 289 | 289 | * @return mixed the data after escaped or the same data if no |
| 290 | 290 | * need escaped |
| 291 | 291 | */ |
| 292 | - public function escape($data, $escaped = true){ |
|
| 292 | + public function escape($data, $escaped = true) { |
|
| 293 | 293 | $data = trim($data); |
| 294 | - if($escaped){ |
|
| 294 | + if ($escaped) { |
|
| 295 | 295 | return $this->pdo->quote($data); |
| 296 | 296 | } |
| 297 | 297 | return $data; |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * Return the number query executed count for the current request |
| 302 | 302 | * @return int |
| 303 | 303 | */ |
| 304 | - public function queryCount(){ |
|
| 304 | + public function queryCount() { |
|
| 305 | 305 | return $this->queryCount; |
| 306 | 306 | } |
| 307 | 307 | |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | * Return the current query SQL string |
| 310 | 310 | * @return string |
| 311 | 311 | */ |
| 312 | - public function getQuery(){ |
|
| 312 | + public function getQuery() { |
|
| 313 | 313 | return $this->query; |
| 314 | 314 | } |
| 315 | 315 | |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | * Return the application database name |
| 318 | 318 | * @return string |
| 319 | 319 | */ |
| 320 | - public function getDatabaseName(){ |
|
| 320 | + public function getDatabaseName() { |
|
| 321 | 321 | return $this->databaseName; |
| 322 | 322 | } |
| 323 | 323 | |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | * Return the PDO instance |
| 326 | 326 | * @return object |
| 327 | 327 | */ |
| 328 | - public function getPdo(){ |
|
| 328 | + public function getPdo() { |
|
| 329 | 329 | return $this->pdo; |
| 330 | 330 | } |
| 331 | 331 | |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | * @param object $pdo the pdo object |
| 335 | 335 | * @return object Database |
| 336 | 336 | */ |
| 337 | - public function setPdo(PDO $pdo){ |
|
| 337 | + public function setPdo(PDO $pdo) { |
|
| 338 | 338 | $this->pdo = $pdo; |
| 339 | 339 | return $this; |
| 340 | 340 | } |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | * Return the Log instance |
| 345 | 345 | * @return Log |
| 346 | 346 | */ |
| 347 | - public function getLogger(){ |
|
| 347 | + public function getLogger() { |
|
| 348 | 348 | return $this->logger; |
| 349 | 349 | } |
| 350 | 350 | |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | * @param Log $logger the log object |
| 354 | 354 | * @return object Database |
| 355 | 355 | */ |
| 356 | - public function setLogger($logger){ |
|
| 356 | + public function setLogger($logger) { |
|
| 357 | 357 | $this->logger = $logger; |
| 358 | 358 | return $this; |
| 359 | 359 | } |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | * Return the cache instance |
| 363 | 363 | * @return CacheInterface |
| 364 | 364 | */ |
| 365 | - public function getCacheInstance(){ |
|
| 365 | + public function getCacheInstance() { |
|
| 366 | 366 | return $this->cacheInstance; |
| 367 | 367 | } |
| 368 | 368 | |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | * @param CacheInterface $cache the cache object |
| 372 | 372 | * @return object Database |
| 373 | 373 | */ |
| 374 | - public function setCacheInstance($cache){ |
|
| 374 | + public function setCacheInstance($cache) { |
|
| 375 | 375 | $this->cacheInstance = $cache; |
| 376 | 376 | return $this; |
| 377 | 377 | } |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | * Return the DatabaseQueryBuilder instance |
| 382 | 382 | * @return object DatabaseQueryBuilder |
| 383 | 383 | */ |
| 384 | - public function getQueryBuilder(){ |
|
| 384 | + public function getQueryBuilder() { |
|
| 385 | 385 | return $this->queryBuilder; |
| 386 | 386 | } |
| 387 | 387 | |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | * Set the DatabaseQueryBuilder instance |
| 390 | 390 | * @param object DatabaseQueryBuilder $queryBuilder the DatabaseQueryBuilder object |
| 391 | 391 | */ |
| 392 | - public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder){ |
|
| 392 | + public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder) { |
|
| 393 | 393 | $this->queryBuilder = $queryBuilder; |
| 394 | 394 | return $this; |
| 395 | 395 | } |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | * Return the DatabaseQueryRunner instance |
| 399 | 399 | * @return object DatabaseQueryRunner |
| 400 | 400 | */ |
| 401 | - public function getQueryRunner(){ |
|
| 401 | + public function getQueryRunner() { |
|
| 402 | 402 | return $this->queryRunner; |
| 403 | 403 | } |
| 404 | 404 | |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | * Set the DatabaseQueryRunner instance |
| 407 | 407 | * @param object DatabaseQueryRunner $queryRunner the DatabaseQueryRunner object |
| 408 | 408 | */ |
| 409 | - public function setQueryRunner(DatabaseQueryRunner $queryRunner){ |
|
| 409 | + public function setQueryRunner(DatabaseQueryRunner $queryRunner) { |
|
| 410 | 410 | $this->queryRunner = $queryRunner; |
| 411 | 411 | return $this; |
| 412 | 412 | } |
@@ -415,7 +415,7 @@ discard block |
||
| 415 | 415 | * Return the data to be used for insert, update, etc. |
| 416 | 416 | * @return array |
| 417 | 417 | */ |
| 418 | - public function getData(){ |
|
| 418 | + public function getData() { |
|
| 419 | 419 | return $this->data; |
| 420 | 420 | } |
| 421 | 421 | |
@@ -426,9 +426,9 @@ discard block |
||
| 426 | 426 | * @param boolean $escape whether to escape or not the $value |
| 427 | 427 | * @return object the current Database instance |
| 428 | 428 | */ |
| 429 | - public function setData($key, $value = null, $escape = true){ |
|
| 430 | - if (is_array($key)){ |
|
| 431 | - foreach($key as $k => $v){ |
|
| 429 | + public function setData($key, $value = null, $escape = true) { |
|
| 430 | + if (is_array($key)) { |
|
| 431 | + foreach ($key as $k => $v) { |
|
| 432 | 432 | $this->setData($k, $v, $escape); |
| 433 | 433 | } |
| 434 | 434 | } else { |
@@ -444,7 +444,7 @@ discard block |
||
| 444 | 444 | * @param boolean $returnAsArray return the result as array or not |
| 445 | 445 | * @return mixed the query result |
| 446 | 446 | */ |
| 447 | - public function query($query, $returnAsList = true, $returnAsArray = false){ |
|
| 447 | + public function query($query, $returnAsList = true, $returnAsArray = false) { |
|
| 448 | 448 | $this->reset(); |
| 449 | 449 | $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query)); |
| 450 | 450 | //If is the SELECT query |
@@ -465,12 +465,12 @@ discard block |
||
| 465 | 465 | //if can use cache feature for this query |
| 466 | 466 | $dbCacheStatus = $cacheEnable && $cacheExpire > 0; |
| 467 | 467 | |
| 468 | - if ($dbCacheStatus && $isSqlSELECTQuery){ |
|
| 468 | + if ($dbCacheStatus && $isSqlSELECTQuery) { |
|
| 469 | 469 | $this->logger->info('The cache is enabled for this query, try to get result from cache'); |
| 470 | 470 | $cacheContent = $this->getCacheContentForQuery($query, $returnAsList, $returnAsArray); |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | - if (!$cacheContent){ |
|
| 473 | + if (!$cacheContent) { |
|
| 474 | 474 | //count the number of query execution to server |
| 475 | 475 | $this->queryCount++; |
| 476 | 476 | |
@@ -479,19 +479,19 @@ discard block |
||
| 479 | 479 | ->setReturnAsArray($returnAsArray) |
| 480 | 480 | ->execute(); |
| 481 | 481 | |
| 482 | - if (!is_object($queryResult)){ |
|
| 482 | + if (!is_object($queryResult)) { |
|
| 483 | 483 | $this->result = false; |
| 484 | 484 | $this->numRows = 0; |
| 485 | 485 | return $this->result; |
| 486 | 486 | } |
| 487 | 487 | $this->result = $queryResult->getResult(); |
| 488 | 488 | $this->numRows = $queryResult->getNumRows(); |
| 489 | - if ($isSqlSELECTQuery && $dbCacheStatus){ |
|
| 489 | + if ($isSqlSELECTQuery && $dbCacheStatus) { |
|
| 490 | 490 | $key = $this->getCacheKeyForQuery($this->query, $returnAsList, $returnAsArray); |
| 491 | 491 | $this->setCacheContentForQuery($this->query, $key, $this->result, $cacheExpire); |
| 492 | 492 | } |
| 493 | - } else if ($isSqlSELECTQuery){ |
|
| 494 | - $this->logger->info('The result for query [' .$this->query. '] already cached use it'); |
|
| 493 | + } else if ($isSqlSELECTQuery) { |
|
| 494 | + $this->logger->info('The result for query [' . $this->query . '] already cached use it'); |
|
| 495 | 495 | $this->result = $cacheContent; |
| 496 | 496 | $this->numRows = count($this->result); |
| 497 | 497 | } |
@@ -505,9 +505,9 @@ discard block |
||
| 505 | 505 | * @param boolean $autoConnect whether to connect to database after set the configuration |
| 506 | 506 | * @return object Database |
| 507 | 507 | */ |
| 508 | - public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true, $autoConnect = false){ |
|
| 508 | + public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true, $autoConnect = false) { |
|
| 509 | 509 | $db = array(); |
| 510 | - if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')){ |
|
| 510 | + if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')) { |
|
| 511 | 511 | //here don't use require_once because somewhere user can create database instance directly |
| 512 | 512 | require CONFIG_PATH . 'database.php'; |
| 513 | 513 | } |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | //determine the port using the hostname like localhost:3307 |
| 523 | 523 | //hostname will be "localhost", and port "3307" |
| 524 | 524 | $p = explode(':', $config['hostname']); |
| 525 | - if (count($p) >= 2){ |
|
| 525 | + if (count($p) >= 2) { |
|
| 526 | 526 | $config['hostname'] = $p[0]; |
| 527 | 527 | $config['port'] = $p[1]; |
| 528 | 528 | } |
@@ -536,7 +536,7 @@ discard block |
||
| 536 | 536 | array('password' => string_hidden($this->config['password'])) |
| 537 | 537 | )) |
| 538 | 538 | ); |
| 539 | - if($autoConnect){ |
|
| 539 | + if ($autoConnect) { |
|
| 540 | 540 | //Now connect to the database |
| 541 | 541 | $this->connect(); |
| 542 | 542 | } |
@@ -547,14 +547,14 @@ discard block |
||
| 547 | 547 | * Return the database configuration |
| 548 | 548 | * @return array |
| 549 | 549 | */ |
| 550 | - public function getDatabaseConfiguration(){ |
|
| 550 | + public function getDatabaseConfiguration() { |
|
| 551 | 551 | return $this->config; |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | /** |
| 555 | 555 | * Close the connexion |
| 556 | 556 | */ |
| 557 | - public function close(){ |
|
| 557 | + public function close() { |
|
| 558 | 558 | $this->pdo = null; |
| 559 | 559 | } |
| 560 | 560 | |
@@ -562,7 +562,7 @@ discard block |
||
| 562 | 562 | * Return the database default configuration |
| 563 | 563 | * @return array |
| 564 | 564 | */ |
| 565 | - protected function getDatabaseDefaultConfiguration(){ |
|
| 565 | + protected function getDatabaseDefaultConfiguration() { |
|
| 566 | 566 | return array( |
| 567 | 567 | 'driver' => '', |
| 568 | 568 | 'username' => '', |
@@ -580,16 +580,16 @@ discard block |
||
| 580 | 580 | * Update the DatabaseQueryBuilder and DatabaseQueryRunner properties |
| 581 | 581 | * @return void |
| 582 | 582 | */ |
| 583 | - protected function updateQueryBuilderAndRunnerProperties(){ |
|
| 583 | + protected function updateQueryBuilderAndRunnerProperties() { |
|
| 584 | 584 | //update queryBuilder with some properties needed |
| 585 | - if (is_object($this->queryBuilder)){ |
|
| 585 | + if (is_object($this->queryBuilder)) { |
|
| 586 | 586 | $this->queryBuilder->setDriver($this->config['driver']) |
| 587 | 587 | ->setPrefix($this->config['prefix']) |
| 588 | 588 | ->setPdo($this->pdo); |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | //update queryRunner with some properties needed |
| 592 | - if (is_object($this->queryRunner)){ |
|
| 592 | + if (is_object($this->queryRunner)) { |
|
| 593 | 593 | $this->queryRunner->setDriver($this->config['driver']) |
| 594 | 594 | ->setPdo($this->pdo); |
| 595 | 595 | } |
@@ -600,10 +600,10 @@ discard block |
||
| 600 | 600 | * This method is used to get the PDO DSN string using the configured driver |
| 601 | 601 | * @return string|null the DSN string or null if can not find it |
| 602 | 602 | */ |
| 603 | - protected function getDsnValueFromConfig(){ |
|
| 603 | + protected function getDsnValueFromConfig() { |
|
| 604 | 604 | $dsn = null; |
| 605 | 605 | $config = $this->getDatabaseConfiguration(); |
| 606 | - if (! empty($config)){ |
|
| 606 | + if (!empty($config)) { |
|
| 607 | 607 | $driver = $config['driver']; |
| 608 | 608 | $driverDsnMap = array( |
| 609 | 609 | 'mysql' => $this->getDsnValueForDriver('mysql'), |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | 'sqlite' => $this->getDsnValueForDriver('sqlite'), |
| 612 | 612 | 'oracle' => $this->getDsnValueForDriver('oracle') |
| 613 | 613 | ); |
| 614 | - if (isset($driverDsnMap[$driver])){ |
|
| 614 | + if (isset($driverDsnMap[$driver])) { |
|
| 615 | 615 | $dsn = $driverDsnMap[$driver]; |
| 616 | 616 | } |
| 617 | 617 | } |
@@ -623,17 +623,17 @@ discard block |
||
| 623 | 623 | * @param string $driver the driver name |
| 624 | 624 | * @return string|null the dsn name |
| 625 | 625 | */ |
| 626 | - protected function getDsnValueForDriver($driver){ |
|
| 626 | + protected function getDsnValueForDriver($driver) { |
|
| 627 | 627 | $dsn = ''; |
| 628 | 628 | $config = $this->getDatabaseConfiguration(); |
| 629 | - if (empty($config)){ |
|
| 629 | + if (empty($config)) { |
|
| 630 | 630 | return null; |
| 631 | 631 | } |
| 632 | 632 | switch ($driver) { |
| 633 | 633 | case 'mysql': |
| 634 | 634 | case 'pgsql': |
| 635 | 635 | $port = ''; |
| 636 | - if (! empty($config['port'])) { |
|
| 636 | + if (!empty($config['port'])) { |
|
| 637 | 637 | $port = 'port=' . $config['port'] . ';'; |
| 638 | 638 | } |
| 639 | 639 | $dsn = $driver . ':host=' . $config['hostname'] . ';' . $port . 'dbname=' . $config['database']; |
@@ -643,10 +643,10 @@ discard block |
||
| 643 | 643 | break; |
| 644 | 644 | case 'oracle': |
| 645 | 645 | $port = ''; |
| 646 | - if (! empty($config['port'])) { |
|
| 646 | + if (!empty($config['port'])) { |
|
| 647 | 647 | $port = ':' . $config['port']; |
| 648 | 648 | } |
| 649 | - $dsn = 'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database']; |
|
| 649 | + $dsn = 'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database']; |
|
| 650 | 650 | break; |
| 651 | 651 | } |
| 652 | 652 | return $dsn; |
@@ -658,9 +658,9 @@ discard block |
||
| 658 | 658 | * |
| 659 | 659 | * @return mixed |
| 660 | 660 | */ |
| 661 | - protected function getCacheContentForQuery($query, $returnAsList, $returnAsArray){ |
|
| 661 | + protected function getCacheContentForQuery($query, $returnAsList, $returnAsArray) { |
|
| 662 | 662 | $cacheKey = $this->getCacheKeyForQuery($query, $returnAsList, $returnAsArray); |
| 663 | - if (! is_object($this->cacheInstance)){ |
|
| 663 | + if (!is_object($this->cacheInstance)) { |
|
| 664 | 664 | //can not call method with reference in argument |
| 665 | 665 | //like $this->setCacheInstance(& get_instance()->cache); |
| 666 | 666 | //use temporary variable |
@@ -677,9 +677,9 @@ discard block |
||
| 677 | 677 | * @param mixed $result the query result to save |
| 678 | 678 | * @param int $expire the cache TTL |
| 679 | 679 | */ |
| 680 | - protected function setCacheContentForQuery($query, $key, $result, $expire){ |
|
| 681 | - $this->logger->info('Save the result for query [' .$query. '] into cache for future use'); |
|
| 682 | - if (! is_object($this->cacheInstance)){ |
|
| 680 | + protected function setCacheContentForQuery($query, $key, $result, $expire) { |
|
| 681 | + $this->logger->info('Save the result for query [' . $query . '] into cache for future use'); |
|
| 682 | + if (!is_object($this->cacheInstance)) { |
|
| 683 | 683 | //can not call method with reference in argument |
| 684 | 684 | //like $this->setCacheInstance(& get_instance()->cache); |
| 685 | 685 | //use temporary variable |
@@ -696,7 +696,7 @@ discard block |
||
| 696 | 696 | * |
| 697 | 697 | * @return string |
| 698 | 698 | */ |
| 699 | - protected function getCacheKeyForQuery($query, $returnAsList, $returnAsArray){ |
|
| 699 | + protected function getCacheKeyForQuery($query, $returnAsList, $returnAsArray) { |
|
| 700 | 700 | return md5($query . $returnAsList . $returnAsArray); |
| 701 | 701 | } |
| 702 | 702 | |
@@ -710,12 +710,12 @@ discard block |
||
| 710 | 710 | * |
| 711 | 711 | * @return object this current instance |
| 712 | 712 | */ |
| 713 | - protected function setDependencyInstanceFromParamOrCreate($name, $instance = null, $loadClassName = null, $loadClassePath = 'classes'){ |
|
| 714 | - if ($instance !== null){ |
|
| 713 | + protected function setDependencyInstanceFromParamOrCreate($name, $instance = null, $loadClassName = null, $loadClassePath = 'classes') { |
|
| 714 | + if ($instance !== null) { |
|
| 715 | 715 | $this->{$name} = $instance; |
| 716 | 716 | return $this; |
| 717 | 717 | } |
| 718 | - $this->{$name} =& class_loader($loadClassName, $loadClassePath); |
|
| 718 | + $this->{$name} = & class_loader($loadClassName, $loadClassePath); |
|
| 719 | 719 | return $this; |
| 720 | 720 | } |
| 721 | 721 | |
@@ -725,9 +725,9 @@ discard block |
||
| 725 | 725 | * |
| 726 | 726 | * @return object this current instance |
| 727 | 727 | */ |
| 728 | - protected function setLoggerFromParamOrCreate(Log $logger = null){ |
|
| 728 | + protected function setLoggerFromParamOrCreate(Log $logger = null) { |
|
| 729 | 729 | $this->setDependencyInstanceFromParamOrCreate('logger', $logger, 'Log', 'classes'); |
| 730 | - if ($logger === null){ |
|
| 730 | + if ($logger === null) { |
|
| 731 | 731 | $this->logger->setLogger('Library::Database'); |
| 732 | 732 | } |
| 733 | 733 | return $this; |
@@ -736,7 +736,7 @@ discard block |
||
| 736 | 736 | /** |
| 737 | 737 | * Reset the database class attributs to the initail values before each query. |
| 738 | 738 | */ |
| 739 | - private function reset(){ |
|
| 739 | + private function reset() { |
|
| 740 | 740 | //query builder reset |
| 741 | 741 | $this->queryBuilder->reset(); |
| 742 | 742 | $this->numRows = 0; |
@@ -749,7 +749,7 @@ discard block |
||
| 749 | 749 | /** |
| 750 | 750 | * The class destructor |
| 751 | 751 | */ |
| 752 | - public function __destruct(){ |
|
| 752 | + public function __destruct() { |
|
| 753 | 753 | $this->pdo = null; |
| 754 | 754 | } |
| 755 | 755 | |
@@ -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 Pagination{ |
|
| 27 | + class Pagination { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The list of loaded config |
@@ -42,14 +42,14 @@ discard block |
||
| 42 | 42 | * Create an instance of pagination |
| 43 | 43 | * @param array $overwriteConfig the list of configuration to overwrite the defined configuration in config_pagination.php |
| 44 | 44 | */ |
| 45 | - public function __construct(array $overwriteConfig = array()){ |
|
| 46 | - if (file_exists(CONFIG_PATH . 'config_pagination.php')){ |
|
| 45 | + public function __construct(array $overwriteConfig = array()) { |
|
| 46 | + if (file_exists(CONFIG_PATH . 'config_pagination.php')) { |
|
| 47 | 47 | $config = array(); |
| 48 | 48 | require_once CONFIG_PATH . 'config_pagination.php'; |
| 49 | - if (empty($config) || ! is_array($config)){ |
|
| 49 | + if (empty($config) || !is_array($config)) { |
|
| 50 | 50 | show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php'); |
| 51 | 51 | } |
| 52 | - else{ |
|
| 52 | + else { |
|
| 53 | 53 | $config = array_merge($config, $overwriteConfig); |
| 54 | 54 | $this->config = $config; |
| 55 | 55 | //put it gobally |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | unset($config); |
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | - else{ |
|
| 60 | + else { |
|
| 61 | 61 | show_error('Unable to find the pagination configuration file'); |
| 62 | 62 | } |
| 63 | 63 | } |
@@ -68,8 +68,8 @@ discard block |
||
| 68 | 68 | * config_pagination.php |
| 69 | 69 | * @param array $config the configuration to overwrite |
| 70 | 70 | */ |
| 71 | - public function setConfig(array $config = array()){ |
|
| 72 | - if (! empty($config)){ |
|
| 71 | + public function setConfig(array $config = array()) { |
|
| 72 | + if (!empty($config)) { |
|
| 73 | 73 | $this->config = array_merge($this->config, $config); |
| 74 | 74 | Config::setAll($config); |
| 75 | 75 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @return array |
| 82 | 82 | */ |
| 83 | - public function getConfig(){ |
|
| 83 | + public function getConfig() { |
|
| 84 | 84 | return $this->config; |
| 85 | 85 | } |
| 86 | 86 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * Return the value of the pagination query string |
| 89 | 89 | * @return string |
| 90 | 90 | */ |
| 91 | - public function getPaginationQueryString(){ |
|
| 91 | + public function getPaginationQueryString() { |
|
| 92 | 92 | return $this->paginationQueryString; |
| 93 | 93 | } |
| 94 | 94 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * @param string $paginationQueryString the new value |
| 98 | 98 | * @return object |
| 99 | 99 | */ |
| 100 | - public function setPaginationQueryString($paginationQueryString){ |
|
| 100 | + public function setPaginationQueryString($paginationQueryString) { |
|
| 101 | 101 | $this->paginationQueryString = $paginationQueryString; |
| 102 | 102 | return $this; |
| 103 | 103 | } |
@@ -108,25 +108,25 @@ discard block |
||
| 108 | 108 | * |
| 109 | 109 | * @return object |
| 110 | 110 | */ |
| 111 | - public function determinePaginationQueryStringValue(){ |
|
| 111 | + public function determinePaginationQueryStringValue() { |
|
| 112 | 112 | $pageQueryName = $this->config['page_query_string_name']; |
| 113 | 113 | $queryString = Url::queryString(); |
| 114 | 114 | $currentUrl = Url::current(); |
| 115 | 115 | $query = ''; |
| 116 | - if ($queryString == ''){ |
|
| 116 | + if ($queryString == '') { |
|
| 117 | 117 | $query = '?' . $pageQueryName . '='; |
| 118 | 118 | } |
| 119 | - else{ |
|
| 119 | + else { |
|
| 120 | 120 | $tab = explode($pageQueryName . '=', $queryString); |
| 121 | 121 | $nb = count($tab); |
| 122 | - if ($nb == 1){ |
|
| 122 | + if ($nb == 1) { |
|
| 123 | 123 | $query = '?' . $queryString . '&' . $pageQueryName . '='; |
| 124 | 124 | } |
| 125 | - else{ |
|
| 126 | - if ($tab[0] == ''){ |
|
| 125 | + else { |
|
| 126 | + if ($tab[0] == '') { |
|
| 127 | 127 | $query = '?' . $pageQueryName . '='; |
| 128 | 128 | } |
| 129 | - else{ |
|
| 129 | + else { |
|
| 130 | 130 | $query = '?' . $tab[0] . '' . $pageQueryName . '='; |
| 131 | 131 | } |
| 132 | 132 | } |
@@ -144,10 +144,10 @@ discard block |
||
| 144 | 144 | * |
| 145 | 145 | * @return string the pagination link |
| 146 | 146 | */ |
| 147 | - public function getLink($totalRows, $currentPageNumber){ |
|
| 147 | + public function getLink($totalRows, $currentPageNumber) { |
|
| 148 | 148 | $numberOfLink = $this->config['nb_link']; |
| 149 | 149 | $numberOfRowPerPage = $this->config['pagination_per_page']; |
| 150 | - if (empty($this->paginationQueryString)){ |
|
| 150 | + if (empty($this->paginationQueryString)) { |
|
| 151 | 151 | //determine the pagination query string value |
| 152 | 152 | $this->determinePaginationQueryStringValue(); |
| 153 | 153 | } |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | $numberOfLink = (int) $numberOfLink; |
| 159 | 159 | $numberOfRowPerPage = (int) $numberOfRowPerPage; |
| 160 | 160 | |
| 161 | - if ($currentPageNumber <= 0){ |
|
| 161 | + if ($currentPageNumber <= 0) { |
|
| 162 | 162 | $currentPageNumber = 1; |
| 163 | 163 | } |
| 164 | 164 | if ($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0) { |
@@ -173,18 +173,18 @@ discard block |
||
| 173 | 173 | * @param int $numberOfPage the total number of page |
| 174 | 174 | * @return string |
| 175 | 175 | */ |
| 176 | - protected function buildPaginationNavbar($currentPageNumber, $numberOfPage){ |
|
| 176 | + protected function buildPaginationNavbar($currentPageNumber, $numberOfPage) { |
|
| 177 | 177 | $values = $this->getPaginationBeginAndEndNumber($currentPageNumber, $numberOfPage); |
| 178 | 178 | $begin = $values['begin']; |
| 179 | 179 | $end = $values['end']; |
| 180 | 180 | $navbar = null; |
| 181 | - if ($currentPageNumber == 1){ |
|
| 181 | + if ($currentPageNumber == 1) { |
|
| 182 | 182 | $navbar .= $this->buildPaginationLinkForFirstPage($begin, $end, $currentPageNumber); |
| 183 | 183 | } |
| 184 | - else if ($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){ |
|
| 184 | + else if ($currentPageNumber > 1 && $currentPageNumber < $numberOfPage) { |
|
| 185 | 185 | $navbar .= $this->buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber); |
| 186 | 186 | } |
| 187 | - else if ($currentPageNumber == $numberOfPage){ |
|
| 187 | + else if ($currentPageNumber == $numberOfPage) { |
|
| 188 | 188 | $navbar .= $this->buildPaginationLinkForLastPage($begin, $end, $currentPageNumber); |
| 189 | 189 | } |
| 190 | 190 | $navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close']; |
@@ -197,32 +197,32 @@ discard block |
||
| 197 | 197 | * @param int $numberOfPage the total number of page |
| 198 | 198 | * @return array the begin and end number |
| 199 | 199 | */ |
| 200 | - protected function getPaginationBeginAndEndNumber($currentPageNumber, $numberOfPage){ |
|
| 200 | + protected function getPaginationBeginAndEndNumber($currentPageNumber, $numberOfPage) { |
|
| 201 | 201 | $start = null; |
| 202 | 202 | $begin = null; |
| 203 | 203 | $end = null; |
| 204 | 204 | $numberOfLink = $this->config['nb_link']; |
| 205 | - if ($numberOfLink % 2 == 0){ |
|
| 205 | + if ($numberOfLink % 2 == 0) { |
|
| 206 | 206 | $start = $currentPageNumber - ($numberOfLink / 2) + 1; |
| 207 | 207 | $end = $currentPageNumber + ($numberOfLink / 2); |
| 208 | 208 | } |
| 209 | - else{ |
|
| 209 | + else { |
|
| 210 | 210 | $start = $currentPageNumber - floor($numberOfLink / 2); |
| 211 | 211 | $end = $currentPageNumber + floor($numberOfLink / 2); |
| 212 | 212 | } |
| 213 | - if ($start <= 1){ |
|
| 213 | + if ($start <= 1) { |
|
| 214 | 214 | $begin = 1; |
| 215 | 215 | $end = $numberOfLink; |
| 216 | 216 | } |
| 217 | - else if ($start > 1 && $end < $numberOfPage){ |
|
| 217 | + else if ($start > 1 && $end < $numberOfPage) { |
|
| 218 | 218 | $begin = $start; |
| 219 | 219 | $end = $end; |
| 220 | 220 | } |
| 221 | - else{ |
|
| 221 | + else { |
|
| 222 | 222 | $begin = ($numberOfPage - $numberOfLink) + 1; |
| 223 | 223 | $end = $numberOfPage; |
| 224 | 224 | } |
| 225 | - if ($numberOfPage <= $numberOfLink){ |
|
| 225 | + if ($numberOfPage <= $numberOfLink) { |
|
| 226 | 226 | $begin = 1; |
| 227 | 227 | $end = $numberOfPage; |
| 228 | 228 | } |
@@ -239,14 +239,14 @@ discard block |
||
| 239 | 239 | * @param int $currentPageNumber the pagination current page number |
| 240 | 240 | * @return string |
| 241 | 241 | */ |
| 242 | - protected function buildPaginationLinkForFirstPage($begin, $end, $currentPageNumber){ |
|
| 242 | + protected function buildPaginationLinkForFirstPage($begin, $end, $currentPageNumber) { |
|
| 243 | 243 | $navbar = null; |
| 244 | 244 | $query = $this->paginationQueryString; |
| 245 | - for($i = $begin; $i <= $end; $i++){ |
|
| 246 | - if ($i == $currentPageNumber){ |
|
| 245 | + for ($i = $begin; $i <= $end; $i++) { |
|
| 246 | + if ($i == $currentPageNumber) { |
|
| 247 | 247 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
| 248 | 248 | } |
| 249 | - else{ |
|
| 249 | + else { |
|
| 250 | 250 | $navbar .= $this->config['digit_open'] |
| 251 | 251 | . '<a href="' . $query . $i . '" ' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' |
| 252 | 252 | . $this->config['digit_close']; |
@@ -265,23 +265,23 @@ discard block |
||
| 265 | 265 | * @param int $currentPageNumber the pagination current page number |
| 266 | 266 | * @return string |
| 267 | 267 | */ |
| 268 | - protected function buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber){ |
|
| 268 | + protected function buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber) { |
|
| 269 | 269 | $navbar = null; |
| 270 | 270 | $query = $this->paginationQueryString; |
| 271 | 271 | $navbar .= $this->config['previous_open'] |
| 272 | 272 | . '<a href="' . $query . ($currentPageNumber - 1) . '">' |
| 273 | 273 | . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
| 274 | - for($i = $begin; $i <= $end; $i++){ |
|
| 275 | - if ($i == $currentPageNumber){ |
|
| 274 | + for ($i = $begin; $i <= $end; $i++) { |
|
| 275 | + if ($i == $currentPageNumber) { |
|
| 276 | 276 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
| 277 | 277 | } |
| 278 | - else{ |
|
| 278 | + else { |
|
| 279 | 279 | $navbar .= $this->config['digit_open'] |
| 280 | - . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i .'</a>' |
|
| 280 | + . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' |
|
| 281 | 281 | . $this->config['digit_close']; |
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | - $navbar .= $this->config['next_open']."<a href='$query".($currentPageNumber + 1)."'>".$this->config['next_text']."</a>".$this->config['next_close']; |
|
| 284 | + $navbar .= $this->config['next_open'] . "<a href='$query" . ($currentPageNumber + 1) . "'>" . $this->config['next_text'] . "</a>" . $this->config['next_close']; |
|
| 285 | 285 | return $navbar; |
| 286 | 286 | } |
| 287 | 287 | |
@@ -292,19 +292,19 @@ discard block |
||
| 292 | 292 | * @param int $currentPageNumber the pagination current page number |
| 293 | 293 | * @return string |
| 294 | 294 | */ |
| 295 | - protected function buildPaginationLinkForLastPage($begin, $end, $currentPageNumber){ |
|
| 295 | + protected function buildPaginationLinkForLastPage($begin, $end, $currentPageNumber) { |
|
| 296 | 296 | $navbar = null; |
| 297 | 297 | $query = $this->paginationQueryString; |
| 298 | 298 | $navbar .= $this->config['previous_open'] |
| 299 | 299 | . '<a href="' . $query . ($currentPageNumber - 1) . '">' |
| 300 | 300 | . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
| 301 | - for($i = $begin; $i <= $end; $i++){ |
|
| 302 | - if ($i == $currentPageNumber){ |
|
| 301 | + for ($i = $begin; $i <= $end; $i++) { |
|
| 302 | + if ($i == $currentPageNumber) { |
|
| 303 | 303 | $navbar .= $this->config['active_link_open'] |
| 304 | 304 | . $currentPageNumber |
| 305 | 305 | . $this->config['active_link_close']; |
| 306 | 306 | } |
| 307 | - else{ |
|
| 307 | + else { |
|
| 308 | 308 | $navbar .= $this->config['digit_open'] |
| 309 | 309 | . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' |
| 310 | 310 | . $this->config['digit_close']; |
@@ -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 Module{ |
|
| 27 | + class Module { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * list of loaded module |
@@ -42,9 +42,9 @@ discard block |
||
| 42 | 42 | * The signleton of the logger |
| 43 | 43 | * @return Object the Log instance |
| 44 | 44 | */ |
| 45 | - private static function getLogger(){ |
|
| 46 | - if(self::$logger == null){ |
|
| 47 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 45 | + private static function getLogger() { |
|
| 46 | + if (self::$logger == null) { |
|
| 47 | + self::$logger[0] = & class_loader('Log', 'classes'); |
|
| 48 | 48 | self::$logger[0]->setLogger('Library::Module'); |
| 49 | 49 | } |
| 50 | 50 | return self::$logger[0]; |
@@ -53,24 +53,24 @@ discard block |
||
| 53 | 53 | /** |
| 54 | 54 | * Initialise the module list by scanning the directory MODULE_PATH |
| 55 | 55 | */ |
| 56 | - public function init(){ |
|
| 56 | + public function init() { |
|
| 57 | 57 | $logger = self::getLogger(); |
| 58 | 58 | $logger->debug('Check if the application contains the modules ...'); |
| 59 | 59 | $moduleDir = opendir(MODULE_PATH); |
| 60 | - if(is_resource($moduleDir)){ |
|
| 61 | - while(($module = readdir($moduleDir)) !== false){ |
|
| 62 | - if(preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){ |
|
| 60 | + if (is_resource($moduleDir)) { |
|
| 61 | + while (($module = readdir($moduleDir)) !== false) { |
|
| 62 | + if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)) { |
|
| 63 | 63 | self::$list[] = $module; |
| 64 | 64 | } |
| 65 | - else{ |
|
| 66 | - $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name'); |
|
| 65 | + else { |
|
| 66 | + $logger->info('Skipping [' . $module . '], may be this is not a directory or does not exists or is invalid name'); |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | closedir($moduleDir); |
| 70 | 70 | } |
| 71 | 71 | ksort(self::$list); |
| 72 | 72 | |
| 73 | - if(self::hasModule()){ |
|
| 73 | + if (self::hasModule()) { |
|
| 74 | 74 | $logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']'); |
| 75 | 75 | } |
| 76 | 76 | } |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | * Get the list of the custom autoload configuration from module if exists |
| 80 | 80 | * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values |
| 81 | 81 | */ |
| 82 | - public static function getModulesAutoloadConfig(){ |
|
| 82 | + public static function getModulesAutoloadConfig() { |
|
| 83 | 83 | $logger = self::getLogger(); |
| 84 | - if(! self::hasModule()){ |
|
| 84 | + if (!self::hasModule()) { |
|
| 85 | 85 | $logger->info('No module was loaded skipping.'); |
| 86 | 86 | return false; |
| 87 | 87 | } |
@@ -94,10 +94,10 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | foreach (self::$list as $module) { |
| 96 | 96 | $file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php'; |
| 97 | - if(file_exists($file)){ |
|
| 97 | + if (file_exists($file)) { |
|
| 98 | 98 | $autoload = array(); |
| 99 | 99 | require_once $file; |
| 100 | - if(! empty($autoload) && is_array($autoload)){ |
|
| 100 | + if (!empty($autoload) && is_array($autoload)) { |
|
| 101 | 101 | $autoloads = array_merge_recursive($autoloads, $autoload); |
| 102 | 102 | unset($autoload); |
| 103 | 103 | } |
@@ -110,19 +110,19 @@ discard block |
||
| 110 | 110 | * Get the list of the custom routes configuration from module if exists |
| 111 | 111 | * @return array|boolean the routes list or false if no module contains the routes configuration |
| 112 | 112 | */ |
| 113 | - public static function getModulesRoutes(){ |
|
| 113 | + public static function getModulesRoutes() { |
|
| 114 | 114 | $logger = self::getLogger(); |
| 115 | - if(! self::hasModule()){ |
|
| 115 | + if (!self::hasModule()) { |
|
| 116 | 116 | $logger->info('No module was loaded skipping.'); |
| 117 | 117 | return false; |
| 118 | 118 | } |
| 119 | 119 | $routes = array(); |
| 120 | 120 | foreach (self::$list as $module) { |
| 121 | 121 | $file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php'; |
| 122 | - if(file_exists($file)){ |
|
| 122 | + if (file_exists($file)) { |
|
| 123 | 123 | $route = array(); |
| 124 | 124 | require_once $file; |
| 125 | - if(! empty($route) && is_array($route)){ |
|
| 125 | + if (!empty($route) && is_array($route)) { |
|
| 126 | 126 | $routes = array_merge($routes, $route); |
| 127 | 127 | unset($route); |
| 128 | 128 | } |
@@ -138,22 +138,22 @@ discard block |
||
| 138 | 138 | * @param string $module the module name |
| 139 | 139 | * @return boolean|string false or null if no module have this controller, path the full path of the controller |
| 140 | 140 | */ |
| 141 | - public static function findControllerFullPath($class, $module = null){ |
|
| 141 | + public static function findControllerFullPath($class, $module = null) { |
|
| 142 | 142 | $logger = self::getLogger(); |
| 143 | - if(! self::hasModule()){ |
|
| 143 | + if (!self::hasModule()) { |
|
| 144 | 144 | $logger->info('No module was loaded skiping.'); |
| 145 | 145 | return false; |
| 146 | 146 | } |
| 147 | 147 | $class = str_ireplace('.php', '', $class); |
| 148 | 148 | $class = ucfirst($class); |
| 149 | - $classFile = $class.'.php'; |
|
| 150 | - $logger->debug('Checking the controller [' . $class . '] in module [' .$module. '] ...'); |
|
| 149 | + $classFile = $class . '.php'; |
|
| 150 | + $logger->debug('Checking the controller [' . $class . '] in module [' . $module . '] ...'); |
|
| 151 | 151 | $filePath = MODULE_PATH . $module . DS . 'controllers' . DS . $classFile; |
| 152 | - if(file_exists($filePath)){ |
|
| 153 | - $logger->info('Found controller [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 152 | + if (file_exists($filePath)) { |
|
| 153 | + $logger->info('Found controller [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
| 154 | 154 | return $filePath; |
| 155 | 155 | } |
| 156 | - $logger->info('Controller [' . $class . '] does not exist in the module [' .$module. ']'); |
|
| 156 | + $logger->info('Controller [' . $class . '] does not exist in the module [' . $module . ']'); |
|
| 157 | 157 | return false; |
| 158 | 158 | } |
| 159 | 159 | |
@@ -163,22 +163,22 @@ discard block |
||
| 163 | 163 | * @param string $module the module name |
| 164 | 164 | * @return boolean|string false or null if no module have this model, return the full path of this model |
| 165 | 165 | */ |
| 166 | - public static function findModelFullPath($class, $module = null){ |
|
| 166 | + public static function findModelFullPath($class, $module = null) { |
|
| 167 | 167 | $logger = self::getLogger(); |
| 168 | - if(! self::hasModule()){ |
|
| 168 | + if (!self::hasModule()) { |
|
| 169 | 169 | $logger->info('No module was loaded skiping.'); |
| 170 | 170 | return false; |
| 171 | 171 | } |
| 172 | 172 | $class = str_ireplace('.php', '', $class); |
| 173 | 173 | $class = ucfirst($class); |
| 174 | - $classFile = $class.'.php'; |
|
| 175 | - $logger->debug('Checking model [' . $class . '] in module [' .$module. '] ...'); |
|
| 174 | + $classFile = $class . '.php'; |
|
| 175 | + $logger->debug('Checking model [' . $class . '] in module [' . $module . '] ...'); |
|
| 176 | 176 | $filePath = MODULE_PATH . $module . DS . 'models' . DS . $classFile; |
| 177 | - if(file_exists($filePath)){ |
|
| 178 | - $logger->info('Found model [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 177 | + if (file_exists($filePath)) { |
|
| 178 | + $logger->info('Found model [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
| 179 | 179 | return $filePath; |
| 180 | 180 | } |
| 181 | - $logger->info('Model [' . $class . '] does not exist in the module [' .$module. ']'); |
|
| 181 | + $logger->info('Model [' . $class . '] does not exist in the module [' . $module . ']'); |
|
| 182 | 182 | return false; |
| 183 | 183 | } |
| 184 | 184 | |
@@ -188,21 +188,21 @@ discard block |
||
| 188 | 188 | * @param string $module the module name |
| 189 | 189 | * @return boolean|string false or null if no module have this configuration, return the full path of this configuration |
| 190 | 190 | */ |
| 191 | - public static function findConfigFullPath($configuration, $module = null){ |
|
| 191 | + public static function findConfigFullPath($configuration, $module = null) { |
|
| 192 | 192 | $logger = self::getLogger(); |
| 193 | - if(! self::hasModule()){ |
|
| 193 | + if (!self::hasModule()) { |
|
| 194 | 194 | $logger->info('No module was loaded skiping.'); |
| 195 | 195 | return false; |
| 196 | 196 | } |
| 197 | 197 | $configuration = str_ireplace('.php', '', $configuration); |
| 198 | - $file = $configuration.'.php'; |
|
| 199 | - $logger->debug('Checking configuration [' . $configuration . '] in module [' .$module. '] ...'); |
|
| 198 | + $file = $configuration . '.php'; |
|
| 199 | + $logger->debug('Checking configuration [' . $configuration . '] in module [' . $module . '] ...'); |
|
| 200 | 200 | $filePath = MODULE_PATH . $module . DS . 'config' . DS . $file; |
| 201 | - if(file_exists($filePath)){ |
|
| 202 | - $logger->info('Found configuration [' . $configuration . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 201 | + if (file_exists($filePath)) { |
|
| 202 | + $logger->info('Found configuration [' . $configuration . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
| 203 | 203 | return $filePath; |
| 204 | 204 | } |
| 205 | - $logger->info('Configuration [' . $configuration . '] does not exist in the module [' .$module. ']'); |
|
| 205 | + $logger->info('Configuration [' . $configuration . '] does not exist in the module [' . $module . ']'); |
|
| 206 | 206 | return false; |
| 207 | 207 | } |
| 208 | 208 | |
@@ -212,22 +212,22 @@ discard block |
||
| 212 | 212 | * @param string $module the module name |
| 213 | 213 | * @return boolean|string false or null if no module have this helper, return the full path of this helper |
| 214 | 214 | */ |
| 215 | - public static function findFunctionFullPath($helper, $module = null){ |
|
| 215 | + public static function findFunctionFullPath($helper, $module = null) { |
|
| 216 | 216 | $logger = self::getLogger(); |
| 217 | - if(! self::hasModule()){ |
|
| 217 | + if (!self::hasModule()) { |
|
| 218 | 218 | $logger->info('No module was loaded skiping.'); |
| 219 | 219 | return false; |
| 220 | 220 | } |
| 221 | 221 | $helper = str_ireplace('.php', '', $helper); |
| 222 | 222 | $helper = str_ireplace('function_', '', $helper); |
| 223 | - $file = 'function_'.$helper.'.php'; |
|
| 224 | - $logger->debug('Checking helper [' . $helper . '] in module [' .$module. '] ...'); |
|
| 223 | + $file = 'function_' . $helper . '.php'; |
|
| 224 | + $logger->debug('Checking helper [' . $helper . '] in module [' . $module . '] ...'); |
|
| 225 | 225 | $filePath = MODULE_PATH . $module . DS . 'functions' . DS . $file; |
| 226 | - if(file_exists($filePath)){ |
|
| 227 | - $logger->info('Found helper [' . $helper . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 226 | + if (file_exists($filePath)) { |
|
| 227 | + $logger->info('Found helper [' . $helper . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
| 228 | 228 | return $filePath; |
| 229 | 229 | } |
| 230 | - $logger->info('Helper [' . $helper . '] does not exist in the module [' .$module. ']'); |
|
| 230 | + $logger->info('Helper [' . $helper . '] does not exist in the module [' . $module . ']'); |
|
| 231 | 231 | return false; |
| 232 | 232 | |
| 233 | 233 | } |
@@ -239,21 +239,21 @@ discard block |
||
| 239 | 239 | * @param string $module the module name |
| 240 | 240 | * @return boolean|string false or null if no module have this library, return the full path of this library |
| 241 | 241 | */ |
| 242 | - public static function findLibraryFullPath($class, $module = null){ |
|
| 242 | + public static function findLibraryFullPath($class, $module = null) { |
|
| 243 | 243 | $logger = self::getLogger(); |
| 244 | - if(! self::hasModule()){ |
|
| 244 | + if (!self::hasModule()) { |
|
| 245 | 245 | $logger->info('No module was loaded skiping.'); |
| 246 | 246 | return false; |
| 247 | 247 | } |
| 248 | 248 | $class = str_ireplace('.php', '', $class); |
| 249 | - $file = $class.'.php'; |
|
| 250 | - $logger->debug('Checking library [' . $class . '] in module [' .$module. '] ...'); |
|
| 249 | + $file = $class . '.php'; |
|
| 250 | + $logger->debug('Checking library [' . $class . '] in module [' . $module . '] ...'); |
|
| 251 | 251 | $filePath = MODULE_PATH . $module . DS . 'libraries' . DS . $file; |
| 252 | - if(file_exists($filePath)){ |
|
| 253 | - $logger->info('Found library [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 252 | + if (file_exists($filePath)) { |
|
| 253 | + $logger->info('Found library [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
| 254 | 254 | return $filePath; |
| 255 | 255 | } |
| 256 | - $logger->info('Library [' . $class . '] does not exist in the module [' .$module. ']'); |
|
| 256 | + $logger->info('Library [' . $class . '] does not exist in the module [' . $module . ']'); |
|
| 257 | 257 | return false; |
| 258 | 258 | } |
| 259 | 259 | |
@@ -264,9 +264,9 @@ discard block |
||
| 264 | 264 | * @param string $module the module name to check |
| 265 | 265 | * @return boolean|string false or null if no module have this view, path the full path of the view |
| 266 | 266 | */ |
| 267 | - public static function findViewFullPath($view, $module = null){ |
|
| 267 | + public static function findViewFullPath($view, $module = null) { |
|
| 268 | 268 | $logger = self::getLogger(); |
| 269 | - if(! self::hasModule()){ |
|
| 269 | + if (!self::hasModule()) { |
|
| 270 | 270 | $logger->info('No module was loaded skiping.'); |
| 271 | 271 | return false; |
| 272 | 272 | } |
@@ -274,13 +274,13 @@ discard block |
||
| 274 | 274 | $view = trim($view, '/\\'); |
| 275 | 275 | $view = str_ireplace('/', DS, $view); |
| 276 | 276 | $viewFile = $view . '.php'; |
| 277 | - $logger->debug('Checking view [' . $view . '] in module [' .$module. '] ...'); |
|
| 277 | + $logger->debug('Checking view [' . $view . '] in module [' . $module . '] ...'); |
|
| 278 | 278 | $filePath = MODULE_PATH . $module . DS . 'views' . DS . $viewFile; |
| 279 | - if(file_exists($filePath)){ |
|
| 280 | - $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 279 | + if (file_exists($filePath)) { |
|
| 280 | + $logger->info('Found view [' . $view . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
| 281 | 281 | return $filePath; |
| 282 | 282 | } |
| 283 | - $logger->info('View [' . $view . '] does not exist in the module [' .$module. ']'); |
|
| 283 | + $logger->info('View [' . $view . '] does not exist in the module [' . $module . ']'); |
|
| 284 | 284 | return false; |
| 285 | 285 | } |
| 286 | 286 | |
@@ -291,22 +291,22 @@ discard block |
||
| 291 | 291 | * @param string $appLang the application language like 'en', 'fr' |
| 292 | 292 | * @return boolean|string false or null if no module have this language, return the full path of this language |
| 293 | 293 | */ |
| 294 | - public static function findLanguageFullPath($language, $module = null, $appLang){ |
|
| 294 | + public static function findLanguageFullPath($language, $module = null, $appLang) { |
|
| 295 | 295 | $logger = self::getLogger(); |
| 296 | - if(! self::hasModule()){ |
|
| 296 | + if (!self::hasModule()) { |
|
| 297 | 297 | $logger->info('No module was loaded skiping.'); |
| 298 | 298 | return false; |
| 299 | 299 | } |
| 300 | 300 | $language = str_ireplace('.php', '', $language); |
| 301 | 301 | $language = str_ireplace('lang_', '', $language); |
| 302 | - $file = 'lang_'.$language.'.php'; |
|
| 303 | - $logger->debug('Checking language [' . $language . '] in module [' .$module. '] ...'); |
|
| 302 | + $file = 'lang_' . $language . '.php'; |
|
| 303 | + $logger->debug('Checking language [' . $language . '] in module [' . $module . '] ...'); |
|
| 304 | 304 | $filePath = MODULE_PATH . $module . DS . 'lang' . DS . $appLang . DS . $file; |
| 305 | - if(file_exists($filePath)){ |
|
| 306 | - $logger->info('Found language [' . $language . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 305 | + if (file_exists($filePath)) { |
|
| 306 | + $logger->info('Found language [' . $language . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
| 307 | 307 | return $filePath; |
| 308 | 308 | } |
| 309 | - $logger->info('Language [' . $language . '] does not exist in the module [' .$module. ']'); |
|
| 309 | + $logger->info('Language [' . $language . '] does not exist in the module [' . $module . ']'); |
|
| 310 | 310 | return false; |
| 311 | 311 | } |
| 312 | 312 | |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | * Get the list of module loaded |
| 315 | 315 | * @return array the module list |
| 316 | 316 | */ |
| 317 | - public static function getModuleList(){ |
|
| 317 | + public static function getModuleList() { |
|
| 318 | 318 | return self::$list; |
| 319 | 319 | } |
| 320 | 320 | |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | * Check if the application has an module |
| 323 | 323 | * @return boolean |
| 324 | 324 | */ |
| 325 | - public static function hasModule(){ |
|
| 325 | + public static function hasModule() { |
|
| 326 | 326 | return !empty(self::$list); |
| 327 | 327 | } |
| 328 | 328 | |