@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | public function setTos(array $emails) |
| 143 | 143 | { |
| 144 | 144 | foreach ($emails as $name => $email) { |
| 145 | - if(is_numeric($name)){ |
|
| 145 | + if (is_numeric($name)) { |
|
| 146 | 146 | $this->setTo($email); |
| 147 | 147 | } |
| 148 | - else{ |
|
| 148 | + else { |
|
| 149 | 149 | $this->setTo($email, $name); |
| 150 | 150 | } |
| 151 | 151 | } |
@@ -275,8 +275,8 @@ discard block |
||
| 275 | 275 | */ |
| 276 | 276 | public function addAttachment($path, $filename = null, $data = null) |
| 277 | 277 | { |
| 278 | - if(! file_exists($path)){ |
|
| 279 | - show_error('The file [' .$path. '] does not exists.'); |
|
| 278 | + if (!file_exists($path)) { |
|
| 279 | + show_error('The file [' . $path . '] does not exists.'); |
|
| 280 | 280 | } |
| 281 | 281 | $filename = empty($filename) ? basename($path) : $filename; |
| 282 | 282 | $filename = $this->encodeUtf8($this->filterOther((string) $filename)); |
@@ -298,13 +298,13 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | public function getAttachmentData($path) |
| 300 | 300 | { |
| 301 | - if(! file_exists($path)){ |
|
| 302 | - show_error('The file [' .$path. '] does not exists.'); |
|
| 301 | + if (!file_exists($path)) { |
|
| 302 | + show_error('The file [' . $path . '] does not exists.'); |
|
| 303 | 303 | } |
| 304 | 304 | $filesize = filesize($path); |
| 305 | 305 | $handle = fopen($path, "r"); |
| 306 | 306 | $attachment = null; |
| 307 | - if(is_resource($handle)){ |
|
| 307 | + if (is_resource($handle)) { |
|
| 308 | 308 | $attachment = fread($handle, $filesize); |
| 309 | 309 | fclose($handle); |
| 310 | 310 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * PDF library to generate PDF document using the library DOMPDF |
| 29 | 29 | */ |
| 30 | - class PDF extends BaseClass{ |
|
| 30 | + class PDF extends BaseClass { |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * The dompdf instance |
@@ -38,10 +38,10 @@ discard block |
||
| 38 | 38 | /** |
| 39 | 39 | * Create PDF library instance |
| 40 | 40 | */ |
| 41 | - public function __construct(){ |
|
| 41 | + public function __construct() { |
|
| 42 | 42 | parent::__construct(); |
| 43 | 43 | |
| 44 | - require_once VENDOR_PATH.'dompdf/dompdf_config.inc.php'; |
|
| 44 | + require_once VENDOR_PATH . 'dompdf/dompdf_config.inc.php'; |
|
| 45 | 45 | $this->dompdf = new Dompdf(); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -55,15 +55,15 @@ discard block |
||
| 55 | 55 | * @return string|void if $stream is true send PDF document to browser for download, else return the generated PDF |
| 56 | 56 | * content like to join in Email attachment of for other purpose use. |
| 57 | 57 | */ |
| 58 | - public function generate($html, $filename = 'output.pdf', $stream = true, $paper = 'A4', $orientation = 'portrait'){ |
|
| 59 | - $this->logger->info('Generating of PDF document: filename [' .$filename. '], stream [' .($stream ? 'TRUE':'FALSE'). '], paper [' .$paper. '], orientation [' .$orientation. ']'); |
|
| 58 | + public function generate($html, $filename = 'output.pdf', $stream = true, $paper = 'A4', $orientation = 'portrait') { |
|
| 59 | + $this->logger->info('Generating of PDF document: filename [' . $filename . '], stream [' . ($stream ? 'TRUE' : 'FALSE') . '], paper [' . $paper . '], orientation [' . $orientation . ']'); |
|
| 60 | 60 | $this->dompdf->load_html($html); |
| 61 | 61 | $this->dompdf->set_paper($paper, $orientation); |
| 62 | 62 | $this->dompdf->render(); |
| 63 | - if($stream){ |
|
| 63 | + if ($stream) { |
|
| 64 | 64 | $this->dompdf->stream($filename); |
| 65 | 65 | } |
| 66 | - else{ |
|
| 66 | + else { |
|
| 67 | 67 | return $this->dompdf->output(); |
| 68 | 68 | } |
| 69 | 69 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @return object the dompdf instance |
| 75 | 75 | */ |
| 76 | - public function getDompdf(){ |
|
| 76 | + public function getDompdf() { |
|
| 77 | 77 | return $this->dompdf; |
| 78 | 78 | } |
| 79 | 79 | |
@@ -25,13 +25,13 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class FormValidation extends BaseClass{ |
|
| 28 | + class FormValidation extends BaseClass { |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * The form validation status |
| 32 | 32 | * @var boolean |
| 33 | 33 | */ |
| 34 | - protected $_success = false; |
|
| 34 | + protected $_success = false; |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * The list of errors messages |
@@ -40,31 +40,31 @@ discard block |
||
| 40 | 40 | protected $_errorsMessages = array(); |
| 41 | 41 | |
| 42 | 42 | // Array of rule sets, fieldName => PIPE seperated ruleString |
| 43 | - protected $_rules = array(); |
|
| 43 | + protected $_rules = array(); |
|
| 44 | 44 | |
| 45 | 45 | // Array of errors, niceName => Error Message |
| 46 | - protected $_errors = array(); |
|
| 46 | + protected $_errors = array(); |
|
| 47 | 47 | |
| 48 | 48 | // Array of post Key => Nice name labels |
| 49 | - protected $_labels = array(); |
|
| 49 | + protected $_labels = array(); |
|
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * The errors delimiters |
| 53 | 53 | * @var array |
| 54 | 54 | */ |
| 55 | - protected $_allErrorsDelimiter = array('<div class="error">', '</div>'); |
|
| 55 | + protected $_allErrorsDelimiter = array('<div class="error">', '</div>'); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * The each error delimiter |
| 59 | 59 | * @var array |
| 60 | 60 | */ |
| 61 | - protected $_eachErrorDelimiter = array('<p class="error">', '</p>'); |
|
| 61 | + protected $_eachErrorDelimiter = array('<p class="error">', '</p>'); |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * Indicated if need force the validation to be failed |
| 65 | 65 | * @var boolean |
| 66 | 66 | */ |
| 67 | - protected $_forceFail = false; |
|
| 67 | + protected $_forceFail = false; |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * The list of the error messages overrides by the original |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | //Load form validation language message |
| 97 | 97 | Loader::lang('form_validation'); |
| 98 | 98 | $obj = & get_instance(); |
| 99 | - $this->_errorsMessages = array( |
|
| 99 | + $this->_errorsMessages = array( |
|
| 100 | 100 | 'required' => $obj->lang->get('fv_required'), |
| 101 | 101 | 'min_length' => $obj->lang->get('fv_min_length'), |
| 102 | 102 | 'max_length' => $obj->lang->get('fv_max_length'), |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * Set the database instance |
| 127 | 127 | * @param object $database the database instance |
| 128 | 128 | */ |
| 129 | - public function setDatabase(Database $database){ |
|
| 129 | + public function setDatabase(Database $database) { |
|
| 130 | 130 | $this->databaseInstance = $database; |
| 131 | 131 | return $this; |
| 132 | 132 | } |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * Get the database instance |
| 136 | 136 | * @return object the database instance |
| 137 | 137 | */ |
| 138 | - public function getDatabase(){ |
|
| 138 | + public function getDatabase() { |
|
| 139 | 139 | return $this->databaseInstance; |
| 140 | 140 | } |
| 141 | 141 | |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * |
| 159 | 159 | * @return FormValidation Current instance of object. |
| 160 | 160 | */ |
| 161 | - public function setData(array $data){ |
|
| 161 | + public function setData(array $data) { |
|
| 162 | 162 | $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data)); |
| 163 | 163 | $this->data = $data; |
| 164 | 164 | return $this; |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * Get the form validation data |
| 169 | 169 | * @return array the form validation data to be validated |
| 170 | 170 | */ |
| 171 | - public function getData(){ |
|
| 171 | + public function getData() { |
|
| 172 | 172 | return $this->data; |
| 173 | 173 | } |
| 174 | 174 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * |
| 178 | 178 | * @return string the function name |
| 179 | 179 | */ |
| 180 | - protected function _toCallCase($funcName, $prefix='_validate') { |
|
| 180 | + protected function _toCallCase($funcName, $prefix = '_validate') { |
|
| 181 | 181 | $funcName = strtolower($funcName); |
| 182 | 182 | $finalFuncName = $prefix; |
| 183 | 183 | foreach (explode('_', $funcName) as $funcNamePart) { |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @return boolean Whether or not the form has been submitted or the data is available for validation. |
| 202 | 202 | */ |
| 203 | 203 | public function canDoValidation() { |
| 204 | - return get_instance()->request->method() === 'POST' || ! empty($this->data); |
|
| 204 | + return get_instance()->request->method() === 'POST' || !empty($this->data); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -221,14 +221,14 @@ discard block |
||
| 221 | 221 | * Validate the CSRF |
| 222 | 222 | * @return void |
| 223 | 223 | */ |
| 224 | - protected function validateCSRF(){ |
|
| 225 | - if(get_instance()->request->method() == 'POST'){ |
|
| 224 | + protected function validateCSRF() { |
|
| 225 | + if (get_instance()->request->method() == 'POST') { |
|
| 226 | 226 | $this->logger->debug('Check if CSRF is enabled in configuration'); |
| 227 | 227 | //first check for CSRF |
| 228 | - if (get_config('csrf_enable', false) && ! Security::validateCSRF()){ |
|
| 228 | + if (get_config('csrf_enable', false) && !Security::validateCSRF()) { |
|
| 229 | 229 | show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.'); |
| 230 | 230 | } |
| 231 | - else{ |
|
| 231 | + else { |
|
| 232 | 232 | $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it'); |
| 233 | 233 | } |
| 234 | 234 | } |
@@ -246,10 +246,10 @@ discard block |
||
| 246 | 246 | $this->_forceFail = false; |
| 247 | 247 | |
| 248 | 248 | foreach ($this->getData() as $inputName => $inputVal) { |
| 249 | - if(is_array($this->data[$inputName])){ |
|
| 249 | + if (is_array($this->data[$inputName])) { |
|
| 250 | 250 | $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
| 251 | 251 | } |
| 252 | - else{ |
|
| 252 | + else { |
|
| 253 | 253 | $this->data[$inputName] = trim($this->data[$inputName]); |
| 254 | 254 | } |
| 255 | 255 | |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | - $this->_success = empty($this->_errors) && $this->_forceFail === false; |
|
| 262 | + $this->_success = empty($this->_errors) && $this->_forceFail === false; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | public function setRule($inputField, $inputLabel, $ruleSets) { |
| 274 | 274 | $this->_rules[$inputField] = $ruleSets; |
| 275 | 275 | $this->_labels[$inputField] = $inputLabel; |
| 276 | - $this->logger->info('Set the field rule: name [' .$inputField. '], label [' .$inputLabel. '], rules [' .$ruleSets. ']'); |
|
| 276 | + $this->logger->info('Set the field rule: name [' . $inputField . '], label [' . $inputLabel . '], rules [' . $ruleSets . ']'); |
|
| 277 | 277 | return $this; |
| 278 | 278 | } |
| 279 | 279 | |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | } |
| 438 | 438 | $errorOutput .= $errorsEnd; |
| 439 | 439 | echo ($echo) ? $errorOutput : ''; |
| 440 | - return (! $echo) ? $errorOutput : null; |
|
| 440 | + return (!$echo) ? $errorOutput : null; |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | /** |
@@ -462,25 +462,25 @@ discard block |
||
| 462 | 462 | /* |
| 463 | 463 | //////////////// hack for regex rule that can contain "|" |
| 464 | 464 | */ |
| 465 | - if(strpos($ruleString, 'regex') !== false){ |
|
| 465 | + if (strpos($ruleString, 'regex') !== false) { |
|
| 466 | 466 | $regexRule = array(); |
| 467 | 467 | $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#'; |
| 468 | 468 | preg_match($rule, $ruleString, $regexRule); |
| 469 | 469 | $ruleStringTemp = preg_replace($rule, '', $ruleString); |
| 470 | - if(!empty($regexRule[0])){ |
|
| 470 | + if (!empty($regexRule[0])) { |
|
| 471 | 471 | $ruleSets[] = $regexRule[0]; |
| 472 | 472 | } |
| 473 | 473 | $ruleStringRegex = explode('|', $ruleStringTemp); |
| 474 | 474 | foreach ($ruleStringRegex as $rule) { |
| 475 | 475 | $rule = trim($rule); |
| 476 | - if($rule){ |
|
| 476 | + if ($rule) { |
|
| 477 | 477 | $ruleSets[] = $rule; |
| 478 | 478 | } |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | } |
| 482 | 482 | /***********************************/ |
| 483 | - else{ |
|
| 483 | + else { |
|
| 484 | 484 | if (strpos($ruleString, '|') !== FALSE) { |
| 485 | 485 | $ruleSets = explode('|', $ruleString); |
| 486 | 486 | } else { |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | * @return void |
| 513 | 513 | */ |
| 514 | 514 | protected function _validateRule($inputName, $inputVal, $ruleName) { |
| 515 | - $this->logger->debug('Rule validation of field [' .$inputName. '], value [' .$inputVal. '], rule [' .$ruleName. ']'); |
|
| 515 | + $this->logger->debug('Rule validation of field [' . $inputName . '], value [' . $inputVal . '], rule [' . $ruleName . ']'); |
|
| 516 | 516 | // Array to store args |
| 517 | 517 | $ruleArgs = array(); |
| 518 | 518 | |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | $key = $i - 1; |
| 558 | 558 | $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase); |
| 559 | 559 | } |
| 560 | - if (! array_key_exists($inputName, $this->_errors)) { |
|
| 560 | + if (!array_key_exists($inputName, $this->_errors)) { |
|
| 561 | 561 | $this->_errors[$inputName] = $rulePhrase; |
| 562 | 562 | } |
| 563 | 563 | } |
@@ -609,13 +609,13 @@ discard block |
||
| 609 | 609 | */ |
| 610 | 610 | protected function _validateRequired($inputName, $ruleName, array $ruleArgs) { |
| 611 | 611 | $inputVal = $this->post($inputName); |
| 612 | - if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) { |
|
| 612 | + if (array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) { |
|
| 613 | 613 | $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]); |
| 614 | 614 | if ($inputVal == '' && $callbackReturn == true) { |
| 615 | 615 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 616 | 616 | } |
| 617 | 617 | } |
| 618 | - else if($inputVal == '') { |
|
| 618 | + else if ($inputVal == '') { |
|
| 619 | 619 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 620 | 620 | } |
| 621 | 621 | } |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | protected function _validateCallback($inputName, $ruleName, array $ruleArgs) { |
| 642 | 642 | if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) { |
| 643 | 643 | $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]); |
| 644 | - if(! $result){ |
|
| 644 | + if (!$result) { |
|
| 645 | 645 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
| 646 | 646 | } |
| 647 | 647 | } |
@@ -675,7 +675,7 @@ discard block |
||
| 675 | 675 | continue; |
| 676 | 676 | } |
| 677 | 677 | } |
| 678 | - else{ |
|
| 678 | + else { |
|
| 679 | 679 | if ($inputVal == $doNotEqual) { |
| 680 | 680 | $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual)); |
| 681 | 681 | continue; |
@@ -705,8 +705,8 @@ discard block |
||
| 705 | 705 | */ |
| 706 | 706 | protected function _validateValidEmail($inputName, $ruleName, array $ruleArgs) { |
| 707 | 707 | $inputVal = $this->post($inputName); |
| 708 | - if (! preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) { |
|
| 709 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 708 | + if (!preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) { |
|
| 709 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 710 | 710 | return; |
| 711 | 711 | } |
| 712 | 712 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
@@ -722,7 +722,7 @@ discard block |
||
| 722 | 722 | protected function _validateExactLength($inputName, $ruleName, array $ruleArgs) { |
| 723 | 723 | $inputVal = $this->post($inputName); |
| 724 | 724 | if (strlen($inputVal) != $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
| 725 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 725 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 726 | 726 | return; |
| 727 | 727 | } |
| 728 | 728 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -738,7 +738,7 @@ discard block |
||
| 738 | 738 | protected function _validateMaxLength($inputName, $ruleName, array $ruleArgs) { |
| 739 | 739 | $inputVal = $this->post($inputName); |
| 740 | 740 | if (strlen($inputVal) > $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
| 741 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 741 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 742 | 742 | return; |
| 743 | 743 | } |
| 744 | 744 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | protected function _validateMinLength($inputName, $ruleName, array $ruleArgs) { |
| 755 | 755 | $inputVal = $this->post($inputName); |
| 756 | 756 | if (strlen($inputVal) < $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
| 757 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 757 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 758 | 758 | return; |
| 759 | 759 | } |
| 760 | 760 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -770,7 +770,7 @@ discard block |
||
| 770 | 770 | protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) { |
| 771 | 771 | $inputVal = $this->post($inputName); |
| 772 | 772 | if ($inputVal >= $ruleArgs[1]) { |
| 773 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 773 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 774 | 774 | return; |
| 775 | 775 | } |
| 776 | 776 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -786,7 +786,7 @@ discard block |
||
| 786 | 786 | protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) { |
| 787 | 787 | $inputVal = $this->post($inputName); |
| 788 | 788 | if ($inputVal <= $ruleArgs[1]) { |
| 789 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 789 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 790 | 790 | return; |
| 791 | 791 | } |
| 792 | 792 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -801,8 +801,8 @@ discard block |
||
| 801 | 801 | */ |
| 802 | 802 | protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) { |
| 803 | 803 | $inputVal = $this->post($inputName); |
| 804 | - if (! is_numeric($inputVal)) { |
|
| 805 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 804 | + if (!is_numeric($inputVal)) { |
|
| 805 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 806 | 806 | return; |
| 807 | 807 | } |
| 808 | 808 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -817,9 +817,9 @@ discard block |
||
| 817 | 817 | */ |
| 818 | 818 | protected function _validateExists($inputName, $ruleName, array $ruleArgs) { |
| 819 | 819 | $inputVal = $this->post($inputName); |
| 820 | - if (! is_object($this->databaseInstance)){ |
|
| 820 | + if (!is_object($this->databaseInstance)) { |
|
| 821 | 821 | $obj = & get_instance(); |
| 822 | - if(isset($obj->database)){ |
|
| 822 | + if (isset($obj->database)) { |
|
| 823 | 823 | $this->databaseInstance = $obj->database; |
| 824 | 824 | } |
| 825 | 825 | } |
@@ -828,7 +828,7 @@ discard block |
||
| 828 | 828 | ->where($column, $inputVal); |
| 829 | 829 | $this->databaseInstance->get(); |
| 830 | 830 | if ($this->databaseInstance->numRows() <= 0) { |
| 831 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 831 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 832 | 832 | return; |
| 833 | 833 | } |
| 834 | 834 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -843,9 +843,9 @@ discard block |
||
| 843 | 843 | */ |
| 844 | 844 | protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) { |
| 845 | 845 | $inputVal = $this->post($inputName); |
| 846 | - if (! is_object($this->databaseInstance)){ |
|
| 846 | + if (!is_object($this->databaseInstance)) { |
|
| 847 | 847 | $obj = & get_instance(); |
| 848 | - if(isset($obj->database)){ |
|
| 848 | + if (isset($obj->database)) { |
|
| 849 | 849 | $this->databaseInstance = $obj->database; |
| 850 | 850 | } |
| 851 | 851 | } |
@@ -854,7 +854,7 @@ discard block |
||
| 854 | 854 | ->where($column, $inputVal); |
| 855 | 855 | $this->databaseInstance->get(); |
| 856 | 856 | if ($this->databaseInstance->numRows() > 0) { |
| 857 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 857 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 858 | 858 | return; |
| 859 | 859 | } |
| 860 | 860 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -869,14 +869,14 @@ discard block |
||
| 869 | 869 | */ |
| 870 | 870 | protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) { |
| 871 | 871 | $inputVal = $this->post($inputName); |
| 872 | - if (! is_object($this->databaseInstance)){ |
|
| 872 | + if (!is_object($this->databaseInstance)) { |
|
| 873 | 873 | $obj = & get_instance(); |
| 874 | - if(isset($obj->database)){ |
|
| 874 | + if (isset($obj->database)) { |
|
| 875 | 875 | $this->databaseInstance = $obj->database; |
| 876 | 876 | } |
| 877 | 877 | } |
| 878 | 878 | $data = explode(',', $ruleArgs[1]); |
| 879 | - if(count($data) < 2){ |
|
| 879 | + if (count($data) < 2) { |
|
| 880 | 880 | return; |
| 881 | 881 | } |
| 882 | 882 | list($table, $column) = explode('.', $data[0]); |
@@ -886,7 +886,7 @@ discard block |
||
| 886 | 886 | ->where($field, '!=', trim($val)); |
| 887 | 887 | $this->databaseInstance->get(); |
| 888 | 888 | if ($this->databaseInstance->numRows() > 0) { |
| 889 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 889 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 890 | 890 | return; |
| 891 | 891 | } |
| 892 | 892 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -903,8 +903,8 @@ discard block |
||
| 903 | 903 | $inputVal = $this->post($inputName); |
| 904 | 904 | $list = explode(',', $ruleArgs[1]); |
| 905 | 905 | $list = array_map('trim', $list); |
| 906 | - if (! in_array($inputVal, $list)) { |
|
| 907 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 906 | + if (!in_array($inputVal, $list)) { |
|
| 907 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 908 | 908 | return; |
| 909 | 909 | } |
| 910 | 910 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -920,8 +920,8 @@ discard block |
||
| 920 | 920 | protected function _validateRegex($inputName, $ruleName, array $ruleArgs) { |
| 921 | 921 | $inputVal = $this->post($inputName); |
| 922 | 922 | $regex = $ruleArgs[1]; |
| 923 | - if (! preg_match($regex, $inputVal)) { |
|
| 924 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 923 | + if (!preg_match($regex, $inputVal)) { |
|
| 924 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 925 | 925 | return; |
| 926 | 926 | } |
| 927 | 927 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @package FileUpload |
| 38 | 38 | * @version 1.5 |
| 39 | 39 | */ |
| 40 | - class Upload extends BaseClass{ |
|
| 40 | + class Upload extends BaseClass { |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Version |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @version 1.0 |
| 70 | 70 | * @var array |
| 71 | 71 | */ |
| 72 | - private $file_array = array(); |
|
| 72 | + private $file_array = array(); |
|
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * If the file you are trying to upload already exists it will |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @version 1.0 |
| 120 | 120 | * @var float |
| 121 | 121 | */ |
| 122 | - private $max_file_size= 0.0; |
|
| 122 | + private $max_file_size = 0.0; |
|
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * List of allowed mime types |
@@ -211,11 +211,11 @@ discard block |
||
| 211 | 211 | * @return object |
| 212 | 212 | * @method object __construct |
| 213 | 213 | */ |
| 214 | - public function __construct(){ |
|
| 214 | + public function __construct() { |
|
| 215 | 215 | parent::__construct(); |
| 216 | 216 | |
| 217 | 217 | Loader::lang('file_upload'); |
| 218 | - $obj =& get_instance(); |
|
| 218 | + $obj = & get_instance(); |
|
| 219 | 219 | |
| 220 | 220 | $this->error_messages = array( |
| 221 | 221 | 'upload_err_ini_size' => $obj->lang->get('fu_upload_err_ini_size'), |
@@ -232,15 +232,15 @@ discard block |
||
| 232 | 232 | ); |
| 233 | 233 | |
| 234 | 234 | $this->file = array( |
| 235 | - 'status' => false, // True: success upload |
|
| 236 | - 'mime' => '', // Empty string |
|
| 237 | - 'filename' => '', // Empty string |
|
| 238 | - 'original' => '', // Empty string |
|
| 239 | - 'size' => 0, // 0 Bytes |
|
| 240 | - 'sizeFormated' => '0B', // 0 Bytes |
|
| 241 | - 'destination' => './', // Default: ./ |
|
| 242 | - 'allowed_mime_types' => array(), // Allowed mime types |
|
| 243 | - 'error' => null, // File error |
|
| 235 | + 'status' => false, // True: success upload |
|
| 236 | + 'mime' => '', // Empty string |
|
| 237 | + 'filename' => '', // Empty string |
|
| 238 | + 'original' => '', // Empty string |
|
| 239 | + 'size' => 0, // 0 Bytes |
|
| 240 | + 'sizeFormated' => '0B', // 0 Bytes |
|
| 241 | + 'destination' => './', // Default: ./ |
|
| 242 | + 'allowed_mime_types' => array(), // Allowed mime types |
|
| 243 | + 'error' => null, // File error |
|
| 244 | 244 | ); |
| 245 | 245 | |
| 246 | 246 | // Change dir to current dir |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | if (isset($_FILES) && is_array($_FILES)) { |
| 251 | 251 | $this->file_array = $_FILES; |
| 252 | 252 | } |
| 253 | - $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array)); |
|
| 253 | + $this->logger->info('The upload file information are : ' . stringfy_vars($this->file_array)); |
|
| 254 | 254 | } |
| 255 | 255 | /** |
| 256 | 256 | * Set input. |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | public function setInput($input) |
| 268 | 268 | { |
| 269 | - if (!empty($input) && (is_string($input) || is_numeric($input) )) { |
|
| 269 | + if (!empty($input) && (is_string($input) || is_numeric($input))) { |
|
| 270 | 270 | $this->input = $input; |
| 271 | 271 | } |
| 272 | 272 | return $this; |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | public function setAutoFilename() |
| 304 | 304 | { |
| 305 | - $this->filename = sha1(mt_rand(1, 9999).uniqid()); |
|
| 305 | + $this->filename = sha1(mt_rand(1, 9999) . uniqid()); |
|
| 306 | 306 | $this->filename .= time(); |
| 307 | 307 | return $this; |
| 308 | 308 | } |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | $php_size = $this->sizeInBytes((int) ini_get('upload_max_filesize')); |
| 324 | 324 | // Calculate difference |
| 325 | 325 | if ($php_size < $file_size) { |
| 326 | - $this->logger->warning('The upload max file size you set [' .$file_size. '] is greather than the PHP configuration for upload max file size [' .$php_size. ']'); |
|
| 326 | + $this->logger->warning('The upload max file size you set [' . $file_size . '] is greather than the PHP configuration for upload max file size [' . $php_size . ']'); |
|
| 327 | 327 | } |
| 328 | 328 | $this->max_file_size = $file_size; |
| 329 | 329 | } |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | public function setAllowedMimeTypes(array $mimes) |
| 342 | 342 | { |
| 343 | 343 | if (count($mimes) > 0) { |
| 344 | - array_map(array($this , 'setAllowMimeType'), $mimes); |
|
| 344 | + array_map(array($this, 'setAllowMimeType'), $mimes); |
|
| 345 | 345 | } |
| 346 | 346 | return $this; |
| 347 | 347 | } |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | { |
| 407 | 407 | if (!empty($name) && is_string($name)) { |
| 408 | 408 | if (array_key_exists($name, $this->mime_helping)) { |
| 409 | - return $this->setAllowedMimeTypes($this->mime_helping[ $name ]); |
|
| 409 | + return $this->setAllowedMimeTypes($this->mime_helping[$name]); |
|
| 410 | 410 | } |
| 411 | 411 | } |
| 412 | 412 | return $this; |
@@ -425,8 +425,8 @@ discard block |
||
| 425 | 425 | */ |
| 426 | 426 | public function setUploadFunction($function) |
| 427 | 427 | { |
| 428 | - if (!empty($function) && (is_array($function) || is_string($function) )) { |
|
| 429 | - if (is_callable( $function)) { |
|
| 428 | + if (!empty($function) && (is_array($function) || is_string($function))) { |
|
| 429 | + if (is_callable($function)) { |
|
| 430 | 430 | $this->upload_function = $function; |
| 431 | 431 | } |
| 432 | 432 | } |
@@ -471,8 +471,8 @@ discard block |
||
| 471 | 471 | $this->destination_directory = $destination_directory; |
| 472 | 472 | chdir($destination_directory); |
| 473 | 473 | } |
| 474 | - else{ |
|
| 475 | - $this->logger->warning('Can not create the upload directory [' .$destination_directory. ']'); |
|
| 474 | + else { |
|
| 475 | + $this->logger->warning('Can not create the upload directory [' . $destination_directory . ']'); |
|
| 476 | 476 | } |
| 477 | 477 | } |
| 478 | 478 | } |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | public function isFilename($filename) |
| 523 | 523 | { |
| 524 | 524 | $filename = basename($filename); |
| 525 | - return (!empty($filename) && (is_string( $filename) || is_numeric($filename))); |
|
| 525 | + return (!empty($filename) && (is_string($filename) || is_numeric($filename))); |
|
| 526 | 526 | } |
| 527 | 527 | /** |
| 528 | 528 | * Validate mime type with allowed mime types, |
@@ -564,11 +564,11 @@ discard block |
||
| 564 | 564 | */ |
| 565 | 565 | public function isDirpath($path) |
| 566 | 566 | { |
| 567 | - if (!empty( $path) && (is_string( $path) || is_numeric($path) )) { |
|
| 567 | + if (!empty($path) && (is_string($path) || is_numeric($path))) { |
|
| 568 | 568 | if (DIRECTORY_SEPARATOR == '/') { |
| 569 | - return (preg_match( '/^[^*?"<>|:]*$/' , $path) == 1 ); |
|
| 569 | + return (preg_match('/^[^*?"<>|:]*$/', $path) == 1); |
|
| 570 | 570 | } else { |
| 571 | - return (preg_match( "/^[^*?\"<>|:]*$/" , substr($path,2) ) == 1); |
|
| 571 | + return (preg_match("/^[^*?\"<>|:]*$/", substr($path, 2)) == 1); |
|
| 572 | 572 | } |
| 573 | 573 | } |
| 574 | 574 | return false; |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | */ |
| 597 | 597 | public function getInfo() |
| 598 | 598 | { |
| 599 | - return (object)$this->file; |
|
| 599 | + return (object) $this->file; |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | * Check if the file is uploaded |
| 605 | 605 | * @return boolean |
| 606 | 606 | */ |
| 607 | - public function isUploaded(){ |
|
| 607 | + public function isUploaded() { |
|
| 608 | 608 | return isset($this->file_array[$this->input]) |
| 609 | 609 | && is_uploaded_file($this->file_array[$this->input]['tmp_name']); |
| 610 | 610 | } |
@@ -618,13 +618,13 @@ discard block |
||
| 618 | 618 | * @return boolean |
| 619 | 619 | * @method boolean save |
| 620 | 620 | */ |
| 621 | - public function save(){ |
|
| 621 | + public function save() { |
|
| 622 | 622 | if (count($this->file_array) > 0 && array_key_exists($this->input, $this->file_array)) { |
| 623 | 623 | // set original filename if not have a new name |
| 624 | 624 | if (empty($this->filename)) { |
| 625 | 625 | $this->filename = $this->file_array[$this->input]['name']; |
| 626 | 626 | } |
| 627 | - else{ |
|
| 627 | + else { |
|
| 628 | 628 | // Replace %s for extension in filename |
| 629 | 629 | // Before: /[\w\d]*(.[\d\w]+)$/i |
| 630 | 630 | // After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu |
@@ -648,10 +648,10 @@ discard block |
||
| 648 | 648 | $this->file['filename'] = $this->filename; |
| 649 | 649 | $this->file['error'] = $this->file_array[$this->input]['error']; |
| 650 | 650 | |
| 651 | - $this->logger->info('The upload file information to process is : ' .stringfy_vars($this->file)); |
|
| 651 | + $this->logger->info('The upload file information to process is : ' . stringfy_vars($this->file)); |
|
| 652 | 652 | |
| 653 | 653 | $error = $this->uploadHasError(); |
| 654 | - if($error){ |
|
| 654 | + if ($error) { |
|
| 655 | 655 | return false; |
| 656 | 656 | } |
| 657 | 657 | // Execute input callback |
@@ -685,10 +685,10 @@ discard block |
||
| 685 | 685 | */ |
| 686 | 686 | public function sizeFormat($size, $precision = 2) |
| 687 | 687 | { |
| 688 | - if($size > 0){ |
|
| 688 | + if ($size > 0) { |
|
| 689 | 689 | $base = log($size) / log(1024); |
| 690 | 690 | $suffixes = array('B', 'K', 'M', 'G', 'T'); |
| 691 | - return round(pow(1024, $base - floor($base)), $precision) . ( isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : ''); |
|
| 691 | + return round(pow(1024, $base - floor($base)), $precision) . (isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : ''); |
|
| 692 | 692 | } |
| 693 | 693 | return null; |
| 694 | 694 | } |
@@ -712,14 +712,14 @@ discard block |
||
| 712 | 712 | if (array_key_exists('unit', $matches)) { |
| 713 | 713 | $unit = strtoupper($matches['unit']); |
| 714 | 714 | } |
| 715 | - return (floatval($matches['size']) * pow(1024, $units[$unit]) ) ; |
|
| 715 | + return (floatval($matches['size']) * pow(1024, $units[$unit])); |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | /** |
| 719 | 719 | * Get the upload error message |
| 720 | 720 | * @return string |
| 721 | 721 | */ |
| 722 | - public function getError(){ |
|
| 722 | + public function getError() { |
|
| 723 | 723 | return $this->error; |
| 724 | 724 | } |
| 725 | 725 | |
@@ -727,7 +727,7 @@ discard block |
||
| 727 | 727 | * Set the upload error message |
| 728 | 728 | * @param string $message the upload error message to set |
| 729 | 729 | */ |
| 730 | - public function setError($message){ |
|
| 730 | + public function setError($message) { |
|
| 731 | 731 | $this->logger->info('The file upload got error : ' . $message); |
| 732 | 732 | $this->error = $message; |
| 733 | 733 | } |
@@ -737,9 +737,9 @@ discard block |
||
| 737 | 737 | * @param string $type the type of callback "input" or "output" |
| 738 | 738 | * @return void |
| 739 | 739 | */ |
| 740 | - protected function runCallback($type){ |
|
| 741 | - if (!empty( $this->callbacks[$type])) { |
|
| 742 | - call_user_func($this->callbacks[$type], (object)$this->file); |
|
| 740 | + protected function runCallback($type) { |
|
| 741 | + if (!empty($this->callbacks[$type])) { |
|
| 742 | + call_user_func($this->callbacks[$type], (object) $this->file); |
|
| 743 | 743 | } |
| 744 | 744 | } |
| 745 | 745 | |
@@ -747,21 +747,21 @@ discard block |
||
| 747 | 747 | * Check if file upload has error |
| 748 | 748 | * @return boolean |
| 749 | 749 | */ |
| 750 | - protected function uploadHasError(){ |
|
| 750 | + protected function uploadHasError() { |
|
| 751 | 751 | //check if file upload is allowed in the configuration |
| 752 | - if(! ini_get('file_uploads')){ |
|
| 752 | + if (!ini_get('file_uploads')) { |
|
| 753 | 753 | $this->setError($this->error_messages['file_uploads']); |
| 754 | 754 | return true; |
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | //check for php upload error |
| 758 | - if(is_numeric($this->file['error']) && $this->file['error'] > 0){ |
|
| 758 | + if (is_numeric($this->file['error']) && $this->file['error'] > 0) { |
|
| 759 | 759 | $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error'])); |
| 760 | 760 | return true; |
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | //check for mime type |
| 764 | - if (! $this->checkMimeType($this->file['mime'])) { |
|
| 764 | + if (!$this->checkMimeType($this->file['mime'])) { |
|
| 765 | 765 | $this->setError($this->error_messages['accept_file_types']); |
| 766 | 766 | return true; |
| 767 | 767 | } |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | * @param int $code the error code |
| 786 | 786 | * @return string the error message |
| 787 | 787 | */ |
| 788 | - private function getPhpUploadErrorMessageByCode($code){ |
|
| 788 | + private function getPhpUploadErrorMessageByCode($code) { |
|
| 789 | 789 | $codeMessageMaps = array( |
| 790 | 790 | 1 => $this->error_messages['upload_err_ini_size'], |
| 791 | 791 | 2 => $this->error_messages['upload_err_form_size'], |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @since 1.0.0 |
| 39 | 39 | * @filesource |
| 40 | 40 | */ |
| 41 | - class Assets extends BaseStaticClass{ |
|
| 41 | + class Assets extends BaseStaticClass { |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -53,13 +53,13 @@ discard block |
||
| 53 | 53 | * @param string $asset the name of the assets file path with the extension. |
| 54 | 54 | * @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist. |
| 55 | 55 | */ |
| 56 | - public static function path($asset){ |
|
| 56 | + public static function path($asset) { |
|
| 57 | 57 | $logger = self::getLogger(); |
| 58 | 58 | $path = ASSETS_PATH . $asset; |
| 59 | 59 | |
| 60 | 60 | $logger->debug('Including the Assets file [' . $path . ']'); |
| 61 | 61 | //Check if the file exists |
| 62 | - if(file_exists($path)){ |
|
| 62 | + if (file_exists($path)) { |
|
| 63 | 63 | $logger->info('Assets file [' . $path . '] included successfully'); |
| 64 | 64 | return Url::base_url($path); |
| 65 | 65 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @param string $path the name of the css file without the extension. |
| 80 | 80 | * @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist. |
| 81 | 81 | */ |
| 82 | - public static function css($path){ |
|
| 82 | + public static function css($path) { |
|
| 83 | 83 | $logger = self::getLogger(); |
| 84 | 84 | /* |
| 85 | 85 | * if the file name contains the ".css" extension, replace it with |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | $logger->debug('Including the Assets file [' . $path . '] for CSS'); |
| 92 | 92 | //Check if the file exists |
| 93 | - if(file_exists($path)){ |
|
| 93 | + if (file_exists($path)) { |
|
| 94 | 94 | $logger->info('Assets file [' . $path . '] for CSS included successfully'); |
| 95 | 95 | return Url::base_url($path); |
| 96 | 96 | } |
@@ -110,12 +110,12 @@ discard block |
||
| 110 | 110 | * @param string $path the name of the javascript file without the extension. |
| 111 | 111 | * @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist. |
| 112 | 112 | */ |
| 113 | - public static function js($path){ |
|
| 113 | + public static function js($path) { |
|
| 114 | 114 | $logger = self::getLogger(); |
| 115 | 115 | $path = str_ireplace('.js', '', $path); |
| 116 | 116 | $path = ASSETS_PATH . 'js/' . $path . '.js'; |
| 117 | 117 | $logger->debug('Including the Assets file [' . $path . '] for javascript'); |
| 118 | - if(file_exists($path)){ |
|
| 118 | + if (file_exists($path)) { |
|
| 119 | 119 | $logger->info('Assets file [' . $path . '] for Javascript included successfully'); |
| 120 | 120 | return Url::base_url($path); |
| 121 | 121 | } |
@@ -135,11 +135,11 @@ discard block |
||
| 135 | 135 | * @param string $path the name of the image file with the extension. |
| 136 | 136 | * @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist. |
| 137 | 137 | */ |
| 138 | - public static function img($path){ |
|
| 138 | + public static function img($path) { |
|
| 139 | 139 | $logger = self::getLogger(); |
| 140 | 140 | $path = ASSETS_PATH . 'images/' . $path; |
| 141 | 141 | $logger->debug('Including the Assets file [' . $path . '] for image'); |
| 142 | - if(file_exists($path)){ |
|
| 142 | + if (file_exists($path)) { |
|
| 143 | 143 | $logger->info('Assets file [' . $path . '] for image included successfully'); |
| 144 | 144 | return Url::base_url($path); |
| 145 | 145 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - class Cookie extends BaseStaticClass{ |
|
| 27 | + class Cookie extends BaseStaticClass { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Get the cookie item value |
@@ -32,9 +32,9 @@ discard block |
||
| 32 | 32 | * @param mixed $default the default value to use if can not find the cokkie item in the list |
| 33 | 33 | * @return mixed the cookie value if exist or the default value |
| 34 | 34 | */ |
| 35 | - public static function get($item, $default = null){ |
|
| 35 | + public static function get($item, $default = null) { |
|
| 36 | 36 | $logger = self::getLogger(); |
| 37 | - if(array_key_exists($item, $_COOKIE)){ |
|
| 37 | + if (array_key_exists($item, $_COOKIE)) { |
|
| 38 | 38 | return $_COOKIE[$item]; |
| 39 | 39 | } |
| 40 | 40 | $logger->warning('Cannot find cookie item [' . $item . '], using the default value [' . $default . ']'); |
@@ -51,14 +51,14 @@ discard block |
||
| 51 | 51 | * @param boolean $secure if this cookie will be available on secure connection or not |
| 52 | 52 | * @param boolean $httponly if this cookie will be available under HTTP protocol. |
| 53 | 53 | */ |
| 54 | - public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false){ |
|
| 55 | - if(headers_sent()){ |
|
| 54 | + public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false) { |
|
| 55 | + if (headers_sent()) { |
|
| 56 | 56 | show_error('There exists a cookie that we wanted to create that we couldn\'t |
| 57 | 57 | because headers was already sent. Make sure to do this first |
| 58 | 58 | before outputing anything.'); |
| 59 | 59 | } |
| 60 | 60 | $timestamp = $expire; |
| 61 | - if($expire){ |
|
| 61 | + if ($expire) { |
|
| 62 | 62 | $timestamp = time() + $expire; |
| 63 | 63 | } |
| 64 | 64 | setcookie($name, $value, $timestamp, $path, $domain, $secure, $httponly); |
@@ -69,15 +69,15 @@ discard block |
||
| 69 | 69 | * @param string $item the cookie item name to be cleared |
| 70 | 70 | * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
| 71 | 71 | */ |
| 72 | - public static function delete($item){ |
|
| 72 | + public static function delete($item) { |
|
| 73 | 73 | $logger = self::getLogger(); |
| 74 | - if(array_key_exists($item, $_COOKIE)){ |
|
| 75 | - $logger->info('Delete cookie item ['.$item.']'); |
|
| 74 | + if (array_key_exists($item, $_COOKIE)) { |
|
| 75 | + $logger->info('Delete cookie item [' . $item . ']'); |
|
| 76 | 76 | unset($_COOKIE[$item]); |
| 77 | 77 | return true; |
| 78 | 78 | } |
| 79 | - else{ |
|
| 80 | - $logger->warning('Cookie item ['.$item.'] to be deleted does not exists'); |
|
| 79 | + else { |
|
| 80 | + $logger->warning('Cookie item [' . $item . '] to be deleted does not exists'); |
|
| 81 | 81 | return false; |
| 82 | 82 | } |
| 83 | 83 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @param string $item the cookie item name |
| 88 | 88 | * @return boolean true if the cookie item is set, false or not |
| 89 | 89 | */ |
| 90 | - public static function exists($item){ |
|
| 90 | + public static function exists($item) { |
|
| 91 | 91 | return array_key_exists($item, $_COOKIE); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - class Module extends BaseStaticClass{ |
|
| 27 | + class Module extends BaseStaticClass { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * list of loaded module |
@@ -35,24 +35,24 @@ discard block |
||
| 35 | 35 | /** |
| 36 | 36 | * Initialise the module list by scanning the directory MODULE_PATH |
| 37 | 37 | */ |
| 38 | - public function init(){ |
|
| 38 | + public function init() { |
|
| 39 | 39 | $logger = self::getLogger(); |
| 40 | 40 | $logger->debug('Check if the application contains the modules ...'); |
| 41 | 41 | $moduleDir = opendir(MODULE_PATH); |
| 42 | - if (is_resource($moduleDir)){ |
|
| 43 | - while(($module = readdir($moduleDir)) !== false){ |
|
| 44 | - if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){ |
|
| 42 | + if (is_resource($moduleDir)) { |
|
| 43 | + while (($module = readdir($moduleDir)) !== false) { |
|
| 44 | + if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)) { |
|
| 45 | 45 | self::$list[] = $module; |
| 46 | 46 | } |
| 47 | - else{ |
|
| 48 | - $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name'); |
|
| 47 | + else { |
|
| 48 | + $logger->info('Skipping [' . $module . '], may be this is not a directory or does not exists or is invalid name'); |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | closedir($moduleDir); |
| 52 | 52 | } |
| 53 | 53 | ksort(self::$list); |
| 54 | 54 | |
| 55 | - if (! empty(self::$list)){ |
|
| 55 | + if (!empty(self::$list)) { |
|
| 56 | 56 | $logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']'); |
| 57 | 57 | } |
| 58 | 58 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @return object the current instance |
| 66 | 66 | */ |
| 67 | - public function add($name){ |
|
| 67 | + public function add($name) { |
|
| 68 | 68 | self::$list[] = $name; |
| 69 | 69 | return $this; |
| 70 | 70 | } |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | * Get the list of the custom autoload configuration from module if exists |
| 74 | 74 | * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values |
| 75 | 75 | */ |
| 76 | - public static function getModulesAutoloadConfig(){ |
|
| 76 | + public static function getModulesAutoloadConfig() { |
|
| 77 | 77 | $logger = self::getLogger(); |
| 78 | - if (empty(self::$list)){ |
|
| 78 | + if (empty(self::$list)) { |
|
| 79 | 79 | $logger->info('No module was loaded skipping.'); |
| 80 | 80 | return false; |
| 81 | 81 | } |
@@ -88,10 +88,10 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | foreach (self::$list as $module) { |
| 90 | 90 | $file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php'; |
| 91 | - if (file_exists($file)){ |
|
| 91 | + if (file_exists($file)) { |
|
| 92 | 92 | $autoload = array(); |
| 93 | 93 | require_once $file; |
| 94 | - if (! empty($autoload) && is_array($autoload)){ |
|
| 94 | + if (!empty($autoload) && is_array($autoload)) { |
|
| 95 | 95 | $autoloads = array_merge_recursive($autoloads, $autoload); |
| 96 | 96 | unset($autoload); |
| 97 | 97 | } |
@@ -104,19 +104,19 @@ discard block |
||
| 104 | 104 | * Get the list of the custom routes configuration from module if exists |
| 105 | 105 | * @return array|boolean the routes list or false if no module contains the routes configuration |
| 106 | 106 | */ |
| 107 | - public static function getModulesRoutesConfig(){ |
|
| 107 | + public static function getModulesRoutesConfig() { |
|
| 108 | 108 | $logger = self::getLogger(); |
| 109 | - if (empty(self::$list)){ |
|
| 109 | + if (empty(self::$list)) { |
|
| 110 | 110 | $logger->info('No module was loaded skipping.'); |
| 111 | 111 | return false; |
| 112 | 112 | } |
| 113 | 113 | $routes = array(); |
| 114 | 114 | foreach (self::$list as $module) { |
| 115 | 115 | $file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php'; |
| 116 | - if (file_exists($file)){ |
|
| 116 | + if (file_exists($file)) { |
|
| 117 | 117 | $route = array(); |
| 118 | 118 | require_once $file; |
| 119 | - if (! empty($route) && is_array($route)){ |
|
| 119 | + if (!empty($route) && is_array($route)) { |
|
| 120 | 120 | $routes = array_merge($routes, $route); |
| 121 | 121 | unset($route); |
| 122 | 122 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * @see Module::findClassInModuleFullFilePath |
| 132 | 132 | * @return boolean|string false or null if no module have this controller, path the full path of the controller |
| 133 | 133 | */ |
| 134 | - public static function findControllerFullPath($class, $module = null){ |
|
| 134 | + public static function findControllerFullPath($class, $module = null) { |
|
| 135 | 135 | return self::findClassInModuleFullFilePath($class, $module, 'controllers'); |
| 136 | 136 | } |
| 137 | 137 | |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * @see Module::findClassInModuleFullFilePath |
| 141 | 141 | * @return boolean|string false or null if no module have this model, return the full path of this model |
| 142 | 142 | */ |
| 143 | - public static function findModelFullPath($class, $module = null){ |
|
| 143 | + public static function findModelFullPath($class, $module = null) { |
|
| 144 | 144 | return self::findClassInModuleFullFilePath($class, $module, 'models'); |
| 145 | 145 | } |
| 146 | 146 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * @see Module::findClassInModuleFullFilePath |
| 150 | 150 | * @return boolean|string false or null if no module have this library, return the full path of this library |
| 151 | 151 | */ |
| 152 | - public static function findLibraryFullPath($class, $module = null){ |
|
| 152 | + public static function findLibraryFullPath($class, $module = null) { |
|
| 153 | 153 | return self::findClassInModuleFullFilePath($class, $module, 'libraries'); |
| 154 | 154 | } |
| 155 | 155 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * @see Module::findNonClassInModuleFullFilePath |
| 160 | 160 | * @return boolean|string false or null if no module have this configuration, return the full path of this configuration |
| 161 | 161 | */ |
| 162 | - public static function findConfigFullPath($configuration, $module = null){ |
|
| 162 | + public static function findConfigFullPath($configuration, $module = null) { |
|
| 163 | 163 | return self::findNonClassInModuleFullFilePath($configuration, $module, 'config'); |
| 164 | 164 | } |
| 165 | 165 | |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * @see Module::findNonClassInModuleFullFilePath |
| 169 | 169 | * @return boolean|string false or null if no module have this helper, return the full path of this helper |
| 170 | 170 | */ |
| 171 | - public static function findFunctionFullPath($helper, $module = null){ |
|
| 171 | + public static function findFunctionFullPath($helper, $module = null) { |
|
| 172 | 172 | return self::findNonClassInModuleFullFilePath($helper, $module, 'functions'); |
| 173 | 173 | } |
| 174 | 174 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * @see Module::findNonClassInModuleFullFilePath |
| 178 | 178 | * @return boolean|string false or null if no module have this view, path the full path of the view |
| 179 | 179 | */ |
| 180 | - public static function findViewFullPath($view, $module = null){ |
|
| 180 | + public static function findViewFullPath($view, $module = null) { |
|
| 181 | 181 | return self::findNonClassInModuleFullFilePath($view, $module, 'views'); |
| 182 | 182 | } |
| 183 | 183 | |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | * @see Module::findNonClassInModuleFullFilePath |
| 187 | 187 | * @return boolean|string false or null if no module have this language, return the full path of this language |
| 188 | 188 | */ |
| 189 | - public static function findLanguageFullPath($language, $appLang, $module = null){ |
|
| 189 | + public static function findLanguageFullPath($language, $appLang, $module = null) { |
|
| 190 | 190 | return self::findNonClassInModuleFullFilePath($language, $module, 'lang', $appLang); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | * Get the list of module loaded |
| 195 | 195 | * @return array the module list |
| 196 | 196 | */ |
| 197 | - public static function getModuleList(){ |
|
| 197 | + public static function getModuleList() { |
|
| 198 | 198 | return self::$list; |
| 199 | 199 | } |
| 200 | 200 | |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * Check if the application has an module |
| 203 | 203 | * @return boolean |
| 204 | 204 | */ |
| 205 | - public static function hasModule(){ |
|
| 205 | + public static function hasModule() { |
|
| 206 | 206 | return !empty(self::$list); |
| 207 | 207 | } |
| 208 | 208 | |
@@ -214,18 +214,18 @@ discard block |
||
| 214 | 214 | * @return boolean|string false or null if no module |
| 215 | 215 | * have this class, return the full path of the class |
| 216 | 216 | */ |
| 217 | - protected static function findClassInModuleFullFilePath($class, $module, $type){ |
|
| 217 | + protected static function findClassInModuleFullFilePath($class, $module, $type) { |
|
| 218 | 218 | $logger = self::getLogger(); |
| 219 | 219 | $class = str_ireplace('.php', '', $class); |
| 220 | 220 | $class = ucfirst($class); |
| 221 | - $classFile = $class.'.php'; |
|
| 221 | + $classFile = $class . '.php'; |
|
| 222 | 222 | $logger->debug('Checking the class [' . $class . '] in module [' . $module . '] for [' . $type . '] ...'); |
| 223 | 223 | $filePath = MODULE_PATH . $module . DS . $type . DS . $classFile; |
| 224 | - if (file_exists($filePath)){ |
|
| 225 | - $logger->info('Found class [' . $class . '] in module [' . $module . '] for [' . $type . '] the file path is [' .$filePath. ']'); |
|
| 224 | + if (file_exists($filePath)) { |
|
| 225 | + $logger->info('Found class [' . $class . '] in module [' . $module . '] for [' . $type . '] the file path is [' . $filePath . ']'); |
|
| 226 | 226 | return $filePath; |
| 227 | 227 | } |
| 228 | - $logger->info('Class [' . $class . '] does not exist in the module [' .$module. '] for [' . $type . ']'); |
|
| 228 | + $logger->info('Class [' . $class . '] does not exist in the module [' . $module . '] for [' . $type . ']'); |
|
| 229 | 229 | return false; |
| 230 | 230 | } |
| 231 | 231 | |
@@ -238,15 +238,15 @@ discard block |
||
| 238 | 238 | * @return boolean|string false or null if no module |
| 239 | 239 | * have this resource, return the full path of the resource |
| 240 | 240 | */ |
| 241 | - protected static function findNonClassInModuleFullFilePath($name, $module, $type, $appLang = null){ |
|
| 241 | + protected static function findNonClassInModuleFullFilePath($name, $module, $type, $appLang = null) { |
|
| 242 | 242 | $logger = self::getLogger(); |
| 243 | 243 | $name = str_ireplace('.php', '', $name); |
| 244 | - $file = $name.'.php'; |
|
| 244 | + $file = $name . '.php'; |
|
| 245 | 245 | $filePath = MODULE_PATH . $module . DS . $type . DS . $file; |
| 246 | - switch($type){ |
|
| 246 | + switch ($type) { |
|
| 247 | 247 | case 'functions': |
| 248 | 248 | $name = str_ireplace('function_', '', $name); |
| 249 | - $file = 'function_'.$name.'.php'; |
|
| 249 | + $file = 'function_' . $name . '.php'; |
|
| 250 | 250 | $filePath = MODULE_PATH . $module . DS . $type . DS . $file; |
| 251 | 251 | break; |
| 252 | 252 | case 'views': |
@@ -257,16 +257,16 @@ discard block |
||
| 257 | 257 | break; |
| 258 | 258 | case 'lang': |
| 259 | 259 | $name = str_ireplace('lang_', '', $name); |
| 260 | - $file = 'lang_'.$name.'.php'; |
|
| 260 | + $file = 'lang_' . $name . '.php'; |
|
| 261 | 261 | $filePath = MODULE_PATH . $module . DS . $type . DS . $appLang . DS . $file; |
| 262 | 262 | break; |
| 263 | 263 | } |
| 264 | - $logger->debug('Checking resource [' . $name . '] in module [' .$module. '] for [' . $type . '] ...'); |
|
| 265 | - if (file_exists($filePath)){ |
|
| 266 | - $logger->info('Found resource [' . $name . '] in module [' .$module. '] for [' . $type . '] the file path is [' .$filePath. ']'); |
|
| 264 | + $logger->debug('Checking resource [' . $name . '] in module [' . $module . '] for [' . $type . '] ...'); |
|
| 265 | + if (file_exists($filePath)) { |
|
| 266 | + $logger->info('Found resource [' . $name . '] in module [' . $module . '] for [' . $type . '] the file path is [' . $filePath . ']'); |
|
| 267 | 267 | return $filePath; |
| 268 | 268 | } |
| 269 | - $logger->info('Resource [' . $name . '] does not exist in the module [' .$module. '] for [' . $type . ']'); |
|
| 269 | + $logger->info('Resource [' . $name . '] does not exist in the module [' . $module . '] for [' . $type . ']'); |
|
| 270 | 270 | return false; |
| 271 | 271 | } |
| 272 | 272 | |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - class Config extends BaseStaticClass{ |
|
| 27 | + class Config extends BaseStaticClass { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The list of loaded configuration |
@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | /** |
| 36 | 36 | * Initialize the configuration by loading all the configuration from config file |
| 37 | 37 | */ |
| 38 | - public static function init(){ |
|
| 38 | + public static function init() { |
|
| 39 | 39 | $logger = self::getLogger(); |
| 40 | 40 | $logger->debug('Initialization of the configuration'); |
| 41 | 41 | self::$config = & load_configurations(); |
| 42 | 42 | self::setBaseUrlUsingServerVar(); |
| 43 | - if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){ |
|
| 43 | + if (ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info', 'all'))) { |
|
| 44 | 44 | $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance'); |
| 45 | 45 | } |
| 46 | 46 | $logger->info('Configuration initialized successfully'); |
@@ -53,12 +53,12 @@ discard block |
||
| 53 | 53 | * @param mixed $default the default value to use if can not find the config item in the list |
| 54 | 54 | * @return mixed the config value if exist or the default value |
| 55 | 55 | */ |
| 56 | - public static function get($item, $default = null){ |
|
| 56 | + public static function get($item, $default = null) { |
|
| 57 | 57 | $logger = self::getLogger(); |
| 58 | - if(array_key_exists($item, self::$config)){ |
|
| 58 | + if (array_key_exists($item, self::$config)) { |
|
| 59 | 59 | return self::$config[$item]; |
| 60 | 60 | } |
| 61 | - $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']'); |
|
| 61 | + $logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']'); |
|
| 62 | 62 | return $default; |
| 63 | 63 | } |
| 64 | 64 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * @param string $item the config item name to set |
| 68 | 68 | * @param mixed $value the config item value |
| 69 | 69 | */ |
| 70 | - public static function set($item, $value){ |
|
| 70 | + public static function set($item, $value) { |
|
| 71 | 71 | self::$config[$item] = $value; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * Get all the configuration values |
| 76 | 76 | * @return array the config values |
| 77 | 77 | */ |
| 78 | - public static function getAll(){ |
|
| 78 | + public static function getAll() { |
|
| 79 | 79 | return self::$config; |
| 80 | 80 | } |
| 81 | 81 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * Set the configuration values bu merged with the existing configuration |
| 84 | 84 | * @param array $config the config values to add in the configuration list |
| 85 | 85 | */ |
| 86 | - public static function setAll(array $config = array()){ |
|
| 86 | + public static function setAll(array $config = array()) { |
|
| 87 | 87 | self::$config = array_merge(self::$config, $config); |
| 88 | 88 | } |
| 89 | 89 | |
@@ -92,15 +92,15 @@ discard block |
||
| 92 | 92 | * @param string $item the config item name to be deleted |
| 93 | 93 | * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
| 94 | 94 | */ |
| 95 | - public static function delete($item){ |
|
| 95 | + public static function delete($item) { |
|
| 96 | 96 | $logger = self::getLogger(); |
| 97 | - if(array_key_exists($item, self::$config)){ |
|
| 98 | - $logger->info('Delete config item ['.$item.']'); |
|
| 97 | + if (array_key_exists($item, self::$config)) { |
|
| 98 | + $logger->info('Delete config item [' . $item . ']'); |
|
| 99 | 99 | unset(self::$config[$item]); |
| 100 | 100 | return true; |
| 101 | 101 | } |
| 102 | - else{ |
|
| 103 | - $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
|
| 102 | + else { |
|
| 103 | + $logger->warning('Config item [' . $item . '] to be deleted does not exists'); |
|
| 104 | 104 | return false; |
| 105 | 105 | } |
| 106 | 106 | } |
@@ -109,39 +109,39 @@ discard block |
||
| 109 | 109 | * Load the configuration file. This an alias to Loader::config() |
| 110 | 110 | * @param string $config the config name to be loaded |
| 111 | 111 | */ |
| 112 | - public static function load($config){ |
|
| 112 | + public static function load($config) { |
|
| 113 | 113 | Loader::config($config); |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | 117 | * Set the configuration for "base_url" if is not set in the configuration |
| 118 | 118 | */ |
| 119 | - private static function setBaseUrlUsingServerVar(){ |
|
| 119 | + private static function setBaseUrlUsingServerVar() { |
|
| 120 | 120 | $logger = self::getLogger(); |
| 121 | - if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){ |
|
| 122 | - if(ENVIRONMENT == 'production'){ |
|
| 121 | + if (!isset(self::$config['base_url']) || !is_url(self::$config['base_url'])) { |
|
| 122 | + if (ENVIRONMENT == 'production') { |
|
| 123 | 123 | $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time'); |
| 124 | 124 | } |
| 125 | 125 | $baseUrl = null; |
| 126 | 126 | $protocol = 'http'; |
| 127 | - if(is_https()){ |
|
| 127 | + if (is_https()) { |
|
| 128 | 128 | $protocol = 'https'; |
| 129 | 129 | } |
| 130 | - $protocol .='://'; |
|
| 130 | + $protocol .= '://'; |
|
| 131 | 131 | |
| 132 | - if (isset($_SERVER['SERVER_ADDR'])){ |
|
| 132 | + if (isset($_SERVER['SERVER_ADDR'])) { |
|
| 133 | 133 | $baseUrl = $_SERVER['SERVER_ADDR']; |
| 134 | 134 | //check if the server is running under IPv6 |
| 135 | - if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){ |
|
| 136 | - $baseUrl = '['.$_SERVER['SERVER_ADDR'].']'; |
|
| 135 | + if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) { |
|
| 136 | + $baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']'; |
|
| 137 | 137 | } |
| 138 | 138 | $serverPort = 80; |
| 139 | 139 | if (isset($_SERVER['SERVER_PORT'])) { |
| 140 | 140 | $serverPort = $_SERVER['SERVER_PORT']; |
| 141 | 141 | } |
| 142 | 142 | $port = ''; |
| 143 | - if($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))){ |
|
| 144 | - $port = ':'.$serverPort; |
|
| 143 | + if ($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))) { |
|
| 144 | + $port = ':' . $serverPort; |
|
| 145 | 145 | } |
| 146 | 146 | $baseUrl = $protocol . $baseUrl . $port . substr( |
| 147 | 147 | $_SERVER['SCRIPT_NAME'], |
@@ -149,12 +149,12 @@ discard block |
||
| 149 | 149 | strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])) |
| 150 | 150 | ); |
| 151 | 151 | } |
| 152 | - else{ |
|
| 152 | + else { |
|
| 153 | 153 | $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
| 154 | 154 | $baseUrl = 'http://localhost/'; |
| 155 | 155 | } |
| 156 | 156 | self::set('base_url', $baseUrl); |
| 157 | 157 | } |
| 158 | - self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/'; |
|
| 158 | + self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/'; |
|
| 159 | 159 | } |
| 160 | 160 | } |
@@ -23,14 +23,14 @@ discard block |
||
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | - class DatabaseQueryRunner extends BaseClass{ |
|
| 26 | + class DatabaseQueryRunner extends BaseClass { |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The last query result |
| 31 | 31 | * @var object |
| 32 | 32 | */ |
| 33 | - private $queryResult = null; |
|
| 33 | + private $queryResult = null; |
|
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * The benchmark instance |
@@ -42,45 +42,45 @@ discard block |
||
| 42 | 42 | * The SQL query statment to execute |
| 43 | 43 | * @var string |
| 44 | 44 | */ |
| 45 | - private $query = null; |
|
| 45 | + private $query = null; |
|
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * Indicate if we need return result as list (boolean) |
| 49 | 49 | * or the data used to replace the placeholder (array) |
| 50 | 50 | * @var array|boolean |
| 51 | 51 | */ |
| 52 | - private $returnAsList = true; |
|
| 52 | + private $returnAsList = true; |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * Indicate if we need return result as array or not |
| 57 | 57 | * @var boolean |
| 58 | 58 | */ |
| 59 | - private $returnAsArray = true; |
|
| 59 | + private $returnAsArray = true; |
|
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * The last PDOStatment instance |
| 63 | 63 | * @var object |
| 64 | 64 | */ |
| 65 | - private $pdoStatment = null; |
|
| 65 | + private $pdoStatment = null; |
|
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * The error returned for the last query |
| 69 | 69 | * @var string |
| 70 | 70 | */ |
| 71 | - private $error = null; |
|
| 71 | + private $error = null; |
|
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * The PDO instance |
| 75 | 75 | * @var object |
| 76 | 76 | */ |
| 77 | - private $pdo = null; |
|
| 77 | + private $pdo = null; |
|
| 78 | 78 | |
| 79 | 79 | /** |
| 80 | 80 | * The database driver name used |
| 81 | 81 | * @var string |
| 82 | 82 | */ |
| 83 | - private $driver = null; |
|
| 83 | + private $driver = null; |
|
| 84 | 84 | |
| 85 | 85 | |
| 86 | 86 | |
@@ -91,9 +91,9 @@ discard block |
||
| 91 | 91 | * @param boolean $returnAsList if need return as list or just one row |
| 92 | 92 | * @param boolean $returnAsArray whether to return the result as array or not |
| 93 | 93 | */ |
| 94 | - public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false){ |
|
| 94 | + public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false) { |
|
| 95 | 95 | parent::__construct(); |
| 96 | - if (is_object($pdo)){ |
|
| 96 | + if (is_object($pdo)) { |
|
| 97 | 97 | $this->pdo = $pdo; |
| 98 | 98 | } |
| 99 | 99 | $this->query = $query; |
@@ -108,13 +108,13 @@ discard block |
||
| 108 | 108 | * |
| 109 | 109 | * @return object|void |
| 110 | 110 | */ |
| 111 | - public function execute(){ |
|
| 111 | + public function execute() { |
|
| 112 | 112 | //reset instance |
| 113 | 113 | $this->reset(); |
| 114 | 114 | |
| 115 | 115 | //for database query execution time |
| 116 | 116 | $benchmarkMarkerKey = $this->getBenchmarkKey(); |
| 117 | - if (! is_object($this->benchmarkInstance)){ |
|
| 117 | + if (!is_object($this->benchmarkInstance)) { |
|
| 118 | 118 | $this->benchmarkInstance = & class_loader('Benchmark'); |
| 119 | 119 | } |
| 120 | 120 | |
@@ -130,19 +130,19 @@ discard block |
||
| 130 | 130 | 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')' |
| 131 | 131 | ); |
| 132 | 132 | //TODO use the configuration value for the high response time currently is 1 second |
| 133 | - if ($responseTime >= 1 ){ |
|
| 133 | + if ($responseTime >= 1) { |
|
| 134 | 134 | $this->logger->warning( |
| 135 | 135 | 'High response time while processing database query [' . $this->query . ']. |
| 136 | - The response time is [' .$responseTime. '] sec.' |
|
| 136 | + The response time is [' .$responseTime . '] sec.' |
|
| 137 | 137 | ); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - if ($this->pdoStatment !== false){ |
|
| 140 | + if ($this->pdoStatment !== false) { |
|
| 141 | 141 | $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false; |
| 142 | - if($isSqlSELECTQuery){ |
|
| 142 | + if ($isSqlSELECTQuery) { |
|
| 143 | 143 | $this->setResultForSelect(); |
| 144 | 144 | } |
| 145 | - else{ |
|
| 145 | + else { |
|
| 146 | 146 | $this->setResultForNonSelect(); |
| 147 | 147 | } |
| 148 | 148 | return $this->queryResult; |
@@ -154,28 +154,28 @@ discard block |
||
| 154 | 154 | * Return the result for SELECT query |
| 155 | 155 | * @see DatabaseQueryRunner::execute |
| 156 | 156 | */ |
| 157 | - protected function setResultForSelect(){ |
|
| 157 | + protected function setResultForSelect() { |
|
| 158 | 158 | //if need return all result like list of record |
| 159 | 159 | $result = null; |
| 160 | 160 | $numRows = 0; |
| 161 | 161 | $fetchMode = PDO::FETCH_OBJ; |
| 162 | - if($this->returnAsArray){ |
|
| 162 | + if ($this->returnAsArray) { |
|
| 163 | 163 | $fetchMode = PDO::FETCH_ASSOC; |
| 164 | 164 | } |
| 165 | - if ($this->returnAsList){ |
|
| 165 | + if ($this->returnAsList) { |
|
| 166 | 166 | $result = $this->pdoStatment->fetchAll($fetchMode); |
| 167 | 167 | } |
| 168 | - else{ |
|
| 168 | + else { |
|
| 169 | 169 | $result = $this->pdoStatment->fetch($fetchMode); |
| 170 | 170 | } |
| 171 | 171 | //Sqlite and pgsql always return 0 when using rowCount() |
| 172 | - if (in_array($this->driver, array('sqlite', 'pgsql'))){ |
|
| 172 | + if (in_array($this->driver, array('sqlite', 'pgsql'))) { |
|
| 173 | 173 | $numRows = count($result); |
| 174 | 174 | } |
| 175 | - else{ |
|
| 175 | + else { |
|
| 176 | 176 | $numRows = $this->pdoStatment->rowCount(); |
| 177 | 177 | } |
| 178 | - if(! is_object($this->queryResult)){ |
|
| 178 | + if (!is_object($this->queryResult)) { |
|
| 179 | 179 | $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database'); |
| 180 | 180 | } |
| 181 | 181 | $this->queryResult->setResult($result); |
@@ -186,20 +186,20 @@ discard block |
||
| 186 | 186 | * Return the result for non SELECT query |
| 187 | 187 | * @see DatabaseQueryRunner::execute |
| 188 | 188 | */ |
| 189 | - protected function setResultForNonSelect(){ |
|
| 189 | + protected function setResultForNonSelect() { |
|
| 190 | 190 | //Sqlite and pgsql always return 0 when using rowCount() |
| 191 | 191 | $result = false; |
| 192 | 192 | $numRows = 0; |
| 193 | - if (in_array($this->driver, array('sqlite', 'pgsql'))){ |
|
| 193 | + if (in_array($this->driver, array('sqlite', 'pgsql'))) { |
|
| 194 | 194 | $result = true; //to test the result for the query like UPDATE, INSERT, DELETE |
| 195 | 195 | $numRows = 1; //TODO use the correct method to get the exact affected row |
| 196 | 196 | } |
| 197 | - else{ |
|
| 197 | + else { |
|
| 198 | 198 | //to test the result for the query like UPDATE, INSERT, DELETE |
| 199 | 199 | $result = $this->pdoStatment->rowCount() >= 0; |
| 200 | 200 | $numRows = $this->pdoStatment->rowCount(); |
| 201 | 201 | } |
| 202 | - if(! is_object($this->queryResult)){ |
|
| 202 | + if (!is_object($this->queryResult)) { |
|
| 203 | 203 | $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database'); |
| 204 | 204 | } |
| 205 | 205 | $this->queryResult->setResult($result); |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | * Return the benchmark instance |
| 212 | 212 | * @return Benchmark |
| 213 | 213 | */ |
| 214 | - public function getBenchmark(){ |
|
| 214 | + public function getBenchmark() { |
|
| 215 | 215 | return $this->benchmarkInstance; |
| 216 | 216 | } |
| 217 | 217 | |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | * @param Benchmark $benchmark the benchmark object |
| 221 | 221 | * @return object DatabaseQueryRunner |
| 222 | 222 | */ |
| 223 | - public function setBenchmark($benchmark){ |
|
| 223 | + public function setBenchmark($benchmark) { |
|
| 224 | 224 | $this->benchmarkInstance = $benchmark; |
| 225 | 225 | return $this; |
| 226 | 226 | } |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | * |
| 231 | 231 | * @return object DatabaseQueryResult |
| 232 | 232 | */ |
| 233 | - public function getQueryResult(){ |
|
| 233 | + public function getQueryResult() { |
|
| 234 | 234 | return $this->queryResult; |
| 235 | 235 | } |
| 236 | 236 | |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | * |
| 241 | 241 | * @return object DatabaseQueryRunner |
| 242 | 242 | */ |
| 243 | - public function setQueryResult(DatabaseQueryResult $queryResult){ |
|
| 243 | + public function setQueryResult(DatabaseQueryResult $queryResult) { |
|
| 244 | 244 | $this->queryResult = $queryResult; |
| 245 | 245 | return $this; |
| 246 | 246 | } |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | * Return the current query SQL string |
| 250 | 250 | * @return string |
| 251 | 251 | */ |
| 252 | - public function getQuery(){ |
|
| 252 | + public function getQuery() { |
|
| 253 | 253 | return $this->query; |
| 254 | 254 | } |
| 255 | 255 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @param string $query the SQL query to set |
| 259 | 259 | * @return object DatabaseQueryRunner |
| 260 | 260 | */ |
| 261 | - public function setQuery($query){ |
|
| 261 | + public function setQuery($query) { |
|
| 262 | 262 | $this->query = $query; |
| 263 | 263 | return $this; |
| 264 | 264 | } |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | * @param boolean $returnType |
| 269 | 269 | * @return object DatabaseQueryRunner |
| 270 | 270 | */ |
| 271 | - public function setReturnType($returnType){ |
|
| 271 | + public function setReturnType($returnType) { |
|
| 272 | 272 | $this->returnAsList = $returnType; |
| 273 | 273 | return $this; |
| 274 | 274 | } |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | * @param boolean $status the status if true will return as array |
| 279 | 279 | * @return object DatabaseQueryRunner |
| 280 | 280 | */ |
| 281 | - public function setReturnAsArray($status = true){ |
|
| 281 | + public function setReturnAsArray($status = true) { |
|
| 282 | 282 | $this->returnAsArray = $status; |
| 283 | 283 | return $this; |
| 284 | 284 | } |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | * Return the error for last query execution |
| 288 | 288 | * @return string |
| 289 | 289 | */ |
| 290 | - public function getQueryError(){ |
|
| 290 | + public function getQueryError() { |
|
| 291 | 291 | return $this->error; |
| 292 | 292 | } |
| 293 | 293 | |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | * Return the PDO instance |
| 296 | 296 | * @return object |
| 297 | 297 | */ |
| 298 | - public function getPdo(){ |
|
| 298 | + public function getPdo() { |
|
| 299 | 299 | return $this->pdo; |
| 300 | 300 | } |
| 301 | 301 | |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | * @param PDO $pdo the pdo object |
| 305 | 305 | * @return object DatabaseQueryRunner |
| 306 | 306 | */ |
| 307 | - public function setPdo(PDO $pdo = null){ |
|
| 307 | + public function setPdo(PDO $pdo = null) { |
|
| 308 | 308 | $this->pdo = $pdo; |
| 309 | 309 | return $this; |
| 310 | 310 | } |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | * Return the database driver |
| 314 | 314 | * @return string |
| 315 | 315 | */ |
| 316 | - public function getDriver(){ |
|
| 316 | + public function getDriver() { |
|
| 317 | 317 | return $this->driver; |
| 318 | 318 | } |
| 319 | 319 | |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | * @param string $driver the new driver |
| 323 | 323 | * @return object DatabaseQueryRunner |
| 324 | 324 | */ |
| 325 | - public function setDriver($driver){ |
|
| 325 | + public function setDriver($driver) { |
|
| 326 | 326 | $this->driver = $driver; |
| 327 | 327 | return $this; |
| 328 | 328 | } |
@@ -332,14 +332,14 @@ discard block |
||
| 332 | 332 | * |
| 333 | 333 | * @return string |
| 334 | 334 | */ |
| 335 | - protected function getBenchmarkKey(){ |
|
| 335 | + protected function getBenchmarkKey() { |
|
| 336 | 336 | return md5($this->query . $this->returnAsList . $this->returnAsArray); |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
| 340 | 340 | * Set error for database query execution |
| 341 | 341 | */ |
| 342 | - protected function setQueryRunnerError(){ |
|
| 342 | + protected function setQueryRunnerError() { |
|
| 343 | 343 | $error = $this->pdo->errorInfo(); |
| 344 | 344 | $this->error = isset($error[2]) ? $error[2] : ''; |
| 345 | 345 | $this->logger->error('The database query execution got an error: ' . stringfy_vars($error)); |
@@ -351,12 +351,12 @@ discard block |
||
| 351 | 351 | * Set the Log instance using argument or create new instance |
| 352 | 352 | * @param object $logger the Log instance if not null |
| 353 | 353 | */ |
| 354 | - protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
|
| 355 | - if ($logger !== null){ |
|
| 354 | + protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) { |
|
| 355 | + if ($logger !== null) { |
|
| 356 | 356 | $this->logger = $logger; |
| 357 | 357 | } |
| 358 | - else{ |
|
| 359 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 358 | + else { |
|
| 359 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 360 | 360 | $this->logger->setLogger('Library::DatabaseQueryRunner'); |
| 361 | 361 | } |
| 362 | 362 | } |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | /** |
| 366 | 366 | * Reset the instance before run each query |
| 367 | 367 | */ |
| 368 | - private function reset(){ |
|
| 368 | + private function reset() { |
|
| 369 | 369 | $this->error = null; |
| 370 | 370 | $this->pdoStatment = null; |
| 371 | 371 | } |