@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @package FileUpload |
| 38 | 38 | * @version 1.5 |
| 39 | 39 | */ |
| 40 | - class Upload{ |
|
| 40 | + class Upload { |
|
| 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 |
@@ -217,12 +217,12 @@ discard block |
||
| 217 | 217 | * @return object |
| 218 | 218 | * @method object __construct |
| 219 | 219 | */ |
| 220 | - public function __construct(){ |
|
| 221 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 220 | + public function __construct() { |
|
| 221 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 222 | 222 | $this->logger->setLogger('Library::Upload'); |
| 223 | 223 | |
| 224 | 224 | Loader::lang('file_upload'); |
| 225 | - $obj =& get_instance(); |
|
| 225 | + $obj = & get_instance(); |
|
| 226 | 226 | |
| 227 | 227 | $this->error_messages = array( |
| 228 | 228 | 'upload_err_ini_size' => $obj->lang->get('fu_upload_err_ini_size'), |
@@ -239,15 +239,15 @@ discard block |
||
| 239 | 239 | ); |
| 240 | 240 | |
| 241 | 241 | $this->file = array( |
| 242 | - 'status' => false, // True: success upload |
|
| 243 | - 'mime' => '', // Empty string |
|
| 244 | - 'filename' => '', // Empty string |
|
| 245 | - 'original' => '', // Empty string |
|
| 246 | - 'size' => 0, // 0 Bytes |
|
| 247 | - 'sizeFormated' => '0B', // 0 Bytes |
|
| 248 | - 'destination' => './', // Default: ./ |
|
| 249 | - 'allowed_mime_types' => array(), // Allowed mime types |
|
| 250 | - 'error' => null, // File error |
|
| 242 | + 'status' => false, // True: success upload |
|
| 243 | + 'mime' => '', // Empty string |
|
| 244 | + 'filename' => '', // Empty string |
|
| 245 | + 'original' => '', // Empty string |
|
| 246 | + 'size' => 0, // 0 Bytes |
|
| 247 | + 'sizeFormated' => '0B', // 0 Bytes |
|
| 248 | + 'destination' => './', // Default: ./ |
|
| 249 | + 'allowed_mime_types' => array(), // Allowed mime types |
|
| 250 | + 'error' => null, // File error |
|
| 251 | 251 | ); |
| 252 | 252 | |
| 253 | 253 | // Change dir to current dir |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | if (isset($_FILES) && is_array($_FILES)) { |
| 258 | 258 | $this->file_array = $_FILES; |
| 259 | 259 | } |
| 260 | - $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array)); |
|
| 260 | + $this->logger->info('The upload file information are : ' . stringfy_vars($this->file_array)); |
|
| 261 | 261 | } |
| 262 | 262 | /** |
| 263 | 263 | * Set input. |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | */ |
| 274 | 274 | public function setInput($input) |
| 275 | 275 | { |
| 276 | - if (!empty($input) && (is_string($input) || is_numeric($input) )) { |
|
| 276 | + if (!empty($input) && (is_string($input) || is_numeric($input))) { |
|
| 277 | 277 | $this->input = $input; |
| 278 | 278 | } |
| 279 | 279 | return $this; |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | */ |
| 310 | 310 | public function setAutoFilename() |
| 311 | 311 | { |
| 312 | - $this->filename = sha1(mt_rand(1, 9999).uniqid()); |
|
| 312 | + $this->filename = sha1(mt_rand(1, 9999) . uniqid()); |
|
| 313 | 313 | $this->filename .= time(); |
| 314 | 314 | return $this; |
| 315 | 315 | } |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | $php_size = $this->sizeInBytes((int) ini_get('upload_max_filesize')); |
| 331 | 331 | // Calculate difference |
| 332 | 332 | if ($php_size < $file_size) { |
| 333 | - $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. ']'); |
|
| 333 | + $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 . ']'); |
|
| 334 | 334 | } |
| 335 | 335 | $this->max_file_size = $file_size; |
| 336 | 336 | } |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | public function setAllowedMimeTypes(array $mimes) |
| 349 | 349 | { |
| 350 | 350 | if (count($mimes) > 0) { |
| 351 | - array_map(array($this , 'setAllowMimeType'), $mimes); |
|
| 351 | + array_map(array($this, 'setAllowMimeType'), $mimes); |
|
| 352 | 352 | } |
| 353 | 353 | return $this; |
| 354 | 354 | } |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | { |
| 414 | 414 | if (!empty($name) && is_string($name)) { |
| 415 | 415 | if (array_key_exists($name, $this->mime_helping)) { |
| 416 | - return $this->setAllowedMimeTypes($this->mime_helping[ $name ]); |
|
| 416 | + return $this->setAllowedMimeTypes($this->mime_helping[$name]); |
|
| 417 | 417 | } |
| 418 | 418 | } |
| 419 | 419 | return $this; |
@@ -432,8 +432,8 @@ discard block |
||
| 432 | 432 | */ |
| 433 | 433 | public function setUploadFunction($function) |
| 434 | 434 | { |
| 435 | - if (!empty($function) && (is_array($function) || is_string($function) )) { |
|
| 436 | - if (is_callable( $function)) { |
|
| 435 | + if (!empty($function) && (is_array($function) || is_string($function))) { |
|
| 436 | + if (is_callable($function)) { |
|
| 437 | 437 | $this->upload_function = $function; |
| 438 | 438 | } |
| 439 | 439 | } |
@@ -478,8 +478,8 @@ discard block |
||
| 478 | 478 | $this->destination_directory = $destination_directory; |
| 479 | 479 | chdir($destination_directory); |
| 480 | 480 | } |
| 481 | - else{ |
|
| 482 | - $this->logger->warning('Can not create the upload directory [' .$destination_directory. ']'); |
|
| 481 | + else { |
|
| 482 | + $this->logger->warning('Can not create the upload directory [' . $destination_directory . ']'); |
|
| 483 | 483 | } |
| 484 | 484 | } |
| 485 | 485 | } |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | public function isFilename($filename) |
| 530 | 530 | { |
| 531 | 531 | $filename = basename($filename); |
| 532 | - return (!empty($filename) && (is_string( $filename) || is_numeric($filename))); |
|
| 532 | + return (!empty($filename) && (is_string($filename) || is_numeric($filename))); |
|
| 533 | 533 | } |
| 534 | 534 | /** |
| 535 | 535 | * Validate mime type with allowed mime types, |
@@ -571,11 +571,11 @@ discard block |
||
| 571 | 571 | */ |
| 572 | 572 | public function isDirpath($path) |
| 573 | 573 | { |
| 574 | - if (!empty( $path) && (is_string( $path) || is_numeric($path) )) { |
|
| 574 | + if (!empty($path) && (is_string($path) || is_numeric($path))) { |
|
| 575 | 575 | if (DIRECTORY_SEPARATOR == '/') { |
| 576 | - return (preg_match( '/^[^*?"<>|:]*$/' , $path) == 1 ); |
|
| 576 | + return (preg_match('/^[^*?"<>|:]*$/', $path) == 1); |
|
| 577 | 577 | } else { |
| 578 | - return (preg_match( "/^[^*?\"<>|:]*$/" , substr($path,2) ) == 1); |
|
| 578 | + return (preg_match("/^[^*?\"<>|:]*$/", substr($path, 2)) == 1); |
|
| 579 | 579 | } |
| 580 | 580 | } |
| 581 | 581 | return false; |
@@ -603,7 +603,7 @@ discard block |
||
| 603 | 603 | */ |
| 604 | 604 | public function getInfo() |
| 605 | 605 | { |
| 606 | - return (object)$this->file; |
|
| 606 | + return (object) $this->file; |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | * Check if the file is uploaded |
| 612 | 612 | * @return boolean |
| 613 | 613 | */ |
| 614 | - public function isUploaded(){ |
|
| 614 | + public function isUploaded() { |
|
| 615 | 615 | return isset($this->file_array[$this->input]) |
| 616 | 616 | && is_uploaded_file($this->file_array[$this->input]['tmp_name']); |
| 617 | 617 | } |
@@ -625,13 +625,13 @@ discard block |
||
| 625 | 625 | * @return boolean |
| 626 | 626 | * @method boolean save |
| 627 | 627 | */ |
| 628 | - public function save(){ |
|
| 628 | + public function save() { |
|
| 629 | 629 | if (count($this->file_array) > 0 && array_key_exists($this->input, $this->file_array)) { |
| 630 | 630 | // set original filename if not have a new name |
| 631 | 631 | if (empty($this->filename)) { |
| 632 | 632 | $this->filename = $this->file_array[$this->input]['name']; |
| 633 | 633 | } |
| 634 | - else{ |
|
| 634 | + else { |
|
| 635 | 635 | // Replace %s for extension in filename |
| 636 | 636 | // Before: /[\w\d]*(.[\d\w]+)$/i |
| 637 | 637 | // After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu |
@@ -655,10 +655,10 @@ discard block |
||
| 655 | 655 | $this->file['filename'] = $this->filename; |
| 656 | 656 | $this->file['error'] = $this->file_array[$this->input]['error']; |
| 657 | 657 | |
| 658 | - $this->logger->info('The upload file information to process is : ' .stringfy_vars($this->file)); |
|
| 658 | + $this->logger->info('The upload file information to process is : ' . stringfy_vars($this->file)); |
|
| 659 | 659 | |
| 660 | 660 | $error = $this->uploadHasError(); |
| 661 | - if($error){ |
|
| 661 | + if ($error) { |
|
| 662 | 662 | return false; |
| 663 | 663 | } |
| 664 | 664 | // Execute input callback |
@@ -692,10 +692,10 @@ discard block |
||
| 692 | 692 | */ |
| 693 | 693 | public function sizeFormat($size, $precision = 2) |
| 694 | 694 | { |
| 695 | - if($size > 0){ |
|
| 695 | + if ($size > 0) { |
|
| 696 | 696 | $base = log($size) / log(1024); |
| 697 | 697 | $suffixes = array('B', 'K', 'M', 'G', 'T'); |
| 698 | - return round(pow(1024, $base - floor($base)), $precision) . ( isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : ''); |
|
| 698 | + return round(pow(1024, $base - floor($base)), $precision) . (isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : ''); |
|
| 699 | 699 | } |
| 700 | 700 | return null; |
| 701 | 701 | } |
@@ -719,14 +719,14 @@ discard block |
||
| 719 | 719 | if (array_key_exists('unit', $matches)) { |
| 720 | 720 | $unit = strtoupper($matches['unit']); |
| 721 | 721 | } |
| 722 | - return (floatval($matches['size']) * pow(1024, $units[$unit]) ) ; |
|
| 722 | + return (floatval($matches['size']) * pow(1024, $units[$unit])); |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | /** |
| 726 | 726 | * Get the upload error message |
| 727 | 727 | * @return string |
| 728 | 728 | */ |
| 729 | - public function getError(){ |
|
| 729 | + public function getError() { |
|
| 730 | 730 | return $this->error; |
| 731 | 731 | } |
| 732 | 732 | |
@@ -734,7 +734,7 @@ discard block |
||
| 734 | 734 | * Set the upload error message |
| 735 | 735 | * @param string $message the upload error message to set |
| 736 | 736 | */ |
| 737 | - public function setError($message){ |
|
| 737 | + public function setError($message) { |
|
| 738 | 738 | $this->logger->info('The file upload got error : ' . $message); |
| 739 | 739 | $this->error = $message; |
| 740 | 740 | } |
@@ -744,9 +744,9 @@ discard block |
||
| 744 | 744 | * @param string $type the type of callback "input" or "output" |
| 745 | 745 | * @return void |
| 746 | 746 | */ |
| 747 | - protected function runCallback($type){ |
|
| 748 | - if (!empty( $this->callbacks[$type])) { |
|
| 749 | - call_user_func($this->callbacks[$type], (object)$this->file); |
|
| 747 | + protected function runCallback($type) { |
|
| 748 | + if (!empty($this->callbacks[$type])) { |
|
| 749 | + call_user_func($this->callbacks[$type], (object) $this->file); |
|
| 750 | 750 | } |
| 751 | 751 | } |
| 752 | 752 | |
@@ -754,21 +754,21 @@ discard block |
||
| 754 | 754 | * Check if file upload has error |
| 755 | 755 | * @return boolean |
| 756 | 756 | */ |
| 757 | - protected function uploadHasError(){ |
|
| 757 | + protected function uploadHasError() { |
|
| 758 | 758 | //check if file upload is allowed in the configuration |
| 759 | - if(! ini_get('file_uploads')){ |
|
| 759 | + if (!ini_get('file_uploads')) { |
|
| 760 | 760 | $this->setError($this->error_messages['file_uploads']); |
| 761 | 761 | return true; |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | //check for php upload error |
| 765 | - if(is_numeric($this->file['error']) && $this->file['error'] > 0){ |
|
| 765 | + if (is_numeric($this->file['error']) && $this->file['error'] > 0) { |
|
| 766 | 766 | $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error'])); |
| 767 | 767 | return true; |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | //check for mime type |
| 771 | - if (! $this->checkMimeType($this->file['mime'])) { |
|
| 771 | + if (!$this->checkMimeType($this->file['mime'])) { |
|
| 772 | 772 | $this->setError($this->error_messages['accept_file_types']); |
| 773 | 773 | return true; |
| 774 | 774 | } |
@@ -792,7 +792,7 @@ discard block |
||
| 792 | 792 | * @param int $code the error code |
| 793 | 793 | * @return string the error message |
| 794 | 794 | */ |
| 795 | - private function getPhpUploadErrorMessageByCode($code){ |
|
| 795 | + private function getPhpUploadErrorMessageByCode($code) { |
|
| 796 | 796 | $codeMessageMaps = array( |
| 797 | 797 | 1 => $this->error_messages['upload_err_ini_size'], |
| 798 | 798 | 2 => $this->error_messages['upload_err_form_size'], |
@@ -24,13 +24,13 @@ discard block |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - class DatabaseQueryResult{ |
|
| 27 | + class DatabaseQueryResult { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The database query result |
| 31 | 31 | * @var mixed |
| 32 | 32 | */ |
| 33 | - private $result = null; |
|
| 33 | + private $result = null; |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param mixed $result the query result |
| 46 | 46 | * @param int $numRows the number of rows returned by the query |
| 47 | 47 | */ |
| 48 | - public function __construct($result = null, $numRows = 0){ |
|
| 48 | + public function __construct($result = null, $numRows = 0) { |
|
| 49 | 49 | $this->result = $result; |
| 50 | 50 | $this->numRows = $numRows; |
| 51 | 51 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * |
| 57 | 57 | * @return mixed |
| 58 | 58 | */ |
| 59 | - public function getResult(){ |
|
| 59 | + public function getResult() { |
|
| 60 | 60 | return $this->result; |
| 61 | 61 | } |
| 62 | 62 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @return object DatabaseQueryResult |
| 68 | 68 | */ |
| 69 | - public function setResult($result){ |
|
| 69 | + public function setResult($result) { |
|
| 70 | 70 | $this->result = $result; |
| 71 | 71 | return $this; |
| 72 | 72 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @return int |
| 78 | 78 | */ |
| 79 | - public function getNumRows(){ |
|
| 79 | + public function getNumRows() { |
|
| 80 | 80 | return $this->numRows; |
| 81 | 81 | } |
| 82 | 82 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @return object DatabaseQueryResult |
| 88 | 88 | */ |
| 89 | - public function setNumRows($numRows){ |
|
| 89 | + public function setNumRows($numRows) { |
|
| 90 | 90 | $this->numRows = $numRows; |
| 91 | 91 | return $this; |
| 92 | 92 | } |
@@ -23,19 +23,19 @@ 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{ |
|
| 26 | + class DatabaseQueryRunner { |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * The logger instance |
| 30 | 30 | * @var object |
| 31 | 31 | */ |
| 32 | - private $logger = null; |
|
| 32 | + private $logger = null; |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * The last query result |
| 36 | 36 | * @var object |
| 37 | 37 | */ |
| 38 | - private $queryResult = null; |
|
| 38 | + private $queryResult = null; |
|
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * The benchmark instance |
@@ -47,45 +47,45 @@ discard block |
||
| 47 | 47 | * The SQL query statment to execute |
| 48 | 48 | * @var string |
| 49 | 49 | */ |
| 50 | - private $query = null; |
|
| 50 | + private $query = null; |
|
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * Indicate if we need return result as list (boolean) |
| 54 | 54 | * or the data used to replace the placeholder (array) |
| 55 | 55 | * @var array|boolean |
| 56 | 56 | */ |
| 57 | - private $returnAsList = true; |
|
| 57 | + private $returnAsList = true; |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * Indicate if we need return result as array or not |
| 62 | 62 | * @var boolean |
| 63 | 63 | */ |
| 64 | - private $returnAsArray = true; |
|
| 64 | + private $returnAsArray = true; |
|
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * The last PDOStatment instance |
| 68 | 68 | * @var object |
| 69 | 69 | */ |
| 70 | - private $pdoStatment = null; |
|
| 70 | + private $pdoStatment = null; |
|
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | 73 | * The error returned for the last query |
| 74 | 74 | * @var string |
| 75 | 75 | */ |
| 76 | - private $error = null; |
|
| 76 | + private $error = null; |
|
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | 79 | * The PDO instance |
| 80 | 80 | * @var object |
| 81 | 81 | */ |
| 82 | - private $pdo = null; |
|
| 82 | + private $pdo = null; |
|
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | 85 | * The database driver name used |
| 86 | 86 | * @var string |
| 87 | 87 | */ |
| 88 | - private $driver = null; |
|
| 88 | + private $driver = null; |
|
| 89 | 89 | |
| 90 | 90 | |
| 91 | 91 | |
@@ -96,8 +96,8 @@ discard block |
||
| 96 | 96 | * @param boolean $returnAsList if need return as list or just one row |
| 97 | 97 | * @param boolean $returnAsArray whether to return the result as array or not |
| 98 | 98 | */ |
| 99 | - public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false){ |
|
| 100 | - if (is_object($pdo)){ |
|
| 99 | + public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false) { |
|
| 100 | + if (is_object($pdo)) { |
|
| 101 | 101 | $this->pdo = $pdo; |
| 102 | 102 | } |
| 103 | 103 | $this->query = $query; |
@@ -112,13 +112,13 @@ discard block |
||
| 112 | 112 | * |
| 113 | 113 | * @return object|void |
| 114 | 114 | */ |
| 115 | - public function execute(){ |
|
| 115 | + public function execute() { |
|
| 116 | 116 | //reset instance |
| 117 | 117 | $this->reset(); |
| 118 | 118 | |
| 119 | 119 | //for database query execution time |
| 120 | 120 | $benchmarkMarkerKey = $this->getBenchmarkKey(); |
| 121 | - if (! is_object($this->benchmarkInstance)){ |
|
| 121 | + if (!is_object($this->benchmarkInstance)) { |
|
| 122 | 122 | $this->benchmarkInstance = & class_loader('Benchmark'); |
| 123 | 123 | } |
| 124 | 124 | |
@@ -134,19 +134,19 @@ discard block |
||
| 134 | 134 | 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')' |
| 135 | 135 | ); |
| 136 | 136 | //TODO use the configuration value for the high response time currently is 1 second |
| 137 | - if ($responseTime >= 1 ){ |
|
| 137 | + if ($responseTime >= 1) { |
|
| 138 | 138 | $this->logger->warning( |
| 139 | 139 | 'High response time while processing database query [' . $this->query . ']. |
| 140 | - The response time is [' .$responseTime. '] sec.' |
|
| 140 | + The response time is [' .$responseTime . '] sec.' |
|
| 141 | 141 | ); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if ($this->pdoStatment !== false){ |
|
| 144 | + if ($this->pdoStatment !== false) { |
|
| 145 | 145 | $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false; |
| 146 | - if($isSqlSELECTQuery){ |
|
| 146 | + if ($isSqlSELECTQuery) { |
|
| 147 | 147 | $this->setResultForSelect(); |
| 148 | 148 | } |
| 149 | - else{ |
|
| 149 | + else { |
|
| 150 | 150 | $this->setResultForNonSelect(); |
| 151 | 151 | } |
| 152 | 152 | return $this->queryResult; |
@@ -158,28 +158,28 @@ discard block |
||
| 158 | 158 | * Return the result for SELECT query |
| 159 | 159 | * @see DatabaseQueryRunner::execute |
| 160 | 160 | */ |
| 161 | - protected function setResultForSelect(){ |
|
| 161 | + protected function setResultForSelect() { |
|
| 162 | 162 | //if need return all result like list of record |
| 163 | 163 | $result = null; |
| 164 | 164 | $numRows = 0; |
| 165 | 165 | $fetchMode = PDO::FETCH_OBJ; |
| 166 | - if($this->returnAsArray){ |
|
| 166 | + if ($this->returnAsArray) { |
|
| 167 | 167 | $fetchMode = PDO::FETCH_ASSOC; |
| 168 | 168 | } |
| 169 | - if ($this->returnAsList){ |
|
| 169 | + if ($this->returnAsList) { |
|
| 170 | 170 | $result = $this->pdoStatment->fetchAll($fetchMode); |
| 171 | 171 | } |
| 172 | - else{ |
|
| 172 | + else { |
|
| 173 | 173 | $result = $this->pdoStatment->fetch($fetchMode); |
| 174 | 174 | } |
| 175 | 175 | //Sqlite and pgsql always return 0 when using rowCount() |
| 176 | - if (in_array($this->driver, array('sqlite', 'pgsql'))){ |
|
| 176 | + if (in_array($this->driver, array('sqlite', 'pgsql'))) { |
|
| 177 | 177 | $numRows = count($result); |
| 178 | 178 | } |
| 179 | - else{ |
|
| 179 | + else { |
|
| 180 | 180 | $numRows = $this->pdoStatment->rowCount(); |
| 181 | 181 | } |
| 182 | - if(! is_object($this->queryResult)){ |
|
| 182 | + if (!is_object($this->queryResult)) { |
|
| 183 | 183 | $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database'); |
| 184 | 184 | } |
| 185 | 185 | $this->queryResult->setResult($result); |
@@ -190,20 +190,20 @@ discard block |
||
| 190 | 190 | * Return the result for non SELECT query |
| 191 | 191 | * @see DatabaseQueryRunner::execute |
| 192 | 192 | */ |
| 193 | - protected function setResultForNonSelect(){ |
|
| 193 | + protected function setResultForNonSelect() { |
|
| 194 | 194 | //Sqlite and pgsql always return 0 when using rowCount() |
| 195 | 195 | $result = false; |
| 196 | 196 | $numRows = 0; |
| 197 | - if (in_array($this->driver, array('sqlite', 'pgsql'))){ |
|
| 197 | + if (in_array($this->driver, array('sqlite', 'pgsql'))) { |
|
| 198 | 198 | $result = true; //to test the result for the query like UPDATE, INSERT, DELETE |
| 199 | 199 | $numRows = 1; //TODO use the correct method to get the exact affected row |
| 200 | 200 | } |
| 201 | - else{ |
|
| 201 | + else { |
|
| 202 | 202 | //to test the result for the query like UPDATE, INSERT, DELETE |
| 203 | 203 | $result = $this->pdoStatment->rowCount() >= 0; |
| 204 | 204 | $numRows = $this->pdoStatment->rowCount(); |
| 205 | 205 | } |
| 206 | - if(! is_object($this->queryResult)){ |
|
| 206 | + if (!is_object($this->queryResult)) { |
|
| 207 | 207 | $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database'); |
| 208 | 208 | } |
| 209 | 209 | $this->queryResult->setResult($result); |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | * Return the benchmark instance |
| 216 | 216 | * @return Benchmark |
| 217 | 217 | */ |
| 218 | - public function getBenchmark(){ |
|
| 218 | + public function getBenchmark() { |
|
| 219 | 219 | return $this->benchmarkInstance; |
| 220 | 220 | } |
| 221 | 221 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * @param Benchmark $benchmark the benchmark object |
| 225 | 225 | * @return object DatabaseQueryRunner |
| 226 | 226 | */ |
| 227 | - public function setBenchmark($benchmark){ |
|
| 227 | + public function setBenchmark($benchmark) { |
|
| 228 | 228 | $this->benchmarkInstance = $benchmark; |
| 229 | 229 | return $this; |
| 230 | 230 | } |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | * |
| 235 | 235 | * @return object DatabaseQueryResult |
| 236 | 236 | */ |
| 237 | - public function getQueryResult(){ |
|
| 237 | + public function getQueryResult() { |
|
| 238 | 238 | return $this->queryResult; |
| 239 | 239 | } |
| 240 | 240 | |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | * |
| 245 | 245 | * @return object DatabaseQueryRunner |
| 246 | 246 | */ |
| 247 | - public function setQueryResult(DatabaseQueryResult $queryResult){ |
|
| 247 | + public function setQueryResult(DatabaseQueryResult $queryResult) { |
|
| 248 | 248 | $this->queryResult = $queryResult; |
| 249 | 249 | return $this; |
| 250 | 250 | } |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | * Return the Log instance |
| 254 | 254 | * @return Log |
| 255 | 255 | */ |
| 256 | - public function getLogger(){ |
|
| 256 | + public function getLogger() { |
|
| 257 | 257 | return $this->logger; |
| 258 | 258 | } |
| 259 | 259 | |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * @param Log $logger the log object |
| 263 | 263 | * @return object DatabaseQueryRunner |
| 264 | 264 | */ |
| 265 | - public function setLogger($logger){ |
|
| 265 | + public function setLogger($logger) { |
|
| 266 | 266 | $this->logger = $logger; |
| 267 | 267 | return $this; |
| 268 | 268 | } |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | * Return the current query SQL string |
| 272 | 272 | * @return string |
| 273 | 273 | */ |
| 274 | - public function getQuery(){ |
|
| 274 | + public function getQuery() { |
|
| 275 | 275 | return $this->query; |
| 276 | 276 | } |
| 277 | 277 | |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | * @param string $query the SQL query to set |
| 281 | 281 | * @return object DatabaseQueryRunner |
| 282 | 282 | */ |
| 283 | - public function setQuery($query){ |
|
| 283 | + public function setQuery($query) { |
|
| 284 | 284 | $this->query = $query; |
| 285 | 285 | return $this; |
| 286 | 286 | } |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * @param boolean $returnType |
| 291 | 291 | * @return object DatabaseQueryRunner |
| 292 | 292 | */ |
| 293 | - public function setReturnType($returnType){ |
|
| 293 | + public function setReturnType($returnType) { |
|
| 294 | 294 | $this->returnAsList = $returnType; |
| 295 | 295 | return $this; |
| 296 | 296 | } |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | * @param boolean $status the status if true will return as array |
| 301 | 301 | * @return object DatabaseQueryRunner |
| 302 | 302 | */ |
| 303 | - public function setReturnAsArray($status = true){ |
|
| 303 | + public function setReturnAsArray($status = true) { |
|
| 304 | 304 | $this->returnAsArray = $status; |
| 305 | 305 | return $this; |
| 306 | 306 | } |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | * Return the error for last query execution |
| 310 | 310 | * @return string |
| 311 | 311 | */ |
| 312 | - public function getQueryError(){ |
|
| 312 | + public function getQueryError() { |
|
| 313 | 313 | return $this->error; |
| 314 | 314 | } |
| 315 | 315 | |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | * Return the PDO instance |
| 318 | 318 | * @return object |
| 319 | 319 | */ |
| 320 | - public function getPdo(){ |
|
| 320 | + public function getPdo() { |
|
| 321 | 321 | return $this->pdo; |
| 322 | 322 | } |
| 323 | 323 | |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | * @param PDO $pdo the pdo object |
| 327 | 327 | * @return object DatabaseQueryRunner |
| 328 | 328 | */ |
| 329 | - public function setPdo(PDO $pdo = null){ |
|
| 329 | + public function setPdo(PDO $pdo = null) { |
|
| 330 | 330 | $this->pdo = $pdo; |
| 331 | 331 | return $this; |
| 332 | 332 | } |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | * Return the database driver |
| 336 | 336 | * @return string |
| 337 | 337 | */ |
| 338 | - public function getDriver(){ |
|
| 338 | + public function getDriver() { |
|
| 339 | 339 | return $this->driver; |
| 340 | 340 | } |
| 341 | 341 | |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | * @param string $driver the new driver |
| 345 | 345 | * @return object DatabaseQueryRunner |
| 346 | 346 | */ |
| 347 | - public function setDriver($driver){ |
|
| 347 | + public function setDriver($driver) { |
|
| 348 | 348 | $this->driver = $driver; |
| 349 | 349 | return $this; |
| 350 | 350 | } |
@@ -354,14 +354,14 @@ discard block |
||
| 354 | 354 | * |
| 355 | 355 | * @return string |
| 356 | 356 | */ |
| 357 | - protected function getBenchmarkKey(){ |
|
| 357 | + protected function getBenchmarkKey() { |
|
| 358 | 358 | return md5($this->query . $this->returnAsList . $this->returnAsArray); |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
| 362 | 362 | * Set error for database query execution |
| 363 | 363 | */ |
| 364 | - protected function setQueryRunnerError(){ |
|
| 364 | + protected function setQueryRunnerError() { |
|
| 365 | 365 | $error = $this->pdo->errorInfo(); |
| 366 | 366 | $this->error = isset($error[2]) ? $error[2] : ''; |
| 367 | 367 | $this->logger->error('The database query execution got an error: ' . stringfy_vars($error)); |
@@ -373,12 +373,12 @@ discard block |
||
| 373 | 373 | * Set the Log instance using argument or create new instance |
| 374 | 374 | * @param object $logger the Log instance if not null |
| 375 | 375 | */ |
| 376 | - protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
|
| 377 | - if ($logger !== null){ |
|
| 376 | + protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) { |
|
| 377 | + if ($logger !== null) { |
|
| 378 | 378 | $this->logger = $logger; |
| 379 | 379 | } |
| 380 | - else{ |
|
| 381 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 380 | + else { |
|
| 381 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 382 | 382 | $this->logger->setLogger('Library::DatabaseQueryRunner'); |
| 383 | 383 | } |
| 384 | 384 | } |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | /** |
| 388 | 388 | * Reset the instance before run each query |
| 389 | 389 | */ |
| 390 | - private function reset(){ |
|
| 390 | + private function reset() { |
|
| 391 | 391 | $this->error = null; |
| 392 | 392 | $this->pdoStatment = null; |
| 393 | 393 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | |
| 43 | 43 | |
| 44 | - if(! function_exists('get_ip')){ |
|
| 44 | + if (!function_exists('get_ip')) { |
|
| 45 | 45 | /** |
| 46 | 46 | * Retrieves the user's IP address |
| 47 | 47 | * |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @return string the IP address. |
| 52 | 52 | */ |
| 53 | - function get_ip(){ |
|
| 53 | + function get_ip() { |
|
| 54 | 54 | $ip = '127.0.0.1'; |
| 55 | 55 | $ipServerVars = array( |
| 56 | 56 | 'REMOTE_ADDR', |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | 'HTTP_FORWARDED' |
| 62 | 62 | ); |
| 63 | 63 | foreach ($ipServerVars as $var) { |
| 64 | - if(isset($_SERVER[$var])){ |
|
| 64 | + if (isset($_SERVER[$var])) { |
|
| 65 | 65 | $ip = $_SERVER[$var]; |
| 66 | 66 | break; |
| 67 | 67 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @since 1.0.0 |
| 39 | 39 | * @filesource |
| 40 | 40 | */ |
| 41 | - class Assets{ |
|
| 41 | + class Assets { |
|
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * The logger instance |
@@ -50,10 +50,10 @@ discard block |
||
| 50 | 50 | * The signleton of the logger |
| 51 | 51 | * @return Object the Log instance |
| 52 | 52 | */ |
| 53 | - private static function getLogger(){ |
|
| 54 | - if(self::$logger == null){ |
|
| 53 | + private static function getLogger() { |
|
| 54 | + if (self::$logger == null) { |
|
| 55 | 55 | //can't assign reference to static variable |
| 56 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 56 | + self::$logger[0] = & class_loader('Log', 'classes'); |
|
| 57 | 57 | self::$logger[0]->setLogger('Library::Assets'); |
| 58 | 58 | } |
| 59 | 59 | return self::$logger[0]; |
@@ -72,13 +72,13 @@ discard block |
||
| 72 | 72 | * @param string $asset the name of the assets file path with the extension. |
| 73 | 73 | * @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist. |
| 74 | 74 | */ |
| 75 | - public static function path($asset){ |
|
| 75 | + public static function path($asset) { |
|
| 76 | 76 | $logger = self::getLogger(); |
| 77 | 77 | $path = ASSETS_PATH . $asset; |
| 78 | 78 | |
| 79 | 79 | $logger->debug('Including the Assets file [' . $path . ']'); |
| 80 | 80 | //Check if the file exists |
| 81 | - if(file_exists($path)){ |
|
| 81 | + if (file_exists($path)) { |
|
| 82 | 82 | $logger->info('Assets file [' . $path . '] included successfully'); |
| 83 | 83 | return Url::base_url($path); |
| 84 | 84 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | * @param string $path the name of the css file without the extension. |
| 99 | 99 | * @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist. |
| 100 | 100 | */ |
| 101 | - public static function css($path){ |
|
| 101 | + public static function css($path) { |
|
| 102 | 102 | $logger = self::getLogger(); |
| 103 | 103 | /* |
| 104 | 104 | * if the file name contains the ".css" extension, replace it with |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | $logger->debug('Including the Assets file [' . $path . '] for CSS'); |
| 111 | 111 | //Check if the file exists |
| 112 | - if(file_exists($path)){ |
|
| 112 | + if (file_exists($path)) { |
|
| 113 | 113 | $logger->info('Assets file [' . $path . '] for CSS included successfully'); |
| 114 | 114 | return Url::base_url($path); |
| 115 | 115 | } |
@@ -129,12 +129,12 @@ discard block |
||
| 129 | 129 | * @param string $path the name of the javascript file without the extension. |
| 130 | 130 | * @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist. |
| 131 | 131 | */ |
| 132 | - public static function js($path){ |
|
| 132 | + public static function js($path) { |
|
| 133 | 133 | $logger = self::getLogger(); |
| 134 | 134 | $path = str_ireplace('.js', '', $path); |
| 135 | 135 | $path = ASSETS_PATH . 'js/' . $path . '.js'; |
| 136 | 136 | $logger->debug('Including the Assets file [' . $path . '] for javascript'); |
| 137 | - if(file_exists($path)){ |
|
| 137 | + if (file_exists($path)) { |
|
| 138 | 138 | $logger->info('Assets file [' . $path . '] for Javascript included successfully'); |
| 139 | 139 | return Url::base_url($path); |
| 140 | 140 | } |
@@ -154,11 +154,11 @@ discard block |
||
| 154 | 154 | * @param string $path the name of the image file with the extension. |
| 155 | 155 | * @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist. |
| 156 | 156 | */ |
| 157 | - public static function img($path){ |
|
| 157 | + public static function img($path) { |
|
| 158 | 158 | $logger = self::getLogger(); |
| 159 | 159 | $path = ASSETS_PATH . 'images/' . $path; |
| 160 | 160 | $logger->debug('Including the Assets file [' . $path . '] for image'); |
| 161 | - if(file_exists($path)){ |
|
| 161 | + if (file_exists($path)) { |
|
| 162 | 162 | $logger->info('Assets file [' . $path . '] for image included successfully'); |
| 163 | 163 | return Url::base_url($path); |
| 164 | 164 | } |
@@ -25,15 +25,15 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class Url{ |
|
| 28 | + class Url { |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Return the link using base_url config without front controller "index.php" |
| 32 | 32 | * @param string $path the link path or full URL |
| 33 | 33 | * @return string the full link URL |
| 34 | 34 | */ |
| 35 | - public static function base_url($path = ''){ |
|
| 36 | - if(is_url($path)){ |
|
| 35 | + public static function base_url($path = '') { |
|
| 36 | + if (is_url($path)) { |
|
| 37 | 37 | return $path; |
| 38 | 38 | } |
| 39 | 39 | return get_config('base_url') . $path; |
@@ -44,26 +44,26 @@ discard block |
||
| 44 | 44 | * @param string $path the link path or full URL |
| 45 | 45 | * @return string the full link URL |
| 46 | 46 | */ |
| 47 | - public static function site_url($path = ''){ |
|
| 48 | - if(is_url($path)){ |
|
| 47 | + public static function site_url($path = '') { |
|
| 48 | + if (is_url($path)) { |
|
| 49 | 49 | return $path; |
| 50 | 50 | } |
| 51 | 51 | $path = rtrim($path, '/'); |
| 52 | 52 | $baseUrl = get_config('base_url'); |
| 53 | 53 | $frontController = get_config('front_controller'); |
| 54 | 54 | $url = $baseUrl; |
| 55 | - if($frontController){ |
|
| 55 | + if ($frontController) { |
|
| 56 | 56 | $url .= $frontController . '/'; |
| 57 | 57 | } |
| 58 | - if(($suffix = get_config('url_suffix')) && $path){ |
|
| 59 | - if(strpos($path, '?') !== false){ |
|
| 58 | + if (($suffix = get_config('url_suffix')) && $path) { |
|
| 59 | + if (strpos($path, '?') !== false) { |
|
| 60 | 60 | $query = explode('?', $path); |
| 61 | 61 | $query[0] = str_ireplace($suffix, '', $query[0]); |
| 62 | 62 | $query[0] = rtrim($query[0], '/'); |
| 63 | 63 | $query[0] .= $suffix; |
| 64 | 64 | $path = implode('?', $query); |
| 65 | 65 | } |
| 66 | - else{ |
|
| 66 | + else { |
|
| 67 | 67 | $path .= $suffix; |
| 68 | 68 | } |
| 69 | 69 | } |
@@ -74,10 +74,10 @@ discard block |
||
| 74 | 74 | * Return the current site URL |
| 75 | 75 | * @return string |
| 76 | 76 | */ |
| 77 | - public static function current(){ |
|
| 77 | + public static function current() { |
|
| 78 | 78 | $current = '/'; |
| 79 | 79 | $requestUri = get_instance()->request->requestUri(); |
| 80 | - if($requestUri){ |
|
| 80 | + if ($requestUri) { |
|
| 81 | 81 | $current = $requestUri; |
| 82 | 82 | } |
| 83 | 83 | return static::domain() . $current; |
@@ -90,18 +90,18 @@ discard block |
||
| 90 | 90 | * @param boolean $lowercase whether to set the final text to lowe case or not |
| 91 | 91 | * @return string the friendly generated text |
| 92 | 92 | */ |
| 93 | - public static function title($str = null, $separator = '-', $lowercase = true){ |
|
| 93 | + public static function title($str = null, $separator = '-', $lowercase = true) { |
|
| 94 | 94 | $str = trim($str); |
| 95 | - $from = array('ç','À','Á','Â','Ã','Ä','Å','à','á','â','ã','ä','å','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','È','É','Ê','Ë','è','é','ê','ë','Ç','ç','Ì','Í','Î','Ï','ì','í','î','ï','Ù','Ú','Û','Ü','ù','ú','û','ü','ÿ','Ñ','ñ'); |
|
| 96 | - $to = array('c','a','a','a','a','a','a','a','a','a','a','a','a','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','i','i','i','i','i','i','i','i','u','u','u','u','u','u','u','u','y','n','n'); |
|
| 95 | + $from = array('ç', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'à', 'á', 'â', 'ã', 'ä', 'å', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'È', 'É', 'Ê', 'Ë', 'è', 'é', 'ê', 'ë', 'Ç', 'ç', 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï', 'Ù', 'Ú', 'Û', 'Ü', 'ù', 'ú', 'û', 'ü', 'ÿ', 'Ñ', 'ñ'); |
|
| 96 | + $to = array('c', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'y', 'n', 'n'); |
|
| 97 | 97 | $str = str_replace($from, $to, $str); |
| 98 | 98 | $str = preg_replace('#([^a-z0-9]+)#i', $separator, $str); |
| 99 | 99 | $str = str_replace('--', $separator, $str); |
| 100 | 100 | //if after process we get something like one-two-three-, need truncate the last separator "-" |
| 101 | - if(substr($str, -1) == $separator){ |
|
| 101 | + if (substr($str, -1) == $separator) { |
|
| 102 | 102 | $str = substr($str, 0, -1); |
| 103 | 103 | } |
| 104 | - if($lowercase){ |
|
| 104 | + if ($lowercase) { |
|
| 105 | 105 | $str = strtolower($str); |
| 106 | 106 | } |
| 107 | 107 | return $str; |
@@ -111,11 +111,11 @@ discard block |
||
| 111 | 111 | * Get the current application domain with protocol |
| 112 | 112 | * @return string the domain name |
| 113 | 113 | */ |
| 114 | - public static function domain(){ |
|
| 114 | + public static function domain() { |
|
| 115 | 115 | $domain = 'localhost'; |
| 116 | 116 | $port = get_instance()->request->server('SERVER_PORT'); |
| 117 | 117 | $protocol = 'http'; |
| 118 | - if(is_https()){ |
|
| 118 | + if (is_https()) { |
|
| 119 | 119 | $protocol = 'https'; |
| 120 | 120 | } |
| 121 | 121 | |
@@ -127,23 +127,23 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | foreach ($domainserverVars as $var) { |
| 129 | 129 | $value = get_instance()->request->server($var); |
| 130 | - if($value){ |
|
| 130 | + if ($value) { |
|
| 131 | 131 | $domain = $value; |
| 132 | 132 | break; |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - if($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))){ |
|
| 137 | - $domain .= ':'.$port; |
|
| 136 | + if ($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))) { |
|
| 137 | + $domain .= ':' . $port; |
|
| 138 | 138 | } |
| 139 | - return $protocol.'://'.$domain; |
|
| 139 | + return $protocol . '://' . $domain; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
| 143 | 143 | * Get the current request query string |
| 144 | 144 | * @return string |
| 145 | 145 | */ |
| 146 | - public static function queryString(){ |
|
| 146 | + public static function queryString() { |
|
| 147 | 147 | return get_instance()->request->server('QUERY_STRING'); |
| 148 | 148 | } |
| 149 | 149 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class Form{ |
|
| 28 | + class Form { |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Generate the form opened tag |
@@ -35,23 +35,23 @@ discard block |
||
| 35 | 35 | * @param string $enctype the form enctype like "multipart/form-data" |
| 36 | 36 | * @return string the generated form html |
| 37 | 37 | */ |
| 38 | - public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null){ |
|
| 39 | - if($path){ |
|
| 38 | + public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null) { |
|
| 39 | + if ($path) { |
|
| 40 | 40 | $path = Url::site_url($path); |
| 41 | 41 | } |
| 42 | 42 | $method = strtoupper($method); |
| 43 | 43 | $str = null; |
| 44 | - $str .= '<form action = "'.$path.'" method = "'.$method.'"'; |
|
| 45 | - if(! empty($enctype)){ |
|
| 46 | - $str .= ' enctype = "'.$enctype.'" '; |
|
| 44 | + $str .= '<form action = "' . $path . '" method = "' . $method . '"'; |
|
| 45 | + if (!empty($enctype)) { |
|
| 46 | + $str .= ' enctype = "' . $enctype . '" '; |
|
| 47 | 47 | } |
| 48 | - if(! isset($attributes['accept-charset'])){ |
|
| 48 | + if (!isset($attributes['accept-charset'])) { |
|
| 49 | 49 | $attributes['accept-charset'] = get_config('charset', 'utf-8'); |
| 50 | 50 | } |
| 51 | 51 | $str .= attributes_to_string($attributes); |
| 52 | 52 | $str .= '>'; |
| 53 | 53 | //if CSRF is enabled in the configuration |
| 54 | - if(get_config('csrf_enable', false) && $method == 'POST'){ |
|
| 54 | + if (get_config('csrf_enable', false) && $method == 'POST') { |
|
| 55 | 55 | $csrfValue = Security::generateCSRF(); |
| 56 | 56 | $csrfName = get_config('csrf_key', 'csrf_key'); |
| 57 | 57 | $str .= static::hidden($csrfName, $csrfValue); |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @see Form::open() for more details |
| 65 | 65 | * @return string the generated multipart form html |
| 66 | 66 | */ |
| 67 | - public static function openMultipart($path = null, array $attributes = array(), $method = 'POST'){ |
|
| 67 | + public static function openMultipart($path = null, array $attributes = array(), $method = 'POST') { |
|
| 68 | 68 | return self::open($path, $attributes, $method, 'multipart/form-data'); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * Generate the form close |
| 73 | 73 | * @return string the form close html |
| 74 | 74 | */ |
| 75 | - public static function close(){ |
|
| 75 | + public static function close() { |
|
| 76 | 76 | return '</form>'; |
| 77 | 77 | } |
| 78 | 78 | |
@@ -83,10 +83,10 @@ discard block |
||
| 83 | 83 | * @param array $legendAttributes the legend additional HTML attributes. Is used only is $legend is not empty |
| 84 | 84 | * @return string the generated fieldset value |
| 85 | 85 | */ |
| 86 | - public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()){ |
|
| 86 | + public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()) { |
|
| 87 | 87 | $str = '<fieldset' . attributes_to_string($fieldsetAttributes) . '>'; |
| 88 | - if($legend){ |
|
| 89 | - $str .= '<legend' . attributes_to_string($legendAttributes) . '>'.$legend.'</legend>'; |
|
| 88 | + if ($legend) { |
|
| 89 | + $str .= '<legend' . attributes_to_string($legendAttributes) . '>' . $legend . '</legend>'; |
|
| 90 | 90 | } |
| 91 | 91 | return $str; |
| 92 | 92 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * Generate the fieldset close tag |
| 96 | 96 | * @return string the generated html for fieldset close |
| 97 | 97 | */ |
| 98 | - public static function fieldsetClose(){ |
|
| 98 | + public static function fieldsetClose() { |
|
| 99 | 99 | return '</fieldset>'; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -105,13 +105,13 @@ discard block |
||
| 105 | 105 | * @param string $name the form field name |
| 106 | 106 | * @return string the error message if exists and null if not |
| 107 | 107 | */ |
| 108 | - public static function error($name){ |
|
| 108 | + public static function error($name) { |
|
| 109 | 109 | $return = null; |
| 110 | 110 | $obj = & get_instance(); |
| 111 | - if(isset($obj->formvalidation)){ |
|
| 111 | + if (isset($obj->formvalidation)) { |
|
| 112 | 112 | $errors = $obj->formvalidation->returnErrors(); |
| 113 | - $error = isset($errors[$name]) ? $errors[$name] : null; |
|
| 114 | - if($error){ |
|
| 113 | + $error = isset($errors[$name]) ? $errors[$name] : null; |
|
| 114 | + if ($error) { |
|
| 115 | 115 | list($errorStart, $errorEnd) = $obj->formvalidation->getErrorDelimiter(); |
| 116 | 116 | $return = $errorStart . $error . $errorEnd; |
| 117 | 117 | } |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @param mixed $default the default value if can not found the given form field name |
| 126 | 126 | * @return mixed the form field value if is set, otherwise return the default value. |
| 127 | 127 | */ |
| 128 | - public static function value($name, $default = null){ |
|
| 128 | + public static function value($name, $default = null) { |
|
| 129 | 129 | $value = get_instance()->request->query($name); |
| 130 | 130 | return $value ? $value : $default; |
| 131 | 131 | } |
@@ -137,14 +137,14 @@ discard block |
||
| 137 | 137 | * @param array $attributes the additional attributes to be added |
| 138 | 138 | * @return string the generated label html content |
| 139 | 139 | */ |
| 140 | - public static function label($label, $for = '', array $attributes = array()){ |
|
| 140 | + public static function label($label, $for = '', array $attributes = array()) { |
|
| 141 | 141 | $str = '<label'; |
| 142 | - if($for){ |
|
| 143 | - $str .= ' for = "'.$for.'"'; |
|
| 142 | + if ($for) { |
|
| 143 | + $str .= ' for = "' . $for . '"'; |
|
| 144 | 144 | } |
| 145 | 145 | $str .= attributes_to_string($attributes); |
| 146 | 146 | $str .= '>'; |
| 147 | - $str .= $label.'</label>'; |
|
| 147 | + $str .= $label . '</label>'; |
|
| 148 | 148 | return $str; |
| 149 | 149 | } |
| 150 | 150 | |
@@ -156,9 +156,9 @@ discard block |
||
| 156 | 156 | * @param string $type the type of the form field (password, text, submit, button, etc.) |
| 157 | 157 | * @return string the generated form field html content for the input |
| 158 | 158 | */ |
| 159 | - public static function input($name, $value = null, array $attributes = array(), $type = 'text'){ |
|
| 159 | + public static function input($name, $value = null, array $attributes = array(), $type = 'text') { |
|
| 160 | 160 | $str = null; |
| 161 | - $str .= '<input name = "'.$name.'" value = "'.$value.'" type = "'.$type.'"'; |
|
| 161 | + $str .= '<input name = "' . $name . '" value = "' . $value . '" type = "' . $type . '"'; |
|
| 162 | 162 | $str .= attributes_to_string($attributes); |
| 163 | 163 | $str .= '/>'; |
| 164 | 164 | return $str; |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * Generate the form field for "text" |
| 169 | 169 | * @see Form::input() for more details |
| 170 | 170 | */ |
| 171 | - public static function text($name, $value = null, array $attributes = array()){ |
|
| 171 | + public static function text($name, $value = null, array $attributes = array()) { |
|
| 172 | 172 | return self::input($name, $value, $attributes, 'text'); |
| 173 | 173 | } |
| 174 | 174 | |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | * Generate the form field for "password" |
| 177 | 177 | * @see Form::input() for more details |
| 178 | 178 | */ |
| 179 | - public static function password($name, $value = null, array $attributes = array()){ |
|
| 179 | + public static function password($name, $value = null, array $attributes = array()) { |
|
| 180 | 180 | return self::input($name, $value, $attributes, 'password'); |
| 181 | 181 | } |
| 182 | 182 | |
@@ -184,8 +184,8 @@ discard block |
||
| 184 | 184 | * Generate the form field for "radio" |
| 185 | 185 | * @see Form::input() for more details |
| 186 | 186 | */ |
| 187 | - public static function radio($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 188 | - if($checked){ |
|
| 187 | + public static function radio($name, $value = null, $checked = false, array $attributes = array()) { |
|
| 188 | + if ($checked) { |
|
| 189 | 189 | $attributes['checked'] = true; |
| 190 | 190 | } |
| 191 | 191 | return self::input($name, $value, $attributes, 'radio'); |
@@ -195,8 +195,8 @@ discard block |
||
| 195 | 195 | * Generate the form field for "checkbox" |
| 196 | 196 | * @see Form::input() for more details |
| 197 | 197 | */ |
| 198 | - public static function checkbox($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 199 | - if($checked){ |
|
| 198 | + public static function checkbox($name, $value = null, $checked = false, array $attributes = array()) { |
|
| 199 | + if ($checked) { |
|
| 200 | 200 | $attributes['checked'] = true; |
| 201 | 201 | } |
| 202 | 202 | return self::input($name, $value, $attributes, 'checkbox'); |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | * Generate the form field for "number" |
| 207 | 207 | * @see Form::input() for more details |
| 208 | 208 | */ |
| 209 | - public static function number($name, $value = null, array $attributes = array()){ |
|
| 209 | + public static function number($name, $value = null, array $attributes = array()) { |
|
| 210 | 210 | return self::input($name, $value, $attributes, 'number'); |
| 211 | 211 | } |
| 212 | 212 | |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | * Generate the form field for "phone" |
| 215 | 215 | * @see Form::input() for more details |
| 216 | 216 | */ |
| 217 | - public static function phone($name, $value = null, array $attributes = array()){ |
|
| 217 | + public static function phone($name, $value = null, array $attributes = array()) { |
|
| 218 | 218 | return self::input($name, $value, $attributes, 'phone'); |
| 219 | 219 | } |
| 220 | 220 | |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | * Generate the form field for "email" |
| 223 | 223 | * @see Form::input() for more details |
| 224 | 224 | */ |
| 225 | - public static function email($name, $value = null, array $attributes = array()){ |
|
| 225 | + public static function email($name, $value = null, array $attributes = array()) { |
|
| 226 | 226 | return self::input($name, $value, $attributes, 'email'); |
| 227 | 227 | } |
| 228 | 228 | |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | * Generate the form field for "search" |
| 231 | 231 | * @see Form::input() for more details |
| 232 | 232 | */ |
| 233 | - public static function search($name, $value = null, array $attributes = array()){ |
|
| 233 | + public static function search($name, $value = null, array $attributes = array()) { |
|
| 234 | 234 | return self::input($name, $value, $attributes, 'search'); |
| 235 | 235 | } |
| 236 | 236 | |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | * Generate the form field for "hidden" |
| 239 | 239 | * @see Form::input() for more details |
| 240 | 240 | */ |
| 241 | - public static function hidden($name, $value = null, array $attributes = array()){ |
|
| 241 | + public static function hidden($name, $value = null, array $attributes = array()) { |
|
| 242 | 242 | return self::input($name, $value, $attributes, 'hidden'); |
| 243 | 243 | } |
| 244 | 244 | |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | * Generate the form field for "file" |
| 247 | 247 | * @see Form::input() for more details |
| 248 | 248 | */ |
| 249 | - public static function file($name, array $attributes = array()){ |
|
| 249 | + public static function file($name, array $attributes = array()) { |
|
| 250 | 250 | return self::input($name, null, $attributes, 'file'); |
| 251 | 251 | } |
| 252 | 252 | |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | * Generate the form field for "button" |
| 255 | 255 | * @see Form::input() for more details |
| 256 | 256 | */ |
| 257 | - public static function button($name, $value = null, array $attributes = array()){ |
|
| 257 | + public static function button($name, $value = null, array $attributes = array()) { |
|
| 258 | 258 | return self::input($name, $value, $attributes, 'button'); |
| 259 | 259 | } |
| 260 | 260 | |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * Generate the form field for "reset" |
| 263 | 263 | * @see Form::input() for more details |
| 264 | 264 | */ |
| 265 | - public static function reset($name, $value = null, array $attributes = array()){ |
|
| 265 | + public static function reset($name, $value = null, array $attributes = array()) { |
|
| 266 | 266 | return self::input($name, $value, $attributes, 'reset'); |
| 267 | 267 | } |
| 268 | 268 | |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * Generate the form field for "submit" |
| 271 | 271 | * @see Form::input() for more details |
| 272 | 272 | */ |
| 273 | - public static function submit($name, $value = null, array $attributes = array()){ |
|
| 273 | + public static function submit($name, $value = null, array $attributes = array()) { |
|
| 274 | 274 | return self::input($name, $value, $attributes, 'submit'); |
| 275 | 275 | } |
| 276 | 276 | |
@@ -281,12 +281,12 @@ discard block |
||
| 281 | 281 | * @param array $attributes the additional attributes to be added |
| 282 | 282 | * @return string the generated textarea form html content |
| 283 | 283 | */ |
| 284 | - public static function textarea($name, $value = '', array $attributes = array()){ |
|
| 284 | + public static function textarea($name, $value = '', array $attributes = array()) { |
|
| 285 | 285 | $str = null; |
| 286 | - $str .= '<textarea name = "'.$name.'"'; |
|
| 286 | + $str .= '<textarea name = "' . $name . '"'; |
|
| 287 | 287 | $str .= attributes_to_string($attributes); |
| 288 | 288 | $str .= '>'; |
| 289 | - $str .= $value.'</textarea>'; |
|
| 289 | + $str .= $value . '</textarea>'; |
|
| 290 | 290 | return $str; |
| 291 | 291 | } |
| 292 | 292 | |
@@ -298,20 +298,20 @@ discard block |
||
| 298 | 298 | * @param array $attributes the additional attribute to be added |
| 299 | 299 | * @return string the generated form field html content for select |
| 300 | 300 | */ |
| 301 | - public static function select($name, $values = null, $selected = null, array $attributes = array()){ |
|
| 302 | - if(! is_array($values)){ |
|
| 301 | + public static function select($name, $values = null, $selected = null, array $attributes = array()) { |
|
| 302 | + if (!is_array($values)) { |
|
| 303 | 303 | $values = array('' => $values); |
| 304 | 304 | } |
| 305 | 305 | $str = null; |
| 306 | - $str .= '<select name = "'.$name.'"'; |
|
| 306 | + $str .= '<select name = "' . $name . '"'; |
|
| 307 | 307 | $str .= attributes_to_string($attributes); |
| 308 | 308 | $str .= '>'; |
| 309 | - foreach($values as $key => $val){ |
|
| 309 | + foreach ($values as $key => $val) { |
|
| 310 | 310 | $select = ''; |
| 311 | - if($key == $selected){ |
|
| 311 | + if ($key == $selected) { |
|
| 312 | 312 | $select = 'selected'; |
| 313 | 313 | } |
| 314 | - $str .= '<option value = "'.$key.'" '.$select.'>'.$val.'</option>'; |
|
| 314 | + $str .= '<option value = "' . $key . '" ' . $select . '>' . $val . '</option>'; |
|
| 315 | 315 | } |
| 316 | 316 | $str .= '</select>'; |
| 317 | 317 | return $str; |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | /** |
| 60 | 60 | * Custom application path for tests |
| 61 | 61 | */ |
| 62 | - define('APPS_PATH', TESTS_PATH .'hmvc' . DS); |
|
| 62 | + define('APPS_PATH', TESTS_PATH . 'hmvc' . DS); |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * The path to the controller directory of your application. |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
| 203 | 203 | * in HMVC architecture (hierichical, controllers, models, views). |
| 204 | 204 | */ |
| 205 | - define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS); |
|
| 205 | + define('MODULE_PATH', dirname(realpath(__FILE__)) . DS . 'hmvc' . DS . 'modules' . DS); |
|
| 206 | 206 | |
| 207 | 207 | /** |
| 208 | 208 | * The path to the directory of sources external to your application. |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | $_SESSION = array(); |
| 243 | 243 | |
| 244 | 244 | //check for composer autoload file if exists include it |
| 245 | - if (file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 245 | + if (file_exists(VENDOR_PATH . 'autoload.php')) { |
|
| 246 | 246 | require_once VENDOR_PATH . 'autoload.php'; |
| 247 | 247 | |
| 248 | 248 | //define the class alias for vstream |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - class FileCache implements CacheInterface{ |
|
| 27 | + class FileCache implements CacheInterface { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Whether to enable compression of the cache data file. |
@@ -39,23 +39,23 @@ discard block |
||
| 39 | 39 | private $logger; |
| 40 | 40 | |
| 41 | 41 | |
| 42 | - public function __construct(Log $logger = null){ |
|
| 43 | - if(! $this->isSupported()){ |
|
| 42 | + public function __construct(Log $logger = null) { |
|
| 43 | + if (!$this->isSupported()) { |
|
| 44 | 44 | show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.'); |
| 45 | 45 | } |
| 46 | 46 | /** |
| 47 | 47 | * instance of the Log class |
| 48 | 48 | */ |
| 49 | - if(is_object($logger)){ |
|
| 49 | + if (is_object($logger)) { |
|
| 50 | 50 | $this->logger = $logger; |
| 51 | 51 | } |
| 52 | - else{ |
|
| 53 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 52 | + else { |
|
| 53 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 54 | 54 | $this->logger->setLogger('Library::FileCache'); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | //if Zlib extension is not loaded set compressCacheData to false |
| 58 | - if(! extension_loaded('zlib')){ |
|
| 58 | + if (!extension_loaded('zlib')) { |
|
| 59 | 59 | $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE'); |
| 60 | 60 | $this->compressCacheData = false; |
| 61 | 61 | } |
@@ -66,17 +66,17 @@ discard block |
||
| 66 | 66 | * @param string $key the key to identify the cache data |
| 67 | 67 | * @return mixed the cache data if exists else return false |
| 68 | 68 | */ |
| 69 | - public function get($key){ |
|
| 70 | - $this->logger->debug('Getting cache data for key ['. $key .']'); |
|
| 69 | + public function get($key) { |
|
| 70 | + $this->logger->debug('Getting cache data for key [' . $key . ']'); |
|
| 71 | 71 | $filePath = $this->getFilePath($key); |
| 72 | - if(! file_exists($filePath)){ |
|
| 73 | - $this->logger->info('No cache file found for the key ['. $key .'], return false'); |
|
| 72 | + if (!file_exists($filePath)) { |
|
| 73 | + $this->logger->info('No cache file found for the key [' . $key . '], return false'); |
|
| 74 | 74 | return false; |
| 75 | 75 | } |
| 76 | - $this->logger->info('The cache file [' .$filePath. '] for the key ['. $key .'] exists, check if the cache data is valid'); |
|
| 77 | - $handle = fopen($filePath,'r'); |
|
| 78 | - if(! is_resource($handle)){ |
|
| 79 | - $this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false'); |
|
| 76 | + $this->logger->info('The cache file [' . $filePath . '] for the key [' . $key . '] exists, check if the cache data is valid'); |
|
| 77 | + $handle = fopen($filePath, 'r'); |
|
| 78 | + if (!is_resource($handle)) { |
|
| 79 | + $this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false'); |
|
| 80 | 80 | return false; |
| 81 | 81 | } |
| 82 | 82 | // Getting a shared lock |
@@ -84,20 +84,20 @@ discard block |
||
| 84 | 84 | $data = file_get_contents($filePath); |
| 85 | 85 | fclose($handle); |
| 86 | 86 | $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
| 87 | - if (! $data) { |
|
| 88 | - $this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false'); |
|
| 87 | + if (!$data) { |
|
| 88 | + $this->logger->error('Can not unserialize the cache data for the key [' . $key . '], return false'); |
|
| 89 | 89 | // If unserializing somehow didn't work out, we'll delete the file |
| 90 | 90 | unlink($filePath); |
| 91 | 91 | return false; |
| 92 | 92 | } |
| 93 | 93 | if (time() > $data['expire']) { |
| 94 | - $this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']'); |
|
| 94 | + $this->logger->info('The cache data for the key [' . $key . '] already expired delete the cache file [' . $filePath . ']'); |
|
| 95 | 95 | // Unlinking when the file was expired |
| 96 | 96 | unlink($filePath); |
| 97 | 97 | return false; |
| 98 | 98 | } |
| 99 | - else{ |
|
| 100 | - $this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']'); |
|
| 99 | + else { |
|
| 100 | + $this->logger->info('The cache not yet expire, now return the cache data for key [' . $key . '], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']'); |
|
| 101 | 101 | return $data['data']; |
| 102 | 102 | } |
| 103 | 103 | } |
@@ -110,13 +110,13 @@ discard block |
||
| 110 | 110 | * @param integer $ttl the cache life time |
| 111 | 111 | * @return boolean true if success otherwise will return false |
| 112 | 112 | */ |
| 113 | - public function set($key, $data, $ttl = 0){ |
|
| 113 | + public function set($key, $data, $ttl = 0) { |
|
| 114 | 114 | $expire = time() + $ttl; |
| 115 | - $this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
| 115 | + $this->logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
| 116 | 116 | $filePath = $this->getFilePath($key); |
| 117 | - $handle = fopen($filePath,'w'); |
|
| 118 | - if(! is_resource($handle)){ |
|
| 119 | - $this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false'); |
|
| 117 | + $handle = fopen($filePath, 'w'); |
|
| 118 | + if (!is_resource($handle)) { |
|
| 119 | + $this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false'); |
|
| 120 | 120 | return false; |
| 121 | 121 | } |
| 122 | 122 | flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed |
@@ -129,13 +129,13 @@ discard block |
||
| 129 | 129 | ) |
| 130 | 130 | ); |
| 131 | 131 | $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData); |
| 132 | - if(! $result){ |
|
| 133 | - $this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false'); |
|
| 132 | + if (!$result) { |
|
| 133 | + $this->logger->error('Can not write cache data into file [' . $filePath . '] for the key [' . $key . '], return false'); |
|
| 134 | 134 | fclose($handle); |
| 135 | 135 | return false; |
| 136 | 136 | } |
| 137 | - else{ |
|
| 138 | - $this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']'); |
|
| 137 | + else { |
|
| 138 | + $this->logger->info('Cache data saved into file [' . $filePath . '] for the key [' . $key . ']'); |
|
| 139 | 139 | fclose($handle); |
| 140 | 140 | chmod($filePath, 0640); |
| 141 | 141 | return true; |
@@ -149,16 +149,16 @@ discard block |
||
| 149 | 149 | * @return boolean true if the cache is delete, false if can't delete |
| 150 | 150 | * the cache or the cache with the given key not exist |
| 151 | 151 | */ |
| 152 | - public function delete($key){ |
|
| 153 | - $this->logger->debug('Deleting of cache data for key [' .$key. ']'); |
|
| 152 | + public function delete($key) { |
|
| 153 | + $this->logger->debug('Deleting of cache data for key [' . $key . ']'); |
|
| 154 | 154 | $filePath = $this->getFilePath($key); |
| 155 | - $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']'); |
|
| 156 | - if(! file_exists($filePath)){ |
|
| 155 | + $this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']'); |
|
| 156 | + if (!file_exists($filePath)) { |
|
| 157 | 157 | $this->logger->info('This cache file does not exists skipping'); |
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | - else{ |
|
| 161 | - $this->logger->info('Found cache file [' .$filePath. '] remove it'); |
|
| 160 | + else { |
|
| 161 | + $this->logger->info('Found cache file [' . $filePath . '] remove it'); |
|
| 162 | 162 | unlink($filePath); |
| 163 | 163 | return true; |
| 164 | 164 | } |
@@ -172,23 +172,23 @@ discard block |
||
| 172 | 172 | * 'expire' => expiration time of the cache (Unix timestamp), |
| 173 | 173 | * 'ttl' => the time to live of the cache in second |
| 174 | 174 | */ |
| 175 | - public function getInfo($key){ |
|
| 176 | - $this->logger->debug('Getting of cache info for key [' .$key. ']'); |
|
| 175 | + public function getInfo($key) { |
|
| 176 | + $this->logger->debug('Getting of cache info for key [' . $key . ']'); |
|
| 177 | 177 | $filePath = $this->getFilePath($key); |
| 178 | - $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']'); |
|
| 179 | - if(! file_exists($filePath)){ |
|
| 178 | + $this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']'); |
|
| 179 | + if (!file_exists($filePath)) { |
|
| 180 | 180 | $this->logger->info('This cache file does not exists skipping'); |
| 181 | 181 | return false; |
| 182 | 182 | } |
| 183 | - $this->logger->info('Found cache file [' .$filePath. '] check the validity'); |
|
| 183 | + $this->logger->info('Found cache file [' . $filePath . '] check the validity'); |
|
| 184 | 184 | $data = file_get_contents($filePath); |
| 185 | 185 | $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
| 186 | - if(! $data){ |
|
| 186 | + if (!$data) { |
|
| 187 | 187 | $this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']'); |
| 188 | 188 | return false; |
| 189 | 189 | } |
| 190 | 190 | $this->logger->info('This cache data is OK check for expire'); |
| 191 | - if(isset($data['expire']) && $data['expire'] > time()){ |
|
| 191 | + if (isset($data['expire']) && $data['expire'] > time()) { |
|
| 192 | 192 | $this->logger->info('This cache not yet expired return cache informations'); |
| 193 | 193 | $info = array( |
| 194 | 194 | 'mtime' => $data['mtime'], |
@@ -205,26 +205,26 @@ discard block |
||
| 205 | 205 | /** |
| 206 | 206 | * Used to delete expired cache data |
| 207 | 207 | */ |
| 208 | - public function deleteExpiredCache(){ |
|
| 208 | + public function deleteExpiredCache() { |
|
| 209 | 209 | $this->logger->debug('Deleting of expired cache files'); |
| 210 | 210 | $list = glob(CACHE_PATH . '*.cache'); |
| 211 | - if(! $list){ |
|
| 211 | + if (!$list) { |
|
| 212 | 212 | $this->logger->info('No cache files were found skipping'); |
| 213 | 213 | } |
| 214 | - else{ |
|
| 214 | + else { |
|
| 215 | 215 | $this->logger->info('Found [' . count($list) . '] cache files to remove if expired'); |
| 216 | 216 | foreach ($list as $file) { |
| 217 | 217 | $this->logger->debug('Processing the cache file [' . $file . ']'); |
| 218 | 218 | $data = file_get_contents($file); |
| 219 | 219 | $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
| 220 | - if(! $data){ |
|
| 220 | + if (!$data) { |
|
| 221 | 221 | $this->logger->warning('Can not unserialize the cache data for file [' . $file . ']'); |
| 222 | 222 | } |
| 223 | - else if(time() > $data['expire']){ |
|
| 223 | + else if (time() > $data['expire']) { |
|
| 224 | 224 | $this->logger->info('The cache data for file [' . $file . '] already expired remove it'); |
| 225 | 225 | unlink($file); |
| 226 | 226 | } |
| 227 | - else{ |
|
| 227 | + else { |
|
| 228 | 228 | $this->logger->info('The cache data for file [' . $file . '] not yet expired skip it'); |
| 229 | 229 | } |
| 230 | 230 | } |
@@ -234,13 +234,13 @@ discard block |
||
| 234 | 234 | /** |
| 235 | 235 | * Remove all file from cache folder |
| 236 | 236 | */ |
| 237 | - public function clean(){ |
|
| 237 | + public function clean() { |
|
| 238 | 238 | $this->logger->debug('Deleting of all cache files'); |
| 239 | 239 | $list = glob(CACHE_PATH . '*.cache'); |
| 240 | - if(! $list){ |
|
| 240 | + if (!$list) { |
|
| 241 | 241 | $this->logger->info('No cache files were found skipping'); |
| 242 | 242 | } |
| 243 | - else{ |
|
| 243 | + else { |
|
| 244 | 244 | $this->logger->info('Found [' . count($list) . '] cache files to remove'); |
| 245 | 245 | foreach ($list as $file) { |
| 246 | 246 | $this->logger->debug('Processing the cache file [' . $file . ']'); |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | /** |
| 253 | 253 | * @return boolean |
| 254 | 254 | */ |
| 255 | - public function isCompressCacheData(){ |
|
| 255 | + public function isCompressCacheData() { |
|
| 256 | 256 | return $this->compressCacheData; |
| 257 | 257 | } |
| 258 | 258 | |
@@ -261,14 +261,14 @@ discard block |
||
| 261 | 261 | * |
| 262 | 262 | * @return object |
| 263 | 263 | */ |
| 264 | - public function setCompressCacheData($status = true){ |
|
| 264 | + public function setCompressCacheData($status = true) { |
|
| 265 | 265 | //if Zlib extension is not loaded set compressCacheData to false |
| 266 | - if($status === true && ! extension_loaded('zlib')){ |
|
| 266 | + if ($status === true && !extension_loaded('zlib')) { |
|
| 267 | 267 | |
| 268 | 268 | $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE'); |
| 269 | 269 | $this->compressCacheData = false; |
| 270 | 270 | } |
| 271 | - else{ |
|
| 271 | + else { |
|
| 272 | 272 | $this->compressCacheData = $status; |
| 273 | 273 | } |
| 274 | 274 | return $this; |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | * |
| 280 | 280 | * @return bool |
| 281 | 281 | */ |
| 282 | - public function isSupported(){ |
|
| 282 | + public function isSupported() { |
|
| 283 | 283 | return CACHE_PATH && is_dir(CACHE_PATH) && is_writable(CACHE_PATH); |
| 284 | 284 | } |
| 285 | 285 | |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | * Return the Log instance |
| 288 | 288 | * @return object |
| 289 | 289 | */ |
| 290 | - public function getLogger(){ |
|
| 290 | + public function getLogger() { |
|
| 291 | 291 | return $this->logger; |
| 292 | 292 | } |
| 293 | 293 | |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | * Set the log instance |
| 296 | 296 | * @param Log $logger the log object |
| 297 | 297 | */ |
| 298 | - public function setLogger(Log $logger){ |
|
| 298 | + public function setLogger(Log $logger) { |
|
| 299 | 299 | $this->logger = $logger; |
| 300 | 300 | return $this; |
| 301 | 301 | } |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | * @param string $key the cache item key |
| 307 | 307 | * @return string the full cache file path for this key |
| 308 | 308 | */ |
| 309 | - private function getFilePath($key){ |
|
| 309 | + private function getFilePath($key) { |
|
| 310 | 310 | return CACHE_PATH . md5($key) . '.cache'; |
| 311 | 311 | } |
| 312 | 312 | } |