@@ -22,10 +22,10 @@ discard block |
||
| 22 | 22 | * You should have received a copy of the GNU General Public License |
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | - */ |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class FormValidation{ |
|
| 28 | + class FormValidation{ |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * The form validation status |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 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 | */ |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $this->logger =& class_loader('Log', 'classes'); |
| 101 | 101 | $this->logger->setLogger('Library::FormValidation'); |
| 102 | 102 | |
| 103 | - //Load form validation language message |
|
| 103 | + //Load form validation language message |
|
| 104 | 104 | Loader::lang('form_validation'); |
| 105 | 105 | $obj = & get_instance(); |
| 106 | 106 | $this->_errorsMessages = array( |
@@ -162,13 +162,13 @@ discard block |
||
| 162 | 162 | /** |
| 163 | 163 | * Set the form validation data |
| 164 | 164 | * @param array $data the values to be validated |
| 165 | - * |
|
| 165 | + * |
|
| 166 | 166 | * @return FormValidation Current instance of object. |
| 167 | 167 | */ |
| 168 | 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 | - return $this; |
|
| 171 | + return $this; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -179,11 +179,11 @@ discard block |
||
| 179 | 179 | return $this->data; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * Get the validation function name to validate a rule |
|
| 184 | - * |
|
| 185 | - * @return string the function name |
|
| 186 | - */ |
|
| 182 | + /** |
|
| 183 | + * Get the validation function name to validate a rule |
|
| 184 | + * |
|
| 185 | + * @return string the function name |
|
| 186 | + */ |
|
| 187 | 187 | protected function _toCallCase($funcName, $prefix='_validate') { |
| 188 | 188 | $funcName = strtolower($funcName); |
| 189 | 189 | $finalFuncName = $prefix; |
@@ -253,12 +253,12 @@ discard block |
||
| 253 | 253 | $this->_forceFail = false; |
| 254 | 254 | |
| 255 | 255 | foreach ($this->getData() as $inputName => $inputVal) { |
| 256 | - if(is_array($this->data[$inputName])){ |
|
| 257 | - $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
|
| 258 | - } |
|
| 259 | - else{ |
|
| 260 | - $this->data[$inputName] = trim($this->data[$inputName]); |
|
| 261 | - } |
|
| 256 | + if(is_array($this->data[$inputName])){ |
|
| 257 | + $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
|
| 258 | + } |
|
| 259 | + else{ |
|
| 260 | + $this->data[$inputName] = trim($this->data[$inputName]); |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | 263 | if (array_key_exists($inputName, $this->_rules)) { |
| 264 | 264 | foreach ($this->_parseRuleString($this->_rules[$inputName]) as $eachRule) { |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | * |
| 275 | 275 | * @param string $inputField Name of the field or the data key to add a rule to |
| 276 | 276 | * @param string $ruleSets PIPE seperated string of rules |
| 277 | - * |
|
| 277 | + * |
|
| 278 | 278 | * @return FormValidation Current instance of object. |
| 279 | 279 | */ |
| 280 | 280 | public function setRule($inputField, $inputLabel, $ruleSets) { |
@@ -288,8 +288,8 @@ discard block |
||
| 288 | 288 | * Takes an array of rules and uses setRule() to set them, accepts an array |
| 289 | 289 | * of rule names rather than a pipe-delimited string as well. |
| 290 | 290 | * @param array $ruleSets |
| 291 | - * |
|
| 292 | - * @return FormValidation Current instance of object. |
|
| 291 | + * |
|
| 292 | + * @return FormValidation Current instance of object. |
|
| 293 | 293 | */ |
| 294 | 294 | public function setRules(array $ruleSets) { |
| 295 | 295 | foreach ($ruleSets as $ruleSet) { |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | * @param string $start Before block of errors gets displayed, HTML allowed. |
| 312 | 312 | * @param string $end After the block of errors gets displayed, HTML allowed. |
| 313 | 313 | * |
| 314 | - * @return FormValidation Current instance of object. |
|
| 314 | + * @return FormValidation Current instance of object. |
|
| 315 | 315 | */ |
| 316 | 316 | public function setErrorsDelimiter($start, $end) { |
| 317 | 317 | $this->_allErrorsDelimiter[0] = $start; |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | * @param string $start Displayed before each error. |
| 327 | 327 | * @param string $end Displayed after each error. |
| 328 | 328 | * |
| 329 | - * @return FormValidation Current instance of object. |
|
| 329 | + * @return FormValidation Current instance of object. |
|
| 330 | 330 | */ |
| 331 | 331 | public function setErrorDelimiter($start, $end) { |
| 332 | 332 | $this->_eachErrorDelimiter[0] = $start; |
@@ -334,21 +334,21 @@ discard block |
||
| 334 | 334 | return $this; |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - /** |
|
| 338 | - * Get the each errors delimiters |
|
| 339 | - * |
|
| 340 | - * @return array |
|
| 341 | - */ |
|
| 342 | - public function getErrorDelimiter() { |
|
| 337 | + /** |
|
| 338 | + * Get the each errors delimiters |
|
| 339 | + * |
|
| 340 | + * @return array |
|
| 341 | + */ |
|
| 342 | + public function getErrorDelimiter() { |
|
| 343 | 343 | return $this->_eachErrorDelimiter; |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | - /** |
|
| 347 | - * Get the all errors delimiters |
|
| 348 | - * |
|
| 349 | - * @return array |
|
| 350 | - */ |
|
| 351 | - public function getErrorsDelimiter() { |
|
| 346 | + /** |
|
| 347 | + * Get the all errors delimiters |
|
| 348 | + * |
|
| 349 | + * @return array |
|
| 350 | + */ |
|
| 351 | + public function getErrorsDelimiter() { |
|
| 352 | 352 | return $this->_allErrorsDelimiter; |
| 353 | 353 | } |
| 354 | 354 | |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | * |
| 387 | 387 | * @param string $inputName The form input name or data key |
| 388 | 388 | * @param string $errorMessage Error to display |
| 389 | - * |
|
| 389 | + * |
|
| 390 | 390 | * @return formValidation Current instance of the object |
| 391 | 391 | */ |
| 392 | 392 | public function setCustomError($inputName, $errorMessage) { |
@@ -423,17 +423,17 @@ discard block |
||
| 423 | 423 | * |
| 424 | 424 | * @param boolean $limit number of error to display or return |
| 425 | 425 | * @param boolean $echo Whether or not the values are to be returned or displayed |
| 426 | - * |
|
| 426 | + * |
|
| 427 | 427 | * @return string Errors formatted for output |
| 428 | 428 | */ |
| 429 | 429 | public function displayErrors($limit = null, $echo = true) { |
| 430 | 430 | list($errorsStart, $errorsEnd) = $this->_allErrorsDelimiter; |
| 431 | 431 | list($errorStart, $errorEnd) = $this->_eachErrorDelimiter; |
| 432 | 432 | $errorOutput = $errorsStart; |
| 433 | - $i = 0; |
|
| 433 | + $i = 0; |
|
| 434 | 434 | if (!empty($this->_errors)) { |
| 435 | 435 | foreach ($this->_errors as $fieldName => $error) { |
| 436 | - if ($i === $limit) { |
|
| 436 | + if ($i === $limit) { |
|
| 437 | 437 | break; |
| 438 | 438 | } |
| 439 | 439 | $errorOutput .= $errorStart; |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | * Breaks up a PIPE seperated string of rules, and puts them into an array. |
| 462 | 462 | * |
| 463 | 463 | * @param string $ruleString String to be parsed. |
| 464 | - * |
|
| 464 | + * |
|
| 465 | 465 | * @return array Array of each value in original string. |
| 466 | 466 | */ |
| 467 | 467 | protected function _parseRuleString($ruleString) { |
@@ -474,10 +474,10 @@ discard block |
||
| 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])){ |
|
| 478 | - $ruleSets[] = $regexRule[0]; |
|
| 479 | - } |
|
| 480 | - $ruleStringRegex = explode('|', $ruleStringTemp); |
|
| 477 | + if(!empty($regexRule[0])){ |
|
| 478 | + $ruleSets[] = $regexRule[0]; |
|
| 479 | + } |
|
| 480 | + $ruleStringRegex = explode('|', $ruleStringTemp); |
|
| 481 | 481 | foreach ($ruleStringRegex as $rule) { |
| 482 | 482 | $rule = trim($rule); |
| 483 | 483 | if($rule){ |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | } else { |
| 494 | 494 | $ruleSets[] = $ruleString; |
| 495 | 495 | } |
| 496 | - } |
|
| 496 | + } |
|
| 497 | 497 | return $ruleSets; |
| 498 | 498 | } |
| 499 | 499 | |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | * Returns whether or not a field obtains the rule "required". |
| 502 | 502 | * |
| 503 | 503 | * @param string $fieldName Field to check if required. |
| 504 | - * |
|
| 504 | + * |
|
| 505 | 505 | * @return boolean Whether or not the field is required. |
| 506 | 506 | */ |
| 507 | 507 | protected function _fieldIsRequired($fieldName) { |
@@ -536,13 +536,13 @@ discard block |
||
| 536 | 536 | return; |
| 537 | 537 | } |
| 538 | 538 | |
| 539 | - /** |
|
| 540 | - * Set error for the given field or key |
|
| 541 | - * |
|
| 542 | - * @param string $inputName the input or key name |
|
| 543 | - * @param string $ruleName the rule name |
|
| 544 | - * @param array|string $replacements |
|
| 545 | - */ |
|
| 539 | + /** |
|
| 540 | + * Set error for the given field or key |
|
| 541 | + * |
|
| 542 | + * @param string $inputName the input or key name |
|
| 543 | + * @param string $ruleName the rule name |
|
| 544 | + * @param array|string $replacements |
|
| 545 | + */ |
|
| 546 | 546 | protected function _setError($inputName, $ruleName, $replacements = array()) { |
| 547 | 547 | $rulePhraseKeyParts = explode(',', $ruleName); |
| 548 | 548 | $rulePhrase = null; |
@@ -559,7 +559,7 @@ discard block |
||
| 559 | 559 | } |
| 560 | 560 | // Type cast to array in case it's a string |
| 561 | 561 | $replacements = (array) $replacements; |
| 562 | - $replacementCount = count($replacements); |
|
| 562 | + $replacementCount = count($replacements); |
|
| 563 | 563 | for ($i = 1; $i <= $replacementCount; $i++) { |
| 564 | 564 | $key = $i - 1; |
| 565 | 565 | $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase); |
@@ -577,11 +577,11 @@ discard block |
||
| 577 | 577 | * |
| 578 | 578 | * @param type $inputArg |
| 579 | 579 | * @param string $callbackFunc |
| 580 | - * |
|
| 580 | + * |
|
| 581 | 581 | * @return mixed |
| 582 | 582 | */ |
| 583 | 583 | protected function _runCallback($inputArg, $callbackFunc) { |
| 584 | - return eval('return ' . $callbackFunc . '("' . $inputArg . '");'); |
|
| 584 | + return eval('return ' . $callbackFunc . '("' . $inputArg . '");'); |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | /** |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | * arguments. |
| 591 | 591 | * |
| 592 | 592 | * @param string $callbackFunc |
| 593 | - * |
|
| 593 | + * |
|
| 594 | 594 | * @return mixed |
| 595 | 595 | */ |
| 596 | 596 | protected function _runEmptyCallback($callbackFunc) { |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | * Gets a specific label of a specific field input name. |
| 602 | 602 | * |
| 603 | 603 | * @param string $inputName |
| 604 | - * |
|
| 604 | + * |
|
| 605 | 605 | * @return string |
| 606 | 606 | */ |
| 607 | 607 | protected function _getLabel($inputName) { |
@@ -614,7 +614,7 @@ discard block |
||
| 614 | 614 | * @param string $ruleName the rule name for this validation ("required") |
| 615 | 615 | * @param array $ruleArgs the rules argument |
| 616 | 616 | */ |
| 617 | - protected function _validateRequired($inputName, $ruleName, array $ruleArgs) { |
|
| 617 | + protected function _validateRequired($inputName, $ruleName, array $ruleArgs) { |
|
| 618 | 618 | $inputVal = $this->post($inputName); |
| 619 | 619 | if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) { |
| 620 | 620 | $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]); |
@@ -622,8 +622,8 @@ discard block |
||
| 622 | 622 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 623 | 623 | } |
| 624 | 624 | } |
| 625 | - else if($inputVal == '') { |
|
| 626 | - $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
|
| 625 | + else if($inputVal == '') { |
|
| 626 | + $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
|
| 627 | 627 | } |
| 628 | 628 | } |
| 629 | 629 | |
@@ -647,10 +647,10 @@ discard block |
||
| 647 | 647 | */ |
| 648 | 648 | protected function _validateCallback($inputName, $ruleName, array $ruleArgs) { |
| 649 | 649 | if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) { |
| 650 | - $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]); |
|
| 651 | - if(! $result){ |
|
| 652 | - $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
|
| 653 | - } |
|
| 650 | + $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]); |
|
| 651 | + if(! $result){ |
|
| 652 | + $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
|
| 653 | + } |
|
| 654 | 654 | } |
| 655 | 655 | } |
| 656 | 656 | |
@@ -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; |
@@ -774,7 +774,7 @@ discard block |
||
| 774 | 774 | * @param string $ruleName the rule name for this validation ("less_than") |
| 775 | 775 | * @param array $ruleArgs the rules argument |
| 776 | 776 | */ |
| 777 | - protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) { |
|
| 777 | + protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) { |
|
| 778 | 778 | $inputVal = $this->post($inputName); |
| 779 | 779 | if ($inputVal >= $ruleArgs[1]) { |
| 780 | 780 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
@@ -790,7 +790,7 @@ discard block |
||
| 790 | 790 | * @param string $ruleName the rule name for this validation ("greater_than") |
| 791 | 791 | * @param array $ruleArgs the rules argument |
| 792 | 792 | */ |
| 793 | - protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) { |
|
| 793 | + protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) { |
|
| 794 | 794 | $inputVal = $this->post($inputName); |
| 795 | 795 | if ($inputVal <= $ruleArgs[1]) { |
| 796 | 796 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
@@ -806,7 +806,7 @@ discard block |
||
| 806 | 806 | * @param string $ruleName the rule name for this validation ("numeric") |
| 807 | 807 | * @param array $ruleArgs the rules argument |
| 808 | 808 | */ |
| 809 | - protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) { |
|
| 809 | + protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) { |
|
| 810 | 810 | $inputVal = $this->post($inputName); |
| 811 | 811 | if (! is_numeric($inputVal)) { |
| 812 | 812 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
@@ -822,18 +822,18 @@ discard block |
||
| 822 | 822 | * @param string $ruleName the rule name for this validation ("exists") |
| 823 | 823 | * @param array $ruleArgs the rules argument |
| 824 | 824 | */ |
| 825 | - protected function _validateExists($inputName, $ruleName, array $ruleArgs) { |
|
| 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 | 829 | if(isset($obj->database)){ |
| 830 | 830 | $this->databaseInstance = $obj->database; |
| 831 | 831 | } |
| 832 | 832 | } |
| 833 | - list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 834 | - $this->databaseInstance->getQueryBuilder()->from($table) |
|
| 835 | - ->where($column, $inputVal); |
|
| 836 | - $this->databaseInstance->get(); |
|
| 833 | + list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 834 | + $this->databaseInstance->getQueryBuilder()->from($table) |
|
| 835 | + ->where($column, $inputVal); |
|
| 836 | + $this->databaseInstance->get(); |
|
| 837 | 837 | if ($this->databaseInstance->numRows() <= 0) { |
| 838 | 838 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
| 839 | 839 | return; |
@@ -848,7 +848,7 @@ discard block |
||
| 848 | 848 | * @param string $ruleName the rule name for this validation ("is_unique") |
| 849 | 849 | * @param array $ruleArgs the rules argument |
| 850 | 850 | */ |
| 851 | - protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) { |
|
| 851 | + protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) { |
|
| 852 | 852 | $inputVal = $this->post($inputName); |
| 853 | 853 | if (! is_object($this->databaseInstance)){ |
| 854 | 854 | $obj = & get_instance(); |
@@ -856,11 +856,11 @@ discard block |
||
| 856 | 856 | $this->databaseInstance = $obj->database; |
| 857 | 857 | } |
| 858 | 858 | } |
| 859 | - list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 860 | - $this->databaseInstance->getQueryBuilder()->from($table) |
|
| 861 | - ->where($column, $inputVal); |
|
| 862 | - $this->databaseInstance->get(); |
|
| 863 | - if ($this->databaseInstance->numRows() > 0) { |
|
| 859 | + list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 860 | + $this->databaseInstance->getQueryBuilder()->from($table) |
|
| 861 | + ->where($column, $inputVal); |
|
| 862 | + $this->databaseInstance->get(); |
|
| 863 | + if ($this->databaseInstance->numRows() > 0) { |
|
| 864 | 864 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
| 865 | 865 | return; |
| 866 | 866 | } |
@@ -874,25 +874,25 @@ discard block |
||
| 874 | 874 | * @param string $ruleName the rule name for this validation ("is_unique_update") |
| 875 | 875 | * @param array $ruleArgs the rules argument |
| 876 | 876 | */ |
| 877 | - protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) { |
|
| 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 | 881 | if(isset($obj->database)){ |
| 882 | 882 | $this->databaseInstance = $obj->database; |
| 883 | 883 | } |
| 884 | 884 | } |
| 885 | - $data = explode(',', $ruleArgs[1]); |
|
| 886 | - if(count($data) < 2){ |
|
| 887 | - return; |
|
| 888 | - } |
|
| 889 | - list($table, $column) = explode('.', $data[0]); |
|
| 890 | - list($field, $val) = explode('=', $data[1]); |
|
| 891 | - $this->databaseInstance->getQueryBuilder()->from($table) |
|
| 892 | - ->where($column, $inputVal) |
|
| 893 | - ->where($field, '!=', trim($val)); |
|
| 885 | + $data = explode(',', $ruleArgs[1]); |
|
| 886 | + if(count($data) < 2){ |
|
| 887 | + return; |
|
| 888 | + } |
|
| 889 | + list($table, $column) = explode('.', $data[0]); |
|
| 890 | + list($field, $val) = explode('=', $data[1]); |
|
| 891 | + $this->databaseInstance->getQueryBuilder()->from($table) |
|
| 892 | + ->where($column, $inputVal) |
|
| 893 | + ->where($field, '!=', trim($val)); |
|
| 894 | 894 | $this->databaseInstance->get(); |
| 895 | - if ($this->databaseInstance->numRows() > 0) { |
|
| 895 | + if ($this->databaseInstance->numRows() > 0) { |
|
| 896 | 896 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
| 897 | 897 | return; |
| 898 | 898 | } |
@@ -908,7 +908,7 @@ discard block |
||
| 908 | 908 | */ |
| 909 | 909 | protected function _validateInList($inputName, $ruleName, array $ruleArgs) { |
| 910 | 910 | $inputVal = $this->post($inputName); |
| 911 | - $list = explode(',', $ruleArgs[1]); |
|
| 911 | + $list = explode(',', $ruleArgs[1]); |
|
| 912 | 912 | $list = array_map('trim', $list); |
| 913 | 913 | if (! in_array($inputVal, $list)) { |
| 914 | 914 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
@@ -926,7 +926,7 @@ discard block |
||
| 926 | 926 | */ |
| 927 | 927 | protected function _validateRegex($inputName, $ruleName, array $ruleArgs) { |
| 928 | 928 | $inputVal = $this->post($inputName); |
| 929 | - $regex = $ruleArgs[1]; |
|
| 929 | + $regex = $ruleArgs[1]; |
|
| 930 | 930 | if (! preg_match($regex, $inputVal)) { |
| 931 | 931 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
| 932 | 932 | return; |
@@ -1669,34 +1669,34 @@ |
||
| 1669 | 1669 | protected function checkPlatform() |
| 1670 | 1670 | { |
| 1671 | 1671 | $platformMaps = array( |
| 1672 | - 'windows' => self::PLATFORM_WINDOWS, |
|
| 1673 | - 'iPad' => self::PLATFORM_IPAD, |
|
| 1674 | - 'iPod' => self::PLATFORM_IPOD, |
|
| 1675 | - 'iPhone' => self::PLATFORM_IPHONE, |
|
| 1676 | - 'mac' => self::PLATFORM_APPLE, |
|
| 1677 | - 'android' => self::PLATFORM_ANDROID, |
|
| 1678 | - 'Silk' => self::PLATFORM_FIRE_OS, |
|
| 1679 | - 'linux_smarttv' => self::PLATFORM_LINUX .'/'.self::PLATFORM_SMART_TV, |
|
| 1680 | - 'linux' => self::PLATFORM_LINUX, |
|
| 1681 | - 'Nokia' => self::PLATFORM_NOKIA, |
|
| 1682 | - 'BlackBerry' => self::PLATFORM_BLACKBERRY, |
|
| 1683 | - 'FreeBSD' => self::PLATFORM_FREEBSD, |
|
| 1684 | - 'OpenBSD' => self::PLATFORM_OPENBSD, |
|
| 1685 | - 'NetBSD' => self::PLATFORM_NETBSD, |
|
| 1686 | - 'OpenSolaris' => self::PLATFORM_OPENSOLARIS, |
|
| 1687 | - 'SunOS' => self::PLATFORM_SUNOS, |
|
| 1688 | - 'OS\/2' => self::PLATFORM_OS2, |
|
| 1689 | - 'BeOS' => self::PLATFORM_BEOS, |
|
| 1690 | - 'win' => self::PLATFORM_WINDOWS, |
|
| 1691 | - 'Playstation' => self::PLATFORM_PLAYSTATION, |
|
| 1692 | - 'Roku' => self::PLATFORM_ROKU, |
|
| 1693 | - 'iOS' => self::PLATFORM_IPHONE . '/' . self::PLATFORM_IPAD, |
|
| 1694 | - 'tvOS' => self::PLATFORM_APPLE_TV, |
|
| 1695 | - 'curl' => self::PLATFORM_TERMINAL, |
|
| 1696 | - 'CrOS' => self::PLATFORM_CHROME_OS, |
|
| 1697 | - 'okhttp' => self::PLATFORM_JAVA_ANDROID, |
|
| 1698 | - 'PostmanRuntime' => self::PLATFORM_POSTMAN, |
|
| 1699 | - 'Iframely' => self::PLATFORM_I_FRAME |
|
| 1672 | + 'windows' => self::PLATFORM_WINDOWS, |
|
| 1673 | + 'iPad' => self::PLATFORM_IPAD, |
|
| 1674 | + 'iPod' => self::PLATFORM_IPOD, |
|
| 1675 | + 'iPhone' => self::PLATFORM_IPHONE, |
|
| 1676 | + 'mac' => self::PLATFORM_APPLE, |
|
| 1677 | + 'android' => self::PLATFORM_ANDROID, |
|
| 1678 | + 'Silk' => self::PLATFORM_FIRE_OS, |
|
| 1679 | + 'linux_smarttv' => self::PLATFORM_LINUX .'/'.self::PLATFORM_SMART_TV, |
|
| 1680 | + 'linux' => self::PLATFORM_LINUX, |
|
| 1681 | + 'Nokia' => self::PLATFORM_NOKIA, |
|
| 1682 | + 'BlackBerry' => self::PLATFORM_BLACKBERRY, |
|
| 1683 | + 'FreeBSD' => self::PLATFORM_FREEBSD, |
|
| 1684 | + 'OpenBSD' => self::PLATFORM_OPENBSD, |
|
| 1685 | + 'NetBSD' => self::PLATFORM_NETBSD, |
|
| 1686 | + 'OpenSolaris' => self::PLATFORM_OPENSOLARIS, |
|
| 1687 | + 'SunOS' => self::PLATFORM_SUNOS, |
|
| 1688 | + 'OS\/2' => self::PLATFORM_OS2, |
|
| 1689 | + 'BeOS' => self::PLATFORM_BEOS, |
|
| 1690 | + 'win' => self::PLATFORM_WINDOWS, |
|
| 1691 | + 'Playstation' => self::PLATFORM_PLAYSTATION, |
|
| 1692 | + 'Roku' => self::PLATFORM_ROKU, |
|
| 1693 | + 'iOS' => self::PLATFORM_IPHONE . '/' . self::PLATFORM_IPAD, |
|
| 1694 | + 'tvOS' => self::PLATFORM_APPLE_TV, |
|
| 1695 | + 'curl' => self::PLATFORM_TERMINAL, |
|
| 1696 | + 'CrOS' => self::PLATFORM_CHROME_OS, |
|
| 1697 | + 'okhttp' => self::PLATFORM_JAVA_ANDROID, |
|
| 1698 | + 'PostmanRuntime' => self::PLATFORM_POSTMAN, |
|
| 1699 | + 'Iframely' => self::PLATFORM_I_FRAME |
|
| 1700 | 1700 | ); |
| 1701 | 1701 | |
| 1702 | 1702 | foreach ($platformMaps as $name => $value) { |
@@ -1,71 +1,71 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @file function_string.php |
|
| 29 | - * |
|
| 30 | - * This file contains the definition of the functions relating to the processing of strings characters. |
|
| 31 | - * |
|
| 32 | - * @package core |
|
| 33 | - * @author Tony NGUEREZA |
|
| 34 | - * @copyright Copyright (c) 2017 |
|
| 35 | - * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 36 | - * @link http://www.iacademy.cf |
|
| 37 | - * @version 1.0.0 |
|
| 38 | - * @since 1.0.0 |
|
| 39 | - * @filesource |
|
| 40 | - */ |
|
| 27 | + /** |
|
| 28 | + * @file function_string.php |
|
| 29 | + * |
|
| 30 | + * This file contains the definition of the functions relating to the processing of strings characters. |
|
| 31 | + * |
|
| 32 | + * @package core |
|
| 33 | + * @author Tony NGUEREZA |
|
| 34 | + * @copyright Copyright (c) 2017 |
|
| 35 | + * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 36 | + * @link http://www.iacademy.cf |
|
| 37 | + * @version 1.0.0 |
|
| 38 | + * @since 1.0.0 |
|
| 39 | + * @filesource |
|
| 40 | + */ |
|
| 41 | 41 | |
| 42 | - if(! function_exists('get_random_string')){ |
|
| 43 | - /** |
|
| 44 | - * Generate a random string |
|
| 45 | - * @param string $type the type of generation. It can take the values: "alpha" for alphabetic characters, |
|
| 46 | - * "alnum" for alpha-numeric characters and "num" for numbers. |
|
| 47 | - * By default it is "alnum". |
|
| 48 | - * @param integer $length the length of the string to generate. By default it is 10. |
|
| 49 | - * @param boolean $lower if we return the generated string in lowercase (true). By default it's false. |
|
| 50 | - * @return string the generated string. |
|
| 51 | - */ |
|
| 52 | - function get_random_string($type = 'alnum', $length = 10, $lower = false){ |
|
| 53 | - $chars = array( |
|
| 54 | - 'alpha' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', |
|
| 55 | - 'alnum' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', |
|
| 56 | - 'num' => '1234567890' |
|
| 57 | - ); |
|
| 58 | - $str = null; |
|
| 59 | - if(isset($chars[$type])){ |
|
| 60 | - $str = $chars[$type]; |
|
| 61 | - } |
|
| 62 | - $random = null; |
|
| 63 | - for($i = 0; $i < $length; $i++){ |
|
| 64 | - $random .= $str[mt_rand() % strlen($str)]; |
|
| 65 | - } |
|
| 66 | - if($lower){ |
|
| 67 | - $random = strtolower($random); |
|
| 68 | - } |
|
| 69 | - return $random; |
|
| 70 | - } |
|
| 71 | - } |
|
| 42 | + if(! function_exists('get_random_string')){ |
|
| 43 | + /** |
|
| 44 | + * Generate a random string |
|
| 45 | + * @param string $type the type of generation. It can take the values: "alpha" for alphabetic characters, |
|
| 46 | + * "alnum" for alpha-numeric characters and "num" for numbers. |
|
| 47 | + * By default it is "alnum". |
|
| 48 | + * @param integer $length the length of the string to generate. By default it is 10. |
|
| 49 | + * @param boolean $lower if we return the generated string in lowercase (true). By default it's false. |
|
| 50 | + * @return string the generated string. |
|
| 51 | + */ |
|
| 52 | + function get_random_string($type = 'alnum', $length = 10, $lower = false){ |
|
| 53 | + $chars = array( |
|
| 54 | + 'alpha' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', |
|
| 55 | + 'alnum' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', |
|
| 56 | + 'num' => '1234567890' |
|
| 57 | + ); |
|
| 58 | + $str = null; |
|
| 59 | + if(isset($chars[$type])){ |
|
| 60 | + $str = $chars[$type]; |
|
| 61 | + } |
|
| 62 | + $random = null; |
|
| 63 | + for($i = 0; $i < $length; $i++){ |
|
| 64 | + $random .= $str[mt_rand() % strlen($str)]; |
|
| 65 | + } |
|
| 66 | + if($lower){ |
|
| 67 | + $random = strtolower($random); |
|
| 68 | + } |
|
| 69 | + return $random; |
|
| 70 | + } |
|
| 71 | + } |
|
@@ -1,108 +1,108 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | defined('ROOT_PATH') || exit('Access denied'); |
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 26 | - class DatabaseQueryBuilder{ |
|
| 27 | - /** |
|
| 28 | - * The SQL SELECT statment |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - private $select = '*'; |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | + class DatabaseQueryBuilder{ |
|
| 27 | + /** |
|
| 28 | + * The SQL SELECT statment |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + private $select = '*'; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * The SQL FROM statment |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 37 | - private $from = null; |
|
| 33 | + /** |
|
| 34 | + * The SQL FROM statment |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | + private $from = null; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * The SQL WHERE statment |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 43 | - private $where = null; |
|
| 39 | + /** |
|
| 40 | + * The SQL WHERE statment |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | + private $where = null; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * The SQL LIMIT statment |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - private $limit = null; |
|
| 45 | + /** |
|
| 46 | + * The SQL LIMIT statment |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + private $limit = null; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * The SQL JOIN statment |
|
| 53 | - * @var string |
|
| 54 | - */ |
|
| 55 | - private $join = null; |
|
| 51 | + /** |
|
| 52 | + * The SQL JOIN statment |
|
| 53 | + * @var string |
|
| 54 | + */ |
|
| 55 | + private $join = null; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * The SQL ORDER BY statment |
|
| 59 | - * @var string |
|
| 60 | - */ |
|
| 61 | - private $orderBy = null; |
|
| 57 | + /** |
|
| 58 | + * The SQL ORDER BY statment |
|
| 59 | + * @var string |
|
| 60 | + */ |
|
| 61 | + private $orderBy = null; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * The SQL GROUP BY statment |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 67 | - private $groupBy = null; |
|
| 63 | + /** |
|
| 64 | + * The SQL GROUP BY statment |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | + private $groupBy = null; |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * The SQL HAVING statment |
|
| 71 | - * @var string |
|
| 72 | - */ |
|
| 73 | - private $having = null; |
|
| 69 | + /** |
|
| 70 | + * The SQL HAVING statment |
|
| 71 | + * @var string |
|
| 72 | + */ |
|
| 73 | + private $having = null; |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * The full SQL query statment after build for each command |
|
| 77 | - * @var string |
|
| 78 | - */ |
|
| 79 | - private $query = null; |
|
| 75 | + /** |
|
| 76 | + * The full SQL query statment after build for each command |
|
| 77 | + * @var string |
|
| 78 | + */ |
|
| 79 | + private $query = null; |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * The list of SQL valid operators |
|
| 83 | - * @var array |
|
| 84 | - */ |
|
| 81 | + /** |
|
| 82 | + * The list of SQL valid operators |
|
| 83 | + * @var array |
|
| 84 | + */ |
|
| 85 | 85 | private $operatorList = array('=','!=','<','>','<=','>=','<>'); |
| 86 | 86 | |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * The prefix used in each database table |
|
| 90 | - * @var string |
|
| 91 | - */ |
|
| 88 | + /** |
|
| 89 | + * The prefix used in each database table |
|
| 90 | + * @var string |
|
| 91 | + */ |
|
| 92 | 92 | private $prefix = null; |
| 93 | 93 | |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | - * The PDO instance |
|
| 97 | - * @var object |
|
| 98 | - */ |
|
| 96 | + * The PDO instance |
|
| 97 | + * @var object |
|
| 98 | + */ |
|
| 99 | 99 | private $pdo = null; |
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * The database driver name used |
|
| 103 | - * @var string |
|
| 104 | - */ |
|
| 105 | - private $driver = null; |
|
| 101 | + /** |
|
| 102 | + * The database driver name used |
|
| 103 | + * @var string |
|
| 104 | + */ |
|
| 105 | + private $driver = null; |
|
| 106 | 106 | |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | public function __construct(PDO $pdo = null){ |
| 113 | 113 | if (is_object($pdo)){ |
| 114 | - $this->setPdo($pdo); |
|
| 114 | + $this->setPdo($pdo); |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
@@ -121,16 +121,16 @@ discard block |
||
| 121 | 121 | * @return object the current DatabaseQueryBuilder instance |
| 122 | 122 | */ |
| 123 | 123 | public function from($table){ |
| 124 | - if (is_array($table)){ |
|
| 124 | + if (is_array($table)){ |
|
| 125 | 125 | $froms = ''; |
| 126 | 126 | foreach($table as $key){ |
| 127 | - $froms .= $this->getPrefix() . $key . ', '; |
|
| 127 | + $froms .= $this->getPrefix() . $key . ', '; |
|
| 128 | 128 | } |
| 129 | 129 | $this->from = rtrim($froms, ', '); |
| 130 | - } else { |
|
| 130 | + } else { |
|
| 131 | 131 | $this->from = $this->getPrefix() . $table; |
| 132 | - } |
|
| 133 | - return $this; |
|
| 132 | + } |
|
| 133 | + return $this; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -139,9 +139,9 @@ discard block |
||
| 139 | 139 | * @return object the current DatabaseQueryBuilder instance |
| 140 | 140 | */ |
| 141 | 141 | public function select($fields){ |
| 142 | - $select = (is_array($fields) ? implode(', ', $fields) : $fields); |
|
| 143 | - $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select); |
|
| 144 | - return $this; |
|
| 142 | + $select = (is_array($fields) ? implode(', ', $fields) : $fields); |
|
| 143 | + $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select); |
|
| 144 | + return $this; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -150,19 +150,19 @@ discard block |
||
| 150 | 150 | * @return object the current DatabaseQueryBuilder instance |
| 151 | 151 | */ |
| 152 | 152 | public function distinct($field){ |
| 153 | - $distinct = ' DISTINCT ' . $field; |
|
| 154 | - $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct); |
|
| 155 | - return $this; |
|
| 153 | + $distinct = ' DISTINCT ' . $field; |
|
| 154 | + $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct); |
|
| 155 | + return $this; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * Set the SQL function COUNT in SELECT statment |
|
| 160 | - * @param string $field the field name |
|
| 161 | - * @param string $name if is not null represent the alias used for this field in the result |
|
| 162 | - * @return object the current DatabaseQueryBuilder instance |
|
| 163 | - */ |
|
| 158 | + /** |
|
| 159 | + * Set the SQL function COUNT in SELECT statment |
|
| 160 | + * @param string $field the field name |
|
| 161 | + * @param string $name if is not null represent the alias used for this field in the result |
|
| 162 | + * @return object the current DatabaseQueryBuilder instance |
|
| 163 | + */ |
|
| 164 | 164 | public function count($field = '*', $name = null){ |
| 165 | - return $this->select_min_max_sum_count_avg('COUNT', $field, $name); |
|
| 165 | + return $this->select_min_max_sum_count_avg('COUNT', $field, $name); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * @return object the current DatabaseQueryBuilder instance |
| 173 | 173 | */ |
| 174 | 174 | public function min($field, $name = null){ |
| 175 | - return $this->select_min_max_sum_count_avg('MIN', $field, $name); |
|
| 175 | + return $this->select_min_max_sum_count_avg('MIN', $field, $name); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * @return object the current DatabaseQueryBuilder instance |
| 183 | 183 | */ |
| 184 | 184 | public function max($field, $name = null){ |
| 185 | - return $this->select_min_max_sum_count_avg('MAX', $field, $name); |
|
| 185 | + return $this->select_min_max_sum_count_avg('MAX', $field, $name); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | * @return object the current DatabaseQueryBuilder instance |
| 193 | 193 | */ |
| 194 | 194 | public function sum($field, $name = null){ |
| 195 | - return $this->select_min_max_sum_count_avg('SUM', $field, $name); |
|
| 195 | + return $this->select_min_max_sum_count_avg('SUM', $field, $name); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | /** |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @return object the current DatabaseQueryBuilder instance |
| 203 | 203 | */ |
| 204 | 204 | public function avg($field, $name = null){ |
| 205 | - return $this->select_min_max_sum_count_avg('AVG', $field, $name); |
|
| 205 | + return $this->select_min_max_sum_count_avg('AVG', $field, $name); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | |
@@ -216,20 +216,20 @@ discard block |
||
| 216 | 216 | * @return object the current DatabaseQueryBuilder instance |
| 217 | 217 | */ |
| 218 | 218 | public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){ |
| 219 | - $on = $field1; |
|
| 220 | - $table = $this->getPrefix() . $table; |
|
| 221 | - if (! is_null($op)){ |
|
| 219 | + $on = $field1; |
|
| 220 | + $table = $this->getPrefix() . $table; |
|
| 221 | + if (! is_null($op)){ |
|
| 222 | 222 | $on = (! in_array($op, $this->operatorList) |
| 223 | - ? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) |
|
| 224 | - : ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2)); |
|
| 225 | - } |
|
| 226 | - if (empty($this->join)){ |
|
| 223 | + ? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) |
|
| 224 | + : ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2)); |
|
| 225 | + } |
|
| 226 | + if (empty($this->join)){ |
|
| 227 | 227 | $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
| 228 | - } |
|
| 229 | - else{ |
|
| 228 | + } |
|
| 229 | + else{ |
|
| 230 | 230 | $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
| 231 | - } |
|
| 232 | - return $this; |
|
| 231 | + } |
|
| 232 | + return $this; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | * @return object the current DatabaseQueryBuilder instance |
| 239 | 239 | */ |
| 240 | 240 | public function innerJoin($table, $field1, $op = null, $field2 = ''){ |
| 241 | - return $this->join($table, $field1, $op, $field2, 'INNER '); |
|
| 241 | + return $this->join($table, $field1, $op, $field2, 'INNER '); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -247,16 +247,16 @@ discard block |
||
| 247 | 247 | * @return object the current DatabaseQueryBuilder instance |
| 248 | 248 | */ |
| 249 | 249 | public function leftJoin($table, $field1, $op = null, $field2 = ''){ |
| 250 | - return $this->join($table, $field1, $op, $field2, 'LEFT '); |
|
| 251 | - } |
|
| 250 | + return $this->join($table, $field1, $op, $field2, 'LEFT '); |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 253 | + /** |
|
| 254 | 254 | * Set the SQL RIGHT JOIN statment |
| 255 | 255 | * @see DatabaseQueryBuilder::join() |
| 256 | 256 | * @return object the current DatabaseQueryBuilder instance |
| 257 | 257 | */ |
| 258 | 258 | public function rightJoin($table, $field1, $op = null, $field2 = ''){ |
| 259 | - return $this->join($table, $field1, $op, $field2, 'RIGHT '); |
|
| 259 | + return $this->join($table, $field1, $op, $field2, 'RIGHT '); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | * @return object the current DatabaseQueryBuilder instance |
| 266 | 266 | */ |
| 267 | 267 | public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){ |
| 268 | - return $this->join($table, $field1, $op, $field2, 'FULL OUTER '); |
|
| 268 | + return $this->join($table, $field1, $op, $field2, 'FULL OUTER '); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | * @return object the current DatabaseQueryBuilder instance |
| 275 | 275 | */ |
| 276 | 276 | public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){ |
| 277 | - return $this->join($table, $field1, $op, $field2, 'LEFT OUTER '); |
|
| 277 | + return $this->join($table, $field1, $op, $field2, 'LEFT OUTER '); |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | /** |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * @return object the current DatabaseQueryBuilder instance |
| 284 | 284 | */ |
| 285 | 285 | public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){ |
| 286 | - return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER '); |
|
| 286 | + return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER '); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | /** |
@@ -293,14 +293,14 @@ discard block |
||
| 293 | 293 | * @return object the current DatabaseQueryBuilder instance |
| 294 | 294 | */ |
| 295 | 295 | public function whereIsNull($field, $andOr = 'AND'){ |
| 296 | - if (is_array($field)){ |
|
| 296 | + if (is_array($field)){ |
|
| 297 | 297 | foreach($field as $f){ |
| 298 | - $this->whereIsNull($f, $andOr); |
|
| 298 | + $this->whereIsNull($f, $andOr); |
|
| 299 | 299 | } |
| 300 | - } else { |
|
| 301 | - $this->setWhereStr($field.' IS NULL ', $andOr); |
|
| 302 | - } |
|
| 303 | - return $this; |
|
| 300 | + } else { |
|
| 301 | + $this->setWhereStr($field.' IS NULL ', $andOr); |
|
| 302 | + } |
|
| 303 | + return $this; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -310,14 +310,14 @@ discard block |
||
| 310 | 310 | * @return object the current DatabaseQueryBuilder instance |
| 311 | 311 | */ |
| 312 | 312 | public function whereIsNotNull($field, $andOr = 'AND'){ |
| 313 | - if (is_array($field)){ |
|
| 313 | + if (is_array($field)){ |
|
| 314 | 314 | foreach($field as $f){ |
| 315 | - $this->whereIsNotNull($f, $andOr); |
|
| 315 | + $this->whereIsNotNull($f, $andOr); |
|
| 316 | + } |
|
| 317 | + } else { |
|
| 318 | + $this->setWhereStr($field.' IS NOT NULL ', $andOr); |
|
| 316 | 319 | } |
| 317 | - } else { |
|
| 318 | - $this->setWhereStr($field.' IS NOT NULL ', $andOr); |
|
| 319 | - } |
|
| 320 | - return $this; |
|
| 320 | + return $this; |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
@@ -331,19 +331,19 @@ discard block |
||
| 331 | 331 | * @return object the current DatabaseQueryBuilder instance |
| 332 | 332 | */ |
| 333 | 333 | public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){ |
| 334 | - $whereStr = ''; |
|
| 335 | - if (is_array($where)){ |
|
| 334 | + $whereStr = ''; |
|
| 335 | + if (is_array($where)){ |
|
| 336 | 336 | $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape); |
| 337 | - } |
|
| 338 | - else{ |
|
| 337 | + } |
|
| 338 | + else{ |
|
| 339 | 339 | if (is_array($op)){ |
| 340 | - $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape); |
|
| 340 | + $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape); |
|
| 341 | 341 | } else { |
| 342 | - $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape); |
|
| 342 | + $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape); |
|
| 343 | + } |
|
| 343 | 344 | } |
| 344 | - } |
|
| 345 | - $this->setWhereStr($whereStr, $andOr); |
|
| 346 | - return $this; |
|
| 345 | + $this->setWhereStr($whereStr, $andOr); |
|
| 346 | + return $this; |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | * @return object the current DatabaseQueryBuilder instance |
| 353 | 353 | */ |
| 354 | 354 | public function orWhere($where, $op = null, $val = null, $escape = true){ |
| 355 | - return $this->where($where, $op, $val, '', 'OR', $escape); |
|
| 355 | + return $this->where($where, $op, $val, '', 'OR', $escape); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | * @return object the current DatabaseQueryBuilder instance |
| 363 | 363 | */ |
| 364 | 364 | public function notWhere($where, $op = null, $val = null, $escape = true){ |
| 365 | - return $this->where($where, $op, $val, 'NOT ', 'AND', $escape); |
|
| 365 | + return $this->where($where, $op, $val, 'NOT ', 'AND', $escape); |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | /** |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | * @return object the current DatabaseQueryBuilder instance |
| 372 | 372 | */ |
| 373 | 373 | public function orNotWhere($where, $op = null, $val = null, $escape = true){ |
| 374 | - return $this->where($where, $op, $val, 'NOT ', 'OR', $escape); |
|
| 374 | + return $this->where($where, $op, $val, 'NOT ', 'OR', $escape); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
@@ -381,16 +381,16 @@ discard block |
||
| 381 | 381 | * @return object the current DatabaseQueryBuilder instance |
| 382 | 382 | */ |
| 383 | 383 | public function groupStart($type = '', $andOr = ' AND'){ |
| 384 | - if (empty($this->where)){ |
|
| 384 | + if (empty($this->where)){ |
|
| 385 | 385 | $this->where = $type . ' ('; |
| 386 | - } else { |
|
| 387 | - if (substr(trim($this->where), -1) == '('){ |
|
| 386 | + } else { |
|
| 387 | + if (substr(trim($this->where), -1) == '('){ |
|
| 388 | 388 | $this->where .= $type . ' ('; |
| 389 | - } else { |
|
| 390 | - $this->where .= $andOr . ' ' . $type . ' ('; |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - return $this; |
|
| 389 | + } else { |
|
| 390 | + $this->where .= $andOr . ' ' . $type . ' ('; |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + return $this; |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | * @return object the current DatabaseQueryBuilder instance |
| 400 | 400 | */ |
| 401 | 401 | public function notGroupStart(){ |
| 402 | - return $this->groupStart('NOT'); |
|
| 402 | + return $this->groupStart('NOT'); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -408,16 +408,16 @@ discard block |
||
| 408 | 408 | * @return object the current DatabaseQueryBuilder instance |
| 409 | 409 | */ |
| 410 | 410 | public function orGroupStart(){ |
| 411 | - return $this->groupStart('', ' OR'); |
|
| 411 | + return $this->groupStart('', ' OR'); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - /** |
|
| 415 | - * Set the opened parenthesis for the complex SQL query using OR for separator and NOT for type |
|
| 416 | - * @see DatabaseQueryBuilder::groupStart() |
|
| 417 | - * @return object the current DatabaseQueryBuilder instance |
|
| 418 | - */ |
|
| 414 | + /** |
|
| 415 | + * Set the opened parenthesis for the complex SQL query using OR for separator and NOT for type |
|
| 416 | + * @see DatabaseQueryBuilder::groupStart() |
|
| 417 | + * @return object the current DatabaseQueryBuilder instance |
|
| 418 | + */ |
|
| 419 | 419 | public function orNotGroupStart(){ |
| 420 | - return $this->groupStart('NOT', ' OR'); |
|
| 420 | + return $this->groupStart('NOT', ' OR'); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -425,8 +425,8 @@ discard block |
||
| 425 | 425 | * @return object the current DatabaseQueryBuilder instance |
| 426 | 426 | */ |
| 427 | 427 | public function groupEnd(){ |
| 428 | - $this->where .= ')'; |
|
| 429 | - return $this; |
|
| 428 | + $this->where .= ')'; |
|
| 429 | + return $this; |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | /** |
@@ -439,17 +439,17 @@ discard block |
||
| 439 | 439 | * @return object the current DatabaseQueryBuilder instance |
| 440 | 440 | */ |
| 441 | 441 | public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){ |
| 442 | - $_keys = array(); |
|
| 443 | - foreach ($keys as $k => $v){ |
|
| 442 | + $_keys = array(); |
|
| 443 | + foreach ($keys as $k => $v){ |
|
| 444 | 444 | if (is_null($v)){ |
| 445 | - $v = ''; |
|
| 445 | + $v = ''; |
|
| 446 | 446 | } |
| 447 | 447 | $_keys[] = (is_numeric($v) ? $v : $this->escape($v, $escape)); |
| 448 | - } |
|
| 449 | - $keys = implode(', ', $_keys); |
|
| 450 | - $whereStr = $field . ' ' . $type . ' IN (' . $keys . ')'; |
|
| 451 | - $this->setWhereStr($whereStr, $andOr); |
|
| 452 | - return $this; |
|
| 448 | + } |
|
| 449 | + $keys = implode(', ', $_keys); |
|
| 450 | + $whereStr = $field . ' ' . $type . ' IN (' . $keys . ')'; |
|
| 451 | + $this->setWhereStr($whereStr, $andOr); |
|
| 452 | + return $this; |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | /** |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | * @return object the current DatabaseQueryBuilder instance |
| 459 | 459 | */ |
| 460 | 460 | public function notIn($field, array $keys, $escape = true){ |
| 461 | - return $this->in($field, $keys, 'NOT ', 'AND', $escape); |
|
| 461 | + return $this->in($field, $keys, 'NOT ', 'AND', $escape); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | /** |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | * @return object the current DatabaseQueryBuilder instance |
| 468 | 468 | */ |
| 469 | 469 | public function orIn($field, array $keys, $escape = true){ |
| 470 | - return $this->in($field, $keys, '', 'OR', $escape); |
|
| 470 | + return $this->in($field, $keys, '', 'OR', $escape); |
|
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | /** |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | * @return object the current DatabaseQueryBuilder instance |
| 477 | 477 | */ |
| 478 | 478 | public function orNotIn($field, array $keys, $escape = true){ |
| 479 | - return $this->in($field, $keys, 'NOT ', 'OR', $escape); |
|
| 479 | + return $this->in($field, $keys, 'NOT ', 'OR', $escape); |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | /** |
@@ -490,15 +490,15 @@ discard block |
||
| 490 | 490 | * @return object the current DatabaseQueryBuilder instance |
| 491 | 491 | */ |
| 492 | 492 | public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){ |
| 493 | - if (is_null($value1)){ |
|
| 493 | + if (is_null($value1)){ |
|
| 494 | 494 | $value1 = ''; |
| 495 | - } |
|
| 496 | - if (is_null($value2)){ |
|
| 495 | + } |
|
| 496 | + if (is_null($value2)){ |
|
| 497 | 497 | $value2 = ''; |
| 498 | - } |
|
| 499 | - $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape); |
|
| 500 | - $this->setWhereStr($whereStr, $andOr); |
|
| 501 | - return $this; |
|
| 498 | + } |
|
| 499 | + $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape); |
|
| 500 | + $this->setWhereStr($whereStr, $andOr); |
|
| 501 | + return $this; |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | /** |
@@ -507,7 +507,7 @@ discard block |
||
| 507 | 507 | * @return object the current DatabaseQueryBuilder instance |
| 508 | 508 | */ |
| 509 | 509 | public function notBetween($field, $value1, $value2, $escape = true){ |
| 510 | - return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape); |
|
| 510 | + return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | /** |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | * @return object the current DatabaseQueryBuilder instance |
| 517 | 517 | */ |
| 518 | 518 | public function orBetween($field, $value1, $value2, $escape = true){ |
| 519 | - return $this->between($field, $value1, $value2, '', 'OR', $escape); |
|
| 519 | + return $this->between($field, $value1, $value2, '', 'OR', $escape); |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | /** |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | * @return object the current DatabaseQueryBuilder instance |
| 526 | 526 | */ |
| 527 | 527 | public function orNotBetween($field, $value1, $value2, $escape = true){ |
| 528 | - return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape); |
|
| 528 | + return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape); |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | /** |
@@ -538,11 +538,11 @@ discard block |
||
| 538 | 538 | * @return object the current DatabaseQueryBuilder instance |
| 539 | 539 | */ |
| 540 | 540 | public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){ |
| 541 | - if (empty($data)){ |
|
| 541 | + if (empty($data)){ |
|
| 542 | 542 | $data = ''; |
| 543 | - } |
|
| 544 | - $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr); |
|
| 545 | - return $this; |
|
| 543 | + } |
|
| 544 | + $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr); |
|
| 545 | + return $this; |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | /** |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | * @return object the current DatabaseQueryBuilder instance |
| 552 | 552 | */ |
| 553 | 553 | public function orLike($field, $data, $escape = true){ |
| 554 | - return $this->like($field, $data, '', 'OR', $escape); |
|
| 554 | + return $this->like($field, $data, '', 'OR', $escape); |
|
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | /** |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | * @return object the current DatabaseQueryBuilder instance |
| 561 | 561 | */ |
| 562 | 562 | public function notLike($field, $data, $escape = true){ |
| 563 | - return $this->like($field, $data, 'NOT ', 'AND', $escape); |
|
| 563 | + return $this->like($field, $data, 'NOT ', 'AND', $escape); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /** |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | * @return object the current DatabaseQueryBuilder instance |
| 570 | 570 | */ |
| 571 | 571 | public function orNotLike($field, $data, $escape = true){ |
| 572 | - return $this->like($field, $data, 'NOT ', 'OR', $escape); |
|
| 572 | + return $this->like($field, $data, 'NOT ', 'OR', $escape); |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
@@ -580,16 +580,16 @@ discard block |
||
| 580 | 580 | * @return object the current DatabaseQueryBuilder instance |
| 581 | 581 | */ |
| 582 | 582 | public function limit($limit, $limitEnd = null){ |
| 583 | - if (empty($limit)){ |
|
| 583 | + if (empty($limit)){ |
|
| 584 | 584 | $limit = 0; |
| 585 | - } |
|
| 586 | - if (! is_null($limitEnd)){ |
|
| 585 | + } |
|
| 586 | + if (! is_null($limitEnd)){ |
|
| 587 | 587 | $this->limit = $limit . ', ' . $limitEnd; |
| 588 | - } |
|
| 589 | - else{ |
|
| 588 | + } |
|
| 589 | + else{ |
|
| 590 | 590 | $this->limit = $limit; |
| 591 | - } |
|
| 592 | - return $this; |
|
| 591 | + } |
|
| 592 | + return $this; |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | /** |
@@ -599,15 +599,15 @@ discard block |
||
| 599 | 599 | * @return object the current DatabaseQueryBuilder instance |
| 600 | 600 | */ |
| 601 | 601 | public function orderBy($orderBy, $orderDir = ' ASC'){ |
| 602 | - if (stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
|
| 602 | + if (stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
|
| 603 | 603 | $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy; |
| 604 | - } |
|
| 605 | - else{ |
|
| 604 | + } |
|
| 605 | + else{ |
|
| 606 | 606 | $this->orderBy = empty($this->orderBy) |
| 607 | - ? ($orderBy . ' ' . strtoupper($orderDir)) |
|
| 608 | - : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
|
| 609 | - } |
|
| 610 | - return $this; |
|
| 607 | + ? ($orderBy . ' ' . strtoupper($orderDir)) |
|
| 608 | + : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
|
| 609 | + } |
|
| 610 | + return $this; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -616,13 +616,13 @@ discard block |
||
| 616 | 616 | * @return object the current DatabaseQueryBuilder instance |
| 617 | 617 | */ |
| 618 | 618 | public function groupBy($field){ |
| 619 | - if (is_array($field)){ |
|
| 619 | + if (is_array($field)){ |
|
| 620 | 620 | $this->groupBy = implode(', ', $field); |
| 621 | - } |
|
| 622 | - else{ |
|
| 621 | + } |
|
| 622 | + else{ |
|
| 623 | 623 | $this->groupBy = $field; |
| 624 | - } |
|
| 625 | - return $this; |
|
| 624 | + } |
|
| 625 | + return $this; |
|
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | /** |
@@ -634,22 +634,22 @@ discard block |
||
| 634 | 634 | * @return object the current DatabaseQueryBuilder instance |
| 635 | 635 | */ |
| 636 | 636 | public function having($field, $op = null, $val = null, $escape = true){ |
| 637 | - if (is_array($op)){ |
|
| 637 | + if (is_array($op)){ |
|
| 638 | 638 | $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape); |
| 639 | - } |
|
| 640 | - else if (! in_array($op, $this->operatorList)){ |
|
| 639 | + } |
|
| 640 | + else if (! in_array($op, $this->operatorList)){ |
|
| 641 | 641 | if (is_null($op)){ |
| 642 | - $op = ''; |
|
| 642 | + $op = ''; |
|
| 643 | 643 | } |
| 644 | 644 | $this->having = $field . ' > ' . ($this->escape($op, $escape)); |
| 645 | - } |
|
| 646 | - else{ |
|
| 645 | + } |
|
| 646 | + else{ |
|
| 647 | 647 | if (is_null($val)){ |
| 648 | - $val = ''; |
|
| 648 | + $val = ''; |
|
| 649 | 649 | } |
| 650 | 650 | $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape)); |
| 651 | - } |
|
| 652 | - return $this; |
|
| 651 | + } |
|
| 652 | + return $this; |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | /** |
@@ -659,12 +659,12 @@ discard block |
||
| 659 | 659 | * @return object the current DatabaseQueryBuilder instance |
| 660 | 660 | */ |
| 661 | 661 | public function insert($data = array(), $escape = true){ |
| 662 | - $columns = array_keys($data); |
|
| 663 | - $column = implode(', ', $columns); |
|
| 664 | - $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data)); |
|
| 662 | + $columns = array_keys($data); |
|
| 663 | + $column = implode(', ', $columns); |
|
| 664 | + $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data)); |
|
| 665 | 665 | |
| 666 | - $this->query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')'; |
|
| 667 | - return $this; |
|
| 666 | + $this->query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')'; |
|
| 667 | + return $this; |
|
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | /** |
@@ -674,25 +674,25 @@ discard block |
||
| 674 | 674 | * @return object the current DatabaseQueryBuilder instance |
| 675 | 675 | */ |
| 676 | 676 | public function update($data = array(), $escape = true){ |
| 677 | - $query = 'UPDATE ' . $this->from . ' SET '; |
|
| 678 | - $values = array(); |
|
| 679 | - foreach ($data as $column => $val){ |
|
| 677 | + $query = 'UPDATE ' . $this->from . ' SET '; |
|
| 678 | + $values = array(); |
|
| 679 | + foreach ($data as $column => $val){ |
|
| 680 | 680 | $values[] = $column . ' = ' . ($this->escape($val, $escape)); |
| 681 | - } |
|
| 682 | - $query .= implode(', ', $values); |
|
| 683 | - if (! empty($this->where)){ |
|
| 681 | + } |
|
| 682 | + $query .= implode(', ', $values); |
|
| 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 | - } |
|
| 694 | - $this->query = $query; |
|
| 695 | - return $this; |
|
| 693 | + } |
|
| 694 | + $this->query = $query; |
|
| 695 | + return $this; |
|
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | /** |
@@ -700,25 +700,25 @@ discard block |
||
| 700 | 700 | * @return object the current DatabaseQueryBuilder instance |
| 701 | 701 | */ |
| 702 | 702 | public function delete(){ |
| 703 | - $query = 'DELETE FROM ' . $this->from; |
|
| 704 | - $isTruncate = $query; |
|
| 705 | - if (! empty($this->where)){ |
|
| 706 | - $query .= ' WHERE ' . $this->where; |
|
| 707 | - } |
|
| 703 | + $query = 'DELETE FROM ' . $this->from; |
|
| 704 | + $isTruncate = $query; |
|
| 705 | + if (! empty($this->where)){ |
|
| 706 | + $query .= ' WHERE ' . $this->where; |
|
| 707 | + } |
|
| 708 | 708 | |
| 709 | - if (! empty($this->orderBy)){ |
|
| 710 | - $query .= ' ORDER BY ' . $this->orderBy; |
|
| 711 | - } |
|
| 709 | + if (! empty($this->orderBy)){ |
|
| 710 | + $query .= ' ORDER BY ' . $this->orderBy; |
|
| 711 | + } |
|
| 712 | 712 | |
| 713 | - if (! empty($this->limit)){ |
|
| 714 | - $query .= ' LIMIT ' . $this->limit; |
|
| 715 | - } |
|
| 713 | + if (! empty($this->limit)){ |
|
| 714 | + $query .= ' LIMIT ' . $this->limit; |
|
| 715 | + } |
|
| 716 | 716 | |
| 717 | - if ($isTruncate == $query && $this->driver != 'sqlite'){ |
|
| 718 | - $query = 'TRUNCATE TABLE ' . $this->from; |
|
| 719 | - } |
|
| 720 | - $this->query = $query; |
|
| 721 | - return $this; |
|
| 717 | + if ($isTruncate == $query && $this->driver != 'sqlite'){ |
|
| 718 | + $query = 'TRUNCATE TABLE ' . $this->from; |
|
| 719 | + } |
|
| 720 | + $this->query = $query; |
|
| 721 | + return $this; |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | /** |
@@ -728,11 +728,11 @@ discard block |
||
| 728 | 728 | * @return mixed the data after escaped or the same data if not |
| 729 | 729 | */ |
| 730 | 730 | public function escape($data, $escaped = true){ |
| 731 | - $data = trim($data); |
|
| 732 | - if($escaped){ |
|
| 731 | + $data = trim($data); |
|
| 732 | + if($escaped){ |
|
| 733 | 733 | return $this->pdo->quote($data); |
| 734 | - } |
|
| 735 | - return $data; |
|
| 734 | + } |
|
| 735 | + return $data; |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | |
@@ -741,126 +741,126 @@ discard block |
||
| 741 | 741 | * @return string |
| 742 | 742 | */ |
| 743 | 743 | public function getQuery(){ |
| 744 | - //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now |
|
| 745 | - if(empty($this->query)){ |
|
| 746 | - $query = 'SELECT ' . $this->select . ' FROM ' . $this->from; |
|
| 747 | - if (! empty($this->join)){ |
|
| 748 | - $query .= $this->join; |
|
| 749 | - } |
|
| 744 | + //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now |
|
| 745 | + if(empty($this->query)){ |
|
| 746 | + $query = 'SELECT ' . $this->select . ' FROM ' . $this->from; |
|
| 747 | + if (! empty($this->join)){ |
|
| 748 | + $query .= $this->join; |
|
| 749 | + } |
|
| 750 | 750 | |
| 751 | - if (! empty($this->where)){ |
|
| 752 | - $query .= ' WHERE ' . $this->where; |
|
| 753 | - } |
|
| 751 | + if (! empty($this->where)){ |
|
| 752 | + $query .= ' WHERE ' . $this->where; |
|
| 753 | + } |
|
| 754 | 754 | |
| 755 | - if (! empty($this->groupBy)){ |
|
| 756 | - $query .= ' GROUP BY ' . $this->groupBy; |
|
| 757 | - } |
|
| 755 | + if (! empty($this->groupBy)){ |
|
| 756 | + $query .= ' GROUP BY ' . $this->groupBy; |
|
| 757 | + } |
|
| 758 | 758 | |
| 759 | - if (! empty($this->having)){ |
|
| 760 | - $query .= ' HAVING ' . $this->having; |
|
| 761 | - } |
|
| 759 | + if (! empty($this->having)){ |
|
| 760 | + $query .= ' HAVING ' . $this->having; |
|
| 761 | + } |
|
| 762 | 762 | |
| 763 | - if (! empty($this->orderBy)){ |
|
| 764 | - $query .= ' ORDER BY ' . $this->orderBy; |
|
| 765 | - } |
|
| 763 | + if (! empty($this->orderBy)){ |
|
| 764 | + $query .= ' ORDER BY ' . $this->orderBy; |
|
| 765 | + } |
|
| 766 | 766 | |
| 767 | - if (! empty($this->limit)){ |
|
| 768 | - $query .= ' LIMIT ' . $this->limit; |
|
| 769 | - } |
|
| 770 | - $this->query = $query; |
|
| 771 | - } |
|
| 772 | - return $this->query; |
|
| 767 | + if (! empty($this->limit)){ |
|
| 768 | + $query .= ' LIMIT ' . $this->limit; |
|
| 769 | + } |
|
| 770 | + $this->query = $query; |
|
| 771 | + } |
|
| 772 | + return $this->query; |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | |
| 776 | - /** |
|
| 777 | - * Return the PDO instance |
|
| 778 | - * @return object |
|
| 779 | - */ |
|
| 776 | + /** |
|
| 777 | + * Return the PDO instance |
|
| 778 | + * @return object |
|
| 779 | + */ |
|
| 780 | 780 | public function getPdo(){ |
| 781 | - return $this->pdo; |
|
| 781 | + return $this->pdo; |
|
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | /** |
| 785 | 785 | * Set the PDO instance |
| 786 | 786 | * @param PDO $pdo the pdo object |
| 787 | - * @return object DatabaseQueryBuilder |
|
| 787 | + * @return object DatabaseQueryBuilder |
|
| 788 | 788 | */ |
| 789 | 789 | public function setPdo(PDO $pdo = null){ |
| 790 | - $this->pdo = $pdo; |
|
| 791 | - return $this; |
|
| 790 | + $this->pdo = $pdo; |
|
| 791 | + return $this; |
|
| 792 | 792 | } |
| 793 | 793 | |
| 794 | - /** |
|
| 795 | - * Return the database table prefix |
|
| 796 | - * @return string |
|
| 797 | - */ |
|
| 794 | + /** |
|
| 795 | + * Return the database table prefix |
|
| 796 | + * @return string |
|
| 797 | + */ |
|
| 798 | 798 | public function getPrefix(){ |
| 799 | - return $this->prefix; |
|
| 799 | + return $this->prefix; |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | /** |
| 803 | 803 | * Set the database table prefix |
| 804 | 804 | * @param string $prefix the new prefix |
| 805 | - * @return object DatabaseQueryBuilder |
|
| 805 | + * @return object DatabaseQueryBuilder |
|
| 806 | 806 | */ |
| 807 | 807 | public function setPrefix($prefix){ |
| 808 | - $this->prefix = $prefix; |
|
| 809 | - return $this; |
|
| 808 | + $this->prefix = $prefix; |
|
| 809 | + return $this; |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | - /** |
|
| 813 | - * Return the database driver |
|
| 814 | - * @return string |
|
| 815 | - */ |
|
| 812 | + /** |
|
| 813 | + * Return the database driver |
|
| 814 | + * @return string |
|
| 815 | + */ |
|
| 816 | 816 | public function getDriver(){ |
| 817 | - return $this->driver; |
|
| 817 | + return $this->driver; |
|
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | /** |
| 821 | 821 | * Set the database driver |
| 822 | 822 | * @param string $driver the new driver |
| 823 | - * @return object DatabaseQueryBuilder |
|
| 823 | + * @return object DatabaseQueryBuilder |
|
| 824 | 824 | */ |
| 825 | 825 | public function setDriver($driver){ |
| 826 | - $this->driver = $driver; |
|
| 827 | - return $this; |
|
| 826 | + $this->driver = $driver; |
|
| 827 | + return $this; |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | - /** |
|
| 831 | - * Reset the DatabaseQueryBuilder class attributs to the initial values before each query. |
|
| 832 | - * @return object the current DatabaseQueryBuilder instance |
|
| 833 | - */ |
|
| 830 | + /** |
|
| 831 | + * Reset the DatabaseQueryBuilder class attributs to the initial values before each query. |
|
| 832 | + * @return object the current DatabaseQueryBuilder instance |
|
| 833 | + */ |
|
| 834 | 834 | public function reset(){ |
| 835 | - $this->select = '*'; |
|
| 836 | - $this->from = null; |
|
| 837 | - $this->where = null; |
|
| 838 | - $this->limit = null; |
|
| 839 | - $this->orderBy = null; |
|
| 840 | - $this->groupBy = null; |
|
| 841 | - $this->having = null; |
|
| 842 | - $this->join = null; |
|
| 843 | - $this->query = null; |
|
| 844 | - return $this; |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - /** |
|
| 848 | - * Get the SQL HAVING clause when operator argument is an array |
|
| 849 | - * @see DatabaseQueryBuilder::having |
|
| 850 | - * |
|
| 851 | - * @return string |
|
| 852 | - */ |
|
| 835 | + $this->select = '*'; |
|
| 836 | + $this->from = null; |
|
| 837 | + $this->where = null; |
|
| 838 | + $this->limit = null; |
|
| 839 | + $this->orderBy = null; |
|
| 840 | + $this->groupBy = null; |
|
| 841 | + $this->having = null; |
|
| 842 | + $this->join = null; |
|
| 843 | + $this->query = null; |
|
| 844 | + return $this; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + /** |
|
| 848 | + * Get the SQL HAVING clause when operator argument is an array |
|
| 849 | + * @see DatabaseQueryBuilder::having |
|
| 850 | + * |
|
| 851 | + * @return string |
|
| 852 | + */ |
|
| 853 | 853 | protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true){ |
| 854 | 854 | $x = explode('?', $field); |
| 855 | 855 | $w = ''; |
| 856 | 856 | foreach($x as $k => $v){ |
| 857 | - if (!empty($v)){ |
|
| 857 | + if (!empty($v)){ |
|
| 858 | 858 | if (! isset($op[$k])){ |
| 859 | - $op[$k] = ''; |
|
| 859 | + $op[$k] = ''; |
|
| 860 | + } |
|
| 861 | + $w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : ''); |
|
| 862 | + } |
|
| 860 | 863 | } |
| 861 | - $w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : ''); |
|
| 862 | - } |
|
| 863 | - } |
|
| 864 | 864 | return $w; |
| 865 | 865 | } |
| 866 | 866 | |
@@ -872,35 +872,35 @@ discard block |
||
| 872 | 872 | * @return string |
| 873 | 873 | */ |
| 874 | 874 | protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){ |
| 875 | - $_where = array(); |
|
| 876 | - foreach ($where as $column => $data){ |
|
| 875 | + $_where = array(); |
|
| 876 | + foreach ($where as $column => $data){ |
|
| 877 | 877 | if (is_null($data)){ |
| 878 | - $data = ''; |
|
| 878 | + $data = ''; |
|
| 879 | 879 | } |
| 880 | 880 | $_where[] = $type . $column . ' = ' . ($this->escape($data, $escape)); |
| 881 | - } |
|
| 882 | - $where = implode(' '.$andOr.' ', $_where); |
|
| 883 | - return $where; |
|
| 881 | + } |
|
| 882 | + $where = implode(' '.$andOr.' ', $_where); |
|
| 883 | + return $where; |
|
| 884 | 884 | } |
| 885 | 885 | |
| 886 | - /** |
|
| 887 | - * Get the SQL WHERE clause when operator argument is an array |
|
| 888 | - * @see DatabaseQueryBuilder::where |
|
| 889 | - * |
|
| 890 | - * @return string |
|
| 891 | - */ |
|
| 886 | + /** |
|
| 887 | + * Get the SQL WHERE clause when operator argument is an array |
|
| 888 | + * @see DatabaseQueryBuilder::where |
|
| 889 | + * |
|
| 890 | + * @return string |
|
| 891 | + */ |
|
| 892 | 892 | protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){ |
| 893 | - $x = explode('?', $where); |
|
| 894 | - $w = ''; |
|
| 895 | - foreach($x as $k => $v){ |
|
| 893 | + $x = explode('?', $where); |
|
| 894 | + $w = ''; |
|
| 895 | + foreach($x as $k => $v){ |
|
| 896 | 896 | if (! empty($v)){ |
| 897 | 897 | if (isset($op[$k]) && is_null($op[$k])){ |
| 898 | - $op[$k] = ''; |
|
| 898 | + $op[$k] = ''; |
|
| 899 | 899 | } |
| 900 | 900 | $w .= $type . $v . (isset($op[$k]) ? ($this->escape($op[$k], $escape)) : ''); |
| 901 | 901 | } |
| 902 | - } |
|
| 903 | - return $w; |
|
| 902 | + } |
|
| 903 | + return $w; |
|
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | /** |
@@ -910,53 +910,53 @@ discard block |
||
| 910 | 910 | * @return string |
| 911 | 911 | */ |
| 912 | 912 | protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){ |
| 913 | - $w = ''; |
|
| 914 | - if (! in_array((string)$op, $this->operatorList)){ |
|
| 915 | - if (is_null($op)){ |
|
| 913 | + $w = ''; |
|
| 914 | + if (! in_array((string)$op, $this->operatorList)){ |
|
| 915 | + if (is_null($op)){ |
|
| 916 | 916 | $op = ''; |
| 917 | - } |
|
| 918 | - $w = $type . $where . ' = ' . ($this->escape($op, $escape)); |
|
| 917 | + } |
|
| 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 | - } |
|
| 923 | - $w = $type . $where . $op . ($this->escape($val, $escape)); |
|
| 922 | + } |
|
| 923 | + $w = $type . $where . $op . ($this->escape($val, $escape)); |
|
| 924 | 924 | } |
| 925 | 925 | return $w; |
| 926 | - } |
|
| 927 | - |
|
| 928 | - /** |
|
| 929 | - * Set the $this->where property |
|
| 930 | - * @param string $whereStr the WHERE clause string |
|
| 931 | - * @param string $andOr the separator type used 'AND', 'OR', etc. |
|
| 932 | - */ |
|
| 933 | - protected function setWhereStr($whereStr, $andOr = 'AND'){ |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + /** |
|
| 929 | + * Set the $this->where property |
|
| 930 | + * @param string $whereStr the WHERE clause string |
|
| 931 | + * @param string $andOr the separator type used 'AND', 'OR', etc. |
|
| 932 | + */ |
|
| 933 | + protected function setWhereStr($whereStr, $andOr = 'AND'){ |
|
| 934 | 934 | if (empty($this->where)){ |
| 935 | - $this->where = $whereStr; |
|
| 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 | - } else { |
|
| 939 | + } else { |
|
| 940 | 940 | $this->where = $this->where . ' '.$andOr.' ' . $whereStr; |
| 941 | - } |
|
| 941 | + } |
|
| 942 | + } |
|
| 942 | 943 | } |
| 943 | - } |
|
| 944 | 944 | |
| 945 | 945 | |
| 946 | - /** |
|
| 947 | - * Set the SQL SELECT for function MIN, MAX, SUM, AVG, COUNT, AVG |
|
| 948 | - * @param string $clause the clause type like MIN, MAX, etc. |
|
| 949 | - * @see DatabaseQueryBuilder::min |
|
| 950 | - * @see DatabaseQueryBuilder::max |
|
| 951 | - * @see DatabaseQueryBuilder::sum |
|
| 952 | - * @see DatabaseQueryBuilder::count |
|
| 953 | - * @see DatabaseQueryBuilder::avg |
|
| 954 | - * @return object |
|
| 955 | - */ |
|
| 946 | + /** |
|
| 947 | + * Set the SQL SELECT for function MIN, MAX, SUM, AVG, COUNT, AVG |
|
| 948 | + * @param string $clause the clause type like MIN, MAX, etc. |
|
| 949 | + * @see DatabaseQueryBuilder::min |
|
| 950 | + * @see DatabaseQueryBuilder::max |
|
| 951 | + * @see DatabaseQueryBuilder::sum |
|
| 952 | + * @see DatabaseQueryBuilder::count |
|
| 953 | + * @see DatabaseQueryBuilder::avg |
|
| 954 | + * @return object |
|
| 955 | + */ |
|
| 956 | 956 | protected function select_min_max_sum_count_avg($clause, $field, $name = null){ |
| 957 | - $clause = strtoupper($clause); |
|
| 958 | - $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
|
| 959 | - $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
|
| 960 | - return $this; |
|
| 957 | + $clause = strtoupper($clause); |
|
| 958 | + $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
|
| 959 | + $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
|
| 960 | + return $this; |
|
| 961 | 961 | } |
| 962 | 962 | } |
@@ -1,146 +1,146 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - class Controller{ |
|
| 27 | + class Controller{ |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * The name of the module if this controller belong to an module |
|
| 31 | - * @var string |
|
| 32 | - */ |
|
| 33 | - public $moduleName = null; |
|
| 29 | + /** |
|
| 30 | + * The name of the module if this controller belong to an module |
|
| 31 | + * @var string |
|
| 32 | + */ |
|
| 33 | + public $moduleName = null; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * The singleton of the super object |
|
| 37 | - * @var Controller |
|
| 38 | - */ |
|
| 39 | - private static $instance; |
|
| 35 | + /** |
|
| 36 | + * The singleton of the super object |
|
| 37 | + * @var Controller |
|
| 38 | + */ |
|
| 39 | + private static $instance; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * The logger instance |
|
| 43 | - * @var Log |
|
| 44 | - */ |
|
| 45 | - protected $logger; |
|
| 41 | + /** |
|
| 42 | + * The logger instance |
|
| 43 | + * @var Log |
|
| 44 | + */ |
|
| 45 | + protected $logger; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Class constructor |
|
| 49 | - * @param object $logger the Log instance to use if is null will create one |
|
| 50 | - */ |
|
| 51 | - public function __construct(Log $logger = null){ |
|
| 52 | - //setting the Log instance |
|
| 53 | - $this->setLoggerFromParamOrCreateNewInstance($logger); |
|
| 47 | + /** |
|
| 48 | + * Class constructor |
|
| 49 | + * @param object $logger the Log instance to use if is null will create one |
|
| 50 | + */ |
|
| 51 | + public function __construct(Log $logger = null){ |
|
| 52 | + //setting the Log instance |
|
| 53 | + $this->setLoggerFromParamOrCreateNewInstance($logger); |
|
| 54 | 54 | |
| 55 | - //instance of the super object |
|
| 56 | - self::$instance = & $this; |
|
| 55 | + //instance of the super object |
|
| 56 | + self::$instance = & $this; |
|
| 57 | 57 | |
| 58 | - //Load the resources loaded during the application bootstrap |
|
| 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); |
|
| 62 | - } |
|
| 58 | + //Load the resources loaded during the application bootstrap |
|
| 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); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - //set module using the router |
|
| 65 | - $this->setModuleNameFromRouter(); |
|
| 64 | + //set module using the router |
|
| 65 | + $this->setModuleNameFromRouter(); |
|
| 66 | 66 | |
| 67 | - //load the required resources |
|
| 68 | - $this->loadRequiredResources(); |
|
| 67 | + //load the required resources |
|
| 68 | + $this->loadRequiredResources(); |
|
| 69 | 69 | |
| 70 | - //set the cache using the configuration |
|
| 71 | - $this->setCacheFromParamOrConfig(null); |
|
| 70 | + //set the cache using the configuration |
|
| 71 | + $this->setCacheFromParamOrConfig(null); |
|
| 72 | 72 | |
| 73 | - //set application session configuration |
|
| 74 | - $this->logger->debug('Setting PHP application session handler'); |
|
| 75 | - set_session_config(); |
|
| 73 | + //set application session configuration |
|
| 74 | + $this->logger->debug('Setting PHP application session handler'); |
|
| 75 | + set_session_config(); |
|
| 76 | 76 | |
| 77 | - //dispatch the loaded instance of super controller event |
|
| 78 | - $this->eventdispatcher->dispatch('SUPER_CONTROLLER_CREATED'); |
|
| 79 | - } |
|
| 77 | + //dispatch the loaded instance of super controller event |
|
| 78 | + $this->eventdispatcher->dispatch('SUPER_CONTROLLER_CREATED'); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * This is a very useful method it's used to get the super object instance |
|
| 84 | - * @return Controller the super object instance |
|
| 85 | - */ |
|
| 86 | - public static function &get_instance(){ |
|
| 87 | - return self::$instance; |
|
| 88 | - } |
|
| 82 | + /** |
|
| 83 | + * This is a very useful method it's used to get the super object instance |
|
| 84 | + * @return Controller the super object instance |
|
| 85 | + */ |
|
| 86 | + public static function &get_instance(){ |
|
| 87 | + return self::$instance; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * This method is used to set the module name |
|
| 92 | - */ |
|
| 93 | - protected function setModuleNameFromRouter(){ |
|
| 94 | - //set the module using the router instance |
|
| 95 | - if(isset($this->router) && $this->router->getModule()){ |
|
| 96 | - $this->moduleName = $this->router->getModule(); |
|
| 97 | - } |
|
| 98 | - } |
|
| 90 | + /** |
|
| 91 | + * This method is used to set the module name |
|
| 92 | + */ |
|
| 93 | + protected function setModuleNameFromRouter(){ |
|
| 94 | + //set the module using the router instance |
|
| 95 | + if(isset($this->router) && $this->router->getModule()){ |
|
| 96 | + $this->moduleName = $this->router->getModule(); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Set the cache using the argument otherwise will use the configuration |
|
| 102 | - * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured |
|
| 103 | - */ |
|
| 104 | - protected function setCacheFromParamOrConfig(CacheInterface $cache = null){ |
|
| 105 | - $this->logger->debug('Setting the cache handler instance'); |
|
| 106 | - //set cache handler instance |
|
| 107 | - if(get_config('cache_enable', false)){ |
|
| 108 | - if ($cache !== null){ |
|
| 109 | - $this->cache = $cache; |
|
| 110 | - } else if (isset($this->{strtolower(get_config('cache_handler'))})){ |
|
| 111 | - $this->cache = $this->{strtolower(get_config('cache_handler'))}; |
|
| 112 | - unset($this->{strtolower(get_config('cache_handler'))}); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 100 | + /** |
|
| 101 | + * Set the cache using the argument otherwise will use the configuration |
|
| 102 | + * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured |
|
| 103 | + */ |
|
| 104 | + protected function setCacheFromParamOrConfig(CacheInterface $cache = null){ |
|
| 105 | + $this->logger->debug('Setting the cache handler instance'); |
|
| 106 | + //set cache handler instance |
|
| 107 | + if(get_config('cache_enable', false)){ |
|
| 108 | + if ($cache !== null){ |
|
| 109 | + $this->cache = $cache; |
|
| 110 | + } else if (isset($this->{strtolower(get_config('cache_handler'))})){ |
|
| 111 | + $this->cache = $this->{strtolower(get_config('cache_handler'))}; |
|
| 112 | + unset($this->{strtolower(get_config('cache_handler'))}); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Set the Log instance using argument or create new instance |
|
| 119 | - * @param object $logger the Log instance if not null |
|
| 120 | - */ |
|
| 121 | - protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
|
| 122 | - if($logger !== null){ |
|
| 123 | - $this->logger = $logger; |
|
| 124 | - } |
|
| 125 | - else{ |
|
| 126 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 127 | - $this->logger->setLogger('MainController'); |
|
| 128 | - } |
|
| 129 | - } |
|
| 117 | + /** |
|
| 118 | + * Set the Log instance using argument or create new instance |
|
| 119 | + * @param object $logger the Log instance if not null |
|
| 120 | + */ |
|
| 121 | + protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
|
| 122 | + if($logger !== null){ |
|
| 123 | + $this->logger = $logger; |
|
| 124 | + } |
|
| 125 | + else{ |
|
| 126 | + $this->logger =& class_loader('Log', 'classes'); |
|
| 127 | + $this->logger->setLogger('MainController'); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * This method is used to load the required resources for framework to work |
|
| 133 | - * @return void |
|
| 134 | - */ |
|
| 135 | - private function loadRequiredResources(){ |
|
| 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'); |
|
| 141 | - //dispatch the request instance created event |
|
| 142 | - $this->eventdispatcher->dispatch('REQUEST_CREATED'); |
|
| 143 | - $this->response =& class_loader('Response', 'classes', 'classes'); |
|
| 144 | - } |
|
| 131 | + /** |
|
| 132 | + * This method is used to load the required resources for framework to work |
|
| 133 | + * @return void |
|
| 134 | + */ |
|
| 135 | + private function loadRequiredResources(){ |
|
| 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'); |
|
| 141 | + //dispatch the request instance created event |
|
| 142 | + $this->eventdispatcher->dispatch('REQUEST_CREATED'); |
|
| 143 | + $this->response =& class_loader('Response', 'classes', 'classes'); |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - } |
|
| 146 | + } |
|
@@ -1,337 +1,337 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework created using the concept of codeigniter with bootstrap twitter |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework created using the concept of codeigniter with bootstrap twitter |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * This file contains the main configuration of your application |
|
| 29 | - * web address, front controller, error logging, session parameters, CSRF, Cache, |
|
| 30 | - * Whitelist IP access, etc. |
|
| 31 | - */ |
|
| 27 | + /** |
|
| 28 | + * This file contains the main configuration of your application |
|
| 29 | + * web address, front controller, error logging, session parameters, CSRF, Cache, |
|
| 30 | + * Whitelist IP access, etc. |
|
| 31 | + */ |
|
| 32 | 32 | |
| 33 | - /*+---------------------------------------------------------------+ |
|
| 33 | + /*+---------------------------------------------------------------+ |
|
| 34 | 34 | * Basic configuration section |
| 35 | 35 | +------------------------------------------------------------------+ |
| 36 | 36 | */ |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * The web address of your application. |
|
| 40 | - * |
|
| 41 | - * The address of your application or website terminated by a slash. |
|
| 42 | - * You can use a domain name or IP address, for example: |
|
| 43 | - * |
|
| 44 | - * $config['base_url'] = 'http://www.mysite.com'; |
|
| 45 | - * or |
|
| 46 | - * $config['base_url'] = 'http://198.15.25.12'; |
|
| 47 | - * |
|
| 48 | - * If this value is empty, we try to determine it automatically by using |
|
| 49 | - * the server variables "SERVER_ADDR" or "SCRIPT_NAME", |
|
| 50 | - * we recommend that you specify this value for a server in production this may reduce the performance of your application. |
|
| 51 | - */ |
|
| 52 | - $config['base_url'] = ''; |
|
| 38 | + /** |
|
| 39 | + * The web address of your application. |
|
| 40 | + * |
|
| 41 | + * The address of your application or website terminated by a slash. |
|
| 42 | + * You can use a domain name or IP address, for example: |
|
| 43 | + * |
|
| 44 | + * $config['base_url'] = 'http://www.mysite.com'; |
|
| 45 | + * or |
|
| 46 | + * $config['base_url'] = 'http://198.15.25.12'; |
|
| 47 | + * |
|
| 48 | + * If this value is empty, we try to determine it automatically by using |
|
| 49 | + * the server variables "SERVER_ADDR" or "SCRIPT_NAME", |
|
| 50 | + * we recommend that you specify this value for a server in production this may reduce the performance of your application. |
|
| 51 | + */ |
|
| 52 | + $config['base_url'] = ''; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * The front controller |
|
| 56 | - * |
|
| 57 | - * This represents the name of the file called by the application during the loading |
|
| 58 | - * process generally the file "index.php". |
|
| 59 | - * If your webserver supports the url rewrite module, then you can leave this value empty. |
|
| 60 | - * You will find a sample file to hide this file in the url inside the root folder of your |
|
| 61 | - * application "htaccess.txt" for the apache web server just rename it to ".htaccess" |
|
| 62 | - * |
|
| 63 | - * Without the rewrite module url enabled, leave this value to "index.php", in this case your urls look like: |
|
| 64 | - * |
|
| 65 | - * http://www.yoursite.com/index.php/controller/method |
|
| 66 | - * |
|
| 67 | - * otherwise if the module is available and activated you can put this value empty and your urls look like: |
|
| 68 | - * |
|
| 69 | - * http://www.yoursite.com/controller/method |
|
| 70 | - * |
|
| 71 | - */ |
|
| 72 | - $config['front_controller'] = 'index.php'; |
|
| 54 | + /** |
|
| 55 | + * The front controller |
|
| 56 | + * |
|
| 57 | + * This represents the name of the file called by the application during the loading |
|
| 58 | + * process generally the file "index.php". |
|
| 59 | + * If your webserver supports the url rewrite module, then you can leave this value empty. |
|
| 60 | + * You will find a sample file to hide this file in the url inside the root folder of your |
|
| 61 | + * application "htaccess.txt" for the apache web server just rename it to ".htaccess" |
|
| 62 | + * |
|
| 63 | + * Without the rewrite module url enabled, leave this value to "index.php", in this case your urls look like: |
|
| 64 | + * |
|
| 65 | + * http://www.yoursite.com/index.php/controller/method |
|
| 66 | + * |
|
| 67 | + * otherwise if the module is available and activated you can put this value empty and your urls look like: |
|
| 68 | + * |
|
| 69 | + * http://www.yoursite.com/controller/method |
|
| 70 | + * |
|
| 71 | + */ |
|
| 72 | + $config['front_controller'] = 'index.php'; |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Url suffix |
|
| 76 | - */ |
|
| 77 | - $config['url_suffix'] = ''; |
|
| 74 | + /** |
|
| 75 | + * Url suffix |
|
| 76 | + */ |
|
| 77 | + $config['url_suffix'] = ''; |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * site charset |
|
| 81 | - */ |
|
| 82 | - $config['charset'] = 'UTF-8'; |
|
| 79 | + /** |
|
| 80 | + * site charset |
|
| 81 | + */ |
|
| 82 | + $config['charset'] = 'UTF-8'; |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Compress the output before send to browser |
|
| 86 | - * |
|
| 87 | - * Enables Gzip output compression for faster page loads. When enabled, |
|
| 88 | - * the Response class will test whether your server supports Gzip. |
|
| 89 | - * Even if it does, however, not all browsers support compression |
|
| 90 | - * so enable only if you are reasonably sure your visitors can handle it. |
|
| 91 | - * |
|
| 92 | - * This is only used if "zlib.output_compression" is turned off in your php configuration. |
|
| 93 | - * Please do not use it together with httpd-level output compression. |
|
| 94 | - * |
|
| 95 | - * IMPORTANT NOTE: If you are getting a blank page when compression is enabled it |
|
| 96 | - * means you are prematurely outputting something to your browser. It could |
|
| 97 | - * even be a line of whitespace at the end of one of your scripts. For |
|
| 98 | - * compression to work, nothing can be sent before the output buffer is called |
|
| 99 | - * by the Response class. Do not 'echo' any values with compression enabled. |
|
| 100 | - */ |
|
| 101 | - $config['compress_output'] = false; |
|
| 84 | + /** |
|
| 85 | + * Compress the output before send to browser |
|
| 86 | + * |
|
| 87 | + * Enables Gzip output compression for faster page loads. When enabled, |
|
| 88 | + * the Response class will test whether your server supports Gzip. |
|
| 89 | + * Even if it does, however, not all browsers support compression |
|
| 90 | + * so enable only if you are reasonably sure your visitors can handle it. |
|
| 91 | + * |
|
| 92 | + * This is only used if "zlib.output_compression" is turned off in your php configuration. |
|
| 93 | + * Please do not use it together with httpd-level output compression. |
|
| 94 | + * |
|
| 95 | + * IMPORTANT NOTE: If you are getting a blank page when compression is enabled it |
|
| 96 | + * means you are prematurely outputting something to your browser. It could |
|
| 97 | + * even be a line of whitespace at the end of one of your scripts. For |
|
| 98 | + * compression to work, nothing can be sent before the output buffer is called |
|
| 99 | + * by the Response class. Do not 'echo' any values with compression enabled. |
|
| 100 | + */ |
|
| 101 | + $config['compress_output'] = false; |
|
| 102 | 102 | |
| 103 | - /*+---------------------------------------------------------------+ |
|
| 103 | + /*+---------------------------------------------------------------+ |
|
| 104 | 104 | * Language configuration section |
| 105 | 105 | +------------------------------------------------------------------+ |
| 106 | 106 | */ |
| 107 | - /** |
|
| 108 | - * list of available supported language |
|
| 109 | - * array( |
|
| 110 | - * 'lang_key' => 'human readable' |
|
| 111 | - * ) |
|
| 112 | - */ |
|
| 113 | - $config['languages'] = array('en' => 'english'); |
|
| 107 | + /** |
|
| 108 | + * list of available supported language |
|
| 109 | + * array( |
|
| 110 | + * 'lang_key' => 'human readable' |
|
| 111 | + * ) |
|
| 112 | + */ |
|
| 113 | + $config['languages'] = array('en' => 'english'); |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * the default language to use if can not find the client language |
|
| 117 | - * need match with the array key of the supported languages |
|
| 118 | - */ |
|
| 119 | - $config['default_language'] = 'en'; //en = english, fr = french |
|
| 115 | + /** |
|
| 116 | + * the default language to use if can not find the client language |
|
| 117 | + * need match with the array key of the supported languages |
|
| 118 | + */ |
|
| 119 | + $config['default_language'] = 'en'; //en = english, fr = french |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * the name of cookie used to store the client language |
|
| 123 | - */ |
|
| 124 | - $config['language_cookie_name'] = 'cookie_lang'; |
|
| 121 | + /** |
|
| 122 | + * the name of cookie used to store the client language |
|
| 123 | + */ |
|
| 124 | + $config['language_cookie_name'] = 'cookie_lang'; |
|
| 125 | 125 | |
| 126 | 126 | |
| 127 | - /*+---------------------------------------------------------------+ |
|
| 127 | + /*+---------------------------------------------------------------+ |
|
| 128 | 128 | * Logs configuration section |
| 129 | 129 | +------------------------------------------------------------------+ |
| 130 | 130 | */ |
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * The log level |
|
| 134 | - * |
|
| 135 | - * The valid level are: OFF, NONE, FATAL, ERROR, WARNING, WARN, INFO, DEBUG, ALL |
|
| 136 | - * |
|
| 137 | - * 'OFF' or 'NONE' = do not save log |
|
| 138 | - * 'FATAL' = enable log for fatal level and above (FATAL) |
|
| 139 | - * 'ERROR' = enable log for error level and above (ERROR, FATAL) |
|
| 140 | - * 'WARNING' or WARN = enable log for warning level and above (WARNING, ERROR, FATAL) |
|
| 141 | - * 'INFO' = enable log for info level and above (INFO, WARNING, ERROR, FATAL) |
|
| 142 | - * 'DEBUG' = enable log for debug level and above (DEBUG, INFO, WARNING, ERROR, FATAL) |
|
| 143 | - * 'ALL' = enable log for all level |
|
| 144 | - * |
|
| 145 | - * The default value is NONE if the config value is: null, '', 0, false |
|
| 146 | - * |
|
| 147 | - * Note: in production environment it's recommand to set the log level to 'WARNING' if not in small |
|
| 148 | - * of time the log file size will increase very fast and will cost the application performance |
|
| 149 | - * and also the filesystem usage of your server. |
|
| 150 | - */ |
|
| 151 | - $config['log_level'] = 'NONE'; |
|
| 132 | + /** |
|
| 133 | + * The log level |
|
| 134 | + * |
|
| 135 | + * The valid level are: OFF, NONE, FATAL, ERROR, WARNING, WARN, INFO, DEBUG, ALL |
|
| 136 | + * |
|
| 137 | + * 'OFF' or 'NONE' = do not save log |
|
| 138 | + * 'FATAL' = enable log for fatal level and above (FATAL) |
|
| 139 | + * 'ERROR' = enable log for error level and above (ERROR, FATAL) |
|
| 140 | + * 'WARNING' or WARN = enable log for warning level and above (WARNING, ERROR, FATAL) |
|
| 141 | + * 'INFO' = enable log for info level and above (INFO, WARNING, ERROR, FATAL) |
|
| 142 | + * 'DEBUG' = enable log for debug level and above (DEBUG, INFO, WARNING, ERROR, FATAL) |
|
| 143 | + * 'ALL' = enable log for all level |
|
| 144 | + * |
|
| 145 | + * The default value is NONE if the config value is: null, '', 0, false |
|
| 146 | + * |
|
| 147 | + * Note: in production environment it's recommand to set the log level to 'WARNING' if not in small |
|
| 148 | + * of time the log file size will increase very fast and will cost the application performance |
|
| 149 | + * and also the filesystem usage of your server. |
|
| 150 | + */ |
|
| 151 | + $config['log_level'] = 'NONE'; |
|
| 152 | 152 | |
| 153 | 153 | |
| 154 | - /** |
|
| 155 | - * The path to log directory |
|
| 156 | - * |
|
| 157 | - * The path that the log data will be saved ending with de "/" or "\", leave empty if you |
|
| 158 | - * want use the default configuration |
|
| 159 | - * warning : if set, this directory must exist and will be writable and owned by the web server |
|
| 160 | - * else the default value will be used i.e the constant LOG_PATH |
|
| 161 | - * for security raison this directory must be outside of the document root of your |
|
| 162 | - * website. |
|
| 163 | - */ |
|
| 164 | - $config['log_save_path'] = ''; |
|
| 154 | + /** |
|
| 155 | + * The path to log directory |
|
| 156 | + * |
|
| 157 | + * The path that the log data will be saved ending with de "/" or "\", leave empty if you |
|
| 158 | + * want use the default configuration |
|
| 159 | + * warning : if set, this directory must exist and will be writable and owned by the web server |
|
| 160 | + * else the default value will be used i.e the constant LOG_PATH |
|
| 161 | + * for security raison this directory must be outside of the document root of your |
|
| 162 | + * website. |
|
| 163 | + */ |
|
| 164 | + $config['log_save_path'] = ''; |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * The logger name to use for the log |
|
| 168 | - * |
|
| 169 | - * If this config is set so means only log message with this or these logger(s) will be saved |
|
| 170 | - * |
|
| 171 | - * Example: |
|
| 172 | - * $config['log_logger_name'] = array('MY_LOGGER1', 'MY_LOGGER2'); //only log message with MY_LOGGER1 or MY_LOGGER2 will be saved in file. |
|
| 173 | - */ |
|
| 174 | - $config['log_logger_name'] = array(); |
|
| 166 | + /** |
|
| 167 | + * The logger name to use for the log |
|
| 168 | + * |
|
| 169 | + * If this config is set so means only log message with this or these logger(s) will be saved |
|
| 170 | + * |
|
| 171 | + * Example: |
|
| 172 | + * $config['log_logger_name'] = array('MY_LOGGER1', 'MY_LOGGER2'); //only log message with MY_LOGGER1 or MY_LOGGER2 will be saved in file. |
|
| 173 | + */ |
|
| 174 | + $config['log_logger_name'] = array(); |
|
| 175 | 175 | |
| 176 | 176 | |
| 177 | - /*+---------------------------------------------------------------+ |
|
| 177 | + /*+---------------------------------------------------------------+ |
|
| 178 | 178 | * Session configuration section |
| 179 | 179 | +------------------------------------------------------------------+ |
| 180 | 180 | */ |
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * The session name |
|
| 184 | - * |
|
| 185 | - * By default is PHPSESSID. this must be alpha-numerical characters |
|
| 186 | - */ |
|
| 187 | - $config['session_name'] = 'PHPSESSID'; |
|
| 182 | + /** |
|
| 183 | + * The session name |
|
| 184 | + * |
|
| 185 | + * By default is PHPSESSID. this must be alpha-numerical characters |
|
| 186 | + */ |
|
| 187 | + $config['session_name'] = 'PHPSESSID'; |
|
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * Session save path |
|
| 191 | - * |
|
| 192 | - * The path that the session data will be saved, leave empty if you |
|
| 193 | - * want use the default configuration in the php.ini |
|
| 194 | - * warning : if set, this directory must exist and will be writable and owned by the web server |
|
| 195 | - * for security raison this directory must be outside of the document root of your |
|
| 196 | - * website. |
|
| 197 | - * Note: if the session handler is "database" the session_save_path is the model name to use |
|
| 198 | - */ |
|
| 199 | - $config['session_save_path'] = ''; |
|
| 189 | + /** |
|
| 190 | + * Session save path |
|
| 191 | + * |
|
| 192 | + * The path that the session data will be saved, leave empty if you |
|
| 193 | + * want use the default configuration in the php.ini |
|
| 194 | + * warning : if set, this directory must exist and will be writable and owned by the web server |
|
| 195 | + * for security raison this directory must be outside of the document root of your |
|
| 196 | + * website. |
|
| 197 | + * Note: if the session handler is "database" the session_save_path is the model name to use |
|
| 198 | + */ |
|
| 199 | + $config['session_save_path'] = ''; |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Session handler |
|
| 203 | - * |
|
| 204 | - * The session handler that we will use to manage the session. |
|
| 205 | - * currently the possible values are "files", "database". |
|
| 206 | - */ |
|
| 207 | - $config['session_handler'] = 'files'; |
|
| 201 | + /** |
|
| 202 | + * Session handler |
|
| 203 | + * |
|
| 204 | + * The session handler that we will use to manage the session. |
|
| 205 | + * currently the possible values are "files", "database". |
|
| 206 | + */ |
|
| 207 | + $config['session_handler'] = 'files'; |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Session secret |
|
| 211 | - * |
|
| 212 | - * This is used to hash the session data if the config "session_handler" is set to "database" |
|
| 213 | - * warning : do not change this value until you already set |
|
| 214 | - * for security raison use the very complicated value include $%)@^&^\''\'\' |
|
| 215 | - * NOTE: this value is an base64 so you need use the tool that generate it, like |
|
| 216 | - * PHP function base64_encode() |
|
| 217 | - */ |
|
| 218 | - $config['session_secret'] = ''; |
|
| 209 | + /** |
|
| 210 | + * Session secret |
|
| 211 | + * |
|
| 212 | + * This is used to hash the session data if the config "session_handler" is set to "database" |
|
| 213 | + * warning : do not change this value until you already set |
|
| 214 | + * for security raison use the very complicated value include $%)@^&^\''\'\' |
|
| 215 | + * NOTE: this value is an base64 so you need use the tool that generate it, like |
|
| 216 | + * PHP function base64_encode() |
|
| 217 | + */ |
|
| 218 | + $config['session_secret'] = ''; |
|
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * number of second that consider the session already expire |
|
| 222 | - */ |
|
| 223 | - $config['session_inactivity_time'] = 600; //in second |
|
| 220 | + /** |
|
| 221 | + * number of second that consider the session already expire |
|
| 222 | + */ |
|
| 223 | + $config['session_inactivity_time'] = 600; //in second |
|
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * Session cookie lifetime |
|
| 227 | - * |
|
| 228 | - * The cookie lifetime that the session will be dropped in seconds, leave 0 if you want |
|
| 229 | - * the cookie expire after the browser is closed |
|
| 230 | - */ |
|
| 231 | - $config['session_cookie_lifetime'] = 0; |
|
| 225 | + /** |
|
| 226 | + * Session cookie lifetime |
|
| 227 | + * |
|
| 228 | + * The cookie lifetime that the session will be dropped in seconds, leave 0 if you want |
|
| 229 | + * the cookie expire after the browser is closed |
|
| 230 | + */ |
|
| 231 | + $config['session_cookie_lifetime'] = 0; |
|
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * Session cookie path |
|
| 235 | - * |
|
| 236 | - * The path to your website that the cookie is available "/" means all path is available |
|
| 237 | - * example : /mysubdirectory => available in http://www.mysite.com/mysubdirectory |
|
| 238 | - */ |
|
| 239 | - $config['session_cookie_path'] = '/'; |
|
| 233 | + /** |
|
| 234 | + * Session cookie path |
|
| 235 | + * |
|
| 236 | + * The path to your website that the cookie is available "/" means all path is available |
|
| 237 | + * example : /mysubdirectory => available in http://www.mysite.com/mysubdirectory |
|
| 238 | + */ |
|
| 239 | + $config['session_cookie_path'] = '/'; |
|
| 240 | 240 | |
| 241 | - /** |
|
| 242 | - * Session cookie domain |
|
| 243 | - * |
|
| 244 | - * The domain of your website that the cookie is available if you want the cookie is available |
|
| 245 | - * in all your subdomain use this dot before the domain name for example ".mysite.com". |
|
| 246 | - * leave empty if you want use the default configuration |
|
| 247 | - */ |
|
| 248 | - $config['session_cookie_domain'] = ''; |
|
| 241 | + /** |
|
| 242 | + * Session cookie domain |
|
| 243 | + * |
|
| 244 | + * The domain of your website that the cookie is available if you want the cookie is available |
|
| 245 | + * in all your subdomain use this dot before the domain name for example ".mysite.com". |
|
| 246 | + * leave empty if you want use the default configuration |
|
| 247 | + */ |
|
| 248 | + $config['session_cookie_domain'] = ''; |
|
| 249 | 249 | |
| 250 | - /** |
|
| 251 | - * Session cookie secure |
|
| 252 | - * |
|
| 253 | - * If your website use SSL i.e https, you set "true" for this configuration, so the cookie |
|
| 254 | - * is available only if the website use the secure connection else set this value to "false" |
|
| 255 | - */ |
|
| 256 | - $config['session_cookie_secure'] = false; |
|
| 250 | + /** |
|
| 251 | + * Session cookie secure |
|
| 252 | + * |
|
| 253 | + * If your website use SSL i.e https, you set "true" for this configuration, so the cookie |
|
| 254 | + * is available only if the website use the secure connection else set this value to "false" |
|
| 255 | + */ |
|
| 256 | + $config['session_cookie_secure'] = false; |
|
| 257 | 257 | |
| 258 | 258 | |
| 259 | - /*+---------------------------------------------------------------+ |
|
| 259 | + /*+---------------------------------------------------------------+ |
|
| 260 | 260 | * CSRF configuration section |
| 261 | 261 | +------------------------------------------------------------------+ |
| 262 | 262 | */ |
| 263 | 263 | |
| 264 | - /** |
|
| 265 | - * CSRF status |
|
| 266 | - * |
|
| 267 | - * if you would to use the CSRF (that we recommand you), set this key to true |
|
| 268 | - */ |
|
| 269 | - $config['csrf_enable'] = false; |
|
| 264 | + /** |
|
| 265 | + * CSRF status |
|
| 266 | + * |
|
| 267 | + * if you would to use the CSRF (that we recommand you), set this key to true |
|
| 268 | + */ |
|
| 269 | + $config['csrf_enable'] = false; |
|
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * CSRF key |
|
| 273 | - * |
|
| 274 | - * the key used to store the csrf data |
|
| 275 | - */ |
|
| 276 | - $config['csrf_key'] = 'csrf_key'; |
|
| 271 | + /** |
|
| 272 | + * CSRF key |
|
| 273 | + * |
|
| 274 | + * the key used to store the csrf data |
|
| 275 | + */ |
|
| 276 | + $config['csrf_key'] = 'csrf_key'; |
|
| 277 | 277 | |
| 278 | - /** |
|
| 279 | - * CSRF expire |
|
| 280 | - * |
|
| 281 | - * expire time in seconds of the CSRF data |
|
| 282 | - */ |
|
| 283 | - $config['csrf_expire'] = 120; |
|
| 278 | + /** |
|
| 279 | + * CSRF expire |
|
| 280 | + * |
|
| 281 | + * expire time in seconds of the CSRF data |
|
| 282 | + */ |
|
| 283 | + $config['csrf_expire'] = 120; |
|
| 284 | 284 | |
| 285 | 285 | |
| 286 | - /*+---------------------------------------------------------------+ |
|
| 286 | + /*+---------------------------------------------------------------+ |
|
| 287 | 287 | * Cache configuration section |
| 288 | 288 | +------------------------------------------------------------------+ |
| 289 | 289 | */ |
| 290 | 290 | |
| 291 | - /** |
|
| 292 | - * Cache status |
|
| 293 | - * |
|
| 294 | - * If you would to use the cache functionnality set this value to true |
|
| 295 | - */ |
|
| 296 | - $config['cache_enable'] = false; |
|
| 291 | + /** |
|
| 292 | + * Cache status |
|
| 293 | + * |
|
| 294 | + * If you would to use the cache functionnality set this value to true |
|
| 295 | + */ |
|
| 296 | + $config['cache_enable'] = false; |
|
| 297 | 297 | |
| 298 | - /** |
|
| 299 | - * Cache Time To Live |
|
| 300 | - * |
|
| 301 | - * expire time in seconds of the cache data |
|
| 302 | - */ |
|
| 303 | - $config['cache_ttl'] = 120; //in second |
|
| 298 | + /** |
|
| 299 | + * Cache Time To Live |
|
| 300 | + * |
|
| 301 | + * expire time in seconds of the cache data |
|
| 302 | + */ |
|
| 303 | + $config['cache_ttl'] = 120; //in second |
|
| 304 | 304 | |
| 305 | - /** |
|
| 306 | - * Cache handler class |
|
| 307 | - * |
|
| 308 | - * The cache handler class inside (CORE_CLASSES_CACHE_PATH, LIBRARY_PATH) directories that implements |
|
| 309 | - * the interface "CacheInterface" that we will use to manage the cache. |
|
| 310 | - * currently the possible values are "FileCache", "ApcCache". |
|
| 311 | - */ |
|
| 312 | - $config['cache_handler'] = 'FileCache'; |
|
| 305 | + /** |
|
| 306 | + * Cache handler class |
|
| 307 | + * |
|
| 308 | + * The cache handler class inside (CORE_CLASSES_CACHE_PATH, LIBRARY_PATH) directories that implements |
|
| 309 | + * the interface "CacheInterface" that we will use to manage the cache. |
|
| 310 | + * currently the possible values are "FileCache", "ApcCache". |
|
| 311 | + */ |
|
| 312 | + $config['cache_handler'] = 'FileCache'; |
|
| 313 | 313 | |
| 314 | 314 | |
| 315 | - /*+---------------------------------------------------------------+ |
|
| 315 | + /*+---------------------------------------------------------------+ |
|
| 316 | 316 | * White list IP access configuration section |
| 317 | 317 | +------------------------------------------------------------------+ |
| 318 | 318 | */ |
| 319 | 319 | |
| 320 | - /** |
|
| 321 | - * White list ip status |
|
| 322 | - * |
|
| 323 | - * if you would to use the white list ip access, set this key to true |
|
| 324 | - */ |
|
| 325 | - $config['white_list_ip_enable'] = false; |
|
| 320 | + /** |
|
| 321 | + * White list ip status |
|
| 322 | + * |
|
| 323 | + * if you would to use the white list ip access, set this key to true |
|
| 324 | + */ |
|
| 325 | + $config['white_list_ip_enable'] = false; |
|
| 326 | 326 | |
| 327 | - /** |
|
| 328 | - * White listed ip addresses |
|
| 329 | - * |
|
| 330 | - * add the allowed ip address list to access this application. |
|
| 331 | - * You can use the wildcard address |
|
| 332 | - * @example: '18.90.09.*', '10.*.*.*', '*' |
|
| 333 | - * |
|
| 334 | - */ |
|
| 335 | - $config['white_list_ip_addresses'] = array('127.0.0.1', '::1'); |
|
| 327 | + /** |
|
| 328 | + * White listed ip addresses |
|
| 329 | + * |
|
| 330 | + * add the allowed ip address list to access this application. |
|
| 331 | + * You can use the wildcard address |
|
| 332 | + * @example: '18.90.09.*', '10.*.*.*', '*' |
|
| 333 | + * |
|
| 334 | + */ |
|
| 335 | + $config['white_list_ip_addresses'] = array('127.0.0.1', '::1'); |
|
| 336 | 336 | |
| 337 | - |
|
| 338 | 337 | \ No newline at end of file |
| 338 | + |
|
| 339 | 339 | \ No newline at end of file |
@@ -1,267 +1,267 @@ |
||
| 1 | 1 | <?php |
| 2 | - /** |
|
| 3 | - * TNH Framework |
|
| 4 | - * |
|
| 5 | - * A simple PHP framework using HMVC architecture |
|
| 6 | - * |
|
| 7 | - * This content is released under the GNU GPL License (GPL) |
|
| 8 | - * |
|
| 9 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 10 | - * |
|
| 11 | - * This program is free software; you can redistribute it and/or |
|
| 12 | - * modify it under the terms of the GNU General Public License |
|
| 13 | - * as published by the Free Software Foundation; either version 3 |
|
| 14 | - * of the License, or (at your option) any later version. |
|
| 15 | - * |
|
| 16 | - * This program is distributed in the hope that it will be useful, |
|
| 17 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 18 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 19 | - * GNU General Public License for more details. |
|
| 20 | - * |
|
| 21 | - * You should have received a copy of the GNU General Public License |
|
| 22 | - * along with this program; if not, write to the Free Software |
|
| 23 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 24 | - */ |
|
| 2 | + /** |
|
| 3 | + * TNH Framework |
|
| 4 | + * |
|
| 5 | + * A simple PHP framework using HMVC architecture |
|
| 6 | + * |
|
| 7 | + * This content is released under the GNU GPL License (GPL) |
|
| 8 | + * |
|
| 9 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 10 | + * |
|
| 11 | + * This program is free software; you can redistribute it and/or |
|
| 12 | + * modify it under the terms of the GNU General Public License |
|
| 13 | + * as published by the Free Software Foundation; either version 3 |
|
| 14 | + * of the License, or (at your option) any later version. |
|
| 15 | + * |
|
| 16 | + * This program is distributed in the hope that it will be useful, |
|
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 19 | + * GNU General Public License for more details. |
|
| 20 | + * |
|
| 21 | + * You should have received a copy of the GNU General Public License |
|
| 22 | + * along with this program; if not, write to the Free Software |
|
| 23 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 24 | + */ |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * the directory separator, under windows it is \ and unix, linux / |
|
| 28 | - */ |
|
| 29 | - define('DS', DIRECTORY_SEPARATOR); |
|
| 26 | + /** |
|
| 27 | + * the directory separator, under windows it is \ and unix, linux / |
|
| 28 | + */ |
|
| 29 | + define('DS', DIRECTORY_SEPARATOR); |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * The root directory of the application. |
|
| 33 | - * |
|
| 34 | - * you can place this directory outside of your web directory, for example "/home/your_app", etc. |
|
| 35 | - */ |
|
| 36 | - define('ROOT_PATH', dirname(realpath(__FILE__)) . DS); |
|
| 31 | + /** |
|
| 32 | + * The root directory of the application. |
|
| 33 | + * |
|
| 34 | + * you can place this directory outside of your web directory, for example "/home/your_app", etc. |
|
| 35 | + */ |
|
| 36 | + define('ROOT_PATH', dirname(realpath(__FILE__)) . DS); |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * The path to the directory. |
|
| 40 | - * |
|
| 41 | - * That contains your static files (javascript, css, images, etc.) |
|
| 42 | - * Note: the path must be relative to the file index.php (the front-end controller). |
|
| 43 | - */ |
|
| 44 | - define('ASSETS_PATH', 'assets/'); |
|
| 38 | + /** |
|
| 39 | + * The path to the directory. |
|
| 40 | + * |
|
| 41 | + * That contains your static files (javascript, css, images, etc.) |
|
| 42 | + * Note: the path must be relative to the file index.php (the front-end controller). |
|
| 43 | + */ |
|
| 44 | + define('ASSETS_PATH', 'assets/'); |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * The path to the directory of your cache files. |
|
| 48 | - * |
|
| 49 | - * This feature is available currently for database and views. |
|
| 50 | - */ |
|
| 51 | - define('CACHE_PATH', ROOT_PATH . 'cache' . DS); |
|
| 46 | + /** |
|
| 47 | + * The path to the directory of your cache files. |
|
| 48 | + * |
|
| 49 | + * This feature is available currently for database and views. |
|
| 50 | + */ |
|
| 51 | + define('CACHE_PATH', ROOT_PATH . 'cache' . DS); |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * The path to the application directory. |
|
| 55 | - * |
|
| 56 | - * It contains your most often used files that is to say which contains your files of the application, |
|
| 57 | - * in MVC architecture (controllers, models, views). |
|
| 58 | - */ |
|
| 59 | - define('APPS_PATH', ROOT_PATH . 'classes' . DS); |
|
| 53 | + /** |
|
| 54 | + * The path to the application directory. |
|
| 55 | + * |
|
| 56 | + * It contains your most often used files that is to say which contains your files of the application, |
|
| 57 | + * in MVC architecture (controllers, models, views). |
|
| 58 | + */ |
|
| 59 | + define('APPS_PATH', ROOT_PATH . 'classes' . DS); |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * The path to the controller directory of your application. |
|
| 63 | - * |
|
| 64 | - * If you already know the MVC architecture you know what a controller means; |
|
| 65 | - * it is he who makes the business logic of your application in general. |
|
| 66 | - */ |
|
| 67 | - define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS); |
|
| 61 | + /** |
|
| 62 | + * The path to the controller directory of your application. |
|
| 63 | + * |
|
| 64 | + * If you already know the MVC architecture you know what a controller means; |
|
| 65 | + * it is he who makes the business logic of your application in general. |
|
| 66 | + */ |
|
| 67 | + define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS); |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * The path to the directory of your model classes of your application. |
|
| 71 | - * |
|
| 72 | - * If you already know the MVC architecture you know what a model means; |
|
| 73 | - * it's the one who interacts with the database, in one word persistent data from your application. |
|
| 74 | - */ |
|
| 75 | - define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS); |
|
| 69 | + /** |
|
| 70 | + * The path to the directory of your model classes of your application. |
|
| 71 | + * |
|
| 72 | + * If you already know the MVC architecture you know what a model means; |
|
| 73 | + * it's the one who interacts with the database, in one word persistent data from your application. |
|
| 74 | + */ |
|
| 75 | + define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS); |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * The path to the directory of your views. |
|
| 79 | - * |
|
| 80 | - * If you already know the MVC architecture you know what a view means, |
|
| 81 | - * a view is just a user interface (html page, form, etc.) that is to say |
|
| 82 | - * everything displayed in the browser interface, etc. |
|
| 83 | - */ |
|
| 84 | - define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS); |
|
| 77 | + /** |
|
| 78 | + * The path to the directory of your views. |
|
| 79 | + * |
|
| 80 | + * If you already know the MVC architecture you know what a view means, |
|
| 81 | + * a view is just a user interface (html page, form, etc.) that is to say |
|
| 82 | + * everything displayed in the browser interface, etc. |
|
| 83 | + */ |
|
| 84 | + define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS); |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * The path to the configuration directory. |
|
| 88 | - * |
|
| 89 | - * That contains most of the configuration files for your |
|
| 90 | - * application (database, class loading file, functions, etc.) |
|
| 91 | - */ |
|
| 92 | - define('CONFIG_PATH', ROOT_PATH . 'config' . DS); |
|
| 86 | + /** |
|
| 87 | + * The path to the configuration directory. |
|
| 88 | + * |
|
| 89 | + * That contains most of the configuration files for your |
|
| 90 | + * application (database, class loading file, functions, etc.) |
|
| 91 | + */ |
|
| 92 | + define('CONFIG_PATH', ROOT_PATH . 'config' . DS); |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * The core directory |
|
| 96 | - * |
|
| 97 | - * It is recommended to put this folder out of the web directory of your server and |
|
| 98 | - * you should not change its content because in case of update you could lose the modified files. |
|
| 99 | - */ |
|
| 100 | - define('CORE_PATH', ROOT_PATH . 'core' . DS); |
|
| 94 | + /** |
|
| 95 | + * The core directory |
|
| 96 | + * |
|
| 97 | + * It is recommended to put this folder out of the web directory of your server and |
|
| 98 | + * you should not change its content because in case of update you could lose the modified files. |
|
| 99 | + */ |
|
| 100 | + define('CORE_PATH', ROOT_PATH . 'core' . DS); |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * The path to the directory of core classes that used by the system. |
|
| 104 | - * |
|
| 105 | - * It contains PHP classes that are used by the framework internally. |
|
| 106 | - */ |
|
| 107 | - define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS); |
|
| 102 | + /** |
|
| 103 | + * The path to the directory of core classes that used by the system. |
|
| 104 | + * |
|
| 105 | + * It contains PHP classes that are used by the framework internally. |
|
| 106 | + */ |
|
| 107 | + define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS); |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * The path to the directory of core classes for the cache used by the system. |
|
| 111 | - * |
|
| 112 | - * It contains PHP classes for the cache drivers. |
|
| 113 | - */ |
|
| 114 | - define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS); |
|
| 109 | + /** |
|
| 110 | + * The path to the directory of core classes for the cache used by the system. |
|
| 111 | + * |
|
| 112 | + * It contains PHP classes for the cache drivers. |
|
| 113 | + */ |
|
| 114 | + define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS); |
|
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | - * The path to the directory of core classes for the database used by the system. |
|
| 118 | - * |
|
| 119 | - * It contains PHP classes for the database library, drivers, etc. |
|
| 120 | - */ |
|
| 121 | - define('CORE_CLASSES_DATABASE_PATH', CORE_CLASSES_PATH . 'database' . DS); |
|
| 117 | + * The path to the directory of core classes for the database used by the system. |
|
| 118 | + * |
|
| 119 | + * It contains PHP classes for the database library, drivers, etc. |
|
| 120 | + */ |
|
| 121 | + define('CORE_CLASSES_DATABASE_PATH', CORE_CLASSES_PATH . 'database' . DS); |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * The path to the directory of core classes for the model used by the system. |
|
| 125 | - * |
|
| 126 | - * It contains PHP classes for the models. |
|
| 127 | - */ |
|
| 128 | - define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS); |
|
| 123 | + /** |
|
| 124 | + * The path to the directory of core classes for the model used by the system. |
|
| 125 | + * |
|
| 126 | + * It contains PHP classes for the models. |
|
| 127 | + */ |
|
| 128 | + define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS); |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * The path to the directory of functions or helper systems. |
|
| 132 | - * |
|
| 133 | - * It contains PHP functions that perform a particular task: character string processing, URL, etc. |
|
| 134 | - */ |
|
| 135 | - define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS); |
|
| 130 | + /** |
|
| 131 | + * The path to the directory of functions or helper systems. |
|
| 132 | + * |
|
| 133 | + * It contains PHP functions that perform a particular task: character string processing, URL, etc. |
|
| 134 | + */ |
|
| 135 | + define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS); |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * The path to the core directory of languages files. |
|
| 139 | - * |
|
| 140 | - */ |
|
| 141 | - define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS); |
|
| 137 | + /** |
|
| 138 | + * The path to the core directory of languages files. |
|
| 139 | + * |
|
| 140 | + */ |
|
| 141 | + define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS); |
|
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * The path to the system library directory. |
|
| 145 | - * |
|
| 146 | - * Which contains the libraries most often used in your web application, as for the |
|
| 147 | - * core directory it is advisable to put it out of the root directory of your application. |
|
| 148 | - */ |
|
| 149 | - define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS); |
|
| 143 | + /** |
|
| 144 | + * The path to the system library directory. |
|
| 145 | + * |
|
| 146 | + * Which contains the libraries most often used in your web application, as for the |
|
| 147 | + * core directory it is advisable to put it out of the root directory of your application. |
|
| 148 | + */ |
|
| 149 | + define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS); |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * The path to the system view directory. |
|
| 153 | - * |
|
| 154 | - * That contains the views used for the system, such as error messages, and so on. |
|
| 155 | - */ |
|
| 156 | - define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS); |
|
| 151 | + /** |
|
| 152 | + * The path to the system view directory. |
|
| 153 | + * |
|
| 154 | + * That contains the views used for the system, such as error messages, and so on. |
|
| 155 | + */ |
|
| 156 | + define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS); |
|
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * The path to the directory of your PHP personal functions or helper. |
|
| 160 | - * |
|
| 161 | - * It contains your PHP functions that perform a particular task: utilities, etc. |
|
| 162 | - * Note: Do not put your personal functions or helpers in the system functions directory, |
|
| 163 | - * because if you update the system you may lose them. |
|
| 164 | - */ |
|
| 165 | - define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS); |
|
| 158 | + /** |
|
| 159 | + * The path to the directory of your PHP personal functions or helper. |
|
| 160 | + * |
|
| 161 | + * It contains your PHP functions that perform a particular task: utilities, etc. |
|
| 162 | + * Note: Do not put your personal functions or helpers in the system functions directory, |
|
| 163 | + * because if you update the system you may lose them. |
|
| 164 | + */ |
|
| 165 | + define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS); |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * The path to the app directory of personal language. |
|
| 169 | - * |
|
| 170 | - * This feature is not yet available. |
|
| 171 | - * You can help us do this if you are nice or wish to see the developed framework. |
|
| 172 | - */ |
|
| 173 | - define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS); |
|
| 167 | + /** |
|
| 168 | + * The path to the app directory of personal language. |
|
| 169 | + * |
|
| 170 | + * This feature is not yet available. |
|
| 171 | + * You can help us do this if you are nice or wish to see the developed framework. |
|
| 172 | + */ |
|
| 173 | + define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS); |
|
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * The path to the directory of your personal libraries |
|
| 177 | - * |
|
| 178 | - * It contains your PHP classes, package, etc. |
|
| 179 | - * Note: you should not put your personal libraries in the system library directory, |
|
| 180 | - * because it is recalled in case of updating the system you might have surprises. |
|
| 181 | - */ |
|
| 182 | - define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS); |
|
| 175 | + /** |
|
| 176 | + * The path to the directory of your personal libraries |
|
| 177 | + * |
|
| 178 | + * It contains your PHP classes, package, etc. |
|
| 179 | + * Note: you should not put your personal libraries in the system library directory, |
|
| 180 | + * because it is recalled in case of updating the system you might have surprises. |
|
| 181 | + */ |
|
| 182 | + define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS); |
|
| 183 | 183 | |
| 184 | - /** |
|
| 185 | - * The path to the directory that contains the log files. |
|
| 186 | - * |
|
| 187 | - * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, |
|
| 188 | - * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more |
|
| 189 | - * details see the documentation of your web server. |
|
| 190 | - * Example for Unix or linux with apache web server: |
|
| 191 | - * # chmod -R 700 /path/to/your/logs/directory/ |
|
| 192 | - * # chown -R www-data:www-data /path/to/your/logs/directory/ |
|
| 193 | - */ |
|
| 194 | - define('LOGS_PATH', ROOT_PATH . 'logs' . DS); |
|
| 184 | + /** |
|
| 185 | + * The path to the directory that contains the log files. |
|
| 186 | + * |
|
| 187 | + * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, |
|
| 188 | + * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more |
|
| 189 | + * details see the documentation of your web server. |
|
| 190 | + * Example for Unix or linux with apache web server: |
|
| 191 | + * # chmod -R 700 /path/to/your/logs/directory/ |
|
| 192 | + * # chown -R www-data:www-data /path/to/your/logs/directory/ |
|
| 193 | + */ |
|
| 194 | + define('LOGS_PATH', ROOT_PATH . 'logs' . DS); |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * The path to the modules directory. |
|
| 198 | - * |
|
| 199 | - * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
|
| 200 | - * in HMVC architecture (hierichical, controllers, models, views). |
|
| 201 | - */ |
|
| 202 | - define('MODULE_PATH', ROOT_PATH . 'modules' . DS); |
|
| 196 | + /** |
|
| 197 | + * The path to the modules directory. |
|
| 198 | + * |
|
| 199 | + * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
|
| 200 | + * in HMVC architecture (hierichical, controllers, models, views). |
|
| 201 | + */ |
|
| 202 | + define('MODULE_PATH', ROOT_PATH . 'modules' . DS); |
|
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * The path to the directory of sources external to your application. |
|
| 206 | - * |
|
| 207 | - * If you have already used "composer" you know what that means. |
|
| 208 | - */ |
|
| 209 | - define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS); |
|
| 204 | + /** |
|
| 205 | + * The path to the directory of sources external to your application. |
|
| 206 | + * |
|
| 207 | + * If you have already used "composer" you know what that means. |
|
| 208 | + */ |
|
| 209 | + define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS); |
|
| 210 | 210 | |
| 211 | - /** |
|
| 212 | - * The front controller of your application. |
|
| 213 | - * |
|
| 214 | - * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of |
|
| 215 | - * your application by using the rewrite module URL of your web server . |
|
| 216 | - * For example, under apache web server, there is a configuration example file that is located at the root |
|
| 217 | - * of your framework folder : "htaccess.txt" rename it to ".htaccess". |
|
| 218 | - */ |
|
| 219 | - define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); |
|
| 211 | + /** |
|
| 212 | + * The front controller of your application. |
|
| 213 | + * |
|
| 214 | + * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of |
|
| 215 | + * your application by using the rewrite module URL of your web server . |
|
| 216 | + * For example, under apache web server, there is a configuration example file that is located at the root |
|
| 217 | + * of your framework folder : "htaccess.txt" rename it to ".htaccess". |
|
| 218 | + */ |
|
| 219 | + define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); |
|
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * Check if user run the application under CLI |
|
| 223 | - */ |
|
| 224 | - define('IS_CLI', stripos('cli', php_sapi_name()) !== false); |
|
| 221 | + /** |
|
| 222 | + * Check if user run the application under CLI |
|
| 223 | + */ |
|
| 224 | + define('IS_CLI', stripos('cli', php_sapi_name()) !== false); |
|
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * The environment of your application (production, test, development). |
|
| 228 | - * |
|
| 229 | - * if your application is still in development you use the value "development" |
|
| 230 | - * so you will have the display of the error messages, etc. |
|
| 231 | - * Once you finish the development of your application that is to put it online |
|
| 232 | - * you change this value to "production" or "testing", in this case there will be deactivation of error messages, |
|
| 233 | - * the loading of the system, will be fast. |
|
| 234 | - */ |
|
| 235 | - define('ENVIRONMENT', 'development'); |
|
| 226 | + /** |
|
| 227 | + * The environment of your application (production, test, development). |
|
| 228 | + * |
|
| 229 | + * if your application is still in development you use the value "development" |
|
| 230 | + * so you will have the display of the error messages, etc. |
|
| 231 | + * Once you finish the development of your application that is to put it online |
|
| 232 | + * you change this value to "production" or "testing", in this case there will be deactivation of error messages, |
|
| 233 | + * the loading of the system, will be fast. |
|
| 234 | + */ |
|
| 235 | + define('ENVIRONMENT', 'development'); |
|
| 236 | 236 | |
| 237 | - /* ---------------------------------------------------------------------------------- */ |
|
| 238 | - /////////////////////////////////////////////////////////////////////////////////////// |
|
| 239 | - /******************** DO NOT CHANGE THE LINES BELOW *********************************/ |
|
| 240 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 237 | + /* ---------------------------------------------------------------------------------- */ |
|
| 238 | + /////////////////////////////////////////////////////////////////////////////////////// |
|
| 239 | + /******************** DO NOT CHANGE THE LINES BELOW *********************************/ |
|
| 240 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 241 | 241 | |
| 242 | - switch (ENVIRONMENT) { |
|
| 243 | - case 'development': |
|
| 244 | - error_reporting(-1); |
|
| 245 | - ini_set('display_errors', 1); |
|
| 246 | - break; |
|
| 247 | - case 'testing': |
|
| 248 | - case 'production': |
|
| 249 | - ini_set('display_errors', 0); |
|
| 250 | - if (version_compare(PHP_VERSION, '5.3', '>=')) { |
|
| 251 | - error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); |
|
| 252 | - } |
|
| 253 | - else{ |
|
| 254 | - error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
|
| 255 | - } |
|
| 256 | - break; |
|
| 257 | - default: |
|
| 258 | - header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); |
|
| 259 | - echo 'The application environment is not set correctly.'; |
|
| 260 | - exit(1); |
|
| 261 | - } |
|
| 242 | + switch (ENVIRONMENT) { |
|
| 243 | + case 'development': |
|
| 244 | + error_reporting(-1); |
|
| 245 | + ini_set('display_errors', 1); |
|
| 246 | + break; |
|
| 247 | + case 'testing': |
|
| 248 | + case 'production': |
|
| 249 | + ini_set('display_errors', 0); |
|
| 250 | + if (version_compare(PHP_VERSION, '5.3', '>=')) { |
|
| 251 | + error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); |
|
| 252 | + } |
|
| 253 | + else{ |
|
| 254 | + error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
|
| 255 | + } |
|
| 256 | + break; |
|
| 257 | + default: |
|
| 258 | + header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); |
|
| 259 | + echo 'The application environment is not set correctly.'; |
|
| 260 | + exit(1); |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * let's go. |
|
| 265 | - * Everything is OK now we launch our application. |
|
| 266 | - */ |
|
| 267 | - require_once CORE_PATH . 'bootstrap.php'; |
|
| 268 | 263 | \ No newline at end of file |
| 264 | + /** |
|
| 265 | + * let's go. |
|
| 266 | + * Everything is OK now we launch our application. |
|
| 267 | + */ |
|
| 268 | + require_once CORE_PATH . 'bootstrap.php'; |
|
| 269 | 269 | \ No newline at end of file |
@@ -1,119 +1,119 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | defined('ROOT_PATH') || exit('Access denied'); |
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 26 | - class Database{ |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | + class Database{ |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * The PDO instance |
|
| 30 | - * @var object |
|
| 31 | - */ |
|
| 28 | + /** |
|
| 29 | + * The PDO instance |
|
| 30 | + * @var object |
|
| 31 | + */ |
|
| 32 | 32 | private $pdo = null; |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * The database name used for the application |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - private $databaseName = null; |
|
| 34 | + /** |
|
| 35 | + * The database name used for the application |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + private $databaseName = null; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * The number of rows returned by the last query |
|
| 42 | - * @var int |
|
| 43 | - */ |
|
| 40 | + /** |
|
| 41 | + * The number of rows returned by the last query |
|
| 42 | + * @var int |
|
| 43 | + */ |
|
| 44 | 44 | private $numRows = 0; |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * The last insert id for the primary key column that have auto increment or sequence |
|
| 48 | - * @var mixed |
|
| 49 | - */ |
|
| 46 | + /** |
|
| 47 | + * The last insert id for the primary key column that have auto increment or sequence |
|
| 48 | + * @var mixed |
|
| 49 | + */ |
|
| 50 | 50 | private $insertId = null; |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * The full SQL query statment after build for each command |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 52 | + /** |
|
| 53 | + * The full SQL query statment after build for each command |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | 56 | private $query = null; |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * The result returned for the last query |
|
| 60 | - * @var mixed |
|
| 61 | - */ |
|
| 58 | + /** |
|
| 59 | + * The result returned for the last query |
|
| 60 | + * @var mixed |
|
| 61 | + */ |
|
| 62 | 62 | private $result = array(); |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * The cache default time to live in second. 0 means no need to use the cache feature |
|
| 66 | - * @var int |
|
| 67 | - */ |
|
| 68 | - private $cacheTtl = 0; |
|
| 64 | + /** |
|
| 65 | + * The cache default time to live in second. 0 means no need to use the cache feature |
|
| 66 | + * @var int |
|
| 67 | + */ |
|
| 68 | + private $cacheTtl = 0; |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * The cache current time to live. 0 means no need to use the cache feature |
|
| 72 | - * @var int |
|
| 73 | - */ |
|
| 70 | + /** |
|
| 71 | + * The cache current time to live. 0 means no need to use the cache feature |
|
| 72 | + * @var int |
|
| 73 | + */ |
|
| 74 | 74 | private $temporaryCacheTtl = 0; |
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * The number of executed query for the current request |
|
| 78 | - * @var int |
|
| 79 | - */ |
|
| 76 | + /** |
|
| 77 | + * The number of executed query for the current request |
|
| 78 | + * @var int |
|
| 79 | + */ |
|
| 80 | 80 | private $queryCount = 0; |
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * The default data to be used in the statments query INSERT, UPDATE |
|
| 84 | - * @var array |
|
| 85 | - */ |
|
| 82 | + /** |
|
| 83 | + * The default data to be used in the statments query INSERT, UPDATE |
|
| 84 | + * @var array |
|
| 85 | + */ |
|
| 86 | 86 | private $data = array(); |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * The database configuration |
|
| 90 | - * @var array |
|
| 91 | - */ |
|
| 88 | + /** |
|
| 89 | + * The database configuration |
|
| 90 | + * @var array |
|
| 91 | + */ |
|
| 92 | 92 | private $config = array(); |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * The logger instance |
|
| 96 | - * @var object |
|
| 97 | - */ |
|
| 94 | + /** |
|
| 95 | + * The logger instance |
|
| 96 | + * @var object |
|
| 97 | + */ |
|
| 98 | 98 | private $logger = null; |
| 99 | 99 | |
| 100 | 100 | /** |
| 101 | - * The cache instance |
|
| 102 | - * @var object |
|
| 103 | - */ |
|
| 101 | + * The cache instance |
|
| 102 | + * @var object |
|
| 103 | + */ |
|
| 104 | 104 | private $cacheInstance = null; |
| 105 | 105 | |
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * The DatabaseQueryBuilder instance |
|
| 109 | - * @var object |
|
| 110 | - */ |
|
| 107 | + /** |
|
| 108 | + * The DatabaseQueryBuilder instance |
|
| 109 | + * @var object |
|
| 110 | + */ |
|
| 111 | 111 | private $queryBuilder = null; |
| 112 | 112 | |
| 113 | 113 | /** |
| 114 | - * The DatabaseQueryRunner instance |
|
| 115 | - * @var object |
|
| 116 | - */ |
|
| 114 | + * The DatabaseQueryRunner instance |
|
| 115 | + * @var object |
|
| 116 | + */ |
|
| 117 | 117 | private $queryRunner = null; |
| 118 | 118 | |
| 119 | 119 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | //Set Log instance to use |
| 127 | 127 | $this->setLoggerFromParamOrCreate(null); |
| 128 | 128 | |
| 129 | - //Set DatabaseQueryBuilder instance to use |
|
| 129 | + //Set DatabaseQueryBuilder instance to use |
|
| 130 | 130 | $this->setDependencyInstanceFromParamOrCreate('queryBuilder', null, 'DatabaseQueryBuilder', 'classes/database'); |
| 131 | 131 | |
| 132 | 132 | //Set DatabaseQueryRunner instance to use |
@@ -144,8 +144,8 @@ discard block |
||
| 144 | 144 | * @return bool |
| 145 | 145 | */ |
| 146 | 146 | public function connect(){ |
| 147 | - $config = $this->getDatabaseConfiguration(); |
|
| 148 | - if (! empty($config)){ |
|
| 147 | + $config = $this->getDatabaseConfiguration(); |
|
| 148 | + if (! empty($config)){ |
|
| 149 | 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'] . "'"); |
@@ -156,14 +156,14 @@ discard block |
||
| 156 | 156 | $this->updateQueryBuilderAndRunnerProperties(); |
| 157 | 157 | |
| 158 | 158 | return is_object($this->pdo); |
| 159 | - } |
|
| 160 | - catch (PDOException $e){ |
|
| 159 | + } |
|
| 160 | + catch (PDOException $e){ |
|
| 161 | 161 | $this->logger->fatal($e->getMessage()); |
| 162 | 162 | show_error('Cannot connect to Database.'); |
| 163 | 163 | return false; |
| 164 | - } |
|
| 165 | - } |
|
| 166 | - return false; |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + return false; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * @return int |
| 173 | 173 | */ |
| 174 | 174 | public function numRows(){ |
| 175 | - return $this->numRows; |
|
| 175 | + return $this->numRows; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | * @return mixed |
| 181 | 181 | */ |
| 182 | 182 | public function insertId(){ |
| 183 | - return $this->insertId; |
|
| 183 | + return $this->insertId; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | |
@@ -191,13 +191,13 @@ discard block |
||
| 191 | 191 | * @return mixed the query SQL string or the record result |
| 192 | 192 | */ |
| 193 | 193 | public function get($returnSQLQueryOrResultType = false){ |
| 194 | - $this->queryBuilder->limit(1); |
|
| 195 | - $query = $this->getAll(true); |
|
| 196 | - if ($returnSQLQueryOrResultType === true){ |
|
| 194 | + $this->queryBuilder->limit(1); |
|
| 195 | + $query = $this->getAll(true); |
|
| 196 | + if ($returnSQLQueryOrResultType === true){ |
|
| 197 | 197 | return $query; |
| 198 | - } else { |
|
| 198 | + } else { |
|
| 199 | 199 | return $this->query($query, false, $returnSQLQueryOrResultType == 'array'); |
| 200 | - } |
|
| 200 | + } |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -207,11 +207,11 @@ discard block |
||
| 207 | 207 | * @return mixed the query SQL string or the record result |
| 208 | 208 | */ |
| 209 | 209 | public function getAll($returnSQLQueryOrResultType = false){ |
| 210 | - $query = $this->queryBuilder->getQuery(); |
|
| 211 | - if ($returnSQLQueryOrResultType === true){ |
|
| 212 | - return $query; |
|
| 213 | - } |
|
| 214 | - return $this->query($query, true, $returnSQLQueryOrResultType == 'array'); |
|
| 210 | + $query = $this->queryBuilder->getQuery(); |
|
| 211 | + if ($returnSQLQueryOrResultType === true){ |
|
| 212 | + return $query; |
|
| 213 | + } |
|
| 214 | + return $this->query($query, true, $returnSQLQueryOrResultType == 'array'); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -221,19 +221,19 @@ discard block |
||
| 221 | 221 | * @return mixed the insert id of the new record or null |
| 222 | 222 | */ |
| 223 | 223 | public function insert($data = array(), $escape = true){ |
| 224 | - if (empty($data) && ! empty($this->data)){ |
|
| 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 | - } |
|
| 229 | - $query = $this->queryBuilder->insert($data, $escape)->getQuery(); |
|
| 230 | - $result = $this->query($query); |
|
| 231 | - if ($result){ |
|
| 228 | + } |
|
| 229 | + $query = $this->queryBuilder->insert($data, $escape)->getQuery(); |
|
| 230 | + $result = $this->query($query); |
|
| 231 | + if ($result){ |
|
| 232 | 232 | $this->insertId = $this->pdo->lastInsertId(); |
| 233 | - //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned |
|
| 233 | + //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned |
|
| 234 | 234 | return ! ($this->insertId) ? true : $this->insertId; |
| 235 | - } |
|
| 236 | - return false; |
|
| 235 | + } |
|
| 236 | + return false; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -243,13 +243,13 @@ discard block |
||
| 243 | 243 | * @return mixed the update status |
| 244 | 244 | */ |
| 245 | 245 | public function update($data = array(), $escape = true){ |
| 246 | - if (empty($data) && ! empty($this->data)){ |
|
| 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; |
| 250 | - } |
|
| 251 | - $query = $this->queryBuilder->update($data, $escape)->getQuery(); |
|
| 252 | - return $this->query($query); |
|
| 250 | + } |
|
| 251 | + $query = $this->queryBuilder->update($data, $escape)->getQuery(); |
|
| 252 | + return $this->query($query); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -257,8 +257,8 @@ discard block |
||
| 257 | 257 | * @return mixed the delete status |
| 258 | 258 | */ |
| 259 | 259 | public function delete(){ |
| 260 | - $query = $this->queryBuilder->delete()->getQuery(); |
|
| 261 | - return $this->query($query); |
|
| 260 | + $query = $this->queryBuilder->delete()->getQuery(); |
|
| 261 | + return $this->query($query); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -267,17 +267,17 @@ discard block |
||
| 267 | 267 | * @return object the current Database instance |
| 268 | 268 | */ |
| 269 | 269 | public function setCache($ttl = 0){ |
| 270 | - $this->cacheTtl = $ttl; |
|
| 271 | - $this->temporaryCacheTtl = $ttl; |
|
| 272 | - return $this; |
|
| 270 | + $this->cacheTtl = $ttl; |
|
| 271 | + $this->temporaryCacheTtl = $ttl; |
|
| 272 | + return $this; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - /** |
|
| 276 | - * Enabled cache temporary for the current query not globally |
|
| 277 | - * @param integer $ttl the cache time to live in second |
|
| 278 | - * @return object the current Database instance |
|
| 279 | - */ |
|
| 280 | - public function cached($ttl = 0){ |
|
| 275 | + /** |
|
| 276 | + * Enabled cache temporary for the current query not globally |
|
| 277 | + * @param integer $ttl the cache time to live in second |
|
| 278 | + * @return object the current Database instance |
|
| 279 | + */ |
|
| 280 | + public function cached($ttl = 0){ |
|
| 281 | 281 | $this->temporaryCacheTtl = $ttl; |
| 282 | 282 | return $this; |
| 283 | 283 | } |
@@ -290,11 +290,11 @@ discard block |
||
| 290 | 290 | * need escaped |
| 291 | 291 | */ |
| 292 | 292 | public function escape($data, $escaped = true){ |
| 293 | - $data = trim($data); |
|
| 294 | - if($escaped){ |
|
| 293 | + $data = trim($data); |
|
| 294 | + if($escaped){ |
|
| 295 | 295 | return $this->pdo->quote($data); |
| 296 | - } |
|
| 297 | - return $data; |
|
| 296 | + } |
|
| 297 | + return $data; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * @return int |
| 303 | 303 | */ |
| 304 | 304 | public function queryCount(){ |
| 305 | - return $this->queryCount; |
|
| 305 | + return $this->queryCount; |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | * @return string |
| 311 | 311 | */ |
| 312 | 312 | public function getQuery(){ |
| 313 | - return $this->query; |
|
| 313 | + return $this->query; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | * @return string |
| 319 | 319 | */ |
| 320 | 320 | public function getDatabaseName(){ |
| 321 | - return $this->databaseName; |
|
| 321 | + return $this->databaseName; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
@@ -326,17 +326,17 @@ discard block |
||
| 326 | 326 | * @return object |
| 327 | 327 | */ |
| 328 | 328 | public function getPdo(){ |
| 329 | - return $this->pdo; |
|
| 329 | + return $this->pdo; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | /** |
| 333 | 333 | * Set the PDO instance |
| 334 | 334 | * @param object $pdo the pdo object |
| 335 | - * @return object Database |
|
| 335 | + * @return object Database |
|
| 336 | 336 | */ |
| 337 | 337 | public function setPdo(PDO $pdo){ |
| 338 | - $this->pdo = $pdo; |
|
| 339 | - return $this; |
|
| 338 | + $this->pdo = $pdo; |
|
| 339 | + return $this; |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | |
@@ -345,44 +345,44 @@ discard block |
||
| 345 | 345 | * @return Log |
| 346 | 346 | */ |
| 347 | 347 | public function getLogger(){ |
| 348 | - return $this->logger; |
|
| 348 | + return $this->logger; |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | /** |
| 352 | 352 | * Set the log instance |
| 353 | 353 | * @param Log $logger the log object |
| 354 | - * @return object Database |
|
| 354 | + * @return object Database |
|
| 355 | 355 | */ |
| 356 | 356 | public function setLogger($logger){ |
| 357 | - $this->logger = $logger; |
|
| 358 | - return $this; |
|
| 357 | + $this->logger = $logger; |
|
| 358 | + return $this; |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - /** |
|
| 362 | - * Return the cache instance |
|
| 363 | - * @return CacheInterface |
|
| 364 | - */ |
|
| 361 | + /** |
|
| 362 | + * Return the cache instance |
|
| 363 | + * @return CacheInterface |
|
| 364 | + */ |
|
| 365 | 365 | public function getCacheInstance(){ |
| 366 | - return $this->cacheInstance; |
|
| 366 | + return $this->cacheInstance; |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | /** |
| 370 | 370 | * Set the cache instance |
| 371 | 371 | * @param CacheInterface $cache the cache object |
| 372 | - * @return object Database |
|
| 372 | + * @return object Database |
|
| 373 | 373 | */ |
| 374 | 374 | public function setCacheInstance($cache){ |
| 375 | - $this->cacheInstance = $cache; |
|
| 376 | - return $this; |
|
| 375 | + $this->cacheInstance = $cache; |
|
| 376 | + return $this; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | |
| 380 | - /** |
|
| 381 | - * Return the DatabaseQueryBuilder instance |
|
| 382 | - * @return object DatabaseQueryBuilder |
|
| 383 | - */ |
|
| 380 | + /** |
|
| 381 | + * Return the DatabaseQueryBuilder instance |
|
| 382 | + * @return object DatabaseQueryBuilder |
|
| 383 | + */ |
|
| 384 | 384 | public function getQueryBuilder(){ |
| 385 | - return $this->queryBuilder; |
|
| 385 | + return $this->queryBuilder; |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
@@ -390,8 +390,8 @@ discard block |
||
| 390 | 390 | * @param object DatabaseQueryBuilder $queryBuilder the DatabaseQueryBuilder object |
| 391 | 391 | */ |
| 392 | 392 | public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder){ |
| 393 | - $this->queryBuilder = $queryBuilder; |
|
| 394 | - return $this; |
|
| 393 | + $this->queryBuilder = $queryBuilder; |
|
| 394 | + return $this; |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | /** |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | * @return object DatabaseQueryRunner |
| 400 | 400 | */ |
| 401 | 401 | public function getQueryRunner(){ |
| 402 | - return $this->queryRunner; |
|
| 402 | + return $this->queryRunner; |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -407,8 +407,8 @@ discard block |
||
| 407 | 407 | * @param object DatabaseQueryRunner $queryRunner the DatabaseQueryRunner object |
| 408 | 408 | */ |
| 409 | 409 | public function setQueryRunner(DatabaseQueryRunner $queryRunner){ |
| 410 | - $this->queryRunner = $queryRunner; |
|
| 411 | - return $this; |
|
| 410 | + $this->queryRunner = $queryRunner; |
|
| 411 | + return $this; |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | /** |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | * @return array |
| 417 | 417 | */ |
| 418 | 418 | public function getData(){ |
| 419 | - return $this->data; |
|
| 419 | + return $this->data; |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
@@ -427,62 +427,62 @@ discard block |
||
| 427 | 427 | * @return object the current Database instance |
| 428 | 428 | */ |
| 429 | 429 | public function setData($key, $value = null, $escape = true){ |
| 430 | - if (is_array($key)){ |
|
| 431 | - foreach($key as $k => $v){ |
|
| 432 | - $this->setData($k, $v, $escape); |
|
| 433 | - } |
|
| 434 | - } else { |
|
| 430 | + if (is_array($key)){ |
|
| 431 | + foreach($key as $k => $v){ |
|
| 432 | + $this->setData($k, $v, $escape); |
|
| 433 | + } |
|
| 434 | + } else { |
|
| 435 | 435 | $this->data[$key] = $this->escape($value, $escape); |
| 436 | - } |
|
| 437 | - return $this; |
|
| 436 | + } |
|
| 437 | + return $this; |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | - /** |
|
| 441 | - * Execute an SQL query |
|
| 442 | - * @param string $query the query SQL string |
|
| 443 | - * @param boolean $returnAsList indicate whether to return all record or just one row |
|
| 444 | - * @param boolean $returnAsArray return the result as array or not |
|
| 445 | - * @return mixed the query result |
|
| 446 | - */ |
|
| 440 | + /** |
|
| 441 | + * Execute an SQL query |
|
| 442 | + * @param string $query the query SQL string |
|
| 443 | + * @param boolean $returnAsList indicate whether to return all record or just one row |
|
| 444 | + * @param boolean $returnAsArray return the result as array or not |
|
| 445 | + * @return mixed the query result |
|
| 446 | + */ |
|
| 447 | 447 | public function query($query, $returnAsList = true, $returnAsArray = false){ |
| 448 | - $this->reset(); |
|
| 449 | - $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query)); |
|
| 450 | - //If is the SELECT query |
|
| 451 | - $isSqlSELECTQuery = stristr($this->query, 'SELECT'); |
|
| 448 | + $this->reset(); |
|
| 449 | + $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query)); |
|
| 450 | + //If is the SELECT query |
|
| 451 | + $isSqlSELECTQuery = stristr($this->query, 'SELECT'); |
|
| 452 | 452 | |
| 453 | - //cache expire time |
|
| 454 | - $cacheExpire = $this->temporaryCacheTtl; |
|
| 453 | + //cache expire time |
|
| 454 | + $cacheExpire = $this->temporaryCacheTtl; |
|
| 455 | 455 | |
| 456 | - //return to the initial cache time |
|
| 457 | - $this->temporaryCacheTtl = $this->cacheTtl; |
|
| 456 | + //return to the initial cache time |
|
| 457 | + $this->temporaryCacheTtl = $this->cacheTtl; |
|
| 458 | 458 | |
| 459 | - //config for cache |
|
| 460 | - $cacheEnable = get_config('cache_enable'); |
|
| 459 | + //config for cache |
|
| 460 | + $cacheEnable = get_config('cache_enable'); |
|
| 461 | 461 | |
| 462 | - //the database cache content |
|
| 463 | - $cacheContent = null; |
|
| 462 | + //the database cache content |
|
| 463 | + $cacheContent = null; |
|
| 464 | 464 | |
| 465 | - //if can use cache feature for this query |
|
| 466 | - $dbCacheStatus = $cacheEnable && $cacheExpire > 0; |
|
| 465 | + //if can use cache feature for this query |
|
| 466 | + $dbCacheStatus = $cacheEnable && $cacheExpire > 0; |
|
| 467 | 467 | |
| 468 | - if ($dbCacheStatus && $isSqlSELECTQuery){ |
|
| 469 | - $this->logger->info('The cache is enabled for this query, try to get result from cache'); |
|
| 470 | - $cacheContent = $this->getCacheContentForQuery($query, $returnAsList, $returnAsArray); |
|
| 471 | - } |
|
| 468 | + if ($dbCacheStatus && $isSqlSELECTQuery){ |
|
| 469 | + $this->logger->info('The cache is enabled for this query, try to get result from cache'); |
|
| 470 | + $cacheContent = $this->getCacheContentForQuery($query, $returnAsList, $returnAsArray); |
|
| 471 | + } |
|
| 472 | 472 | |
| 473 | - if (!$cacheContent){ |
|
| 474 | - //count the number of query execution to server |
|
| 473 | + if (!$cacheContent){ |
|
| 474 | + //count the number of query execution to server |
|
| 475 | 475 | $this->queryCount++; |
| 476 | 476 | |
| 477 | 477 | $queryResult = $this->queryRunner->setQuery($query) |
| 478 | - ->setReturnType($returnAsList) |
|
| 479 | - ->setReturnAsArray($returnAsArray) |
|
| 480 | - ->execute(); |
|
| 478 | + ->setReturnType($returnAsList) |
|
| 479 | + ->setReturnAsArray($returnAsArray) |
|
| 480 | + ->execute(); |
|
| 481 | 481 | |
| 482 | 482 | if (!is_object($queryResult)){ |
| 483 | - $this->result = false; |
|
| 484 | - $this->numRows = 0; |
|
| 485 | - return $this->result; |
|
| 483 | + $this->result = false; |
|
| 484 | + $this->numRows = 0; |
|
| 485 | + return $this->result; |
|
| 486 | 486 | } |
| 487 | 487 | $this->result = $queryResult->getResult(); |
| 488 | 488 | $this->numRows = $queryResult->getNumRows(); |
@@ -490,72 +490,72 @@ discard block |
||
| 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'); |
|
| 495 | - $this->result = $cacheContent; |
|
| 496 | - $this->numRows = count($this->result); |
|
| 497 | - } |
|
| 498 | - return $this->result; |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * Setting the database configuration using the configuration file and additional configuration from param |
|
| 503 | - * @param array $overwriteConfig the additional configuration to overwrite with the existing one |
|
| 504 | - * @param boolean $useConfigFile whether to use database configuration file |
|
| 505 | - * @param boolean $autoConnect whether to connect to database after set the configuration |
|
| 506 | - * @return object Database |
|
| 507 | - */ |
|
| 493 | + } else if ($isSqlSELECTQuery){ |
|
| 494 | + $this->logger->info('The result for query [' .$this->query. '] already cached use it'); |
|
| 495 | + $this->result = $cacheContent; |
|
| 496 | + $this->numRows = count($this->result); |
|
| 497 | + } |
|
| 498 | + return $this->result; |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * Setting the database configuration using the configuration file and additional configuration from param |
|
| 503 | + * @param array $overwriteConfig the additional configuration to overwrite with the existing one |
|
| 504 | + * @param boolean $useConfigFile whether to use database configuration file |
|
| 505 | + * @param boolean $autoConnect whether to connect to database after set the configuration |
|
| 506 | + * @return object Database |
|
| 507 | + */ |
|
| 508 | 508 | public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true, $autoConnect = false){ |
| 509 | - $db = array(); |
|
| 510 | - if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')){ |
|
| 511 | - //here don't use require_once because somewhere user can create database instance directly |
|
| 512 | - require CONFIG_PATH . 'database.php'; |
|
| 513 | - } |
|
| 509 | + $db = array(); |
|
| 510 | + if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')){ |
|
| 511 | + //here don't use require_once because somewhere user can create database instance directly |
|
| 512 | + require CONFIG_PATH . 'database.php'; |
|
| 513 | + } |
|
| 514 | 514 | |
| 515 | - //merge with the parameter |
|
| 516 | - $db = array_merge($db, $overwriteConfig); |
|
| 515 | + //merge with the parameter |
|
| 516 | + $db = array_merge($db, $overwriteConfig); |
|
| 517 | 517 | |
| 518 | - //get the default configuration |
|
| 519 | - $config = $this->getDatabaseDefaultConfiguration(); |
|
| 518 | + //get the default configuration |
|
| 519 | + $config = $this->getDatabaseDefaultConfiguration(); |
|
| 520 | 520 | |
| 521 | - $config = array_merge($config, $db); |
|
| 522 | - //determine the port using the hostname like localhost:3307 |
|
| 523 | - //hostname will be "localhost", and port "3307" |
|
| 524 | - $p = explode(':', $config['hostname']); |
|
| 525 | - if (count($p) >= 2){ |
|
| 526 | - $config['hostname'] = $p[0]; |
|
| 527 | - $config['port'] = $p[1]; |
|
| 528 | - } |
|
| 521 | + $config = array_merge($config, $db); |
|
| 522 | + //determine the port using the hostname like localhost:3307 |
|
| 523 | + //hostname will be "localhost", and port "3307" |
|
| 524 | + $p = explode(':', $config['hostname']); |
|
| 525 | + if (count($p) >= 2){ |
|
| 526 | + $config['hostname'] = $p[0]; |
|
| 527 | + $config['port'] = $p[1]; |
|
| 528 | + } |
|
| 529 | 529 | |
| 530 | - $this->databaseName = $config['database']; |
|
| 531 | - $this->config = $config; |
|
| 532 | - $this->logger->info( |
|
| 533 | - 'The database configuration are listed below: ' |
|
| 534 | - . stringfy_vars(array_merge( |
|
| 535 | - $this->config, |
|
| 536 | - array('password' => string_hidden($this->config['password'])) |
|
| 537 | - )) |
|
| 538 | - ); |
|
| 539 | - if($autoConnect){ |
|
| 540 | - //Now connect to the database |
|
| 541 | - $this->connect(); |
|
| 542 | - } |
|
| 543 | - return $this; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Return the database configuration |
|
| 548 | - * @return array |
|
| 549 | - */ |
|
| 530 | + $this->databaseName = $config['database']; |
|
| 531 | + $this->config = $config; |
|
| 532 | + $this->logger->info( |
|
| 533 | + 'The database configuration are listed below: ' |
|
| 534 | + . stringfy_vars(array_merge( |
|
| 535 | + $this->config, |
|
| 536 | + array('password' => string_hidden($this->config['password'])) |
|
| 537 | + )) |
|
| 538 | + ); |
|
| 539 | + if($autoConnect){ |
|
| 540 | + //Now connect to the database |
|
| 541 | + $this->connect(); |
|
| 542 | + } |
|
| 543 | + return $this; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Return the database configuration |
|
| 548 | + * @return array |
|
| 549 | + */ |
|
| 550 | 550 | public function getDatabaseConfiguration(){ |
| 551 | - return $this->config; |
|
| 551 | + return $this->config; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | /** |
| 555 | 555 | * Close the connexion |
| 556 | 556 | */ |
| 557 | 557 | public function close(){ |
| 558 | - $this->pdo = null; |
|
| 558 | + $this->pdo = null; |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | /** |
@@ -563,16 +563,16 @@ discard block |
||
| 563 | 563 | * @return array |
| 564 | 564 | */ |
| 565 | 565 | protected function getDatabaseDefaultConfiguration(){ |
| 566 | - return array( |
|
| 567 | - 'driver' => '', |
|
| 568 | - 'username' => '', |
|
| 569 | - 'password' => '', |
|
| 570 | - 'database' => '', |
|
| 571 | - 'hostname' => 'localhost', |
|
| 572 | - 'charset' => 'utf8', |
|
| 573 | - 'collation' => 'utf8_general_ci', |
|
| 574 | - 'prefix' => '', |
|
| 575 | - 'port' => '' |
|
| 566 | + return array( |
|
| 567 | + 'driver' => '', |
|
| 568 | + 'username' => '', |
|
| 569 | + 'password' => '', |
|
| 570 | + 'database' => '', |
|
| 571 | + 'hostname' => 'localhost', |
|
| 572 | + 'charset' => 'utf8', |
|
| 573 | + 'collation' => 'utf8_general_ci', |
|
| 574 | + 'prefix' => '', |
|
| 575 | + 'port' => '' |
|
| 576 | 576 | ); |
| 577 | 577 | } |
| 578 | 578 | |
@@ -581,18 +581,18 @@ discard block |
||
| 581 | 581 | * @return void |
| 582 | 582 | */ |
| 583 | 583 | protected function updateQueryBuilderAndRunnerProperties(){ |
| 584 | - //update queryBuilder with some properties needed |
|
| 585 | - if (is_object($this->queryBuilder)){ |
|
| 584 | + //update queryBuilder with some properties needed |
|
| 585 | + if (is_object($this->queryBuilder)){ |
|
| 586 | 586 | $this->queryBuilder->setDriver($this->config['driver']) |
| 587 | - ->setPrefix($this->config['prefix']) |
|
| 588 | - ->setPdo($this->pdo); |
|
| 589 | - } |
|
| 587 | + ->setPrefix($this->config['prefix']) |
|
| 588 | + ->setPdo($this->pdo); |
|
| 589 | + } |
|
| 590 | 590 | |
| 591 | - //update queryRunner with some properties needed |
|
| 592 | - if (is_object($this->queryRunner)){ |
|
| 591 | + //update queryRunner with some properties needed |
|
| 592 | + if (is_object($this->queryRunner)){ |
|
| 593 | 593 | $this->queryRunner->setDriver($this->config['driver']) |
| 594 | - ->setPdo($this->pdo); |
|
| 595 | - } |
|
| 594 | + ->setPdo($this->pdo); |
|
| 595 | + } |
|
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | |
@@ -601,21 +601,21 @@ discard block |
||
| 601 | 601 | * @return string|null the DSN string or null if can not find it |
| 602 | 602 | */ |
| 603 | 603 | protected function getDsnValueFromConfig(){ |
| 604 | - $dsn = null; |
|
| 605 | - $config = $this->getDatabaseConfiguration(); |
|
| 606 | - if (! empty($config)){ |
|
| 604 | + $dsn = null; |
|
| 605 | + $config = $this->getDatabaseConfiguration(); |
|
| 606 | + if (! empty($config)){ |
|
| 607 | 607 | $driver = $config['driver']; |
| 608 | 608 | $driverDsnMap = array( |
| 609 | - 'mysql' => $this->getDsnValueForDriver('mysql'), |
|
| 610 | - 'pgsql' => $this->getDsnValueForDriver('pgsql'), |
|
| 611 | - 'sqlite' => $this->getDsnValueForDriver('sqlite'), |
|
| 612 | - 'oracle' => $this->getDsnValueForDriver('oracle') |
|
| 613 | - ); |
|
| 609 | + 'mysql' => $this->getDsnValueForDriver('mysql'), |
|
| 610 | + 'pgsql' => $this->getDsnValueForDriver('pgsql'), |
|
| 611 | + 'sqlite' => $this->getDsnValueForDriver('sqlite'), |
|
| 612 | + 'oracle' => $this->getDsnValueForDriver('oracle') |
|
| 613 | + ); |
|
| 614 | 614 | if (isset($driverDsnMap[$driver])){ |
| 615 | - $dsn = $driverDsnMap[$driver]; |
|
| 615 | + $dsn = $driverDsnMap[$driver]; |
|
| 616 | 616 | } |
| 617 | - } |
|
| 618 | - return $dsn; |
|
| 617 | + } |
|
| 618 | + return $dsn; |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | /** |
@@ -624,32 +624,32 @@ discard block |
||
| 624 | 624 | * @return string|null the dsn name |
| 625 | 625 | */ |
| 626 | 626 | protected function getDsnValueForDriver($driver){ |
| 627 | - $dsn = ''; |
|
| 628 | - $config = $this->getDatabaseConfiguration(); |
|
| 629 | - if (empty($config)){ |
|
| 627 | + $dsn = ''; |
|
| 628 | + $config = $this->getDatabaseConfiguration(); |
|
| 629 | + if (empty($config)){ |
|
| 630 | 630 | return null; |
| 631 | - } |
|
| 632 | - switch ($driver) { |
|
| 631 | + } |
|
| 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 | - } |
|
| 639 | - $dsn = $driver . ':host=' . $config['hostname'] . ';' . $port . 'dbname=' . $config['database']; |
|
| 640 | - break; |
|
| 638 | + } |
|
| 639 | + $dsn = $driver . ':host=' . $config['hostname'] . ';' . $port . 'dbname=' . $config['database']; |
|
| 640 | + break; |
|
| 641 | 641 | case 'sqlite': |
| 642 | 642 | $dsn = 'sqlite:' . $config['database']; |
| 643 | - break; |
|
| 644 | - case 'oracle': |
|
| 643 | + break; |
|
| 644 | + case 'oracle': |
|
| 645 | 645 | $port = ''; |
| 646 | - if (! empty($config['port'])) { |
|
| 646 | + if (! empty($config['port'])) { |
|
| 647 | 647 | $port = ':' . $config['port']; |
| 648 | - } |
|
| 649 | - $dsn = 'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database']; |
|
| 650 | - break; |
|
| 651 | - } |
|
| 652 | - return $dsn; |
|
| 648 | + } |
|
| 649 | + $dsn = 'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database']; |
|
| 650 | + break; |
|
| 651 | + } |
|
| 652 | + return $dsn; |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | /** |
@@ -661,11 +661,11 @@ discard block |
||
| 661 | 661 | protected function getCacheContentForQuery($query, $returnAsList, $returnAsArray){ |
| 662 | 662 | $cacheKey = $this->getCacheKeyForQuery($query, $returnAsList, $returnAsArray); |
| 663 | 663 | if (! is_object($this->cacheInstance)){ |
| 664 | - //can not call method with reference in argument |
|
| 665 | - //like $this->setCacheInstance(& get_instance()->cache); |
|
| 666 | - //use temporary variable |
|
| 667 | - $instance = & get_instance()->cache; |
|
| 668 | - $this->cacheInstance = $instance; |
|
| 664 | + //can not call method with reference in argument |
|
| 665 | + //like $this->setCacheInstance(& get_instance()->cache); |
|
| 666 | + //use temporary variable |
|
| 667 | + $instance = & get_instance()->cache; |
|
| 668 | + $this->cacheInstance = $instance; |
|
| 669 | 669 | } |
| 670 | 670 | return $this->cacheInstance->get($cacheKey); |
| 671 | 671 | } |
@@ -677,80 +677,80 @@ 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){ |
|
| 680 | + protected function setCacheContentForQuery($query, $key, $result, $expire){ |
|
| 681 | 681 | $this->logger->info('Save the result for query [' .$query. '] into cache for future use'); |
| 682 | 682 | if (! is_object($this->cacheInstance)){ |
| 683 | - //can not call method with reference in argument |
|
| 684 | - //like $this->setCacheInstance(& get_instance()->cache); |
|
| 685 | - //use temporary variable |
|
| 686 | - $instance = & get_instance()->cache; |
|
| 687 | - $this->cacheInstance = $instance; |
|
| 688 | - } |
|
| 683 | + //can not call method with reference in argument |
|
| 684 | + //like $this->setCacheInstance(& get_instance()->cache); |
|
| 685 | + //use temporary variable |
|
| 686 | + $instance = & get_instance()->cache; |
|
| 687 | + $this->cacheInstance = $instance; |
|
| 688 | + } |
|
| 689 | 689 | $this->cacheInstance->set($key, $result, $expire); |
| 690 | - } |
|
| 690 | + } |
|
| 691 | 691 | |
| 692 | 692 | |
| 693 | - /** |
|
| 694 | - * Return the cache key for the given query |
|
| 695 | - * @see Database::query |
|
| 696 | - * |
|
| 697 | - * @return string |
|
| 698 | - */ |
|
| 693 | + /** |
|
| 694 | + * Return the cache key for the given query |
|
| 695 | + * @see Database::query |
|
| 696 | + * |
|
| 697 | + * @return string |
|
| 698 | + */ |
|
| 699 | 699 | protected function getCacheKeyForQuery($query, $returnAsList, $returnAsArray){ |
| 700 | - return md5($query . $returnAsList . $returnAsArray); |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - /** |
|
| 704 | - * Set the dependencies instance using argument or create new instance if is null |
|
| 705 | - * @param string $name this class property name. |
|
| 706 | - * @param object $instance the instance. If is not null will use it |
|
| 707 | - * otherwise will create new instance. |
|
| 708 | - * @param string $loadClassName the name of class to load using class_loader function. |
|
| 709 | - * @param string $loadClassPath the path of class to load using class_loader function. |
|
| 710 | - * |
|
| 711 | - * @return object this current instance |
|
| 712 | - */ |
|
| 700 | + return md5($query . $returnAsList . $returnAsArray); |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + /** |
|
| 704 | + * Set the dependencies instance using argument or create new instance if is null |
|
| 705 | + * @param string $name this class property name. |
|
| 706 | + * @param object $instance the instance. If is not null will use it |
|
| 707 | + * otherwise will create new instance. |
|
| 708 | + * @param string $loadClassName the name of class to load using class_loader function. |
|
| 709 | + * @param string $loadClassPath the path of class to load using class_loader function. |
|
| 710 | + * |
|
| 711 | + * @return object this current instance |
|
| 712 | + */ |
|
| 713 | 713 | protected function setDependencyInstanceFromParamOrCreate($name, $instance = null, $loadClassName = null, $loadClassePath = 'classes'){ |
| 714 | - if ($instance !== null){ |
|
| 714 | + if ($instance !== null){ |
|
| 715 | 715 | $this->{$name} = $instance; |
| 716 | 716 | return $this; |
| 717 | - } |
|
| 718 | - $this->{$name} =& class_loader($loadClassName, $loadClassePath); |
|
| 719 | - return $this; |
|
| 717 | + } |
|
| 718 | + $this->{$name} =& class_loader($loadClassName, $loadClassePath); |
|
| 719 | + return $this; |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | - /** |
|
| 723 | - * Set the Log instance using argument or create new instance |
|
| 724 | - * @param object $logger the Log instance if not null |
|
| 725 | - * |
|
| 726 | - * @return object this current instance |
|
| 727 | - */ |
|
| 722 | + /** |
|
| 723 | + * Set the Log instance using argument or create new instance |
|
| 724 | + * @param object $logger the Log instance if not null |
|
| 725 | + * |
|
| 726 | + * @return object this current instance |
|
| 727 | + */ |
|
| 728 | 728 | protected function setLoggerFromParamOrCreate(Log $logger = null){ |
| 729 | - $this->setDependencyInstanceFromParamOrCreate('logger', $logger, 'Log', 'classes'); |
|
| 730 | - if ($logger === null){ |
|
| 729 | + $this->setDependencyInstanceFromParamOrCreate('logger', $logger, 'Log', 'classes'); |
|
| 730 | + if ($logger === null){ |
|
| 731 | 731 | $this->logger->setLogger('Library::Database'); |
| 732 | - } |
|
| 733 | - return $this; |
|
| 732 | + } |
|
| 733 | + return $this; |
|
| 734 | 734 | } |
| 735 | 735 | |
| 736 | 736 | /** |
| 737 | 737 | * Reset the database class attributs to the initail values before each query. |
| 738 | 738 | */ |
| 739 | 739 | private function reset(){ |
| 740 | - //query builder reset |
|
| 741 | - $this->queryBuilder->reset(); |
|
| 742 | - $this->numRows = 0; |
|
| 743 | - $this->insertId = null; |
|
| 744 | - $this->query = null; |
|
| 745 | - $this->result = array(); |
|
| 746 | - $this->data = array(); |
|
| 740 | + //query builder reset |
|
| 741 | + $this->queryBuilder->reset(); |
|
| 742 | + $this->numRows = 0; |
|
| 743 | + $this->insertId = null; |
|
| 744 | + $this->query = null; |
|
| 745 | + $this->result = array(); |
|
| 746 | + $this->data = array(); |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | /** |
| 750 | 750 | * The class destructor |
| 751 | 751 | */ |
| 752 | 752 | public function __destruct(){ |
| 753 | - $this->pdo = null; |
|
| 753 | + $this->pdo = null; |
|
| 754 | 754 | } |
| 755 | 755 | |
| 756 | 756 | } |
@@ -1,32 +1,32 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | defined('ROOT_PATH') || exit('Access denied'); |
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | class Pagination{ |
| 28 | 28 | |
| 29 | - /** |
|
| 29 | + /** |
|
| 30 | 30 | * The list of loaded config |
| 31 | 31 | * @var array |
| 32 | 32 | */ |
@@ -49,13 +49,13 @@ discard block |
||
| 49 | 49 | if (empty($config) || ! is_array($config)){ |
| 50 | 50 | show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php'); |
| 51 | 51 | } |
| 52 | - else{ |
|
| 53 | - $config = array_merge($config, $overwriteConfig); |
|
| 54 | - $this->config = $config; |
|
| 52 | + else{ |
|
| 53 | + $config = array_merge($config, $overwriteConfig); |
|
| 54 | + $this->config = $config; |
|
| 55 | 55 | //put it gobally |
| 56 | - Config::setAll($config); |
|
| 57 | - unset($config); |
|
| 58 | - } |
|
| 56 | + Config::setAll($config); |
|
| 57 | + unset($config); |
|
| 58 | + } |
|
| 59 | 59 | } |
| 60 | 60 | else{ |
| 61 | 61 | show_error('Unable to find the pagination configuration file'); |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | return $this->paginationQueryString; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Set the value of the pagination query string |
|
| 97 | - * @param string $paginationQueryString the new value |
|
| 98 | - * @return object |
|
| 99 | - */ |
|
| 95 | + /** |
|
| 96 | + * Set the value of the pagination query string |
|
| 97 | + * @param string $paginationQueryString the new value |
|
| 98 | + * @return object |
|
| 99 | + */ |
|
| 100 | 100 | public function setPaginationQueryString($paginationQueryString){ |
| 101 | 101 | $this->paginationQueryString = $paginationQueryString; |
| 102 | 102 | return $this; |
@@ -113,7 +113,7 @@ discard block |
||
| 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 | 119 | else{ |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | public function getLink($totalRows, $currentPageNumber){ |
| 148 | 148 | $numberOfLink = $this->config['nb_link']; |
| 149 | - $numberOfRowPerPage = $this->config['pagination_per_page']; |
|
| 149 | + $numberOfRowPerPage = $this->config['pagination_per_page']; |
|
| 150 | 150 | if (empty($this->paginationQueryString)){ |
| 151 | 151 | //determine the pagination query string value |
| 152 | 152 | $this->determinePaginationQueryStringValue(); |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | $numberOfRowPerPage = (int) $numberOfRowPerPage; |
| 160 | 160 | |
| 161 | 161 | if ($currentPageNumber <= 0){ |
| 162 | - $currentPageNumber = 1; |
|
| 163 | - } |
|
| 162 | + $currentPageNumber = 1; |
|
| 163 | + } |
|
| 164 | 164 | if ($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0) { |
| 165 | 165 | return $navbar; |
| 166 | 166 | } |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | $navbar .= $this->buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber); |
| 186 | 186 | } |
| 187 | 187 | else if ($currentPageNumber == $numberOfPage){ |
| 188 | - $navbar .= $this->buildPaginationLinkForLastPage($begin, $end, $currentPageNumber); |
|
| 188 | + $navbar .= $this->buildPaginationLinkForLastPage($begin, $end, $currentPageNumber); |
|
| 189 | 189 | } |
| 190 | 190 | $navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close']; |
| 191 | 191 | return $navbar; |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | $navbar .= $this->config['next_open'] |
| 256 | - . '<a href="' . $query . ($currentPageNumber + 1) . '">' |
|
| 257 | - . $this->config['next_text'] . '</a>' . $this->config['next_close']; |
|
| 256 | + . '<a href="' . $query . ($currentPageNumber + 1) . '">' |
|
| 257 | + . $this->config['next_text'] . '</a>' . $this->config['next_close']; |
|
| 258 | 258 | return $navbar; |
| 259 | 259 | } |
| 260 | 260 | |