@@ -62,8 +62,7 @@ |
||
| 62 | 62 | $query[0] = rtrim($query[0], '/'); |
| 63 | 63 | $query[0] .= $suffix; |
| 64 | 64 | $path = implode('?', $query); |
| 65 | - } |
|
| 66 | - else{ |
|
| 65 | + } else{ |
|
| 67 | 66 | $path .= $suffix; |
| 68 | 67 | } |
| 69 | 68 | } |
@@ -1,149 +1,149 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') or exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') or exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class Url{ |
|
| 28 | + class Url{ |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Return the link using base_url config without front controller "index.php" |
|
| 32 | - * @param string $path the link path or full URL |
|
| 33 | - * @return string the full link URL |
|
| 34 | - */ |
|
| 35 | - public static function base_url($path = ''){ |
|
| 36 | - if(is_url($path)){ |
|
| 37 | - return $path; |
|
| 38 | - } |
|
| 39 | - return get_config('base_url') . $path; |
|
| 40 | - } |
|
| 30 | + /** |
|
| 31 | + * Return the link using base_url config without front controller "index.php" |
|
| 32 | + * @param string $path the link path or full URL |
|
| 33 | + * @return string the full link URL |
|
| 34 | + */ |
|
| 35 | + public static function base_url($path = ''){ |
|
| 36 | + if(is_url($path)){ |
|
| 37 | + return $path; |
|
| 38 | + } |
|
| 39 | + return get_config('base_url') . $path; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Return the link using base_url config with front controller "index.php" |
|
| 44 | - * @param string $path the link path or full URL |
|
| 45 | - * @return string the full link URL |
|
| 46 | - */ |
|
| 47 | - public static function site_url($path = ''){ |
|
| 48 | - if(is_url($path)){ |
|
| 49 | - return $path; |
|
| 50 | - } |
|
| 51 | - $path = rtrim($path, '/'); |
|
| 52 | - $baseUrl = get_config('base_url'); |
|
| 53 | - $frontController = get_config('front_controller'); |
|
| 54 | - $url = $baseUrl; |
|
| 55 | - if($frontController){ |
|
| 56 | - $url .= $frontController . '/'; |
|
| 57 | - } |
|
| 58 | - if(($suffix = get_config('url_suffix')) && $path){ |
|
| 59 | - if(strpos($path, '?') !== false){ |
|
| 60 | - $query = explode('?', $path); |
|
| 61 | - $query[0] = str_ireplace($suffix, '', $query[0]); |
|
| 62 | - $query[0] = rtrim($query[0], '/'); |
|
| 63 | - $query[0] .= $suffix; |
|
| 64 | - $path = implode('?', $query); |
|
| 65 | - } |
|
| 66 | - else{ |
|
| 67 | - $path .= $suffix; |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - return $url . $path; |
|
| 71 | - } |
|
| 42 | + /** |
|
| 43 | + * Return the link using base_url config with front controller "index.php" |
|
| 44 | + * @param string $path the link path or full URL |
|
| 45 | + * @return string the full link URL |
|
| 46 | + */ |
|
| 47 | + public static function site_url($path = ''){ |
|
| 48 | + if(is_url($path)){ |
|
| 49 | + return $path; |
|
| 50 | + } |
|
| 51 | + $path = rtrim($path, '/'); |
|
| 52 | + $baseUrl = get_config('base_url'); |
|
| 53 | + $frontController = get_config('front_controller'); |
|
| 54 | + $url = $baseUrl; |
|
| 55 | + if($frontController){ |
|
| 56 | + $url .= $frontController . '/'; |
|
| 57 | + } |
|
| 58 | + if(($suffix = get_config('url_suffix')) && $path){ |
|
| 59 | + if(strpos($path, '?') !== false){ |
|
| 60 | + $query = explode('?', $path); |
|
| 61 | + $query[0] = str_ireplace($suffix, '', $query[0]); |
|
| 62 | + $query[0] = rtrim($query[0], '/'); |
|
| 63 | + $query[0] .= $suffix; |
|
| 64 | + $path = implode('?', $query); |
|
| 65 | + } |
|
| 66 | + else{ |
|
| 67 | + $path .= $suffix; |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + return $url . $path; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Return the current site URL |
|
| 75 | - * @return string |
|
| 76 | - */ |
|
| 77 | - public static function current(){ |
|
| 78 | - $current = '/'; |
|
| 79 | - $requestUri = get_instance()->request->requestUri(); |
|
| 80 | - if($requestUri){ |
|
| 81 | - $current = $requestUri; |
|
| 82 | - } |
|
| 83 | - return static::domain() . $current; |
|
| 84 | - } |
|
| 73 | + /** |
|
| 74 | + * Return the current site URL |
|
| 75 | + * @return string |
|
| 76 | + */ |
|
| 77 | + public static function current(){ |
|
| 78 | + $current = '/'; |
|
| 79 | + $requestUri = get_instance()->request->requestUri(); |
|
| 80 | + if($requestUri){ |
|
| 81 | + $current = $requestUri; |
|
| 82 | + } |
|
| 83 | + return static::domain() . $current; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Generate a friendly text to use in link (slugs) |
|
| 88 | - * @param string $str the title or text to use to get the friendly text |
|
| 89 | - * @param string $separator the caracters separator |
|
| 90 | - * @param boolean $lowercase whether to set the final text to lowe case or not |
|
| 91 | - * @return string the friendly generated text |
|
| 92 | - */ |
|
| 93 | - public static function title($str = null, $separator = '-', $lowercase = true){ |
|
| 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'); |
|
| 97 | - $str = str_replace($from, $to, $str); |
|
| 98 | - $str = preg_replace('#([^a-z0-9]+)#i', $separator, $str); |
|
| 99 | - $str = str_replace('--', $separator, $str); |
|
| 100 | - //if after process we get something like one-two-three-, need truncate the last separator "-" |
|
| 101 | - if(substr($str, -1) == $separator){ |
|
| 102 | - $str = substr($str, 0, -1); |
|
| 103 | - } |
|
| 104 | - if($lowercase){ |
|
| 105 | - $str = strtolower($str); |
|
| 106 | - } |
|
| 107 | - return $str; |
|
| 108 | - } |
|
| 86 | + /** |
|
| 87 | + * Generate a friendly text to use in link (slugs) |
|
| 88 | + * @param string $str the title or text to use to get the friendly text |
|
| 89 | + * @param string $separator the caracters separator |
|
| 90 | + * @param boolean $lowercase whether to set the final text to lowe case or not |
|
| 91 | + * @return string the friendly generated text |
|
| 92 | + */ |
|
| 93 | + public static function title($str = null, $separator = '-', $lowercase = true){ |
|
| 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'); |
|
| 97 | + $str = str_replace($from, $to, $str); |
|
| 98 | + $str = preg_replace('#([^a-z0-9]+)#i', $separator, $str); |
|
| 99 | + $str = str_replace('--', $separator, $str); |
|
| 100 | + //if after process we get something like one-two-three-, need truncate the last separator "-" |
|
| 101 | + if(substr($str, -1) == $separator){ |
|
| 102 | + $str = substr($str, 0, -1); |
|
| 103 | + } |
|
| 104 | + if($lowercase){ |
|
| 105 | + $str = strtolower($str); |
|
| 106 | + } |
|
| 107 | + return $str; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Get the current application domain with protocol |
|
| 112 | - * @return string the domain name |
|
| 113 | - */ |
|
| 114 | - public static function domain(){ |
|
| 115 | - $domain = 'localhost'; |
|
| 116 | - $port = get_instance()->request->server('SERVER_PORT'); |
|
| 117 | - $protocol = 'http'; |
|
| 118 | - if(is_https()){ |
|
| 119 | - $protocol = 'https'; |
|
| 120 | - } |
|
| 110 | + /** |
|
| 111 | + * Get the current application domain with protocol |
|
| 112 | + * @return string the domain name |
|
| 113 | + */ |
|
| 114 | + public static function domain(){ |
|
| 115 | + $domain = 'localhost'; |
|
| 116 | + $port = get_instance()->request->server('SERVER_PORT'); |
|
| 117 | + $protocol = 'http'; |
|
| 118 | + if(is_https()){ |
|
| 119 | + $protocol = 'https'; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - $domainserverVars = array( |
|
| 123 | - 'HTTP_HOST', |
|
| 124 | - 'SERVER_NAME', |
|
| 125 | - 'SERVER_ADDR' |
|
| 126 | - ); |
|
| 122 | + $domainserverVars = array( |
|
| 123 | + 'HTTP_HOST', |
|
| 124 | + 'SERVER_NAME', |
|
| 125 | + 'SERVER_ADDR' |
|
| 126 | + ); |
|
| 127 | 127 | |
| 128 | - foreach ($domainserverVars as $var) { |
|
| 129 | - $value = get_instance()->request->server($var); |
|
| 130 | - if($value){ |
|
| 131 | - $domain = $value; |
|
| 132 | - break; |
|
| 133 | - } |
|
| 134 | - } |
|
| 128 | + foreach ($domainserverVars as $var) { |
|
| 129 | + $value = get_instance()->request->server($var); |
|
| 130 | + if($value){ |
|
| 131 | + $domain = $value; |
|
| 132 | + break; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - if($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))){ |
|
| 137 | - $domain .= ':'.$port; |
|
| 138 | - } |
|
| 139 | - return $protocol.'://'.$domain; |
|
| 140 | - } |
|
| 136 | + if($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))){ |
|
| 137 | + $domain .= ':'.$port; |
|
| 138 | + } |
|
| 139 | + return $protocol.'://'.$domain; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Get the current request query string |
|
| 144 | - * @return string |
|
| 145 | - */ |
|
| 146 | - public static function queryString(){ |
|
| 147 | - return get_instance()->request->server('QUERY_STRING'); |
|
| 148 | - } |
|
| 149 | - } |
|
| 142 | + /** |
|
| 143 | + * Get the current request query string |
|
| 144 | + * @return string |
|
| 145 | + */ |
|
| 146 | + public static function queryString(){ |
|
| 147 | + return get_instance()->request->server('QUERY_STRING'); |
|
| 148 | + } |
|
| 149 | + } |
|
@@ -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 | } |
@@ -1,75 +1,75 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @file function_user_agent.php |
|
| 30 | - * |
|
| 31 | - * Contains most of the utility functions for agent, platform, mobile, browser, and other management. |
|
| 32 | - * |
|
| 33 | - * @package core |
|
| 34 | - * @author Tony NGUEREZA |
|
| 35 | - * @copyright Copyright (c) 2017 |
|
| 36 | - * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 37 | - * @link http://www.iacademy.cf |
|
| 38 | - * @version 1.0.0 |
|
| 39 | - * @since 1.0.0 |
|
| 40 | - * @filesource |
|
| 41 | - */ |
|
| 28 | + /** |
|
| 29 | + * @file function_user_agent.php |
|
| 30 | + * |
|
| 31 | + * Contains most of the utility functions for agent, platform, mobile, browser, and other management. |
|
| 32 | + * |
|
| 33 | + * @package core |
|
| 34 | + * @author Tony NGUEREZA |
|
| 35 | + * @copyright Copyright (c) 2017 |
|
| 36 | + * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 37 | + * @link http://www.iacademy.cf |
|
| 38 | + * @version 1.0.0 |
|
| 39 | + * @since 1.0.0 |
|
| 40 | + * @filesource |
|
| 41 | + */ |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | - if(! function_exists('get_ip')){ |
|
| 45 | - /** |
|
| 46 | - * Retrieves the user's IP address |
|
| 47 | - * |
|
| 48 | - * This function allows to retrieve the IP address of the client |
|
| 49 | - * even if it uses a proxy, the actual IP address is retrieved. |
|
| 50 | - * |
|
| 51 | - * @return string the IP address. |
|
| 52 | - */ |
|
| 53 | - function get_ip(){ |
|
| 54 | - $ip = '127.0.0.1'; |
|
| 55 | - $ipServerVars = array( |
|
| 56 | - 'REMOTE_ADDR', |
|
| 57 | - 'HTTP_CLIENT_IP', |
|
| 58 | - 'HTTP_X_FORWARDED_FOR', |
|
| 59 | - 'HTTP_X_FORWARDED', |
|
| 60 | - 'HTTP_FORWARDED_FOR', |
|
| 61 | - 'HTTP_FORWARDED' |
|
| 62 | - ); |
|
| 63 | - foreach ($ipServerVars as $var) { |
|
| 64 | - if(isset($_SERVER[$var])){ |
|
| 65 | - $ip = $_SERVER[$var]; |
|
| 66 | - break; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - // Strip any secondary IP etc from the IP address |
|
| 70 | - if (strpos($ip, ',') > 0) { |
|
| 71 | - $ip = substr($ip, 0, strpos($ip, ',')); |
|
| 72 | - } |
|
| 73 | - return $ip; |
|
| 74 | - } |
|
| 75 | - } |
|
| 44 | + if(! function_exists('get_ip')){ |
|
| 45 | + /** |
|
| 46 | + * Retrieves the user's IP address |
|
| 47 | + * |
|
| 48 | + * This function allows to retrieve the IP address of the client |
|
| 49 | + * even if it uses a proxy, the actual IP address is retrieved. |
|
| 50 | + * |
|
| 51 | + * @return string the IP address. |
|
| 52 | + */ |
|
| 53 | + function get_ip(){ |
|
| 54 | + $ip = '127.0.0.1'; |
|
| 55 | + $ipServerVars = array( |
|
| 56 | + 'REMOTE_ADDR', |
|
| 57 | + 'HTTP_CLIENT_IP', |
|
| 58 | + 'HTTP_X_FORWARDED_FOR', |
|
| 59 | + 'HTTP_X_FORWARDED', |
|
| 60 | + 'HTTP_FORWARDED_FOR', |
|
| 61 | + 'HTTP_FORWARDED' |
|
| 62 | + ); |
|
| 63 | + foreach ($ipServerVars as $var) { |
|
| 64 | + if(isset($_SERVER[$var])){ |
|
| 65 | + $ip = $_SERVER[$var]; |
|
| 66 | + break; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + // Strip any secondary IP etc from the IP address |
|
| 70 | + if (strpos($ip, ',') > 0) { |
|
| 71 | + $ip = substr($ip, 0, strpos($ip, ',')); |
|
| 72 | + } |
|
| 73 | + return $ip; |
|
| 74 | + } |
|
| 75 | + } |
|
@@ -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 | } |
@@ -128,8 +128,7 @@ discard block |
||
| 128 | 128 | $logger->info('Delete config item ['.$item.']'); |
| 129 | 129 | unset(self::$config[$item]); |
| 130 | 130 | return true; |
| 131 | - } |
|
| 132 | - else{ |
|
| 131 | + } else{ |
|
| 133 | 132 | $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
| 134 | 133 | return false; |
| 135 | 134 | } |
@@ -179,8 +178,7 @@ discard block |
||
| 179 | 178 | 0, |
| 180 | 179 | strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])) |
| 181 | 180 | ); |
| 182 | - } |
|
| 183 | - else{ |
|
| 181 | + } else{ |
|
| 184 | 182 | $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
| 185 | 183 | $baseUrl = 'http://localhost/'; |
| 186 | 184 | } |
@@ -1,160 +1,160 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - class Config extends BaseStaticClass{ |
|
| 27 | + class Config extends BaseStaticClass{ |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * The list of loaded configuration |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - private static $config = array(); |
|
| 29 | + /** |
|
| 30 | + * The list of loaded configuration |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + private static $config = array(); |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Initialize the configuration by loading all the configuration from config file |
|
| 37 | - */ |
|
| 38 | - public static function init(){ |
|
| 39 | - $logger = self::getLogger(); |
|
| 40 | - $logger->debug('Initialization of the configuration'); |
|
| 41 | - self::$config = & load_configurations(); |
|
| 42 | - self::setBaseUrlUsingServerVar(); |
|
| 43 | - if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){ |
|
| 44 | - $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance'); |
|
| 45 | - } |
|
| 46 | - $logger->info('Configuration initialized successfully'); |
|
| 47 | - $logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config)); |
|
| 48 | - } |
|
| 35 | + /** |
|
| 36 | + * Initialize the configuration by loading all the configuration from config file |
|
| 37 | + */ |
|
| 38 | + public static function init(){ |
|
| 39 | + $logger = self::getLogger(); |
|
| 40 | + $logger->debug('Initialization of the configuration'); |
|
| 41 | + self::$config = & load_configurations(); |
|
| 42 | + self::setBaseUrlUsingServerVar(); |
|
| 43 | + if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){ |
|
| 44 | + $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance'); |
|
| 45 | + } |
|
| 46 | + $logger->info('Configuration initialized successfully'); |
|
| 47 | + $logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config)); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Get the configuration item value |
|
| 52 | - * @param string $item the configuration item name to get |
|
| 53 | - * @param mixed $default the default value to use if can not find the config item in the list |
|
| 54 | - * @return mixed the config value if exist or the default value |
|
| 55 | - */ |
|
| 56 | - public static function get($item, $default = null){ |
|
| 57 | - $logger = self::getLogger(); |
|
| 58 | - if(array_key_exists($item, self::$config)){ |
|
| 59 | - return self::$config[$item]; |
|
| 60 | - } |
|
| 61 | - $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']'); |
|
| 62 | - return $default; |
|
| 63 | - } |
|
| 50 | + /** |
|
| 51 | + * Get the configuration item value |
|
| 52 | + * @param string $item the configuration item name to get |
|
| 53 | + * @param mixed $default the default value to use if can not find the config item in the list |
|
| 54 | + * @return mixed the config value if exist or the default value |
|
| 55 | + */ |
|
| 56 | + public static function get($item, $default = null){ |
|
| 57 | + $logger = self::getLogger(); |
|
| 58 | + if(array_key_exists($item, self::$config)){ |
|
| 59 | + return self::$config[$item]; |
|
| 60 | + } |
|
| 61 | + $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']'); |
|
| 62 | + return $default; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Set the configuration item value |
|
| 67 | - * @param string $item the config item name to set |
|
| 68 | - * @param mixed $value the config item value |
|
| 69 | - */ |
|
| 70 | - public static function set($item, $value){ |
|
| 71 | - self::$config[$item] = $value; |
|
| 72 | - } |
|
| 65 | + /** |
|
| 66 | + * Set the configuration item value |
|
| 67 | + * @param string $item the config item name to set |
|
| 68 | + * @param mixed $value the config item value |
|
| 69 | + */ |
|
| 70 | + public static function set($item, $value){ |
|
| 71 | + self::$config[$item] = $value; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Get all the configuration values |
|
| 76 | - * @return array the config values |
|
| 77 | - */ |
|
| 78 | - public static function getAll(){ |
|
| 79 | - return self::$config; |
|
| 80 | - } |
|
| 74 | + /** |
|
| 75 | + * Get all the configuration values |
|
| 76 | + * @return array the config values |
|
| 77 | + */ |
|
| 78 | + public static function getAll(){ |
|
| 79 | + return self::$config; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Set the configuration values bu merged with the existing configuration |
|
| 84 | - * @param array $config the config values to add in the configuration list |
|
| 85 | - */ |
|
| 86 | - public static function setAll(array $config = array()){ |
|
| 87 | - self::$config = array_merge(self::$config, $config); |
|
| 88 | - } |
|
| 82 | + /** |
|
| 83 | + * Set the configuration values bu merged with the existing configuration |
|
| 84 | + * @param array $config the config values to add in the configuration list |
|
| 85 | + */ |
|
| 86 | + public static function setAll(array $config = array()){ |
|
| 87 | + self::$config = array_merge(self::$config, $config); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Delete the configuration item in the list |
|
| 92 | - * @param string $item the config item name to be deleted |
|
| 93 | - * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
|
| 94 | - */ |
|
| 95 | - public static function delete($item){ |
|
| 96 | - $logger = self::getLogger(); |
|
| 97 | - if(array_key_exists($item, self::$config)){ |
|
| 98 | - $logger->info('Delete config item ['.$item.']'); |
|
| 99 | - unset(self::$config[$item]); |
|
| 100 | - return true; |
|
| 101 | - } |
|
| 102 | - else{ |
|
| 103 | - $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
|
| 104 | - return false; |
|
| 105 | - } |
|
| 106 | - } |
|
| 90 | + /** |
|
| 91 | + * Delete the configuration item in the list |
|
| 92 | + * @param string $item the config item name to be deleted |
|
| 93 | + * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
|
| 94 | + */ |
|
| 95 | + public static function delete($item){ |
|
| 96 | + $logger = self::getLogger(); |
|
| 97 | + if(array_key_exists($item, self::$config)){ |
|
| 98 | + $logger->info('Delete config item ['.$item.']'); |
|
| 99 | + unset(self::$config[$item]); |
|
| 100 | + return true; |
|
| 101 | + } |
|
| 102 | + else{ |
|
| 103 | + $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
|
| 104 | + return false; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Load the configuration file. This an alias to Loader::config() |
|
| 110 | - * @param string $config the config name to be loaded |
|
| 111 | - */ |
|
| 112 | - public static function load($config){ |
|
| 113 | - Loader::config($config); |
|
| 114 | - } |
|
| 108 | + /** |
|
| 109 | + * Load the configuration file. This an alias to Loader::config() |
|
| 110 | + * @param string $config the config name to be loaded |
|
| 111 | + */ |
|
| 112 | + public static function load($config){ |
|
| 113 | + Loader::config($config); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * Set the configuration for "base_url" if is not set in the configuration |
|
| 118 | - */ |
|
| 119 | - private static function setBaseUrlUsingServerVar(){ |
|
| 120 | - $logger = self::getLogger(); |
|
| 121 | - if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){ |
|
| 122 | - if(ENVIRONMENT == 'production'){ |
|
| 123 | - $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time'); |
|
| 124 | - } |
|
| 125 | - $baseUrl = null; |
|
| 126 | - $protocol = 'http'; |
|
| 127 | - if(is_https()){ |
|
| 128 | - $protocol = 'https'; |
|
| 129 | - } |
|
| 130 | - $protocol .='://'; |
|
| 116 | + /** |
|
| 117 | + * Set the configuration for "base_url" if is not set in the configuration |
|
| 118 | + */ |
|
| 119 | + private static function setBaseUrlUsingServerVar(){ |
|
| 120 | + $logger = self::getLogger(); |
|
| 121 | + if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){ |
|
| 122 | + if(ENVIRONMENT == 'production'){ |
|
| 123 | + $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time'); |
|
| 124 | + } |
|
| 125 | + $baseUrl = null; |
|
| 126 | + $protocol = 'http'; |
|
| 127 | + if(is_https()){ |
|
| 128 | + $protocol = 'https'; |
|
| 129 | + } |
|
| 130 | + $protocol .='://'; |
|
| 131 | 131 | |
| 132 | - if (isset($_SERVER['SERVER_ADDR'])){ |
|
| 133 | - $baseUrl = $_SERVER['SERVER_ADDR']; |
|
| 134 | - //check if the server is running under IPv6 |
|
| 135 | - if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){ |
|
| 136 | - $baseUrl = '['.$_SERVER['SERVER_ADDR'].']'; |
|
| 137 | - } |
|
| 138 | - $serverPort = 80; |
|
| 139 | - if (isset($_SERVER['SERVER_PORT'])) { |
|
| 140 | - $serverPort = $_SERVER['SERVER_PORT']; |
|
| 141 | - } |
|
| 142 | - $port = ''; |
|
| 143 | - if($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))){ |
|
| 144 | - $port = ':'.$serverPort; |
|
| 145 | - } |
|
| 146 | - $baseUrl = $protocol . $baseUrl . $port . substr( |
|
| 147 | - $_SERVER['SCRIPT_NAME'], |
|
| 148 | - 0, |
|
| 149 | - strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])) |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - else{ |
|
| 153 | - $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
|
| 154 | - $baseUrl = 'http://localhost/'; |
|
| 155 | - } |
|
| 156 | - self::set('base_url', $baseUrl); |
|
| 157 | - } |
|
| 158 | - self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/'; |
|
| 159 | - } |
|
| 160 | - } |
|
| 132 | + if (isset($_SERVER['SERVER_ADDR'])){ |
|
| 133 | + $baseUrl = $_SERVER['SERVER_ADDR']; |
|
| 134 | + //check if the server is running under IPv6 |
|
| 135 | + if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){ |
|
| 136 | + $baseUrl = '['.$_SERVER['SERVER_ADDR'].']'; |
|
| 137 | + } |
|
| 138 | + $serverPort = 80; |
|
| 139 | + if (isset($_SERVER['SERVER_PORT'])) { |
|
| 140 | + $serverPort = $_SERVER['SERVER_PORT']; |
|
| 141 | + } |
|
| 142 | + $port = ''; |
|
| 143 | + if($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))){ |
|
| 144 | + $port = ':'.$serverPort; |
|
| 145 | + } |
|
| 146 | + $baseUrl = $protocol . $baseUrl . $port . substr( |
|
| 147 | + $_SERVER['SCRIPT_NAME'], |
|
| 148 | + 0, |
|
| 149 | + strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])) |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + else{ |
|
| 153 | + $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
|
| 154 | + $baseUrl = 'http://localhost/'; |
|
| 155 | + } |
|
| 156 | + self::set('base_url', $baseUrl); |
|
| 157 | + } |
|
| 158 | + self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/'; |
|
| 159 | + } |
|
| 160 | + } |
|
@@ -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 | } |
@@ -234,8 +234,7 @@ discard block |
||
| 234 | 234 | //first check for CSRF |
| 235 | 235 | if (get_config('csrf_enable', false) && ! Security::validateCSRF()){ |
| 236 | 236 | show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.'); |
| 237 | - } |
|
| 238 | - else{ |
|
| 237 | + } else{ |
|
| 239 | 238 | $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it'); |
| 240 | 239 | } |
| 241 | 240 | } |
@@ -255,8 +254,7 @@ discard block |
||
| 255 | 254 | foreach ($this->getData() as $inputName => $inputVal) { |
| 256 | 255 | if(is_array($this->data[$inputName])){ |
| 257 | 256 | $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
| 258 | - } |
|
| 259 | - else{ |
|
| 257 | + } else{ |
|
| 260 | 258 | $this->data[$inputName] = trim($this->data[$inputName]); |
| 261 | 259 | } |
| 262 | 260 | |
@@ -624,8 +622,7 @@ discard block |
||
| 624 | 622 | if ($inputVal == '' && $callbackReturn == true) { |
| 625 | 623 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 626 | 624 | } |
| 627 | - } |
|
| 628 | - else if($inputVal == '') { |
|
| 625 | + } else if($inputVal == '') { |
|
| 629 | 626 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 630 | 627 | } |
| 631 | 628 | } |
@@ -684,8 +681,7 @@ discard block |
||
| 684 | 681 | $this->_setError($inputName, $ruleName . ',post:key', array($this->_getLabel($inputName), $this->_getLabel(str_replace('post:', '', $doNotEqual)))); |
| 685 | 682 | continue; |
| 686 | 683 | } |
| 687 | - } |
|
| 688 | - else{ |
|
| 684 | + } else{ |
|
| 689 | 685 | if ($inputVal == $doNotEqual) { |
| 690 | 686 | $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual)); |
| 691 | 687 | continue; |
@@ -22,10 +22,10 @@ discard block |
||
| 22 | 22 | * You should have received a copy of the GNU General Public License |
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | - */ |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class FormValidation extends BaseClass{ |
|
| 28 | + class FormValidation extends BaseClass{ |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * The form validation status |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | protected $_eachErrorDelimiter = array('<p class="error">', '</p>'); |
| 62 | 62 | |
| 63 | - /** |
|
| 63 | + /** |
|
| 64 | 64 | * Indicated if need force the validation to be failed |
| 65 | 65 | * @var boolean |
| 66 | 66 | */ |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | public function __construct() { |
| 94 | 94 | parent::__construct(); |
| 95 | 95 | |
| 96 | - //Load form validation language message |
|
| 96 | + //Load form validation language message |
|
| 97 | 97 | Loader::lang('form_validation'); |
| 98 | 98 | $obj = & get_instance(); |
| 99 | 99 | $this->_errorsMessages = array( |
@@ -155,13 +155,13 @@ discard block |
||
| 155 | 155 | /** |
| 156 | 156 | * Set the form validation data |
| 157 | 157 | * @param array $data the values to be validated |
| 158 | - * |
|
| 158 | + * |
|
| 159 | 159 | * @return FormValidation Current instance of object. |
| 160 | 160 | */ |
| 161 | 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 | - return $this; |
|
| 164 | + return $this; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -172,11 +172,11 @@ discard block |
||
| 172 | 172 | return $this->data; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * Get the validation function name to validate a rule |
|
| 177 | - * |
|
| 178 | - * @return string the function name |
|
| 179 | - */ |
|
| 175 | + /** |
|
| 176 | + * Get the validation function name to validate a rule |
|
| 177 | + * |
|
| 178 | + * @return string the function name |
|
| 179 | + */ |
|
| 180 | 180 | protected function _toCallCase($funcName, $prefix='_validate') { |
| 181 | 181 | $funcName = strtolower($funcName); |
| 182 | 182 | $finalFuncName = $prefix; |
@@ -246,12 +246,12 @@ discard block |
||
| 246 | 246 | $this->_forceFail = false; |
| 247 | 247 | |
| 248 | 248 | foreach ($this->getData() as $inputName => $inputVal) { |
| 249 | - if(is_array($this->data[$inputName])){ |
|
| 250 | - $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
|
| 251 | - } |
|
| 252 | - else{ |
|
| 253 | - $this->data[$inputName] = trim($this->data[$inputName]); |
|
| 254 | - } |
|
| 249 | + if(is_array($this->data[$inputName])){ |
|
| 250 | + $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
|
| 251 | + } |
|
| 252 | + else{ |
|
| 253 | + $this->data[$inputName] = trim($this->data[$inputName]); |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | 256 | if (array_key_exists($inputName, $this->_rules)) { |
| 257 | 257 | foreach ($this->_parseRuleString($this->_rules[$inputName]) as $eachRule) { |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | * |
| 268 | 268 | * @param string $inputField Name of the field or the data key to add a rule to |
| 269 | 269 | * @param string $ruleSets PIPE seperated string of rules |
| 270 | - * |
|
| 270 | + * |
|
| 271 | 271 | * @return FormValidation Current instance of object. |
| 272 | 272 | */ |
| 273 | 273 | public function setRule($inputField, $inputLabel, $ruleSets) { |
@@ -281,8 +281,8 @@ discard block |
||
| 281 | 281 | * Takes an array of rules and uses setRule() to set them, accepts an array |
| 282 | 282 | * of rule names rather than a pipe-delimited string as well. |
| 283 | 283 | * @param array $ruleSets |
| 284 | - * |
|
| 285 | - * @return FormValidation Current instance of object. |
|
| 284 | + * |
|
| 285 | + * @return FormValidation Current instance of object. |
|
| 286 | 286 | */ |
| 287 | 287 | public function setRules(array $ruleSets) { |
| 288 | 288 | foreach ($ruleSets as $ruleSet) { |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | * @param string $start Before block of errors gets displayed, HTML allowed. |
| 305 | 305 | * @param string $end After the block of errors gets displayed, HTML allowed. |
| 306 | 306 | * |
| 307 | - * @return FormValidation Current instance of object. |
|
| 307 | + * @return FormValidation Current instance of object. |
|
| 308 | 308 | */ |
| 309 | 309 | public function setErrorsDelimiter($start, $end) { |
| 310 | 310 | $this->_allErrorsDelimiter[0] = $start; |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | * @param string $start Displayed before each error. |
| 320 | 320 | * @param string $end Displayed after each error. |
| 321 | 321 | * |
| 322 | - * @return FormValidation Current instance of object. |
|
| 322 | + * @return FormValidation Current instance of object. |
|
| 323 | 323 | */ |
| 324 | 324 | public function setErrorDelimiter($start, $end) { |
| 325 | 325 | $this->_eachErrorDelimiter[0] = $start; |
@@ -327,21 +327,21 @@ discard block |
||
| 327 | 327 | return $this; |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | - /** |
|
| 331 | - * Get the each errors delimiters |
|
| 332 | - * |
|
| 333 | - * @return array |
|
| 334 | - */ |
|
| 335 | - public function getErrorDelimiter() { |
|
| 330 | + /** |
|
| 331 | + * Get the each errors delimiters |
|
| 332 | + * |
|
| 333 | + * @return array |
|
| 334 | + */ |
|
| 335 | + public function getErrorDelimiter() { |
|
| 336 | 336 | return $this->_eachErrorDelimiter; |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | - /** |
|
| 340 | - * Get the all errors delimiters |
|
| 341 | - * |
|
| 342 | - * @return array |
|
| 343 | - */ |
|
| 344 | - public function getErrorsDelimiter() { |
|
| 339 | + /** |
|
| 340 | + * Get the all errors delimiters |
|
| 341 | + * |
|
| 342 | + * @return array |
|
| 343 | + */ |
|
| 344 | + public function getErrorsDelimiter() { |
|
| 345 | 345 | return $this->_allErrorsDelimiter; |
| 346 | 346 | } |
| 347 | 347 | |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | * |
| 380 | 380 | * @param string $inputName The form input name or data key |
| 381 | 381 | * @param string $errorMessage Error to display |
| 382 | - * |
|
| 382 | + * |
|
| 383 | 383 | * @return formValidation Current instance of the object |
| 384 | 384 | */ |
| 385 | 385 | public function setCustomError($inputName, $errorMessage) { |
@@ -416,17 +416,17 @@ discard block |
||
| 416 | 416 | * |
| 417 | 417 | * @param boolean $limit number of error to display or return |
| 418 | 418 | * @param boolean $echo Whether or not the values are to be returned or displayed |
| 419 | - * |
|
| 419 | + * |
|
| 420 | 420 | * @return string Errors formatted for output |
| 421 | 421 | */ |
| 422 | 422 | public function displayErrors($limit = null, $echo = true) { |
| 423 | 423 | list($errorsStart, $errorsEnd) = $this->_allErrorsDelimiter; |
| 424 | 424 | list($errorStart, $errorEnd) = $this->_eachErrorDelimiter; |
| 425 | 425 | $errorOutput = $errorsStart; |
| 426 | - $i = 0; |
|
| 426 | + $i = 0; |
|
| 427 | 427 | if (!empty($this->_errors)) { |
| 428 | 428 | foreach ($this->_errors as $fieldName => $error) { |
| 429 | - if ($i === $limit) { |
|
| 429 | + if ($i === $limit) { |
|
| 430 | 430 | break; |
| 431 | 431 | } |
| 432 | 432 | $errorOutput .= $errorStart; |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | * Breaks up a PIPE seperated string of rules, and puts them into an array. |
| 455 | 455 | * |
| 456 | 456 | * @param string $ruleString String to be parsed. |
| 457 | - * |
|
| 457 | + * |
|
| 458 | 458 | * @return array Array of each value in original string. |
| 459 | 459 | */ |
| 460 | 460 | protected function _parseRuleString($ruleString) { |
@@ -467,10 +467,10 @@ discard block |
||
| 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])){ |
|
| 471 | - $ruleSets[] = $regexRule[0]; |
|
| 472 | - } |
|
| 473 | - $ruleStringRegex = explode('|', $ruleStringTemp); |
|
| 470 | + if(!empty($regexRule[0])){ |
|
| 471 | + $ruleSets[] = $regexRule[0]; |
|
| 472 | + } |
|
| 473 | + $ruleStringRegex = explode('|', $ruleStringTemp); |
|
| 474 | 474 | foreach ($ruleStringRegex as $rule) { |
| 475 | 475 | $rule = trim($rule); |
| 476 | 476 | if($rule){ |
@@ -486,7 +486,7 @@ discard block |
||
| 486 | 486 | } else { |
| 487 | 487 | $ruleSets[] = $ruleString; |
| 488 | 488 | } |
| 489 | - } |
|
| 489 | + } |
|
| 490 | 490 | return $ruleSets; |
| 491 | 491 | } |
| 492 | 492 | |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | * Returns whether or not a field obtains the rule "required". |
| 495 | 495 | * |
| 496 | 496 | * @param string $fieldName Field to check if required. |
| 497 | - * |
|
| 497 | + * |
|
| 498 | 498 | * @return boolean Whether or not the field is required. |
| 499 | 499 | */ |
| 500 | 500 | protected function _fieldIsRequired($fieldName) { |
@@ -529,13 +529,13 @@ discard block |
||
| 529 | 529 | return; |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | - /** |
|
| 533 | - * Set error for the given field or key |
|
| 534 | - * |
|
| 535 | - * @param string $inputName the input or key name |
|
| 536 | - * @param string $ruleName the rule name |
|
| 537 | - * @param array|string $replacements |
|
| 538 | - */ |
|
| 532 | + /** |
|
| 533 | + * Set error for the given field or key |
|
| 534 | + * |
|
| 535 | + * @param string $inputName the input or key name |
|
| 536 | + * @param string $ruleName the rule name |
|
| 537 | + * @param array|string $replacements |
|
| 538 | + */ |
|
| 539 | 539 | protected function _setError($inputName, $ruleName, $replacements = array()) { |
| 540 | 540 | $rulePhraseKeyParts = explode(',', $ruleName); |
| 541 | 541 | $rulePhrase = null; |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | } |
| 553 | 553 | // Type cast to array in case it's a string |
| 554 | 554 | $replacements = (array) $replacements; |
| 555 | - $replacementCount = count($replacements); |
|
| 555 | + $replacementCount = count($replacements); |
|
| 556 | 556 | for ($i = 1; $i <= $replacementCount; $i++) { |
| 557 | 557 | $key = $i - 1; |
| 558 | 558 | $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase); |
@@ -570,11 +570,11 @@ discard block |
||
| 570 | 570 | * |
| 571 | 571 | * @param type $inputArg |
| 572 | 572 | * @param string $callbackFunc |
| 573 | - * |
|
| 573 | + * |
|
| 574 | 574 | * @return mixed |
| 575 | 575 | */ |
| 576 | 576 | protected function _runCallback($inputArg, $callbackFunc) { |
| 577 | - return eval('return ' . $callbackFunc . '("' . $inputArg . '");'); |
|
| 577 | + return eval('return ' . $callbackFunc . '("' . $inputArg . '");'); |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | /** |
@@ -583,7 +583,7 @@ discard block |
||
| 583 | 583 | * arguments. |
| 584 | 584 | * |
| 585 | 585 | * @param string $callbackFunc |
| 586 | - * |
|
| 586 | + * |
|
| 587 | 587 | * @return mixed |
| 588 | 588 | */ |
| 589 | 589 | protected function _runEmptyCallback($callbackFunc) { |
@@ -594,7 +594,7 @@ discard block |
||
| 594 | 594 | * Gets a specific label of a specific field input name. |
| 595 | 595 | * |
| 596 | 596 | * @param string $inputName |
| 597 | - * |
|
| 597 | + * |
|
| 598 | 598 | * @return string |
| 599 | 599 | */ |
| 600 | 600 | protected function _getLabel($inputName) { |
@@ -607,7 +607,7 @@ discard block |
||
| 607 | 607 | * @param string $ruleName the rule name for this validation ("required") |
| 608 | 608 | * @param array $ruleArgs the rules argument |
| 609 | 609 | */ |
| 610 | - protected function _validateRequired($inputName, $ruleName, array $ruleArgs) { |
|
| 610 | + protected function _validateRequired($inputName, $ruleName, array $ruleArgs) { |
|
| 611 | 611 | $inputVal = $this->post($inputName); |
| 612 | 612 | if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) { |
| 613 | 613 | $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]); |
@@ -615,8 +615,8 @@ discard block |
||
| 615 | 615 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 616 | 616 | } |
| 617 | 617 | } |
| 618 | - else if($inputVal == '') { |
|
| 619 | - $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
|
| 618 | + else if($inputVal == '') { |
|
| 619 | + $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
|
| 620 | 620 | } |
| 621 | 621 | } |
| 622 | 622 | |
@@ -640,10 +640,10 @@ discard block |
||
| 640 | 640 | */ |
| 641 | 641 | protected function _validateCallback($inputName, $ruleName, array $ruleArgs) { |
| 642 | 642 | if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) { |
| 643 | - $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]); |
|
| 644 | - if(! $result){ |
|
| 645 | - $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
|
| 646 | - } |
|
| 643 | + $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]); |
|
| 644 | + if(! $result){ |
|
| 645 | + $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
|
| 646 | + } |
|
| 647 | 647 | } |
| 648 | 648 | } |
| 649 | 649 | |
@@ -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; |
@@ -767,7 +767,7 @@ discard block |
||
| 767 | 767 | * @param string $ruleName the rule name for this validation ("less_than") |
| 768 | 768 | * @param array $ruleArgs the rules argument |
| 769 | 769 | */ |
| 770 | - protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) { |
|
| 770 | + protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) { |
|
| 771 | 771 | $inputVal = $this->post($inputName); |
| 772 | 772 | if ($inputVal >= $ruleArgs[1]) { |
| 773 | 773 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
@@ -783,7 +783,7 @@ discard block |
||
| 783 | 783 | * @param string $ruleName the rule name for this validation ("greater_than") |
| 784 | 784 | * @param array $ruleArgs the rules argument |
| 785 | 785 | */ |
| 786 | - protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) { |
|
| 786 | + protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) { |
|
| 787 | 787 | $inputVal = $this->post($inputName); |
| 788 | 788 | if ($inputVal <= $ruleArgs[1]) { |
| 789 | 789 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
@@ -799,7 +799,7 @@ discard block |
||
| 799 | 799 | * @param string $ruleName the rule name for this validation ("numeric") |
| 800 | 800 | * @param array $ruleArgs the rules argument |
| 801 | 801 | */ |
| 802 | - protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) { |
|
| 802 | + protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) { |
|
| 803 | 803 | $inputVal = $this->post($inputName); |
| 804 | 804 | if (! is_numeric($inputVal)) { |
| 805 | 805 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
@@ -815,18 +815,18 @@ discard block |
||
| 815 | 815 | * @param string $ruleName the rule name for this validation ("exists") |
| 816 | 816 | * @param array $ruleArgs the rules argument |
| 817 | 817 | */ |
| 818 | - protected function _validateExists($inputName, $ruleName, array $ruleArgs) { |
|
| 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 | 822 | if(isset($obj->database)){ |
| 823 | 823 | $this->databaseInstance = $obj->database; |
| 824 | 824 | } |
| 825 | 825 | } |
| 826 | - list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 827 | - $this->databaseInstance->getQueryBuilder()->from($table) |
|
| 828 | - ->where($column, $inputVal); |
|
| 829 | - $this->databaseInstance->get(); |
|
| 826 | + list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 827 | + $this->databaseInstance->getQueryBuilder()->from($table) |
|
| 828 | + ->where($column, $inputVal); |
|
| 829 | + $this->databaseInstance->get(); |
|
| 830 | 830 | if ($this->databaseInstance->numRows() <= 0) { |
| 831 | 831 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
| 832 | 832 | return; |
@@ -841,7 +841,7 @@ discard block |
||
| 841 | 841 | * @param string $ruleName the rule name for this validation ("is_unique") |
| 842 | 842 | * @param array $ruleArgs the rules argument |
| 843 | 843 | */ |
| 844 | - protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) { |
|
| 844 | + protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) { |
|
| 845 | 845 | $inputVal = $this->post($inputName); |
| 846 | 846 | if (! is_object($this->databaseInstance)){ |
| 847 | 847 | $obj = & get_instance(); |
@@ -849,11 +849,11 @@ discard block |
||
| 849 | 849 | $this->databaseInstance = $obj->database; |
| 850 | 850 | } |
| 851 | 851 | } |
| 852 | - list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 853 | - $this->databaseInstance->getQueryBuilder()->from($table) |
|
| 854 | - ->where($column, $inputVal); |
|
| 855 | - $this->databaseInstance->get(); |
|
| 856 | - if ($this->databaseInstance->numRows() > 0) { |
|
| 852 | + list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 853 | + $this->databaseInstance->getQueryBuilder()->from($table) |
|
| 854 | + ->where($column, $inputVal); |
|
| 855 | + $this->databaseInstance->get(); |
|
| 856 | + if ($this->databaseInstance->numRows() > 0) { |
|
| 857 | 857 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
| 858 | 858 | return; |
| 859 | 859 | } |
@@ -867,25 +867,25 @@ discard block |
||
| 867 | 867 | * @param string $ruleName the rule name for this validation ("is_unique_update") |
| 868 | 868 | * @param array $ruleArgs the rules argument |
| 869 | 869 | */ |
| 870 | - protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) { |
|
| 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 | 874 | if(isset($obj->database)){ |
| 875 | 875 | $this->databaseInstance = $obj->database; |
| 876 | 876 | } |
| 877 | 877 | } |
| 878 | - $data = explode(',', $ruleArgs[1]); |
|
| 879 | - if(count($data) < 2){ |
|
| 880 | - return; |
|
| 881 | - } |
|
| 882 | - list($table, $column) = explode('.', $data[0]); |
|
| 883 | - list($field, $val) = explode('=', $data[1]); |
|
| 884 | - $this->databaseInstance->getQueryBuilder()->from($table) |
|
| 885 | - ->where($column, $inputVal) |
|
| 886 | - ->where($field, '!=', trim($val)); |
|
| 878 | + $data = explode(',', $ruleArgs[1]); |
|
| 879 | + if(count($data) < 2){ |
|
| 880 | + return; |
|
| 881 | + } |
|
| 882 | + list($table, $column) = explode('.', $data[0]); |
|
| 883 | + list($field, $val) = explode('=', $data[1]); |
|
| 884 | + $this->databaseInstance->getQueryBuilder()->from($table) |
|
| 885 | + ->where($column, $inputVal) |
|
| 886 | + ->where($field, '!=', trim($val)); |
|
| 887 | 887 | $this->databaseInstance->get(); |
| 888 | - if ($this->databaseInstance->numRows() > 0) { |
|
| 888 | + if ($this->databaseInstance->numRows() > 0) { |
|
| 889 | 889 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
| 890 | 890 | return; |
| 891 | 891 | } |
@@ -901,7 +901,7 @@ discard block |
||
| 901 | 901 | */ |
| 902 | 902 | protected function _validateInList($inputName, $ruleName, array $ruleArgs) { |
| 903 | 903 | $inputVal = $this->post($inputName); |
| 904 | - $list = explode(',', $ruleArgs[1]); |
|
| 904 | + $list = explode(',', $ruleArgs[1]); |
|
| 905 | 905 | $list = array_map('trim', $list); |
| 906 | 906 | if (! in_array($inputVal, $list)) { |
| 907 | 907 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
@@ -919,7 +919,7 @@ discard block |
||
| 919 | 919 | */ |
| 920 | 920 | protected function _validateRegex($inputName, $ruleName, array $ruleArgs) { |
| 921 | 921 | $inputVal = $this->post($inputName); |
| 922 | - $regex = $ruleArgs[1]; |
|
| 922 | + $regex = $ruleArgs[1]; |
|
| 923 | 923 | if (! preg_match($regex, $inputVal)) { |
| 924 | 924 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
| 925 | 925 | return; |
@@ -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))); |
@@ -60,8 +60,7 @@ discard block |
||
| 60 | 60 | if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){ |
| 61 | 61 | $logger->info('The CSRF token not yet expire just return it'); |
| 62 | 62 | return Session::get($key); |
| 63 | - } |
|
| 64 | - else{ |
|
| 63 | + } else{ |
|
| 65 | 64 | $newTime = $currentTime + $expire; |
| 66 | 65 | $token = sha1(uniqid()) . sha1(uniqid()); |
| 67 | 66 | $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']'); |
@@ -123,8 +122,7 @@ discard block |
||
| 123 | 122 | $logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP'); |
| 124 | 123 | //wildcard to access all ip address |
| 125 | 124 | return; |
| 126 | - } |
|
| 127 | - else{ |
|
| 125 | + } else{ |
|
| 128 | 126 | // go through all whitelisted ips |
| 129 | 127 | foreach ($list as $ipaddr) { |
| 130 | 128 | // find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*") |
@@ -149,8 +147,7 @@ discard block |
||
| 149 | 147 | show_error('Access to this application is not allowed'); |
| 150 | 148 | } |
| 151 | 149 | } |
| 152 | - } |
|
| 153 | - else{ |
|
| 150 | + } else{ |
|
| 154 | 151 | $logger->info('Whitelist IP access is not enabled in the configuration, ignore checking'); |
| 155 | 152 | } |
| 156 | 153 | } |
@@ -1,138 +1,138 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') or exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') or exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - class Security extends BaseStaticClass{ |
|
| 27 | + class Security extends BaseStaticClass{ |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * This method is used to generate the CSRF token |
|
| 31 | - * @return string the generated CSRF token |
|
| 32 | - */ |
|
| 33 | - public static function generateCSRF(){ |
|
| 34 | - $logger = self::getLogger(); |
|
| 35 | - $logger->debug('Generation of CSRF ...'); |
|
| 29 | + /** |
|
| 30 | + * This method is used to generate the CSRF token |
|
| 31 | + * @return string the generated CSRF token |
|
| 32 | + */ |
|
| 33 | + public static function generateCSRF(){ |
|
| 34 | + $logger = self::getLogger(); |
|
| 35 | + $logger->debug('Generation of CSRF ...'); |
|
| 36 | 36 | |
| 37 | - $key = get_config('csrf_key', 'csrf_key'); |
|
| 38 | - $expire = get_config('csrf_expire', 60); |
|
| 39 | - $keyExpire = 'csrf_expire'; |
|
| 40 | - $currentTime = time(); |
|
| 41 | - if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){ |
|
| 42 | - $logger->info('The CSRF token not yet expire just return it'); |
|
| 43 | - return Session::get($key); |
|
| 44 | - } |
|
| 45 | - else{ |
|
| 46 | - $newTime = $currentTime + $expire; |
|
| 47 | - $token = sha1(uniqid()) . sha1(uniqid()); |
|
| 48 | - $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']'); |
|
| 49 | - Session::set($keyExpire, $newTime); |
|
| 50 | - Session::set($key, $token); |
|
| 51 | - return Session::get($key); |
|
| 52 | - } |
|
| 53 | - } |
|
| 37 | + $key = get_config('csrf_key', 'csrf_key'); |
|
| 38 | + $expire = get_config('csrf_expire', 60); |
|
| 39 | + $keyExpire = 'csrf_expire'; |
|
| 40 | + $currentTime = time(); |
|
| 41 | + if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){ |
|
| 42 | + $logger->info('The CSRF token not yet expire just return it'); |
|
| 43 | + return Session::get($key); |
|
| 44 | + } |
|
| 45 | + else{ |
|
| 46 | + $newTime = $currentTime + $expire; |
|
| 47 | + $token = sha1(uniqid()) . sha1(uniqid()); |
|
| 48 | + $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']'); |
|
| 49 | + Session::set($keyExpire, $newTime); |
|
| 50 | + Session::set($key, $token); |
|
| 51 | + return Session::get($key); |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * This method is used to check the CSRF if is valid, not yet expire, etc. |
|
| 57 | - * @return boolean true if valid, false if not valid |
|
| 58 | - */ |
|
| 59 | - public static function validateCSRF(){ |
|
| 60 | - $logger = self::getLogger(); |
|
| 61 | - $logger->debug('Validation of CSRF ...'); |
|
| 55 | + /** |
|
| 56 | + * This method is used to check the CSRF if is valid, not yet expire, etc. |
|
| 57 | + * @return boolean true if valid, false if not valid |
|
| 58 | + */ |
|
| 59 | + public static function validateCSRF(){ |
|
| 60 | + $logger = self::getLogger(); |
|
| 61 | + $logger->debug('Validation of CSRF ...'); |
|
| 62 | 62 | |
| 63 | - $key = get_config('csrf_key', 'csrf_key'); |
|
| 64 | - $expire = get_config('csrf_expire', 60); |
|
| 65 | - $keyExpire = 'csrf_expire'; |
|
| 66 | - $currentTime = time(); |
|
| 67 | - $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. ']'); |
|
| 68 | - if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){ |
|
| 69 | - $logger->warning('The CSRF session data is not valide'); |
|
| 70 | - return false; |
|
| 71 | - } |
|
| 72 | - //perform form data |
|
| 73 | - //need use request->query() for best retrieve |
|
| 74 | - //super instance |
|
| 75 | - $obj = & get_instance(); |
|
| 76 | - $token = $obj->request->query($key); |
|
| 77 | - if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){ |
|
| 78 | - $logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job'); |
|
| 79 | - return false; |
|
| 80 | - } |
|
| 81 | - $logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue'); |
|
| 82 | - //remove the token from session |
|
| 83 | - Session::clear($key); |
|
| 84 | - Session::clear($keyExpire); |
|
| 85 | - return true; |
|
| 86 | - } |
|
| 63 | + $key = get_config('csrf_key', 'csrf_key'); |
|
| 64 | + $expire = get_config('csrf_expire', 60); |
|
| 65 | + $keyExpire = 'csrf_expire'; |
|
| 66 | + $currentTime = time(); |
|
| 67 | + $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. ']'); |
|
| 68 | + if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){ |
|
| 69 | + $logger->warning('The CSRF session data is not valide'); |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 72 | + //perform form data |
|
| 73 | + //need use request->query() for best retrieve |
|
| 74 | + //super instance |
|
| 75 | + $obj = & get_instance(); |
|
| 76 | + $token = $obj->request->query($key); |
|
| 77 | + if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){ |
|
| 78 | + $logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job'); |
|
| 79 | + return false; |
|
| 80 | + } |
|
| 81 | + $logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue'); |
|
| 82 | + //remove the token from session |
|
| 83 | + Session::clear($key); |
|
| 84 | + Session::clear($keyExpire); |
|
| 85 | + return true; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * This method is used to check the whitelist IP address access |
|
| 90 | - */ |
|
| 91 | - public static function checkWhiteListIpAccess(){ |
|
| 92 | - $logger = self::getLogger(); |
|
| 93 | - $logger->debug('Validation of the IP address access ...'); |
|
| 94 | - $logger->debug('Check if whitelist IP access is enabled in the configuration ...'); |
|
| 95 | - $isEnable = get_config('white_list_ip_enable', false); |
|
| 96 | - if($isEnable){ |
|
| 97 | - $logger->info('Whitelist IP access is enabled in the configuration'); |
|
| 98 | - $list = get_config('white_list_ip_addresses', array()); |
|
| 99 | - if(! empty($list)){ |
|
| 100 | - //Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing |
|
| 101 | - require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
|
| 102 | - $ip = get_ip(); |
|
| 103 | - if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){ |
|
| 104 | - $logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP'); |
|
| 105 | - //wildcard to access all ip address |
|
| 106 | - return; |
|
| 107 | - } |
|
| 108 | - else{ |
|
| 109 | - // go through all whitelisted ips |
|
| 110 | - foreach ($list as $ipaddr) { |
|
| 111 | - // find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*") |
|
| 112 | - $wildcardPosition = strpos($ipaddr, '*'); |
|
| 113 | - if ($wildcardPosition === false) { |
|
| 114 | - // no wild card in whitelisted ip --continue searching |
|
| 115 | - continue; |
|
| 116 | - } |
|
| 117 | - // cut ip at the position where we got the wild card on the whitelisted ip |
|
| 118 | - // and add the wold card to get the same pattern |
|
| 119 | - if (substr($ip, 0, $wildcardPosition) . '*' === $ipaddr) { |
|
| 120 | - // f.e. we got |
|
| 121 | - // ip "127.0.0.1" |
|
| 122 | - // whitelisted ip "127.0.*" |
|
| 123 | - // then we compared "127.0.*" with "127.0.*" |
|
| 124 | - // return success |
|
| 125 | - $logger->info('IP address ' . $ip . ' allowed using the wildcard like "x.x.x.*"'); |
|
| 126 | - return; |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - $logger->warning('IP address ' . $ip . ' is not allowed to access to this application'); |
|
| 130 | - show_error('Access to this application is not allowed'); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - else{ |
|
| 135 | - $logger->info('Whitelist IP access is not enabled in the configuration, ignore checking'); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - } |
|
| 88 | + /** |
|
| 89 | + * This method is used to check the whitelist IP address access |
|
| 90 | + */ |
|
| 91 | + public static function checkWhiteListIpAccess(){ |
|
| 92 | + $logger = self::getLogger(); |
|
| 93 | + $logger->debug('Validation of the IP address access ...'); |
|
| 94 | + $logger->debug('Check if whitelist IP access is enabled in the configuration ...'); |
|
| 95 | + $isEnable = get_config('white_list_ip_enable', false); |
|
| 96 | + if($isEnable){ |
|
| 97 | + $logger->info('Whitelist IP access is enabled in the configuration'); |
|
| 98 | + $list = get_config('white_list_ip_addresses', array()); |
|
| 99 | + if(! empty($list)){ |
|
| 100 | + //Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing |
|
| 101 | + require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
|
| 102 | + $ip = get_ip(); |
|
| 103 | + if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){ |
|
| 104 | + $logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP'); |
|
| 105 | + //wildcard to access all ip address |
|
| 106 | + return; |
|
| 107 | + } |
|
| 108 | + else{ |
|
| 109 | + // go through all whitelisted ips |
|
| 110 | + foreach ($list as $ipaddr) { |
|
| 111 | + // find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*") |
|
| 112 | + $wildcardPosition = strpos($ipaddr, '*'); |
|
| 113 | + if ($wildcardPosition === false) { |
|
| 114 | + // no wild card in whitelisted ip --continue searching |
|
| 115 | + continue; |
|
| 116 | + } |
|
| 117 | + // cut ip at the position where we got the wild card on the whitelisted ip |
|
| 118 | + // and add the wold card to get the same pattern |
|
| 119 | + if (substr($ip, 0, $wildcardPosition) . '*' === $ipaddr) { |
|
| 120 | + // f.e. we got |
|
| 121 | + // ip "127.0.0.1" |
|
| 122 | + // whitelisted ip "127.0.*" |
|
| 123 | + // then we compared "127.0.*" with "127.0.*" |
|
| 124 | + // return success |
|
| 125 | + $logger->info('IP address ' . $ip . ' allowed using the wildcard like "x.x.x.*"'); |
|
| 126 | + return; |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + $logger->warning('IP address ' . $ip . ' is not allowed to access to this application'); |
|
| 130 | + show_error('Access to this application is not allowed'); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + else{ |
|
| 135 | + $logger->info('Whitelist IP access is not enabled in the configuration, ignore checking'); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + } |
|
@@ -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 Security extends BaseStaticClass{ |
|
| 27 | + class Security extends BaseStaticClass { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * This method is used to generate the CSRF token |
| 31 | 31 | * @return string the generated CSRF token |
| 32 | 32 | */ |
| 33 | - public static function generateCSRF(){ |
|
| 33 | + public static function generateCSRF() { |
|
| 34 | 34 | $logger = self::getLogger(); |
| 35 | 35 | $logger->debug('Generation of CSRF ...'); |
| 36 | 36 | |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | $expire = get_config('csrf_expire', 60); |
| 39 | 39 | $keyExpire = 'csrf_expire'; |
| 40 | 40 | $currentTime = time(); |
| 41 | - if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){ |
|
| 41 | + if (Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime) { |
|
| 42 | 42 | $logger->info('The CSRF token not yet expire just return it'); |
| 43 | 43 | return Session::get($key); |
| 44 | 44 | } |
| 45 | - else{ |
|
| 45 | + else { |
|
| 46 | 46 | $newTime = $currentTime + $expire; |
| 47 | 47 | $token = sha1(uniqid()) . sha1(uniqid()); |
| 48 | - $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']'); |
|
| 48 | + $logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . '], token [' . $token . ']'); |
|
| 49 | 49 | Session::set($keyExpire, $newTime); |
| 50 | 50 | Session::set($key, $token); |
| 51 | 51 | return Session::get($key); |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * This method is used to check the CSRF if is valid, not yet expire, etc. |
| 57 | 57 | * @return boolean true if valid, false if not valid |
| 58 | 58 | */ |
| 59 | - public static function validateCSRF(){ |
|
| 59 | + public static function validateCSRF() { |
|
| 60 | 60 | $logger = self::getLogger(); |
| 61 | 61 | $logger->debug('Validation of CSRF ...'); |
| 62 | 62 | |
@@ -64,8 +64,8 @@ discard block |
||
| 64 | 64 | $expire = get_config('csrf_expire', 60); |
| 65 | 65 | $keyExpire = 'csrf_expire'; |
| 66 | 66 | $currentTime = time(); |
| 67 | - $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. ']'); |
|
| 68 | - if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){ |
|
| 67 | + $logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . ']'); |
|
| 68 | + if (!Session::exists($key) || Session::get($keyExpire) <= $currentTime) { |
|
| 69 | 69 | $logger->warning('The CSRF session data is not valide'); |
| 70 | 70 | return false; |
| 71 | 71 | } |
@@ -74,11 +74,11 @@ discard block |
||
| 74 | 74 | //super instance |
| 75 | 75 | $obj = & get_instance(); |
| 76 | 76 | $token = $obj->request->query($key); |
| 77 | - if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){ |
|
| 78 | - $logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job'); |
|
| 77 | + if (!$token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime) { |
|
| 78 | + $logger->warning('The CSRF data [' . $token . '] is not valide may be attacker do his job'); |
|
| 79 | 79 | return false; |
| 80 | 80 | } |
| 81 | - $logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue'); |
|
| 81 | + $logger->info('The CSRF data [' . $token . '] is valide the form data is safe continue'); |
|
| 82 | 82 | //remove the token from session |
| 83 | 83 | Session::clear($key); |
| 84 | 84 | Session::clear($keyExpire); |
@@ -88,24 +88,24 @@ discard block |
||
| 88 | 88 | /** |
| 89 | 89 | * This method is used to check the whitelist IP address access |
| 90 | 90 | */ |
| 91 | - public static function checkWhiteListIpAccess(){ |
|
| 91 | + public static function checkWhiteListIpAccess() { |
|
| 92 | 92 | $logger = self::getLogger(); |
| 93 | 93 | $logger->debug('Validation of the IP address access ...'); |
| 94 | 94 | $logger->debug('Check if whitelist IP access is enabled in the configuration ...'); |
| 95 | 95 | $isEnable = get_config('white_list_ip_enable', false); |
| 96 | - if($isEnable){ |
|
| 96 | + if ($isEnable) { |
|
| 97 | 97 | $logger->info('Whitelist IP access is enabled in the configuration'); |
| 98 | 98 | $list = get_config('white_list_ip_addresses', array()); |
| 99 | - if(! empty($list)){ |
|
| 99 | + if (!empty($list)) { |
|
| 100 | 100 | //Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing |
| 101 | 101 | require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
| 102 | 102 | $ip = get_ip(); |
| 103 | - if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){ |
|
| 103 | + if ((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)) { |
|
| 104 | 104 | $logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP'); |
| 105 | 105 | //wildcard to access all ip address |
| 106 | 106 | return; |
| 107 | 107 | } |
| 108 | - else{ |
|
| 108 | + else { |
|
| 109 | 109 | // go through all whitelisted ips |
| 110 | 110 | foreach ($list as $ipaddr) { |
| 111 | 111 | // find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*") |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | - else{ |
|
| 134 | + else { |
|
| 135 | 135 | $logger->info('Whitelist IP access is not enabled in the configuration, ignore checking'); |
| 136 | 136 | } |
| 137 | 137 | } |
@@ -1,71 +1,71 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @file function_string.php |
|
| 29 | - * |
|
| 30 | - * This file contains the definition of the functions relating to the processing of strings characters. |
|
| 31 | - * |
|
| 32 | - * @package core |
|
| 33 | - * @author Tony NGUEREZA |
|
| 34 | - * @copyright Copyright (c) 2017 |
|
| 35 | - * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 36 | - * @link http://www.iacademy.cf |
|
| 37 | - * @version 1.0.0 |
|
| 38 | - * @since 1.0.0 |
|
| 39 | - * @filesource |
|
| 40 | - */ |
|
| 27 | + /** |
|
| 28 | + * @file function_string.php |
|
| 29 | + * |
|
| 30 | + * This file contains the definition of the functions relating to the processing of strings characters. |
|
| 31 | + * |
|
| 32 | + * @package core |
|
| 33 | + * @author Tony NGUEREZA |
|
| 34 | + * @copyright Copyright (c) 2017 |
|
| 35 | + * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 36 | + * @link http://www.iacademy.cf |
|
| 37 | + * @version 1.0.0 |
|
| 38 | + * @since 1.0.0 |
|
| 39 | + * @filesource |
|
| 40 | + */ |
|
| 41 | 41 | |
| 42 | - if(! function_exists('get_random_string')){ |
|
| 43 | - /** |
|
| 44 | - * Generate a random string |
|
| 45 | - * @param string $type the type of generation. It can take the values: "alpha" for alphabetic characters, |
|
| 46 | - * "alnum" for alpha-numeric characters and "num" for numbers. |
|
| 47 | - * By default it is "alnum". |
|
| 48 | - * @param integer $length the length of the string to generate. By default it is 10. |
|
| 49 | - * @param boolean $lower if we return the generated string in lowercase (true). By default it's false. |
|
| 50 | - * @return string the generated string. |
|
| 51 | - */ |
|
| 52 | - function get_random_string($type = 'alnum', $length = 10, $lower = false){ |
|
| 53 | - $chars = array( |
|
| 54 | - 'alpha' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', |
|
| 55 | - 'alnum' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', |
|
| 56 | - 'num' => '1234567890' |
|
| 57 | - ); |
|
| 58 | - $str = null; |
|
| 59 | - if(isset($chars[$type])){ |
|
| 60 | - $str = $chars[$type]; |
|
| 61 | - } |
|
| 62 | - $random = null; |
|
| 63 | - for($i = 0; $i < $length; $i++){ |
|
| 64 | - $random .= $str[mt_rand() % strlen($str)]; |
|
| 65 | - } |
|
| 66 | - if($lower){ |
|
| 67 | - $random = strtolower($random); |
|
| 68 | - } |
|
| 69 | - return $random; |
|
| 70 | - } |
|
| 71 | - } |
|
| 42 | + if(! function_exists('get_random_string')){ |
|
| 43 | + /** |
|
| 44 | + * Generate a random string |
|
| 45 | + * @param string $type the type of generation. It can take the values: "alpha" for alphabetic characters, |
|
| 46 | + * "alnum" for alpha-numeric characters and "num" for numbers. |
|
| 47 | + * By default it is "alnum". |
|
| 48 | + * @param integer $length the length of the string to generate. By default it is 10. |
|
| 49 | + * @param boolean $lower if we return the generated string in lowercase (true). By default it's false. |
|
| 50 | + * @return string the generated string. |
|
| 51 | + */ |
|
| 52 | + function get_random_string($type = 'alnum', $length = 10, $lower = false){ |
|
| 53 | + $chars = array( |
|
| 54 | + 'alpha' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', |
|
| 55 | + 'alnum' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', |
|
| 56 | + 'num' => '1234567890' |
|
| 57 | + ); |
|
| 58 | + $str = null; |
|
| 59 | + if(isset($chars[$type])){ |
|
| 60 | + $str = $chars[$type]; |
|
| 61 | + } |
|
| 62 | + $random = null; |
|
| 63 | + for($i = 0; $i < $length; $i++){ |
|
| 64 | + $random .= $str[mt_rand() % strlen($str)]; |
|
| 65 | + } |
|
| 66 | + if($lower){ |
|
| 67 | + $random = strtolower($random); |
|
| 68 | + } |
|
| 69 | + return $random; |
|
| 70 | + } |
|
| 71 | + } |
|
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @filesource |
| 40 | 40 | */ |
| 41 | 41 | |
| 42 | - if(! function_exists('get_random_string')){ |
|
| 42 | + if (!function_exists('get_random_string')) { |
|
| 43 | 43 | /** |
| 44 | 44 | * Generate a random string |
| 45 | 45 | * @param string $type the type of generation. It can take the values: "alpha" for alphabetic characters, |
@@ -49,21 +49,21 @@ discard block |
||
| 49 | 49 | * @param boolean $lower if we return the generated string in lowercase (true). By default it's false. |
| 50 | 50 | * @return string the generated string. |
| 51 | 51 | */ |
| 52 | - function get_random_string($type = 'alnum', $length = 10, $lower = false){ |
|
| 52 | + function get_random_string($type = 'alnum', $length = 10, $lower = false) { |
|
| 53 | 53 | $chars = array( |
| 54 | 54 | 'alpha' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', |
| 55 | 55 | 'alnum' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', |
| 56 | 56 | 'num' => '1234567890' |
| 57 | 57 | ); |
| 58 | 58 | $str = null; |
| 59 | - if(isset($chars[$type])){ |
|
| 59 | + if (isset($chars[$type])) { |
|
| 60 | 60 | $str = $chars[$type]; |
| 61 | 61 | } |
| 62 | 62 | $random = null; |
| 63 | - for($i = 0; $i < $length; $i++){ |
|
| 63 | + for ($i = 0; $i < $length; $i++) { |
|
| 64 | 64 | $random .= $str[mt_rand() % strlen($str)]; |
| 65 | 65 | } |
| 66 | - if($lower){ |
|
| 66 | + if ($lower) { |
|
| 67 | 67 | $random = strtolower($random); |
| 68 | 68 | } |
| 69 | 69 | return $random; |
@@ -107,8 +107,7 @@ discard block |
||
| 107 | 107 | if ($moduleModelFilePath){ |
| 108 | 108 | $logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it'); |
| 109 | 109 | $classFilePath = $moduleModelFilePath; |
| 110 | - } |
|
| 111 | - else{ |
|
| 110 | + } else{ |
|
| 112 | 111 | $logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
| 113 | 112 | } |
| 114 | 113 | $logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
@@ -120,12 +119,10 @@ discard block |
||
| 120 | 119 | $obj->{$instance} = $c; |
| 121 | 120 | static::$loaded[$instance] = $class; |
| 122 | 121 | $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
| 123 | - } |
|
| 124 | - else{ |
|
| 122 | + } else{ |
|
| 125 | 123 | show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']'); |
| 126 | 124 | } |
| 127 | - } |
|
| 128 | - else{ |
|
| 125 | + } else{ |
|
| 129 | 126 | show_error('Unable to find the model [' . $class . ']'); |
| 130 | 127 | } |
| 131 | 128 | } |
@@ -168,8 +165,7 @@ discard block |
||
| 168 | 165 | $libraryFilePath = CORE_LIBRARY_PATH . $file; |
| 169 | 166 | $class = ucfirst($class); |
| 170 | 167 | $logger->info('This library is a system library'); |
| 171 | - } |
|
| 172 | - else{ |
|
| 168 | + } else{ |
|
| 173 | 169 | $logger->info('This library is not a system library'); |
| 174 | 170 | //first check if this library is in the module |
| 175 | 171 | $libraryFilePath = self::getLibraryPathUsingModuleInfo($class); |
@@ -214,8 +210,7 @@ discard block |
||
| 214 | 210 | if ($moduleFunctionPath){ |
| 215 | 211 | $logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it'); |
| 216 | 212 | $functionFilePath = $moduleFunctionPath; |
| 217 | - } |
|
| 218 | - else{ |
|
| 213 | + } else{ |
|
| 219 | 214 | $logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
| 220 | 215 | } |
| 221 | 216 | if (! $functionFilePath){ |
@@ -234,8 +229,7 @@ discard block |
||
| 234 | 229 | require_once $functionFilePath; |
| 235 | 230 | static::$loaded['function_' . $function] = $functionFilePath; |
| 236 | 231 | $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
| 237 | - } |
|
| 238 | - else{ |
|
| 232 | + } else{ |
|
| 239 | 233 | show_error('Unable to find helper file [' . $file . ']'); |
| 240 | 234 | } |
| 241 | 235 | } |
@@ -268,8 +262,7 @@ discard block |
||
| 268 | 262 | if ($moduleConfigPath){ |
| 269 | 263 | $logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it'); |
| 270 | 264 | $configFilePath = $moduleConfigPath; |
| 271 | - } |
|
| 272 | - else{ |
|
| 265 | + } else{ |
|
| 273 | 266 | $logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
| 274 | 267 | } |
| 275 | 268 | $logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
@@ -283,8 +276,7 @@ discard block |
||
| 283 | 276 | $logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config)); |
| 284 | 277 | unset($config); |
| 285 | 278 | } |
| 286 | - } |
|
| 287 | - else{ |
|
| 279 | + } else{ |
|
| 288 | 280 | show_error('Unable to find config file ['. $configFilePath . ']'); |
| 289 | 281 | } |
| 290 | 282 | } |
@@ -323,8 +315,7 @@ discard block |
||
| 323 | 315 | if ($moduleLanguagePath){ |
| 324 | 316 | $logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it'); |
| 325 | 317 | $languageFilePath = $moduleLanguagePath; |
| 326 | - } |
|
| 327 | - else{ |
|
| 318 | + } else{ |
|
| 328 | 319 | $logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
| 329 | 320 | } |
| 330 | 321 | if (! $languageFilePath){ |
@@ -377,8 +368,7 @@ discard block |
||
| 377 | 368 | $module = $path[0]; |
| 378 | 369 | $class = ucfirst($path[1]); |
| 379 | 370 | } |
| 380 | - } |
|
| 381 | - else{ |
|
| 371 | + } else{ |
|
| 382 | 372 | $class = ucfirst($class); |
| 383 | 373 | } |
| 384 | 374 | if (! $module && !empty($obj->moduleName)){ |
@@ -499,8 +489,7 @@ discard block |
||
| 499 | 489 | if (isset($path[1])){ |
| 500 | 490 | $instance = strtolower($path[1]); |
| 501 | 491 | } |
| 502 | - } |
|
| 503 | - else{ |
|
| 492 | + } else{ |
|
| 504 | 493 | $instance = strtolower($class); |
| 505 | 494 | } |
| 506 | 495 | return $instance; |
@@ -522,8 +511,7 @@ discard block |
||
| 522 | 511 | if ($moduleLibraryPath){ |
| 523 | 512 | $logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it'); |
| 524 | 513 | $libraryFilePath = $moduleLibraryPath; |
| 525 | - } |
|
| 526 | - else{ |
|
| 514 | + } else{ |
|
| 527 | 515 | $logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
| 528 | 516 | } |
| 529 | 517 | return $libraryFilePath; |
@@ -547,12 +535,10 @@ discard block |
||
| 547 | 535 | $obj->{$instance} = $c; |
| 548 | 536 | static::$loaded[$instance] = $class; |
| 549 | 537 | $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
| 550 | - } |
|
| 551 | - else{ |
|
| 538 | + } else{ |
|
| 552 | 539 | show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class); |
| 553 | 540 | } |
| 554 | - } |
|
| 555 | - else{ |
|
| 541 | + } else{ |
|
| 556 | 542 | show_error('Unable to find library class [' . $class . ']'); |
| 557 | 543 | } |
| 558 | 544 | } |
@@ -578,8 +564,7 @@ discard block |
||
| 578 | 564 | } |
| 579 | 565 | static::$loaded['lang_' . $language] = $languageFilePath; |
| 580 | 566 | $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
| 581 | - } |
|
| 582 | - else{ |
|
| 567 | + } else{ |
|
| 583 | 568 | show_error('Unable to find language [' . $language . ']'); |
| 584 | 569 | } |
| 585 | 570 | } |
@@ -1,627 +1,627 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 26 | - class Loader extends BaseStaticClass{ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | + class Loader extends BaseStaticClass{ |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * List of loaded resources |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - public static $loaded = array(); |
|
| 28 | + /** |
|
| 29 | + * List of loaded resources |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + public static $loaded = array(); |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | - public function __construct(){ |
|
| 36 | - //add the resources already loaded during application bootstrap |
|
| 37 | - //in the list to prevent duplicate or loading the resources again. |
|
| 38 | - static::$loaded = class_loaded(); |
|
| 35 | + public function __construct(){ |
|
| 36 | + //add the resources already loaded during application bootstrap |
|
| 37 | + //in the list to prevent duplicate or loading the resources again. |
|
| 38 | + static::$loaded = class_loaded(); |
|
| 39 | 39 | |
| 40 | - //Load resources from autoload configuration |
|
| 41 | - $this->loadResourcesFromAutoloadConfig(); |
|
| 42 | - } |
|
| 40 | + //Load resources from autoload configuration |
|
| 41 | + $this->loadResourcesFromAutoloadConfig(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Load the model class |
|
| 47 | - * |
|
| 48 | - * @param string $class the class name to be loaded |
|
| 49 | - * @param string $instance the name of the instance to use in super object |
|
| 50 | - * |
|
| 51 | - * @return void |
|
| 52 | - */ |
|
| 53 | - public static function model($class, $instance = null){ |
|
| 54 | - $logger = static::getLogger(); |
|
| 55 | - $class = str_ireplace('.php', '', $class); |
|
| 56 | - $class = trim($class, '/\\'); |
|
| 57 | - $file = ucfirst($class).'.php'; |
|
| 58 | - $logger->debug('Loading model [' . $class . '] ...'); |
|
| 59 | - //************ |
|
| 60 | - if (! $instance){ |
|
| 61 | - $instance = self::getModelLibraryInstanceName($class); |
|
| 62 | - } |
|
| 63 | - //**************** |
|
| 64 | - if (isset(static::$loaded[$instance])){ |
|
| 65 | - $logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance'); |
|
| 66 | - return; |
|
| 67 | - } |
|
| 68 | - $classFilePath = APPS_MODEL_PATH . $file; |
|
| 69 | - //first check if this model is in the module |
|
| 70 | - $logger->debug('Checking model [' . $class . '] from module list ...'); |
|
| 71 | - //check if the request class contains module name |
|
| 72 | - $moduleInfo = self::getModuleInfoForModelLibrary($class); |
|
| 73 | - $module = $moduleInfo['module']; |
|
| 74 | - $class = $moduleInfo['class']; |
|
| 45 | + /** |
|
| 46 | + * Load the model class |
|
| 47 | + * |
|
| 48 | + * @param string $class the class name to be loaded |
|
| 49 | + * @param string $instance the name of the instance to use in super object |
|
| 50 | + * |
|
| 51 | + * @return void |
|
| 52 | + */ |
|
| 53 | + public static function model($class, $instance = null){ |
|
| 54 | + $logger = static::getLogger(); |
|
| 55 | + $class = str_ireplace('.php', '', $class); |
|
| 56 | + $class = trim($class, '/\\'); |
|
| 57 | + $file = ucfirst($class).'.php'; |
|
| 58 | + $logger->debug('Loading model [' . $class . '] ...'); |
|
| 59 | + //************ |
|
| 60 | + if (! $instance){ |
|
| 61 | + $instance = self::getModelLibraryInstanceName($class); |
|
| 62 | + } |
|
| 63 | + //**************** |
|
| 64 | + if (isset(static::$loaded[$instance])){ |
|
| 65 | + $logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance'); |
|
| 66 | + return; |
|
| 67 | + } |
|
| 68 | + $classFilePath = APPS_MODEL_PATH . $file; |
|
| 69 | + //first check if this model is in the module |
|
| 70 | + $logger->debug('Checking model [' . $class . '] from module list ...'); |
|
| 71 | + //check if the request class contains module name |
|
| 72 | + $moduleInfo = self::getModuleInfoForModelLibrary($class); |
|
| 73 | + $module = $moduleInfo['module']; |
|
| 74 | + $class = $moduleInfo['class']; |
|
| 75 | 75 | |
| 76 | - $moduleModelFilePath = Module::findModelFullPath($class, $module); |
|
| 77 | - if ($moduleModelFilePath){ |
|
| 78 | - $logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it'); |
|
| 79 | - $classFilePath = $moduleModelFilePath; |
|
| 80 | - } |
|
| 81 | - else{ |
|
| 82 | - $logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
|
| 83 | - } |
|
| 84 | - $logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
|
| 85 | - if (file_exists($classFilePath)){ |
|
| 86 | - require_once $classFilePath; |
|
| 87 | - if (class_exists($class)){ |
|
| 88 | - $c = new $class(); |
|
| 89 | - $obj = & get_instance(); |
|
| 90 | - $obj->{$instance} = $c; |
|
| 91 | - static::$loaded[$instance] = $class; |
|
| 92 | - $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
|
| 93 | - } |
|
| 94 | - else{ |
|
| 95 | - show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']'); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - else{ |
|
| 99 | - show_error('Unable to find the model [' . $class . ']'); |
|
| 100 | - } |
|
| 101 | - } |
|
| 76 | + $moduleModelFilePath = Module::findModelFullPath($class, $module); |
|
| 77 | + if ($moduleModelFilePath){ |
|
| 78 | + $logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it'); |
|
| 79 | + $classFilePath = $moduleModelFilePath; |
|
| 80 | + } |
|
| 81 | + else{ |
|
| 82 | + $logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
|
| 83 | + } |
|
| 84 | + $logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
|
| 85 | + if (file_exists($classFilePath)){ |
|
| 86 | + require_once $classFilePath; |
|
| 87 | + if (class_exists($class)){ |
|
| 88 | + $c = new $class(); |
|
| 89 | + $obj = & get_instance(); |
|
| 90 | + $obj->{$instance} = $c; |
|
| 91 | + static::$loaded[$instance] = $class; |
|
| 92 | + $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
|
| 93 | + } |
|
| 94 | + else{ |
|
| 95 | + show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']'); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + else{ |
|
| 99 | + show_error('Unable to find the model [' . $class . ']'); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * Load the library class |
|
| 106 | - * |
|
| 107 | - * @param string $class the library class name to be loaded |
|
| 108 | - * @param string $instance the instance name to use in super object |
|
| 109 | - * @param mixed $params the arguments to pass to the constructor |
|
| 110 | - * |
|
| 111 | - * @return void |
|
| 112 | - */ |
|
| 113 | - public static function library($class, $instance = null, array $params = array()){ |
|
| 114 | - $logger = static::getLogger(); |
|
| 115 | - $class = str_ireplace('.php', '', $class); |
|
| 116 | - $class = trim($class, '/\\'); |
|
| 117 | - $file = ucfirst($class) .'.php'; |
|
| 118 | - $logger->debug('Loading library [' . $class . '] ...'); |
|
| 119 | - if (! $instance){ |
|
| 120 | - $instance = self::getModelLibraryInstanceName($class); |
|
| 121 | - } |
|
| 122 | - if (isset(static::$loaded[$instance])){ |
|
| 123 | - $logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance'); |
|
| 124 | - return; |
|
| 125 | - } |
|
| 126 | - $obj = & get_instance(); |
|
| 127 | - //Check and load Database library |
|
| 128 | - if (strtolower($class) == 'database'){ |
|
| 129 | - $logger->info('This is the Database library ...'); |
|
| 130 | - $obj->{$instance} = & class_loader('Database', 'classes/database', $params); |
|
| 131 | - static::$loaded[$instance] = $class; |
|
| 132 | - $logger->info('Library Database loaded successfully.'); |
|
| 133 | - return; |
|
| 134 | - } |
|
| 135 | - $libraryFilePath = null; |
|
| 136 | - $logger->debug('Check if this is a system library ...'); |
|
| 137 | - if (file_exists(CORE_LIBRARY_PATH . $file)){ |
|
| 138 | - $libraryFilePath = CORE_LIBRARY_PATH . $file; |
|
| 139 | - $class = ucfirst($class); |
|
| 140 | - $logger->info('This library is a system library'); |
|
| 141 | - } |
|
| 142 | - else{ |
|
| 143 | - $logger->info('This library is not a system library'); |
|
| 144 | - //first check if this library is in the module |
|
| 145 | - $libraryFilePath = self::getLibraryPathUsingModuleInfo($class); |
|
| 146 | - //*************** |
|
| 147 | - } |
|
| 148 | - if (! $libraryFilePath && file_exists(LIBRARY_PATH . $file)){ |
|
| 149 | - $libraryFilePath = LIBRARY_PATH . $file; |
|
| 150 | - } |
|
| 151 | - $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']'); |
|
| 152 | - //************************* |
|
| 153 | - self::loadLibrary($libraryFilePath, $class, $instance, $params); |
|
| 154 | - } |
|
| 104 | + /** |
|
| 105 | + * Load the library class |
|
| 106 | + * |
|
| 107 | + * @param string $class the library class name to be loaded |
|
| 108 | + * @param string $instance the instance name to use in super object |
|
| 109 | + * @param mixed $params the arguments to pass to the constructor |
|
| 110 | + * |
|
| 111 | + * @return void |
|
| 112 | + */ |
|
| 113 | + public static function library($class, $instance = null, array $params = array()){ |
|
| 114 | + $logger = static::getLogger(); |
|
| 115 | + $class = str_ireplace('.php', '', $class); |
|
| 116 | + $class = trim($class, '/\\'); |
|
| 117 | + $file = ucfirst($class) .'.php'; |
|
| 118 | + $logger->debug('Loading library [' . $class . '] ...'); |
|
| 119 | + if (! $instance){ |
|
| 120 | + $instance = self::getModelLibraryInstanceName($class); |
|
| 121 | + } |
|
| 122 | + if (isset(static::$loaded[$instance])){ |
|
| 123 | + $logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance'); |
|
| 124 | + return; |
|
| 125 | + } |
|
| 126 | + $obj = & get_instance(); |
|
| 127 | + //Check and load Database library |
|
| 128 | + if (strtolower($class) == 'database'){ |
|
| 129 | + $logger->info('This is the Database library ...'); |
|
| 130 | + $obj->{$instance} = & class_loader('Database', 'classes/database', $params); |
|
| 131 | + static::$loaded[$instance] = $class; |
|
| 132 | + $logger->info('Library Database loaded successfully.'); |
|
| 133 | + return; |
|
| 134 | + } |
|
| 135 | + $libraryFilePath = null; |
|
| 136 | + $logger->debug('Check if this is a system library ...'); |
|
| 137 | + if (file_exists(CORE_LIBRARY_PATH . $file)){ |
|
| 138 | + $libraryFilePath = CORE_LIBRARY_PATH . $file; |
|
| 139 | + $class = ucfirst($class); |
|
| 140 | + $logger->info('This library is a system library'); |
|
| 141 | + } |
|
| 142 | + else{ |
|
| 143 | + $logger->info('This library is not a system library'); |
|
| 144 | + //first check if this library is in the module |
|
| 145 | + $libraryFilePath = self::getLibraryPathUsingModuleInfo($class); |
|
| 146 | + //*************** |
|
| 147 | + } |
|
| 148 | + if (! $libraryFilePath && file_exists(LIBRARY_PATH . $file)){ |
|
| 149 | + $libraryFilePath = LIBRARY_PATH . $file; |
|
| 150 | + } |
|
| 151 | + $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']'); |
|
| 152 | + //************************* |
|
| 153 | + self::loadLibrary($libraryFilePath, $class, $instance, $params); |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * Load the helper |
|
| 158 | - * |
|
| 159 | - * @param string $function the helper name to be loaded |
|
| 160 | - * |
|
| 161 | - * @return void |
|
| 162 | - */ |
|
| 163 | - public static function functions($function){ |
|
| 164 | - $logger = static::getLogger(); |
|
| 165 | - $function = str_ireplace('.php', '', $function); |
|
| 166 | - $function = trim($function, '/\\'); |
|
| 167 | - $function = str_ireplace('function_', '', $function); |
|
| 168 | - $file = 'function_'.$function.'.php'; |
|
| 169 | - $logger->debug('Loading helper [' . $function . '] ...'); |
|
| 170 | - if (isset(static::$loaded['function_' . $function])){ |
|
| 171 | - $logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance'); |
|
| 172 | - return; |
|
| 173 | - } |
|
| 174 | - $functionFilePath = null; |
|
| 175 | - //first check if this helper is in the module |
|
| 176 | - $logger->debug('Checking helper [' . $function . '] from module list ...'); |
|
| 177 | - $moduleInfo = self::getModuleInfoForFunction($function); |
|
| 178 | - $module = $moduleInfo['module']; |
|
| 179 | - $function = $moduleInfo['function']; |
|
| 180 | - if(! empty($moduleInfo['file'])){ |
|
| 181 | - $file = $moduleInfo['file']; |
|
| 182 | - } |
|
| 183 | - $moduleFunctionPath = Module::findFunctionFullPath($function, $module); |
|
| 184 | - if ($moduleFunctionPath){ |
|
| 185 | - $logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it'); |
|
| 186 | - $functionFilePath = $moduleFunctionPath; |
|
| 187 | - } |
|
| 188 | - else{ |
|
| 189 | - $logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
|
| 190 | - } |
|
| 191 | - if (! $functionFilePath){ |
|
| 192 | - $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH); |
|
| 193 | - foreach($searchDir as $dir){ |
|
| 194 | - $filePath = $dir . $file; |
|
| 195 | - if (file_exists($filePath)){ |
|
| 196 | - $functionFilePath = $filePath; |
|
| 197 | - //is already found not to continue |
|
| 198 | - break; |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']'); |
|
| 203 | - if ($functionFilePath){ |
|
| 204 | - require_once $functionFilePath; |
|
| 205 | - static::$loaded['function_' . $function] = $functionFilePath; |
|
| 206 | - $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
|
| 207 | - } |
|
| 208 | - else{ |
|
| 209 | - show_error('Unable to find helper file [' . $file . ']'); |
|
| 210 | - } |
|
| 211 | - } |
|
| 156 | + /** |
|
| 157 | + * Load the helper |
|
| 158 | + * |
|
| 159 | + * @param string $function the helper name to be loaded |
|
| 160 | + * |
|
| 161 | + * @return void |
|
| 162 | + */ |
|
| 163 | + public static function functions($function){ |
|
| 164 | + $logger = static::getLogger(); |
|
| 165 | + $function = str_ireplace('.php', '', $function); |
|
| 166 | + $function = trim($function, '/\\'); |
|
| 167 | + $function = str_ireplace('function_', '', $function); |
|
| 168 | + $file = 'function_'.$function.'.php'; |
|
| 169 | + $logger->debug('Loading helper [' . $function . '] ...'); |
|
| 170 | + if (isset(static::$loaded['function_' . $function])){ |
|
| 171 | + $logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance'); |
|
| 172 | + return; |
|
| 173 | + } |
|
| 174 | + $functionFilePath = null; |
|
| 175 | + //first check if this helper is in the module |
|
| 176 | + $logger->debug('Checking helper [' . $function . '] from module list ...'); |
|
| 177 | + $moduleInfo = self::getModuleInfoForFunction($function); |
|
| 178 | + $module = $moduleInfo['module']; |
|
| 179 | + $function = $moduleInfo['function']; |
|
| 180 | + if(! empty($moduleInfo['file'])){ |
|
| 181 | + $file = $moduleInfo['file']; |
|
| 182 | + } |
|
| 183 | + $moduleFunctionPath = Module::findFunctionFullPath($function, $module); |
|
| 184 | + if ($moduleFunctionPath){ |
|
| 185 | + $logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it'); |
|
| 186 | + $functionFilePath = $moduleFunctionPath; |
|
| 187 | + } |
|
| 188 | + else{ |
|
| 189 | + $logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
|
| 190 | + } |
|
| 191 | + if (! $functionFilePath){ |
|
| 192 | + $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH); |
|
| 193 | + foreach($searchDir as $dir){ |
|
| 194 | + $filePath = $dir . $file; |
|
| 195 | + if (file_exists($filePath)){ |
|
| 196 | + $functionFilePath = $filePath; |
|
| 197 | + //is already found not to continue |
|
| 198 | + break; |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']'); |
|
| 203 | + if ($functionFilePath){ |
|
| 204 | + require_once $functionFilePath; |
|
| 205 | + static::$loaded['function_' . $function] = $functionFilePath; |
|
| 206 | + $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
|
| 207 | + } |
|
| 208 | + else{ |
|
| 209 | + show_error('Unable to find helper file [' . $file . ']'); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - /** |
|
| 214 | - * Load the configuration file |
|
| 215 | - * |
|
| 216 | - * @param string $filename the configuration filename located at CONFIG_PATH or MODULE_PATH/config |
|
| 217 | - * |
|
| 218 | - * @return void |
|
| 219 | - */ |
|
| 220 | - public static function config($filename){ |
|
| 221 | - $logger = static::getLogger(); |
|
| 222 | - $filename = str_ireplace('.php', '', $filename); |
|
| 223 | - $filename = trim($filename, '/\\'); |
|
| 224 | - $filename = str_ireplace('config_', '', $filename); |
|
| 225 | - $file = 'config_'.$filename.'.php'; |
|
| 226 | - $logger->debug('Loading configuration [' . $filename . '] ...'); |
|
| 227 | - if (isset(static::$loaded['config_' . $filename])){ |
|
| 228 | - $logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance'); |
|
| 229 | - return; |
|
| 230 | - } |
|
| 231 | - $configFilePath = CONFIG_PATH . $file; |
|
| 232 | - //first check if this config is in the module |
|
| 233 | - $logger->debug('Checking config [' . $filename . '] from module list ...'); |
|
| 234 | - $moduleInfo = self::getModuleInfoForConfig($filename); |
|
| 235 | - $module = $moduleInfo['module']; |
|
| 236 | - $filename = $moduleInfo['filename']; |
|
| 237 | - $moduleConfigPath = Module::findConfigFullPath($filename, $module); |
|
| 238 | - if ($moduleConfigPath){ |
|
| 239 | - $logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it'); |
|
| 240 | - $configFilePath = $moduleConfigPath; |
|
| 241 | - } |
|
| 242 | - else{ |
|
| 243 | - $logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
|
| 244 | - } |
|
| 245 | - $logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
|
| 246 | - $config = array(); |
|
| 247 | - if (file_exists($configFilePath)){ |
|
| 248 | - require_once $configFilePath; |
|
| 249 | - if (! empty($config) && is_array($config)){ |
|
| 250 | - Config::setAll($config); |
|
| 251 | - static::$loaded['config_' . $filename] = $configFilePath; |
|
| 252 | - $logger->info('Configuration [' . $configFilePath . '] loaded successfully.'); |
|
| 253 | - $logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config)); |
|
| 254 | - unset($config); |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - else{ |
|
| 258 | - show_error('Unable to find config file ['. $configFilePath . ']'); |
|
| 259 | - } |
|
| 260 | - } |
|
| 213 | + /** |
|
| 214 | + * Load the configuration file |
|
| 215 | + * |
|
| 216 | + * @param string $filename the configuration filename located at CONFIG_PATH or MODULE_PATH/config |
|
| 217 | + * |
|
| 218 | + * @return void |
|
| 219 | + */ |
|
| 220 | + public static function config($filename){ |
|
| 221 | + $logger = static::getLogger(); |
|
| 222 | + $filename = str_ireplace('.php', '', $filename); |
|
| 223 | + $filename = trim($filename, '/\\'); |
|
| 224 | + $filename = str_ireplace('config_', '', $filename); |
|
| 225 | + $file = 'config_'.$filename.'.php'; |
|
| 226 | + $logger->debug('Loading configuration [' . $filename . '] ...'); |
|
| 227 | + if (isset(static::$loaded['config_' . $filename])){ |
|
| 228 | + $logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance'); |
|
| 229 | + return; |
|
| 230 | + } |
|
| 231 | + $configFilePath = CONFIG_PATH . $file; |
|
| 232 | + //first check if this config is in the module |
|
| 233 | + $logger->debug('Checking config [' . $filename . '] from module list ...'); |
|
| 234 | + $moduleInfo = self::getModuleInfoForConfig($filename); |
|
| 235 | + $module = $moduleInfo['module']; |
|
| 236 | + $filename = $moduleInfo['filename']; |
|
| 237 | + $moduleConfigPath = Module::findConfigFullPath($filename, $module); |
|
| 238 | + if ($moduleConfigPath){ |
|
| 239 | + $logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it'); |
|
| 240 | + $configFilePath = $moduleConfigPath; |
|
| 241 | + } |
|
| 242 | + else{ |
|
| 243 | + $logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
|
| 244 | + } |
|
| 245 | + $logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
|
| 246 | + $config = array(); |
|
| 247 | + if (file_exists($configFilePath)){ |
|
| 248 | + require_once $configFilePath; |
|
| 249 | + if (! empty($config) && is_array($config)){ |
|
| 250 | + Config::setAll($config); |
|
| 251 | + static::$loaded['config_' . $filename] = $configFilePath; |
|
| 252 | + $logger->info('Configuration [' . $configFilePath . '] loaded successfully.'); |
|
| 253 | + $logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config)); |
|
| 254 | + unset($config); |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + else{ |
|
| 258 | + show_error('Unable to find config file ['. $configFilePath . ']'); |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * Load the language |
|
| 265 | - * |
|
| 266 | - * @param string $language the language name to be loaded |
|
| 267 | - * |
|
| 268 | - * @return void |
|
| 269 | - */ |
|
| 270 | - public static function lang($language){ |
|
| 271 | - $logger = static::getLogger(); |
|
| 272 | - $language = str_ireplace('.php', '', $language); |
|
| 273 | - $language = trim($language, '/\\'); |
|
| 274 | - $language = str_ireplace('lang_', '', $language); |
|
| 275 | - $file = 'lang_'.$language.'.php'; |
|
| 276 | - $logger->debug('Loading language [' . $language . '] ...'); |
|
| 277 | - if (isset(static::$loaded['lang_' . $language])){ |
|
| 278 | - $logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance'); |
|
| 279 | - return; |
|
| 280 | - } |
|
| 281 | - //get the current language |
|
| 282 | - $appLang = self::getAppLang(); |
|
| 283 | - $languageFilePath = null; |
|
| 284 | - //first check if this language is in the module |
|
| 285 | - $logger->debug('Checking language [' . $language . '] from module list ...'); |
|
| 286 | - $moduleInfo = self::getModuleInfoForLanguage($language); |
|
| 287 | - $module = $moduleInfo['module']; |
|
| 288 | - $language = $moduleInfo['language']; |
|
| 289 | - if(! empty($moduleInfo['file'])){ |
|
| 290 | - $file = $moduleInfo['file']; |
|
| 291 | - } |
|
| 292 | - $moduleLanguagePath = Module::findLanguageFullPath($language, $appLang, $module); |
|
| 293 | - if ($moduleLanguagePath){ |
|
| 294 | - $logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it'); |
|
| 295 | - $languageFilePath = $moduleLanguagePath; |
|
| 296 | - } |
|
| 297 | - else{ |
|
| 298 | - $logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
|
| 299 | - } |
|
| 300 | - if (! $languageFilePath){ |
|
| 301 | - $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH); |
|
| 302 | - foreach($searchDir as $dir){ |
|
| 303 | - $filePath = $dir . $appLang . DS . $file; |
|
| 304 | - if (file_exists($filePath)){ |
|
| 305 | - $languageFilePath = $filePath; |
|
| 306 | - //already found no need continue |
|
| 307 | - break; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - $logger->info('The language file path to be loaded is [' . $languageFilePath . ']'); |
|
| 312 | - self::loadLanguage($languageFilePath, $language); |
|
| 313 | - } |
|
| 263 | + /** |
|
| 264 | + * Load the language |
|
| 265 | + * |
|
| 266 | + * @param string $language the language name to be loaded |
|
| 267 | + * |
|
| 268 | + * @return void |
|
| 269 | + */ |
|
| 270 | + public static function lang($language){ |
|
| 271 | + $logger = static::getLogger(); |
|
| 272 | + $language = str_ireplace('.php', '', $language); |
|
| 273 | + $language = trim($language, '/\\'); |
|
| 274 | + $language = str_ireplace('lang_', '', $language); |
|
| 275 | + $file = 'lang_'.$language.'.php'; |
|
| 276 | + $logger->debug('Loading language [' . $language . '] ...'); |
|
| 277 | + if (isset(static::$loaded['lang_' . $language])){ |
|
| 278 | + $logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance'); |
|
| 279 | + return; |
|
| 280 | + } |
|
| 281 | + //get the current language |
|
| 282 | + $appLang = self::getAppLang(); |
|
| 283 | + $languageFilePath = null; |
|
| 284 | + //first check if this language is in the module |
|
| 285 | + $logger->debug('Checking language [' . $language . '] from module list ...'); |
|
| 286 | + $moduleInfo = self::getModuleInfoForLanguage($language); |
|
| 287 | + $module = $moduleInfo['module']; |
|
| 288 | + $language = $moduleInfo['language']; |
|
| 289 | + if(! empty($moduleInfo['file'])){ |
|
| 290 | + $file = $moduleInfo['file']; |
|
| 291 | + } |
|
| 292 | + $moduleLanguagePath = Module::findLanguageFullPath($language, $appLang, $module); |
|
| 293 | + if ($moduleLanguagePath){ |
|
| 294 | + $logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it'); |
|
| 295 | + $languageFilePath = $moduleLanguagePath; |
|
| 296 | + } |
|
| 297 | + else{ |
|
| 298 | + $logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
|
| 299 | + } |
|
| 300 | + if (! $languageFilePath){ |
|
| 301 | + $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH); |
|
| 302 | + foreach($searchDir as $dir){ |
|
| 303 | + $filePath = $dir . $appLang . DS . $file; |
|
| 304 | + if (file_exists($filePath)){ |
|
| 305 | + $languageFilePath = $filePath; |
|
| 306 | + //already found no need continue |
|
| 307 | + break; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + $logger->info('The language file path to be loaded is [' . $languageFilePath . ']'); |
|
| 312 | + self::loadLanguage($languageFilePath, $language); |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - /** |
|
| 316 | - * Return the current app language by default will use the value from cookie |
|
| 317 | - * if can not found will use the default value from configuration |
|
| 318 | - * @return string the app language like "en", "fr" |
|
| 319 | - */ |
|
| 320 | - protected static function getAppLang(){ |
|
| 321 | - //determine the current language |
|
| 322 | - $appLang = get_config('default_language'); |
|
| 323 | - //if the language exists in the cookie use it |
|
| 324 | - $cfgKey = get_config('language_cookie_name'); |
|
| 325 | - $objCookie = & class_loader('Cookie'); |
|
| 326 | - $cookieLang = $objCookie->get($cfgKey); |
|
| 327 | - if ($cookieLang){ |
|
| 328 | - $appLang = $cookieLang; |
|
| 329 | - } |
|
| 330 | - return $appLang; |
|
| 331 | - } |
|
| 332 | - /** |
|
| 333 | - * Get the module information for the model and library to load |
|
| 334 | - * @param string $class the full class name like moduleName/className, className, |
|
| 335 | - * @return array the module information |
|
| 336 | - * array( |
|
| 337 | - * 'module'=> 'module_name' |
|
| 338 | - * 'class' => 'class_name' |
|
| 339 | - * ) |
|
| 340 | - */ |
|
| 341 | - protected static function getModuleInfoForModelLibrary($class){ |
|
| 342 | - $module = null; |
|
| 343 | - $obj = & get_instance(); |
|
| 344 | - if (strpos($class, '/') !== false){ |
|
| 345 | - $path = explode('/', $class); |
|
| 346 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
| 347 | - $module = $path[0]; |
|
| 348 | - $class = ucfirst($path[1]); |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - else{ |
|
| 352 | - $class = ucfirst($class); |
|
| 353 | - } |
|
| 354 | - if (! $module && !empty($obj->moduleName)){ |
|
| 355 | - $module = $obj->moduleName; |
|
| 356 | - } |
|
| 357 | - return array( |
|
| 358 | - 'class' => $class, |
|
| 359 | - 'module' => $module |
|
| 360 | - ); |
|
| 361 | - } |
|
| 315 | + /** |
|
| 316 | + * Return the current app language by default will use the value from cookie |
|
| 317 | + * if can not found will use the default value from configuration |
|
| 318 | + * @return string the app language like "en", "fr" |
|
| 319 | + */ |
|
| 320 | + protected static function getAppLang(){ |
|
| 321 | + //determine the current language |
|
| 322 | + $appLang = get_config('default_language'); |
|
| 323 | + //if the language exists in the cookie use it |
|
| 324 | + $cfgKey = get_config('language_cookie_name'); |
|
| 325 | + $objCookie = & class_loader('Cookie'); |
|
| 326 | + $cookieLang = $objCookie->get($cfgKey); |
|
| 327 | + if ($cookieLang){ |
|
| 328 | + $appLang = $cookieLang; |
|
| 329 | + } |
|
| 330 | + return $appLang; |
|
| 331 | + } |
|
| 332 | + /** |
|
| 333 | + * Get the module information for the model and library to load |
|
| 334 | + * @param string $class the full class name like moduleName/className, className, |
|
| 335 | + * @return array the module information |
|
| 336 | + * array( |
|
| 337 | + * 'module'=> 'module_name' |
|
| 338 | + * 'class' => 'class_name' |
|
| 339 | + * ) |
|
| 340 | + */ |
|
| 341 | + protected static function getModuleInfoForModelLibrary($class){ |
|
| 342 | + $module = null; |
|
| 343 | + $obj = & get_instance(); |
|
| 344 | + if (strpos($class, '/') !== false){ |
|
| 345 | + $path = explode('/', $class); |
|
| 346 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
| 347 | + $module = $path[0]; |
|
| 348 | + $class = ucfirst($path[1]); |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + else{ |
|
| 352 | + $class = ucfirst($class); |
|
| 353 | + } |
|
| 354 | + if (! $module && !empty($obj->moduleName)){ |
|
| 355 | + $module = $obj->moduleName; |
|
| 356 | + } |
|
| 357 | + return array( |
|
| 358 | + 'class' => $class, |
|
| 359 | + 'module' => $module |
|
| 360 | + ); |
|
| 361 | + } |
|
| 362 | 362 | |
| 363 | - /** |
|
| 364 | - * Get the module information for the function to load |
|
| 365 | - * @param string $function the function name like moduleName/functionName, functionName, |
|
| 366 | - * @return array the module information |
|
| 367 | - * array( |
|
| 368 | - * 'module'=> 'module_name' |
|
| 369 | - * 'function' => 'function' |
|
| 370 | - * 'file' => 'file' |
|
| 371 | - * ) |
|
| 372 | - */ |
|
| 373 | - protected static function getModuleInfoForFunction($function){ |
|
| 374 | - $module = null; |
|
| 375 | - $file = null; |
|
| 376 | - $obj = & get_instance(); |
|
| 377 | - //check if the request class contains module name |
|
| 378 | - if (strpos($function, '/') !== false){ |
|
| 379 | - $path = explode('/', $function); |
|
| 380 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
| 381 | - $module = $path[0]; |
|
| 382 | - $function = 'function_' . $path[1]; |
|
| 383 | - $file = $path[0] . DS . $function.'.php'; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - if (! $module && !empty($obj->moduleName)){ |
|
| 387 | - $module = $obj->moduleName; |
|
| 388 | - } |
|
| 389 | - return array( |
|
| 390 | - 'function' => $function, |
|
| 391 | - 'module' => $module, |
|
| 392 | - 'file' => $file |
|
| 393 | - ); |
|
| 394 | - } |
|
| 363 | + /** |
|
| 364 | + * Get the module information for the function to load |
|
| 365 | + * @param string $function the function name like moduleName/functionName, functionName, |
|
| 366 | + * @return array the module information |
|
| 367 | + * array( |
|
| 368 | + * 'module'=> 'module_name' |
|
| 369 | + * 'function' => 'function' |
|
| 370 | + * 'file' => 'file' |
|
| 371 | + * ) |
|
| 372 | + */ |
|
| 373 | + protected static function getModuleInfoForFunction($function){ |
|
| 374 | + $module = null; |
|
| 375 | + $file = null; |
|
| 376 | + $obj = & get_instance(); |
|
| 377 | + //check if the request class contains module name |
|
| 378 | + if (strpos($function, '/') !== false){ |
|
| 379 | + $path = explode('/', $function); |
|
| 380 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
| 381 | + $module = $path[0]; |
|
| 382 | + $function = 'function_' . $path[1]; |
|
| 383 | + $file = $path[0] . DS . $function.'.php'; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + if (! $module && !empty($obj->moduleName)){ |
|
| 387 | + $module = $obj->moduleName; |
|
| 388 | + } |
|
| 389 | + return array( |
|
| 390 | + 'function' => $function, |
|
| 391 | + 'module' => $module, |
|
| 392 | + 'file' => $file |
|
| 393 | + ); |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | - /** |
|
| 397 | - * Get the module information for the language to load |
|
| 398 | - * @param string $language the language name like moduleName/languageName, languageName, |
|
| 399 | - * @return array the module information |
|
| 400 | - * array( |
|
| 401 | - * 'module'=> 'module_name' |
|
| 402 | - * 'language' => 'language' |
|
| 403 | - * 'file' => 'file' |
|
| 404 | - * ) |
|
| 405 | - */ |
|
| 406 | - protected static function getModuleInfoForLanguage($language){ |
|
| 407 | - $module = null; |
|
| 408 | - $file = null; |
|
| 409 | - $obj = & get_instance(); |
|
| 410 | - //check if the request class contains module name |
|
| 411 | - if (strpos($language, '/') !== false){ |
|
| 412 | - $path = explode('/', $language); |
|
| 413 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
| 414 | - $module = $path[0]; |
|
| 415 | - $language = 'lang_' . $path[1] . '.php'; |
|
| 416 | - $file = $path[0] . DS .$language; |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - if (! $module && !empty($obj->moduleName)){ |
|
| 420 | - $module = $obj->moduleName; |
|
| 421 | - } |
|
| 422 | - return array( |
|
| 423 | - 'language' => $language, |
|
| 424 | - 'module' => $module, |
|
| 425 | - 'file' => $file |
|
| 426 | - ); |
|
| 427 | - } |
|
| 396 | + /** |
|
| 397 | + * Get the module information for the language to load |
|
| 398 | + * @param string $language the language name like moduleName/languageName, languageName, |
|
| 399 | + * @return array the module information |
|
| 400 | + * array( |
|
| 401 | + * 'module'=> 'module_name' |
|
| 402 | + * 'language' => 'language' |
|
| 403 | + * 'file' => 'file' |
|
| 404 | + * ) |
|
| 405 | + */ |
|
| 406 | + protected static function getModuleInfoForLanguage($language){ |
|
| 407 | + $module = null; |
|
| 408 | + $file = null; |
|
| 409 | + $obj = & get_instance(); |
|
| 410 | + //check if the request class contains module name |
|
| 411 | + if (strpos($language, '/') !== false){ |
|
| 412 | + $path = explode('/', $language); |
|
| 413 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
| 414 | + $module = $path[0]; |
|
| 415 | + $language = 'lang_' . $path[1] . '.php'; |
|
| 416 | + $file = $path[0] . DS .$language; |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + if (! $module && !empty($obj->moduleName)){ |
|
| 420 | + $module = $obj->moduleName; |
|
| 421 | + } |
|
| 422 | + return array( |
|
| 423 | + 'language' => $language, |
|
| 424 | + 'module' => $module, |
|
| 425 | + 'file' => $file |
|
| 426 | + ); |
|
| 427 | + } |
|
| 428 | 428 | |
| 429 | 429 | |
| 430 | - /** |
|
| 431 | - * Get the module information for the config to load |
|
| 432 | - * @param string $filename the filename of the configuration file, |
|
| 433 | - * @return array the module information |
|
| 434 | - * array( |
|
| 435 | - * 'module'=> 'module_name' |
|
| 436 | - * 'filename' => 'filename' |
|
| 437 | - * ) |
|
| 438 | - */ |
|
| 439 | - protected static function getModuleInfoForConfig($filename){ |
|
| 440 | - $module = null; |
|
| 441 | - $obj = & get_instance(); |
|
| 442 | - //check if the request class contains module name |
|
| 443 | - if (strpos($filename, '/') !== false){ |
|
| 444 | - $path = explode('/', $filename); |
|
| 445 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
| 446 | - $module = $path[0]; |
|
| 447 | - $filename = $path[1] . '.php'; |
|
| 448 | - } |
|
| 449 | - } |
|
| 450 | - if (! $module && !empty($obj->moduleName)){ |
|
| 451 | - $module = $obj->moduleName; |
|
| 452 | - } |
|
| 453 | - return array( |
|
| 454 | - 'filename' => $filename, |
|
| 455 | - 'module' => $module |
|
| 456 | - ); |
|
| 457 | - } |
|
| 430 | + /** |
|
| 431 | + * Get the module information for the config to load |
|
| 432 | + * @param string $filename the filename of the configuration file, |
|
| 433 | + * @return array the module information |
|
| 434 | + * array( |
|
| 435 | + * 'module'=> 'module_name' |
|
| 436 | + * 'filename' => 'filename' |
|
| 437 | + * ) |
|
| 438 | + */ |
|
| 439 | + protected static function getModuleInfoForConfig($filename){ |
|
| 440 | + $module = null; |
|
| 441 | + $obj = & get_instance(); |
|
| 442 | + //check if the request class contains module name |
|
| 443 | + if (strpos($filename, '/') !== false){ |
|
| 444 | + $path = explode('/', $filename); |
|
| 445 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
| 446 | + $module = $path[0]; |
|
| 447 | + $filename = $path[1] . '.php'; |
|
| 448 | + } |
|
| 449 | + } |
|
| 450 | + if (! $module && !empty($obj->moduleName)){ |
|
| 451 | + $module = $obj->moduleName; |
|
| 452 | + } |
|
| 453 | + return array( |
|
| 454 | + 'filename' => $filename, |
|
| 455 | + 'module' => $module |
|
| 456 | + ); |
|
| 457 | + } |
|
| 458 | 458 | |
| 459 | - /** |
|
| 460 | - * Get the name of model or library instance if is null |
|
| 461 | - * @param string $class the class name to determine the instance |
|
| 462 | - * @return string the instance name |
|
| 463 | - */ |
|
| 464 | - protected static function getModelLibraryInstanceName($class){ |
|
| 465 | - //for module |
|
| 466 | - $instance = null; |
|
| 467 | - if (strpos($class, '/') !== false){ |
|
| 468 | - $path = explode('/', $class); |
|
| 469 | - if (isset($path[1])){ |
|
| 470 | - $instance = strtolower($path[1]); |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - else{ |
|
| 474 | - $instance = strtolower($class); |
|
| 475 | - } |
|
| 476 | - return $instance; |
|
| 477 | - } |
|
| 459 | + /** |
|
| 460 | + * Get the name of model or library instance if is null |
|
| 461 | + * @param string $class the class name to determine the instance |
|
| 462 | + * @return string the instance name |
|
| 463 | + */ |
|
| 464 | + protected static function getModelLibraryInstanceName($class){ |
|
| 465 | + //for module |
|
| 466 | + $instance = null; |
|
| 467 | + if (strpos($class, '/') !== false){ |
|
| 468 | + $path = explode('/', $class); |
|
| 469 | + if (isset($path[1])){ |
|
| 470 | + $instance = strtolower($path[1]); |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + else{ |
|
| 474 | + $instance = strtolower($class); |
|
| 475 | + } |
|
| 476 | + return $instance; |
|
| 477 | + } |
|
| 478 | 478 | |
| 479 | - /** |
|
| 480 | - * Get the library file path using the module information |
|
| 481 | - * @param string $class the class name |
|
| 482 | - * @return string|null the library file path otherwise null will be returned |
|
| 483 | - */ |
|
| 484 | - protected static function getLibraryPathUsingModuleInfo($class){ |
|
| 485 | - $logger = static::getLogger(); |
|
| 486 | - $libraryFilePath = null; |
|
| 487 | - $logger->debug('Checking library [' . $class . '] from module list ...'); |
|
| 488 | - $moduleInfo = self::getModuleInfoForModelLibrary($class); |
|
| 489 | - $module = $moduleInfo['module']; |
|
| 490 | - $class = $moduleInfo['class']; |
|
| 491 | - $moduleLibraryPath = Module::findLibraryFullPath($class, $module); |
|
| 492 | - if ($moduleLibraryPath){ |
|
| 493 | - $logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it'); |
|
| 494 | - $libraryFilePath = $moduleLibraryPath; |
|
| 495 | - } |
|
| 496 | - else{ |
|
| 497 | - $logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
|
| 498 | - } |
|
| 499 | - return $libraryFilePath; |
|
| 500 | - } |
|
| 479 | + /** |
|
| 480 | + * Get the library file path using the module information |
|
| 481 | + * @param string $class the class name |
|
| 482 | + * @return string|null the library file path otherwise null will be returned |
|
| 483 | + */ |
|
| 484 | + protected static function getLibraryPathUsingModuleInfo($class){ |
|
| 485 | + $logger = static::getLogger(); |
|
| 486 | + $libraryFilePath = null; |
|
| 487 | + $logger->debug('Checking library [' . $class . '] from module list ...'); |
|
| 488 | + $moduleInfo = self::getModuleInfoForModelLibrary($class); |
|
| 489 | + $module = $moduleInfo['module']; |
|
| 490 | + $class = $moduleInfo['class']; |
|
| 491 | + $moduleLibraryPath = Module::findLibraryFullPath($class, $module); |
|
| 492 | + if ($moduleLibraryPath){ |
|
| 493 | + $logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it'); |
|
| 494 | + $libraryFilePath = $moduleLibraryPath; |
|
| 495 | + } |
|
| 496 | + else{ |
|
| 497 | + $logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
|
| 498 | + } |
|
| 499 | + return $libraryFilePath; |
|
| 500 | + } |
|
| 501 | 501 | |
| 502 | - /** |
|
| 503 | - * Load the library |
|
| 504 | - * @param string $libraryFilePath the file path of the library to load |
|
| 505 | - * @param string $class the class name |
|
| 506 | - * @param string $instance the instance |
|
| 507 | - * @param array $params the parameter to use |
|
| 508 | - * @return void |
|
| 509 | - */ |
|
| 510 | - protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()){ |
|
| 511 | - if ($libraryFilePath){ |
|
| 512 | - $logger = static::getLogger(); |
|
| 513 | - require_once $libraryFilePath; |
|
| 514 | - if (class_exists($class)){ |
|
| 515 | - $c = $params ? new $class($params) : new $class(); |
|
| 516 | - $obj = & get_instance(); |
|
| 517 | - $obj->{$instance} = $c; |
|
| 518 | - static::$loaded[$instance] = $class; |
|
| 519 | - $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
|
| 520 | - } |
|
| 521 | - else{ |
|
| 522 | - show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class); |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - else{ |
|
| 526 | - show_error('Unable to find library class [' . $class . ']'); |
|
| 527 | - } |
|
| 528 | - } |
|
| 502 | + /** |
|
| 503 | + * Load the library |
|
| 504 | + * @param string $libraryFilePath the file path of the library to load |
|
| 505 | + * @param string $class the class name |
|
| 506 | + * @param string $instance the instance |
|
| 507 | + * @param array $params the parameter to use |
|
| 508 | + * @return void |
|
| 509 | + */ |
|
| 510 | + protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()){ |
|
| 511 | + if ($libraryFilePath){ |
|
| 512 | + $logger = static::getLogger(); |
|
| 513 | + require_once $libraryFilePath; |
|
| 514 | + if (class_exists($class)){ |
|
| 515 | + $c = $params ? new $class($params) : new $class(); |
|
| 516 | + $obj = & get_instance(); |
|
| 517 | + $obj->{$instance} = $c; |
|
| 518 | + static::$loaded[$instance] = $class; |
|
| 519 | + $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
|
| 520 | + } |
|
| 521 | + else{ |
|
| 522 | + show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class); |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + else{ |
|
| 526 | + show_error('Unable to find library class [' . $class . ']'); |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | 529 | |
| 530 | - /** |
|
| 531 | - * Load the language |
|
| 532 | - * @param string $languageFilePath the file path of the language to load |
|
| 533 | - * @param string $language the language name |
|
| 534 | - * @return void |
|
| 535 | - */ |
|
| 536 | - protected static function loadLanguage($languageFilePath, $language){ |
|
| 537 | - if ($languageFilePath){ |
|
| 538 | - $logger = static::getLogger(); |
|
| 539 | - $lang = array(); |
|
| 540 | - require_once $languageFilePath; |
|
| 541 | - if (! empty($lang) && is_array($lang)){ |
|
| 542 | - $logger->info('Language file [' .$languageFilePath. '] contains the valid languages keys add them to language list'); |
|
| 543 | - //Note: may be here the class 'Lang' not yet loaded |
|
| 544 | - $langObj =& class_loader('Lang', 'classes'); |
|
| 545 | - $langObj->addLangMessages($lang); |
|
| 546 | - //free the memory |
|
| 547 | - unset($lang); |
|
| 548 | - } |
|
| 549 | - static::$loaded['lang_' . $language] = $languageFilePath; |
|
| 550 | - $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
|
| 551 | - } |
|
| 552 | - else{ |
|
| 553 | - show_error('Unable to find language [' . $language . ']'); |
|
| 554 | - } |
|
| 555 | - } |
|
| 530 | + /** |
|
| 531 | + * Load the language |
|
| 532 | + * @param string $languageFilePath the file path of the language to load |
|
| 533 | + * @param string $language the language name |
|
| 534 | + * @return void |
|
| 535 | + */ |
|
| 536 | + protected static function loadLanguage($languageFilePath, $language){ |
|
| 537 | + if ($languageFilePath){ |
|
| 538 | + $logger = static::getLogger(); |
|
| 539 | + $lang = array(); |
|
| 540 | + require_once $languageFilePath; |
|
| 541 | + if (! empty($lang) && is_array($lang)){ |
|
| 542 | + $logger->info('Language file [' .$languageFilePath. '] contains the valid languages keys add them to language list'); |
|
| 543 | + //Note: may be here the class 'Lang' not yet loaded |
|
| 544 | + $langObj =& class_loader('Lang', 'classes'); |
|
| 545 | + $langObj->addLangMessages($lang); |
|
| 546 | + //free the memory |
|
| 547 | + unset($lang); |
|
| 548 | + } |
|
| 549 | + static::$loaded['lang_' . $language] = $languageFilePath; |
|
| 550 | + $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
|
| 551 | + } |
|
| 552 | + else{ |
|
| 553 | + show_error('Unable to find language [' . $language . ']'); |
|
| 554 | + } |
|
| 555 | + } |
|
| 556 | 556 | |
| 557 | - /** |
|
| 558 | - * Get all the autoload using the configuration file |
|
| 559 | - * @return array |
|
| 560 | - */ |
|
| 561 | - private function getResourcesFromAutoloadConfig(){ |
|
| 562 | - $autoloads = array(); |
|
| 563 | - $autoloads['config'] = array(); |
|
| 564 | - $autoloads['languages'] = array(); |
|
| 565 | - $autoloads['libraries'] = array(); |
|
| 566 | - $autoloads['models'] = array(); |
|
| 567 | - $autoloads['functions'] = array(); |
|
| 568 | - //loading of the resources from autoload configuration file |
|
| 569 | - if (file_exists(CONFIG_PATH . 'autoload.php')){ |
|
| 570 | - $autoload = array(); |
|
| 571 | - require_once CONFIG_PATH . 'autoload.php'; |
|
| 572 | - if (! empty($autoload) && is_array($autoload)){ |
|
| 573 | - $autoloads = array_merge($autoloads, $autoload); |
|
| 574 | - unset($autoload); |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - //loading autoload configuration for modules |
|
| 578 | - $modulesAutoloads = Module::getModulesAutoloadConfig(); |
|
| 579 | - if (! empty($modulesAutoloads) && is_array($modulesAutoloads)){ |
|
| 580 | - $autoloads = array_merge_recursive($autoloads, $modulesAutoloads); |
|
| 581 | - } |
|
| 582 | - return $autoloads; |
|
| 583 | - } |
|
| 557 | + /** |
|
| 558 | + * Get all the autoload using the configuration file |
|
| 559 | + * @return array |
|
| 560 | + */ |
|
| 561 | + private function getResourcesFromAutoloadConfig(){ |
|
| 562 | + $autoloads = array(); |
|
| 563 | + $autoloads['config'] = array(); |
|
| 564 | + $autoloads['languages'] = array(); |
|
| 565 | + $autoloads['libraries'] = array(); |
|
| 566 | + $autoloads['models'] = array(); |
|
| 567 | + $autoloads['functions'] = array(); |
|
| 568 | + //loading of the resources from autoload configuration file |
|
| 569 | + if (file_exists(CONFIG_PATH . 'autoload.php')){ |
|
| 570 | + $autoload = array(); |
|
| 571 | + require_once CONFIG_PATH . 'autoload.php'; |
|
| 572 | + if (! empty($autoload) && is_array($autoload)){ |
|
| 573 | + $autoloads = array_merge($autoloads, $autoload); |
|
| 574 | + unset($autoload); |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + //loading autoload configuration for modules |
|
| 578 | + $modulesAutoloads = Module::getModulesAutoloadConfig(); |
|
| 579 | + if (! empty($modulesAutoloads) && is_array($modulesAutoloads)){ |
|
| 580 | + $autoloads = array_merge_recursive($autoloads, $modulesAutoloads); |
|
| 581 | + } |
|
| 582 | + return $autoloads; |
|
| 583 | + } |
|
| 584 | 584 | |
| 585 | - /** |
|
| 586 | - * Load the autoload configuration |
|
| 587 | - * @return void |
|
| 588 | - */ |
|
| 589 | - private function loadResourcesFromAutoloadConfig(){ |
|
| 590 | - $autoloads = array(); |
|
| 591 | - $autoloads['config'] = array(); |
|
| 592 | - $autoloads['languages'] = array(); |
|
| 593 | - $autoloads['libraries'] = array(); |
|
| 594 | - $autoloads['models'] = array(); |
|
| 595 | - $autoloads['functions'] = array(); |
|
| 585 | + /** |
|
| 586 | + * Load the autoload configuration |
|
| 587 | + * @return void |
|
| 588 | + */ |
|
| 589 | + private function loadResourcesFromAutoloadConfig(){ |
|
| 590 | + $autoloads = array(); |
|
| 591 | + $autoloads['config'] = array(); |
|
| 592 | + $autoloads['languages'] = array(); |
|
| 593 | + $autoloads['libraries'] = array(); |
|
| 594 | + $autoloads['models'] = array(); |
|
| 595 | + $autoloads['functions'] = array(); |
|
| 596 | 596 | |
| 597 | - $list = $this->getResourcesFromAutoloadConfig(); |
|
| 598 | - $autoloads = array_merge($autoloads, $list); |
|
| 597 | + $list = $this->getResourcesFromAutoloadConfig(); |
|
| 598 | + $autoloads = array_merge($autoloads, $list); |
|
| 599 | 599 | |
| 600 | - //config autoload |
|
| 601 | - $this->loadAutoloadResourcesArray('config', $autoloads['config']); |
|
| 600 | + //config autoload |
|
| 601 | + $this->loadAutoloadResourcesArray('config', $autoloads['config']); |
|
| 602 | 602 | |
| 603 | - //languages autoload |
|
| 604 | - $this->loadAutoloadResourcesArray('lang', $autoloads['languages']); |
|
| 603 | + //languages autoload |
|
| 604 | + $this->loadAutoloadResourcesArray('lang', $autoloads['languages']); |
|
| 605 | 605 | |
| 606 | - //libraries autoload |
|
| 607 | - $this->loadAutoloadResourcesArray('library', $autoloads['libraries']); |
|
| 606 | + //libraries autoload |
|
| 607 | + $this->loadAutoloadResourcesArray('library', $autoloads['libraries']); |
|
| 608 | 608 | |
| 609 | - //models autoload |
|
| 610 | - $this->loadAutoloadResourcesArray('model', $autoloads['models']); |
|
| 609 | + //models autoload |
|
| 610 | + $this->loadAutoloadResourcesArray('model', $autoloads['models']); |
|
| 611 | 611 | |
| 612 | - //functions autoload |
|
| 613 | - $this->loadAutoloadResourcesArray('functions', $autoloads['functions']); |
|
| 614 | - } |
|
| 612 | + //functions autoload |
|
| 613 | + $this->loadAutoloadResourcesArray('functions', $autoloads['functions']); |
|
| 614 | + } |
|
| 615 | 615 | |
| 616 | - /** |
|
| 617 | - * Load the resources autoload array |
|
| 618 | - * @param string $method this object method name to call |
|
| 619 | - * @param array $resources the resource to load |
|
| 620 | - * @return void |
|
| 621 | - */ |
|
| 622 | - private function loadAutoloadResourcesArray($method, array $resources){ |
|
| 623 | - foreach ($resources as $name) { |
|
| 624 | - $this->{$method}($name); |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - } |
|
| 616 | + /** |
|
| 617 | + * Load the resources autoload array |
|
| 618 | + * @param string $method this object method name to call |
|
| 619 | + * @param array $resources the resource to load |
|
| 620 | + * @return void |
|
| 621 | + */ |
|
| 622 | + private function loadAutoloadResourcesArray($method, array $resources){ |
|
| 623 | + foreach ($resources as $name) { |
|
| 624 | + $this->{$method}($name); |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + } |
|
@@ -23,7 +23,7 @@ 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 Loader extends BaseStaticClass{ |
|
| 26 | + class Loader extends BaseStaticClass { |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * List of loaded resources |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | public static $loaded = array(); |
| 33 | 33 | |
| 34 | 34 | |
| 35 | - public function __construct(){ |
|
| 35 | + public function __construct() { |
|
| 36 | 36 | //add the resources already loaded during application bootstrap |
| 37 | 37 | //in the list to prevent duplicate or loading the resources again. |
| 38 | 38 | static::$loaded = class_loaded(); |
@@ -50,18 +50,18 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @return void |
| 52 | 52 | */ |
| 53 | - public static function model($class, $instance = null){ |
|
| 53 | + public static function model($class, $instance = null) { |
|
| 54 | 54 | $logger = static::getLogger(); |
| 55 | 55 | $class = str_ireplace('.php', '', $class); |
| 56 | 56 | $class = trim($class, '/\\'); |
| 57 | - $file = ucfirst($class).'.php'; |
|
| 57 | + $file = ucfirst($class) . '.php'; |
|
| 58 | 58 | $logger->debug('Loading model [' . $class . '] ...'); |
| 59 | 59 | //************ |
| 60 | - if (! $instance){ |
|
| 60 | + if (!$instance) { |
|
| 61 | 61 | $instance = self::getModelLibraryInstanceName($class); |
| 62 | 62 | } |
| 63 | 63 | //**************** |
| 64 | - if (isset(static::$loaded[$instance])){ |
|
| 64 | + if (isset(static::$loaded[$instance])) { |
|
| 65 | 65 | $logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance'); |
| 66 | 66 | return; |
| 67 | 67 | } |
@@ -74,28 +74,28 @@ discard block |
||
| 74 | 74 | $class = $moduleInfo['class']; |
| 75 | 75 | |
| 76 | 76 | $moduleModelFilePath = Module::findModelFullPath($class, $module); |
| 77 | - if ($moduleModelFilePath){ |
|
| 78 | - $logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it'); |
|
| 77 | + if ($moduleModelFilePath) { |
|
| 78 | + $logger->info('Found model [' . $class . '] from module [' . $module . '], the file path is [' . $moduleModelFilePath . '] we will used it'); |
|
| 79 | 79 | $classFilePath = $moduleModelFilePath; |
| 80 | 80 | } |
| 81 | - else{ |
|
| 81 | + else { |
|
| 82 | 82 | $logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
| 83 | 83 | } |
| 84 | 84 | $logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
| 85 | - if (file_exists($classFilePath)){ |
|
| 85 | + if (file_exists($classFilePath)) { |
|
| 86 | 86 | require_once $classFilePath; |
| 87 | - if (class_exists($class)){ |
|
| 87 | + if (class_exists($class)) { |
|
| 88 | 88 | $c = new $class(); |
| 89 | 89 | $obj = & get_instance(); |
| 90 | 90 | $obj->{$instance} = $c; |
| 91 | 91 | static::$loaded[$instance] = $class; |
| 92 | 92 | $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
| 93 | 93 | } |
| 94 | - else{ |
|
| 95 | - show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']'); |
|
| 94 | + else { |
|
| 95 | + show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']'); |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | - else{ |
|
| 98 | + else { |
|
| 99 | 99 | show_error('Unable to find the model [' . $class . ']'); |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -110,22 +110,22 @@ discard block |
||
| 110 | 110 | * |
| 111 | 111 | * @return void |
| 112 | 112 | */ |
| 113 | - public static function library($class, $instance = null, array $params = array()){ |
|
| 113 | + public static function library($class, $instance = null, array $params = array()) { |
|
| 114 | 114 | $logger = static::getLogger(); |
| 115 | 115 | $class = str_ireplace('.php', '', $class); |
| 116 | 116 | $class = trim($class, '/\\'); |
| 117 | - $file = ucfirst($class) .'.php'; |
|
| 117 | + $file = ucfirst($class) . '.php'; |
|
| 118 | 118 | $logger->debug('Loading library [' . $class . '] ...'); |
| 119 | - if (! $instance){ |
|
| 119 | + if (!$instance) { |
|
| 120 | 120 | $instance = self::getModelLibraryInstanceName($class); |
| 121 | 121 | } |
| 122 | - if (isset(static::$loaded[$instance])){ |
|
| 122 | + if (isset(static::$loaded[$instance])) { |
|
| 123 | 123 | $logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance'); |
| 124 | 124 | return; |
| 125 | 125 | } |
| 126 | 126 | $obj = & get_instance(); |
| 127 | 127 | //Check and load Database library |
| 128 | - if (strtolower($class) == 'database'){ |
|
| 128 | + if (strtolower($class) == 'database') { |
|
| 129 | 129 | $logger->info('This is the Database library ...'); |
| 130 | 130 | $obj->{$instance} = & class_loader('Database', 'classes/database', $params); |
| 131 | 131 | static::$loaded[$instance] = $class; |
@@ -134,18 +134,18 @@ discard block |
||
| 134 | 134 | } |
| 135 | 135 | $libraryFilePath = null; |
| 136 | 136 | $logger->debug('Check if this is a system library ...'); |
| 137 | - if (file_exists(CORE_LIBRARY_PATH . $file)){ |
|
| 137 | + if (file_exists(CORE_LIBRARY_PATH . $file)) { |
|
| 138 | 138 | $libraryFilePath = CORE_LIBRARY_PATH . $file; |
| 139 | 139 | $class = ucfirst($class); |
| 140 | 140 | $logger->info('This library is a system library'); |
| 141 | 141 | } |
| 142 | - else{ |
|
| 142 | + else { |
|
| 143 | 143 | $logger->info('This library is not a system library'); |
| 144 | 144 | //first check if this library is in the module |
| 145 | 145 | $libraryFilePath = self::getLibraryPathUsingModuleInfo($class); |
| 146 | 146 | //*************** |
| 147 | 147 | } |
| 148 | - if (! $libraryFilePath && file_exists(LIBRARY_PATH . $file)){ |
|
| 148 | + if (!$libraryFilePath && file_exists(LIBRARY_PATH . $file)) { |
|
| 149 | 149 | $libraryFilePath = LIBRARY_PATH . $file; |
| 150 | 150 | } |
| 151 | 151 | $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']'); |
@@ -160,14 +160,14 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @return void |
| 162 | 162 | */ |
| 163 | - public static function functions($function){ |
|
| 163 | + public static function functions($function) { |
|
| 164 | 164 | $logger = static::getLogger(); |
| 165 | 165 | $function = str_ireplace('.php', '', $function); |
| 166 | 166 | $function = trim($function, '/\\'); |
| 167 | 167 | $function = str_ireplace('function_', '', $function); |
| 168 | - $file = 'function_'.$function.'.php'; |
|
| 168 | + $file = 'function_' . $function . '.php'; |
|
| 169 | 169 | $logger->debug('Loading helper [' . $function . '] ...'); |
| 170 | - if (isset(static::$loaded['function_' . $function])){ |
|
| 170 | + if (isset(static::$loaded['function_' . $function])) { |
|
| 171 | 171 | $logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance'); |
| 172 | 172 | return; |
| 173 | 173 | } |
@@ -177,22 +177,22 @@ discard block |
||
| 177 | 177 | $moduleInfo = self::getModuleInfoForFunction($function); |
| 178 | 178 | $module = $moduleInfo['module']; |
| 179 | 179 | $function = $moduleInfo['function']; |
| 180 | - if(! empty($moduleInfo['file'])){ |
|
| 180 | + if (!empty($moduleInfo['file'])) { |
|
| 181 | 181 | $file = $moduleInfo['file']; |
| 182 | 182 | } |
| 183 | 183 | $moduleFunctionPath = Module::findFunctionFullPath($function, $module); |
| 184 | - if ($moduleFunctionPath){ |
|
| 185 | - $logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it'); |
|
| 184 | + if ($moduleFunctionPath) { |
|
| 185 | + $logger->info('Found helper [' . $function . '] from module [' . $module . '], the file path is [' . $moduleFunctionPath . '] we will used it'); |
|
| 186 | 186 | $functionFilePath = $moduleFunctionPath; |
| 187 | 187 | } |
| 188 | - else{ |
|
| 188 | + else { |
|
| 189 | 189 | $logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
| 190 | 190 | } |
| 191 | - if (! $functionFilePath){ |
|
| 191 | + if (!$functionFilePath) { |
|
| 192 | 192 | $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH); |
| 193 | - foreach($searchDir as $dir){ |
|
| 193 | + foreach ($searchDir as $dir) { |
|
| 194 | 194 | $filePath = $dir . $file; |
| 195 | - if (file_exists($filePath)){ |
|
| 195 | + if (file_exists($filePath)) { |
|
| 196 | 196 | $functionFilePath = $filePath; |
| 197 | 197 | //is already found not to continue |
| 198 | 198 | break; |
@@ -200,12 +200,12 @@ discard block |
||
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']'); |
| 203 | - if ($functionFilePath){ |
|
| 203 | + if ($functionFilePath) { |
|
| 204 | 204 | require_once $functionFilePath; |
| 205 | 205 | static::$loaded['function_' . $function] = $functionFilePath; |
| 206 | 206 | $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
| 207 | 207 | } |
| 208 | - else{ |
|
| 208 | + else { |
|
| 209 | 209 | show_error('Unable to find helper file [' . $file . ']'); |
| 210 | 210 | } |
| 211 | 211 | } |
@@ -217,14 +217,14 @@ discard block |
||
| 217 | 217 | * |
| 218 | 218 | * @return void |
| 219 | 219 | */ |
| 220 | - public static function config($filename){ |
|
| 220 | + public static function config($filename) { |
|
| 221 | 221 | $logger = static::getLogger(); |
| 222 | 222 | $filename = str_ireplace('.php', '', $filename); |
| 223 | 223 | $filename = trim($filename, '/\\'); |
| 224 | 224 | $filename = str_ireplace('config_', '', $filename); |
| 225 | - $file = 'config_'.$filename.'.php'; |
|
| 225 | + $file = 'config_' . $filename . '.php'; |
|
| 226 | 226 | $logger->debug('Loading configuration [' . $filename . '] ...'); |
| 227 | - if (isset(static::$loaded['config_' . $filename])){ |
|
| 227 | + if (isset(static::$loaded['config_' . $filename])) { |
|
| 228 | 228 | $logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance'); |
| 229 | 229 | return; |
| 230 | 230 | } |
@@ -235,18 +235,18 @@ discard block |
||
| 235 | 235 | $module = $moduleInfo['module']; |
| 236 | 236 | $filename = $moduleInfo['filename']; |
| 237 | 237 | $moduleConfigPath = Module::findConfigFullPath($filename, $module); |
| 238 | - if ($moduleConfigPath){ |
|
| 239 | - $logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it'); |
|
| 238 | + if ($moduleConfigPath) { |
|
| 239 | + $logger->info('Found config [' . $filename . '] from module [' . $module . '], the file path is [' . $moduleConfigPath . '] we will used it'); |
|
| 240 | 240 | $configFilePath = $moduleConfigPath; |
| 241 | 241 | } |
| 242 | - else{ |
|
| 242 | + else { |
|
| 243 | 243 | $logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
| 244 | 244 | } |
| 245 | 245 | $logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
| 246 | 246 | $config = array(); |
| 247 | - if (file_exists($configFilePath)){ |
|
| 247 | + if (file_exists($configFilePath)) { |
|
| 248 | 248 | require_once $configFilePath; |
| 249 | - if (! empty($config) && is_array($config)){ |
|
| 249 | + if (!empty($config) && is_array($config)) { |
|
| 250 | 250 | Config::setAll($config); |
| 251 | 251 | static::$loaded['config_' . $filename] = $configFilePath; |
| 252 | 252 | $logger->info('Configuration [' . $configFilePath . '] loaded successfully.'); |
@@ -254,8 +254,8 @@ discard block |
||
| 254 | 254 | unset($config); |
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | - else{ |
|
| 258 | - show_error('Unable to find config file ['. $configFilePath . ']'); |
|
| 257 | + else { |
|
| 258 | + show_error('Unable to find config file [' . $configFilePath . ']'); |
|
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | |
@@ -267,14 +267,14 @@ discard block |
||
| 267 | 267 | * |
| 268 | 268 | * @return void |
| 269 | 269 | */ |
| 270 | - public static function lang($language){ |
|
| 270 | + public static function lang($language) { |
|
| 271 | 271 | $logger = static::getLogger(); |
| 272 | 272 | $language = str_ireplace('.php', '', $language); |
| 273 | 273 | $language = trim($language, '/\\'); |
| 274 | 274 | $language = str_ireplace('lang_', '', $language); |
| 275 | - $file = 'lang_'.$language.'.php'; |
|
| 275 | + $file = 'lang_' . $language . '.php'; |
|
| 276 | 276 | $logger->debug('Loading language [' . $language . '] ...'); |
| 277 | - if (isset(static::$loaded['lang_' . $language])){ |
|
| 277 | + if (isset(static::$loaded['lang_' . $language])) { |
|
| 278 | 278 | $logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance'); |
| 279 | 279 | return; |
| 280 | 280 | } |
@@ -286,22 +286,22 @@ discard block |
||
| 286 | 286 | $moduleInfo = self::getModuleInfoForLanguage($language); |
| 287 | 287 | $module = $moduleInfo['module']; |
| 288 | 288 | $language = $moduleInfo['language']; |
| 289 | - if(! empty($moduleInfo['file'])){ |
|
| 289 | + if (!empty($moduleInfo['file'])) { |
|
| 290 | 290 | $file = $moduleInfo['file']; |
| 291 | 291 | } |
| 292 | 292 | $moduleLanguagePath = Module::findLanguageFullPath($language, $appLang, $module); |
| 293 | - if ($moduleLanguagePath){ |
|
| 294 | - $logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it'); |
|
| 293 | + if ($moduleLanguagePath) { |
|
| 294 | + $logger->info('Found language [' . $language . '] from module [' . $module . '], the file path is [' . $moduleLanguagePath . '] we will used it'); |
|
| 295 | 295 | $languageFilePath = $moduleLanguagePath; |
| 296 | 296 | } |
| 297 | - else{ |
|
| 297 | + else { |
|
| 298 | 298 | $logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
| 299 | 299 | } |
| 300 | - if (! $languageFilePath){ |
|
| 300 | + if (!$languageFilePath) { |
|
| 301 | 301 | $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH); |
| 302 | - foreach($searchDir as $dir){ |
|
| 302 | + foreach ($searchDir as $dir) { |
|
| 303 | 303 | $filePath = $dir . $appLang . DS . $file; |
| 304 | - if (file_exists($filePath)){ |
|
| 304 | + if (file_exists($filePath)) { |
|
| 305 | 305 | $languageFilePath = $filePath; |
| 306 | 306 | //already found no need continue |
| 307 | 307 | break; |
@@ -317,14 +317,14 @@ discard block |
||
| 317 | 317 | * if can not found will use the default value from configuration |
| 318 | 318 | * @return string the app language like "en", "fr" |
| 319 | 319 | */ |
| 320 | - protected static function getAppLang(){ |
|
| 320 | + protected static function getAppLang() { |
|
| 321 | 321 | //determine the current language |
| 322 | 322 | $appLang = get_config('default_language'); |
| 323 | 323 | //if the language exists in the cookie use it |
| 324 | 324 | $cfgKey = get_config('language_cookie_name'); |
| 325 | 325 | $objCookie = & class_loader('Cookie'); |
| 326 | 326 | $cookieLang = $objCookie->get($cfgKey); |
| 327 | - if ($cookieLang){ |
|
| 327 | + if ($cookieLang) { |
|
| 328 | 328 | $appLang = $cookieLang; |
| 329 | 329 | } |
| 330 | 330 | return $appLang; |
@@ -338,20 +338,20 @@ discard block |
||
| 338 | 338 | * 'class' => 'class_name' |
| 339 | 339 | * ) |
| 340 | 340 | */ |
| 341 | - protected static function getModuleInfoForModelLibrary($class){ |
|
| 341 | + protected static function getModuleInfoForModelLibrary($class) { |
|
| 342 | 342 | $module = null; |
| 343 | 343 | $obj = & get_instance(); |
| 344 | - if (strpos($class, '/') !== false){ |
|
| 344 | + if (strpos($class, '/') !== false) { |
|
| 345 | 345 | $path = explode('/', $class); |
| 346 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
| 346 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
| 347 | 347 | $module = $path[0]; |
| 348 | 348 | $class = ucfirst($path[1]); |
| 349 | 349 | } |
| 350 | 350 | } |
| 351 | - else{ |
|
| 351 | + else { |
|
| 352 | 352 | $class = ucfirst($class); |
| 353 | 353 | } |
| 354 | - if (! $module && !empty($obj->moduleName)){ |
|
| 354 | + if (!$module && !empty($obj->moduleName)) { |
|
| 355 | 355 | $module = $obj->moduleName; |
| 356 | 356 | } |
| 357 | 357 | return array( |
@@ -370,20 +370,20 @@ discard block |
||
| 370 | 370 | * 'file' => 'file' |
| 371 | 371 | * ) |
| 372 | 372 | */ |
| 373 | - protected static function getModuleInfoForFunction($function){ |
|
| 373 | + protected static function getModuleInfoForFunction($function) { |
|
| 374 | 374 | $module = null; |
| 375 | 375 | $file = null; |
| 376 | 376 | $obj = & get_instance(); |
| 377 | 377 | //check if the request class contains module name |
| 378 | - if (strpos($function, '/') !== false){ |
|
| 378 | + if (strpos($function, '/') !== false) { |
|
| 379 | 379 | $path = explode('/', $function); |
| 380 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
| 380 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
| 381 | 381 | $module = $path[0]; |
| 382 | 382 | $function = 'function_' . $path[1]; |
| 383 | - $file = $path[0] . DS . $function.'.php'; |
|
| 383 | + $file = $path[0] . DS . $function . '.php'; |
|
| 384 | 384 | } |
| 385 | 385 | } |
| 386 | - if (! $module && !empty($obj->moduleName)){ |
|
| 386 | + if (!$module && !empty($obj->moduleName)) { |
|
| 387 | 387 | $module = $obj->moduleName; |
| 388 | 388 | } |
| 389 | 389 | return array( |
@@ -403,20 +403,20 @@ discard block |
||
| 403 | 403 | * 'file' => 'file' |
| 404 | 404 | * ) |
| 405 | 405 | */ |
| 406 | - protected static function getModuleInfoForLanguage($language){ |
|
| 406 | + protected static function getModuleInfoForLanguage($language) { |
|
| 407 | 407 | $module = null; |
| 408 | 408 | $file = null; |
| 409 | 409 | $obj = & get_instance(); |
| 410 | 410 | //check if the request class contains module name |
| 411 | - if (strpos($language, '/') !== false){ |
|
| 411 | + if (strpos($language, '/') !== false) { |
|
| 412 | 412 | $path = explode('/', $language); |
| 413 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
| 413 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
| 414 | 414 | $module = $path[0]; |
| 415 | 415 | $language = 'lang_' . $path[1] . '.php'; |
| 416 | - $file = $path[0] . DS .$language; |
|
| 416 | + $file = $path[0] . DS . $language; |
|
| 417 | 417 | } |
| 418 | 418 | } |
| 419 | - if (! $module && !empty($obj->moduleName)){ |
|
| 419 | + if (!$module && !empty($obj->moduleName)) { |
|
| 420 | 420 | $module = $obj->moduleName; |
| 421 | 421 | } |
| 422 | 422 | return array( |
@@ -436,18 +436,18 @@ discard block |
||
| 436 | 436 | * 'filename' => 'filename' |
| 437 | 437 | * ) |
| 438 | 438 | */ |
| 439 | - protected static function getModuleInfoForConfig($filename){ |
|
| 439 | + protected static function getModuleInfoForConfig($filename) { |
|
| 440 | 440 | $module = null; |
| 441 | 441 | $obj = & get_instance(); |
| 442 | 442 | //check if the request class contains module name |
| 443 | - if (strpos($filename, '/') !== false){ |
|
| 443 | + if (strpos($filename, '/') !== false) { |
|
| 444 | 444 | $path = explode('/', $filename); |
| 445 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
| 445 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
| 446 | 446 | $module = $path[0]; |
| 447 | 447 | $filename = $path[1] . '.php'; |
| 448 | 448 | } |
| 449 | 449 | } |
| 450 | - if (! $module && !empty($obj->moduleName)){ |
|
| 450 | + if (!$module && !empty($obj->moduleName)) { |
|
| 451 | 451 | $module = $obj->moduleName; |
| 452 | 452 | } |
| 453 | 453 | return array( |
@@ -461,16 +461,16 @@ discard block |
||
| 461 | 461 | * @param string $class the class name to determine the instance |
| 462 | 462 | * @return string the instance name |
| 463 | 463 | */ |
| 464 | - protected static function getModelLibraryInstanceName($class){ |
|
| 464 | + protected static function getModelLibraryInstanceName($class) { |
|
| 465 | 465 | //for module |
| 466 | 466 | $instance = null; |
| 467 | - if (strpos($class, '/') !== false){ |
|
| 467 | + if (strpos($class, '/') !== false) { |
|
| 468 | 468 | $path = explode('/', $class); |
| 469 | - if (isset($path[1])){ |
|
| 469 | + if (isset($path[1])) { |
|
| 470 | 470 | $instance = strtolower($path[1]); |
| 471 | 471 | } |
| 472 | 472 | } |
| 473 | - else{ |
|
| 473 | + else { |
|
| 474 | 474 | $instance = strtolower($class); |
| 475 | 475 | } |
| 476 | 476 | return $instance; |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | * @param string $class the class name |
| 482 | 482 | * @return string|null the library file path otherwise null will be returned |
| 483 | 483 | */ |
| 484 | - protected static function getLibraryPathUsingModuleInfo($class){ |
|
| 484 | + protected static function getLibraryPathUsingModuleInfo($class) { |
|
| 485 | 485 | $logger = static::getLogger(); |
| 486 | 486 | $libraryFilePath = null; |
| 487 | 487 | $logger->debug('Checking library [' . $class . '] from module list ...'); |
@@ -489,11 +489,11 @@ discard block |
||
| 489 | 489 | $module = $moduleInfo['module']; |
| 490 | 490 | $class = $moduleInfo['class']; |
| 491 | 491 | $moduleLibraryPath = Module::findLibraryFullPath($class, $module); |
| 492 | - if ($moduleLibraryPath){ |
|
| 493 | - $logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it'); |
|
| 492 | + if ($moduleLibraryPath) { |
|
| 493 | + $logger->info('Found library [' . $class . '] from module [' . $module . '], the file path is [' . $moduleLibraryPath . '] we will used it'); |
|
| 494 | 494 | $libraryFilePath = $moduleLibraryPath; |
| 495 | 495 | } |
| 496 | - else{ |
|
| 496 | + else { |
|
| 497 | 497 | $logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
| 498 | 498 | } |
| 499 | 499 | return $libraryFilePath; |
@@ -507,22 +507,22 @@ discard block |
||
| 507 | 507 | * @param array $params the parameter to use |
| 508 | 508 | * @return void |
| 509 | 509 | */ |
| 510 | - protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()){ |
|
| 511 | - if ($libraryFilePath){ |
|
| 510 | + protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()) { |
|
| 511 | + if ($libraryFilePath) { |
|
| 512 | 512 | $logger = static::getLogger(); |
| 513 | 513 | require_once $libraryFilePath; |
| 514 | - if (class_exists($class)){ |
|
| 514 | + if (class_exists($class)) { |
|
| 515 | 515 | $c = $params ? new $class($params) : new $class(); |
| 516 | 516 | $obj = & get_instance(); |
| 517 | 517 | $obj->{$instance} = $c; |
| 518 | 518 | static::$loaded[$instance] = $class; |
| 519 | 519 | $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
| 520 | 520 | } |
| 521 | - else{ |
|
| 522 | - show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class); |
|
| 521 | + else { |
|
| 522 | + show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class); |
|
| 523 | 523 | } |
| 524 | 524 | } |
| 525 | - else{ |
|
| 525 | + else { |
|
| 526 | 526 | show_error('Unable to find library class [' . $class . ']'); |
| 527 | 527 | } |
| 528 | 528 | } |
@@ -533,15 +533,15 @@ discard block |
||
| 533 | 533 | * @param string $language the language name |
| 534 | 534 | * @return void |
| 535 | 535 | */ |
| 536 | - protected static function loadLanguage($languageFilePath, $language){ |
|
| 537 | - if ($languageFilePath){ |
|
| 536 | + protected static function loadLanguage($languageFilePath, $language) { |
|
| 537 | + if ($languageFilePath) { |
|
| 538 | 538 | $logger = static::getLogger(); |
| 539 | 539 | $lang = array(); |
| 540 | 540 | require_once $languageFilePath; |
| 541 | - if (! empty($lang) && is_array($lang)){ |
|
| 542 | - $logger->info('Language file [' .$languageFilePath. '] contains the valid languages keys add them to language list'); |
|
| 541 | + if (!empty($lang) && is_array($lang)) { |
|
| 542 | + $logger->info('Language file [' . $languageFilePath . '] contains the valid languages keys add them to language list'); |
|
| 543 | 543 | //Note: may be here the class 'Lang' not yet loaded |
| 544 | - $langObj =& class_loader('Lang', 'classes'); |
|
| 544 | + $langObj = & class_loader('Lang', 'classes'); |
|
| 545 | 545 | $langObj->addLangMessages($lang); |
| 546 | 546 | //free the memory |
| 547 | 547 | unset($lang); |
@@ -549,7 +549,7 @@ discard block |
||
| 549 | 549 | static::$loaded['lang_' . $language] = $languageFilePath; |
| 550 | 550 | $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
| 551 | 551 | } |
| 552 | - else{ |
|
| 552 | + else { |
|
| 553 | 553 | show_error('Unable to find language [' . $language . ']'); |
| 554 | 554 | } |
| 555 | 555 | } |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | * Get all the autoload using the configuration file |
| 559 | 559 | * @return array |
| 560 | 560 | */ |
| 561 | - private function getResourcesFromAutoloadConfig(){ |
|
| 561 | + private function getResourcesFromAutoloadConfig() { |
|
| 562 | 562 | $autoloads = array(); |
| 563 | 563 | $autoloads['config'] = array(); |
| 564 | 564 | $autoloads['languages'] = array(); |
@@ -566,17 +566,17 @@ discard block |
||
| 566 | 566 | $autoloads['models'] = array(); |
| 567 | 567 | $autoloads['functions'] = array(); |
| 568 | 568 | //loading of the resources from autoload configuration file |
| 569 | - if (file_exists(CONFIG_PATH . 'autoload.php')){ |
|
| 569 | + if (file_exists(CONFIG_PATH . 'autoload.php')) { |
|
| 570 | 570 | $autoload = array(); |
| 571 | 571 | require_once CONFIG_PATH . 'autoload.php'; |
| 572 | - if (! empty($autoload) && is_array($autoload)){ |
|
| 572 | + if (!empty($autoload) && is_array($autoload)) { |
|
| 573 | 573 | $autoloads = array_merge($autoloads, $autoload); |
| 574 | 574 | unset($autoload); |
| 575 | 575 | } |
| 576 | 576 | } |
| 577 | 577 | //loading autoload configuration for modules |
| 578 | 578 | $modulesAutoloads = Module::getModulesAutoloadConfig(); |
| 579 | - if (! empty($modulesAutoloads) && is_array($modulesAutoloads)){ |
|
| 579 | + if (!empty($modulesAutoloads) && is_array($modulesAutoloads)) { |
|
| 580 | 580 | $autoloads = array_merge_recursive($autoloads, $modulesAutoloads); |
| 581 | 581 | } |
| 582 | 582 | return $autoloads; |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | * Load the autoload configuration |
| 587 | 587 | * @return void |
| 588 | 588 | */ |
| 589 | - private function loadResourcesFromAutoloadConfig(){ |
|
| 589 | + private function loadResourcesFromAutoloadConfig() { |
|
| 590 | 590 | $autoloads = array(); |
| 591 | 591 | $autoloads['config'] = array(); |
| 592 | 592 | $autoloads['languages'] = array(); |
@@ -619,7 +619,7 @@ discard block |
||
| 619 | 619 | * @param array $resources the resource to load |
| 620 | 620 | * @return void |
| 621 | 621 | */ |
| 622 | - private function loadAutoloadResourcesArray($method, array $resources){ |
|
| 622 | + private function loadAutoloadResourcesArray($method, array $resources) { |
|
| 623 | 623 | foreach ($resources as $name) { |
| 624 | 624 | $this->{$method}($name); |
| 625 | 625 | } |
@@ -1,337 +1,337 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework created using the concept of codeigniter with bootstrap twitter |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework created using the concept of codeigniter with bootstrap twitter |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * This file contains the main configuration of your application |
|
| 29 | - * web address, front controller, error logging, session parameters, CSRF, Cache, |
|
| 30 | - * Whitelist IP access, etc. |
|
| 31 | - */ |
|
| 27 | + /** |
|
| 28 | + * This file contains the main configuration of your application |
|
| 29 | + * web address, front controller, error logging, session parameters, CSRF, Cache, |
|
| 30 | + * Whitelist IP access, etc. |
|
| 31 | + */ |
|
| 32 | 32 | |
| 33 | - /*+---------------------------------------------------------------+ |
|
| 33 | + /*+---------------------------------------------------------------+ |
|
| 34 | 34 | * Basic configuration section |
| 35 | 35 | +------------------------------------------------------------------+ |
| 36 | 36 | */ |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * The web address of your application. |
|
| 40 | - * |
|
| 41 | - * The address of your application or website terminated by a slash. |
|
| 42 | - * You can use a domain name or IP address, for example: |
|
| 43 | - * |
|
| 44 | - * $config['base_url'] = 'http://www.mysite.com'; |
|
| 45 | - * or |
|
| 46 | - * $config['base_url'] = 'http://198.15.25.12'; |
|
| 47 | - * |
|
| 48 | - * If this value is empty, we try to determine it automatically by using |
|
| 49 | - * the server variables "SERVER_ADDR" or "SCRIPT_NAME", |
|
| 50 | - * we recommend that you specify this value for a server in production this may reduce the performance of your application. |
|
| 51 | - */ |
|
| 52 | - $config['base_url'] = ''; |
|
| 38 | + /** |
|
| 39 | + * The web address of your application. |
|
| 40 | + * |
|
| 41 | + * The address of your application or website terminated by a slash. |
|
| 42 | + * You can use a domain name or IP address, for example: |
|
| 43 | + * |
|
| 44 | + * $config['base_url'] = 'http://www.mysite.com'; |
|
| 45 | + * or |
|
| 46 | + * $config['base_url'] = 'http://198.15.25.12'; |
|
| 47 | + * |
|
| 48 | + * If this value is empty, we try to determine it automatically by using |
|
| 49 | + * the server variables "SERVER_ADDR" or "SCRIPT_NAME", |
|
| 50 | + * we recommend that you specify this value for a server in production this may reduce the performance of your application. |
|
| 51 | + */ |
|
| 52 | + $config['base_url'] = ''; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * The front controller |
|
| 56 | - * |
|
| 57 | - * This represents the name of the file called by the application during the loading |
|
| 58 | - * process generally the file "index.php". |
|
| 59 | - * If your webserver supports the url rewrite module, then you can leave this value empty. |
|
| 60 | - * You will find a sample file to hide this file in the url inside the root folder of your |
|
| 61 | - * application "htaccess.txt" for the apache web server just rename it to ".htaccess" |
|
| 62 | - * |
|
| 63 | - * Without the rewrite module url enabled, leave this value to "index.php", in this case your urls look like: |
|
| 64 | - * |
|
| 65 | - * http://www.yoursite.com/index.php/controller/method |
|
| 66 | - * |
|
| 67 | - * otherwise if the module is available and activated you can put this value empty and your urls look like: |
|
| 68 | - * |
|
| 69 | - * http://www.yoursite.com/controller/method |
|
| 70 | - * |
|
| 71 | - */ |
|
| 72 | - $config['front_controller'] = 'index.php'; |
|
| 54 | + /** |
|
| 55 | + * The front controller |
|
| 56 | + * |
|
| 57 | + * This represents the name of the file called by the application during the loading |
|
| 58 | + * process generally the file "index.php". |
|
| 59 | + * If your webserver supports the url rewrite module, then you can leave this value empty. |
|
| 60 | + * You will find a sample file to hide this file in the url inside the root folder of your |
|
| 61 | + * application "htaccess.txt" for the apache web server just rename it to ".htaccess" |
|
| 62 | + * |
|
| 63 | + * Without the rewrite module url enabled, leave this value to "index.php", in this case your urls look like: |
|
| 64 | + * |
|
| 65 | + * http://www.yoursite.com/index.php/controller/method |
|
| 66 | + * |
|
| 67 | + * otherwise if the module is available and activated you can put this value empty and your urls look like: |
|
| 68 | + * |
|
| 69 | + * http://www.yoursite.com/controller/method |
|
| 70 | + * |
|
| 71 | + */ |
|
| 72 | + $config['front_controller'] = 'index.php'; |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Url suffix |
|
| 76 | - */ |
|
| 77 | - $config['url_suffix'] = ''; |
|
| 74 | + /** |
|
| 75 | + * Url suffix |
|
| 76 | + */ |
|
| 77 | + $config['url_suffix'] = ''; |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * site charset |
|
| 81 | - */ |
|
| 82 | - $config['charset'] = 'UTF-8'; |
|
| 79 | + /** |
|
| 80 | + * site charset |
|
| 81 | + */ |
|
| 82 | + $config['charset'] = 'UTF-8'; |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Compress the output before send to browser |
|
| 86 | - * |
|
| 87 | - * Enables Gzip output compression for faster page loads. When enabled, |
|
| 88 | - * the Response class will test whether your server supports Gzip. |
|
| 89 | - * Even if it does, however, not all browsers support compression |
|
| 90 | - * so enable only if you are reasonably sure your visitors can handle it. |
|
| 91 | - * |
|
| 92 | - * This is only used if "zlib.output_compression" is turned off in your php configuration. |
|
| 93 | - * Please do not use it together with httpd-level output compression. |
|
| 94 | - * |
|
| 95 | - * IMPORTANT NOTE: If you are getting a blank page when compression is enabled it |
|
| 96 | - * means you are prematurely outputting something to your browser. It could |
|
| 97 | - * even be a line of whitespace at the end of one of your scripts. For |
|
| 98 | - * compression to work, nothing can be sent before the output buffer is called |
|
| 99 | - * by the Response class. Do not 'echo' any values with compression enabled. |
|
| 100 | - */ |
|
| 101 | - $config['compress_output'] = false; |
|
| 84 | + /** |
|
| 85 | + * Compress the output before send to browser |
|
| 86 | + * |
|
| 87 | + * Enables Gzip output compression for faster page loads. When enabled, |
|
| 88 | + * the Response class will test whether your server supports Gzip. |
|
| 89 | + * Even if it does, however, not all browsers support compression |
|
| 90 | + * so enable only if you are reasonably sure your visitors can handle it. |
|
| 91 | + * |
|
| 92 | + * This is only used if "zlib.output_compression" is turned off in your php configuration. |
|
| 93 | + * Please do not use it together with httpd-level output compression. |
|
| 94 | + * |
|
| 95 | + * IMPORTANT NOTE: If you are getting a blank page when compression is enabled it |
|
| 96 | + * means you are prematurely outputting something to your browser. It could |
|
| 97 | + * even be a line of whitespace at the end of one of your scripts. For |
|
| 98 | + * compression to work, nothing can be sent before the output buffer is called |
|
| 99 | + * by the Response class. Do not 'echo' any values with compression enabled. |
|
| 100 | + */ |
|
| 101 | + $config['compress_output'] = false; |
|
| 102 | 102 | |
| 103 | - /*+---------------------------------------------------------------+ |
|
| 103 | + /*+---------------------------------------------------------------+ |
|
| 104 | 104 | * Language configuration section |
| 105 | 105 | +------------------------------------------------------------------+ |
| 106 | 106 | */ |
| 107 | - /** |
|
| 108 | - * list of available supported language |
|
| 109 | - * array( |
|
| 110 | - * 'lang_key' => 'human readable' |
|
| 111 | - * ) |
|
| 112 | - */ |
|
| 113 | - $config['languages'] = array('en' => 'english'); |
|
| 107 | + /** |
|
| 108 | + * list of available supported language |
|
| 109 | + * array( |
|
| 110 | + * 'lang_key' => 'human readable' |
|
| 111 | + * ) |
|
| 112 | + */ |
|
| 113 | + $config['languages'] = array('en' => 'english'); |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * the default language to use if can not find the client language |
|
| 117 | - * need match with the array key of the supported languages |
|
| 118 | - */ |
|
| 119 | - $config['default_language'] = 'en'; //en = english, fr = french |
|
| 115 | + /** |
|
| 116 | + * the default language to use if can not find the client language |
|
| 117 | + * need match with the array key of the supported languages |
|
| 118 | + */ |
|
| 119 | + $config['default_language'] = 'en'; //en = english, fr = french |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * the name of cookie used to store the client language |
|
| 123 | - */ |
|
| 124 | - $config['language_cookie_name'] = 'cookie_lang'; |
|
| 121 | + /** |
|
| 122 | + * the name of cookie used to store the client language |
|
| 123 | + */ |
|
| 124 | + $config['language_cookie_name'] = 'cookie_lang'; |
|
| 125 | 125 | |
| 126 | 126 | |
| 127 | - /*+---------------------------------------------------------------+ |
|
| 127 | + /*+---------------------------------------------------------------+ |
|
| 128 | 128 | * Logs configuration section |
| 129 | 129 | +------------------------------------------------------------------+ |
| 130 | 130 | */ |
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * The log level |
|
| 134 | - * |
|
| 135 | - * The valid level are: OFF, NONE, FATAL, ERROR, WARNING, WARN, INFO, DEBUG, ALL |
|
| 136 | - * |
|
| 137 | - * 'OFF' or 'NONE' = do not save log |
|
| 138 | - * 'FATAL' = enable log for fatal level and above (FATAL) |
|
| 139 | - * 'ERROR' = enable log for error level and above (ERROR, FATAL) |
|
| 140 | - * 'WARNING' or WARN = enable log for warning level and above (WARNING, ERROR, FATAL) |
|
| 141 | - * 'INFO' = enable log for info level and above (INFO, WARNING, ERROR, FATAL) |
|
| 142 | - * 'DEBUG' = enable log for debug level and above (DEBUG, INFO, WARNING, ERROR, FATAL) |
|
| 143 | - * 'ALL' = enable log for all level |
|
| 144 | - * |
|
| 145 | - * The default value is NONE if the config value is: null, '', 0, false |
|
| 146 | - * |
|
| 147 | - * Note: in production environment it's recommand to set the log level to 'WARNING' if not in small |
|
| 148 | - * of time the log file size will increase very fast and will cost the application performance |
|
| 149 | - * and also the filesystem usage of your server. |
|
| 150 | - */ |
|
| 151 | - $config['log_level'] = 'NONE'; |
|
| 132 | + /** |
|
| 133 | + * The log level |
|
| 134 | + * |
|
| 135 | + * The valid level are: OFF, NONE, FATAL, ERROR, WARNING, WARN, INFO, DEBUG, ALL |
|
| 136 | + * |
|
| 137 | + * 'OFF' or 'NONE' = do not save log |
|
| 138 | + * 'FATAL' = enable log for fatal level and above (FATAL) |
|
| 139 | + * 'ERROR' = enable log for error level and above (ERROR, FATAL) |
|
| 140 | + * 'WARNING' or WARN = enable log for warning level and above (WARNING, ERROR, FATAL) |
|
| 141 | + * 'INFO' = enable log for info level and above (INFO, WARNING, ERROR, FATAL) |
|
| 142 | + * 'DEBUG' = enable log for debug level and above (DEBUG, INFO, WARNING, ERROR, FATAL) |
|
| 143 | + * 'ALL' = enable log for all level |
|
| 144 | + * |
|
| 145 | + * The default value is NONE if the config value is: null, '', 0, false |
|
| 146 | + * |
|
| 147 | + * Note: in production environment it's recommand to set the log level to 'WARNING' if not in small |
|
| 148 | + * of time the log file size will increase very fast and will cost the application performance |
|
| 149 | + * and also the filesystem usage of your server. |
|
| 150 | + */ |
|
| 151 | + $config['log_level'] = 'NONE'; |
|
| 152 | 152 | |
| 153 | 153 | |
| 154 | - /** |
|
| 155 | - * The path to log directory |
|
| 156 | - * |
|
| 157 | - * The path that the log data will be saved ending with de "/" or "\", leave empty if you |
|
| 158 | - * want use the default configuration |
|
| 159 | - * warning : if set, this directory must exist and will be writable and owned by the web server |
|
| 160 | - * else the default value will be used i.e the constant LOG_PATH |
|
| 161 | - * for security raison this directory must be outside of the document root of your |
|
| 162 | - * website. |
|
| 163 | - */ |
|
| 164 | - $config['log_save_path'] = ''; |
|
| 154 | + /** |
|
| 155 | + * The path to log directory |
|
| 156 | + * |
|
| 157 | + * The path that the log data will be saved ending with de "/" or "\", leave empty if you |
|
| 158 | + * want use the default configuration |
|
| 159 | + * warning : if set, this directory must exist and will be writable and owned by the web server |
|
| 160 | + * else the default value will be used i.e the constant LOG_PATH |
|
| 161 | + * for security raison this directory must be outside of the document root of your |
|
| 162 | + * website. |
|
| 163 | + */ |
|
| 164 | + $config['log_save_path'] = ''; |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * The logger name to use for the log |
|
| 168 | - * |
|
| 169 | - * If this config is set so means only log message with this or these logger(s) will be saved |
|
| 170 | - * |
|
| 171 | - * Example: |
|
| 172 | - * $config['log_logger_name'] = array('MY_LOGGER1', 'MY_LOGGER2'); //only log message with MY_LOGGER1 or MY_LOGGER2 will be saved in file. |
|
| 173 | - */ |
|
| 174 | - $config['log_logger_name'] = array(); |
|
| 166 | + /** |
|
| 167 | + * The logger name to use for the log |
|
| 168 | + * |
|
| 169 | + * If this config is set so means only log message with this or these logger(s) will be saved |
|
| 170 | + * |
|
| 171 | + * Example: |
|
| 172 | + * $config['log_logger_name'] = array('MY_LOGGER1', 'MY_LOGGER2'); //only log message with MY_LOGGER1 or MY_LOGGER2 will be saved in file. |
|
| 173 | + */ |
|
| 174 | + $config['log_logger_name'] = array(); |
|
| 175 | 175 | |
| 176 | 176 | |
| 177 | - /*+---------------------------------------------------------------+ |
|
| 177 | + /*+---------------------------------------------------------------+ |
|
| 178 | 178 | * Session configuration section |
| 179 | 179 | +------------------------------------------------------------------+ |
| 180 | 180 | */ |
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * The session name |
|
| 184 | - * |
|
| 185 | - * By default is PHPSESSID. this must be alpha-numerical characters |
|
| 186 | - */ |
|
| 187 | - $config['session_name'] = 'PHPSESSID'; |
|
| 182 | + /** |
|
| 183 | + * The session name |
|
| 184 | + * |
|
| 185 | + * By default is PHPSESSID. this must be alpha-numerical characters |
|
| 186 | + */ |
|
| 187 | + $config['session_name'] = 'PHPSESSID'; |
|
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * Session save path |
|
| 191 | - * |
|
| 192 | - * The path that the session data will be saved, leave empty if you |
|
| 193 | - * want use the default configuration in the php.ini |
|
| 194 | - * warning : if set, this directory must exist and will be writable and owned by the web server |
|
| 195 | - * for security raison this directory must be outside of the document root of your |
|
| 196 | - * website. |
|
| 197 | - * Note: if the session handler is "database" the session_save_path is the model name to use |
|
| 198 | - */ |
|
| 199 | - $config['session_save_path'] = ''; |
|
| 189 | + /** |
|
| 190 | + * Session save path |
|
| 191 | + * |
|
| 192 | + * The path that the session data will be saved, leave empty if you |
|
| 193 | + * want use the default configuration in the php.ini |
|
| 194 | + * warning : if set, this directory must exist and will be writable and owned by the web server |
|
| 195 | + * for security raison this directory must be outside of the document root of your |
|
| 196 | + * website. |
|
| 197 | + * Note: if the session handler is "database" the session_save_path is the model name to use |
|
| 198 | + */ |
|
| 199 | + $config['session_save_path'] = ''; |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Session handler |
|
| 203 | - * |
|
| 204 | - * The session handler that we will use to manage the session. |
|
| 205 | - * currently the possible values are "files", "database". |
|
| 206 | - */ |
|
| 207 | - $config['session_handler'] = 'files'; |
|
| 201 | + /** |
|
| 202 | + * Session handler |
|
| 203 | + * |
|
| 204 | + * The session handler that we will use to manage the session. |
|
| 205 | + * currently the possible values are "files", "database". |
|
| 206 | + */ |
|
| 207 | + $config['session_handler'] = 'files'; |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Session secret |
|
| 211 | - * |
|
| 212 | - * This is used to hash the session data if the config "session_handler" is set to "database" |
|
| 213 | - * warning : do not change this value until you already set |
|
| 214 | - * for security raison use the very complicated value include $%)@^&^\''\'\' |
|
| 215 | - * NOTE: this value is an base64 so you need use the tool that generate it, like |
|
| 216 | - * PHP function base64_encode() |
|
| 217 | - */ |
|
| 218 | - $config['session_secret'] = ''; |
|
| 209 | + /** |
|
| 210 | + * Session secret |
|
| 211 | + * |
|
| 212 | + * This is used to hash the session data if the config "session_handler" is set to "database" |
|
| 213 | + * warning : do not change this value until you already set |
|
| 214 | + * for security raison use the very complicated value include $%)@^&^\''\'\' |
|
| 215 | + * NOTE: this value is an base64 so you need use the tool that generate it, like |
|
| 216 | + * PHP function base64_encode() |
|
| 217 | + */ |
|
| 218 | + $config['session_secret'] = ''; |
|
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * number of second that consider the session already expire |
|
| 222 | - */ |
|
| 223 | - $config['session_inactivity_time'] = 600; //in second |
|
| 220 | + /** |
|
| 221 | + * number of second that consider the session already expire |
|
| 222 | + */ |
|
| 223 | + $config['session_inactivity_time'] = 600; //in second |
|
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * Session cookie lifetime |
|
| 227 | - * |
|
| 228 | - * The cookie lifetime that the session will be dropped in seconds, leave 0 if you want |
|
| 229 | - * the cookie expire after the browser is closed |
|
| 230 | - */ |
|
| 231 | - $config['session_cookie_lifetime'] = 0; |
|
| 225 | + /** |
|
| 226 | + * Session cookie lifetime |
|
| 227 | + * |
|
| 228 | + * The cookie lifetime that the session will be dropped in seconds, leave 0 if you want |
|
| 229 | + * the cookie expire after the browser is closed |
|
| 230 | + */ |
|
| 231 | + $config['session_cookie_lifetime'] = 0; |
|
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * Session cookie path |
|
| 235 | - * |
|
| 236 | - * The path to your website that the cookie is available "/" means all path is available |
|
| 237 | - * example : /mysubdirectory => available in http://www.mysite.com/mysubdirectory |
|
| 238 | - */ |
|
| 239 | - $config['session_cookie_path'] = '/'; |
|
| 233 | + /** |
|
| 234 | + * Session cookie path |
|
| 235 | + * |
|
| 236 | + * The path to your website that the cookie is available "/" means all path is available |
|
| 237 | + * example : /mysubdirectory => available in http://www.mysite.com/mysubdirectory |
|
| 238 | + */ |
|
| 239 | + $config['session_cookie_path'] = '/'; |
|
| 240 | 240 | |
| 241 | - /** |
|
| 242 | - * Session cookie domain |
|
| 243 | - * |
|
| 244 | - * The domain of your website that the cookie is available if you want the cookie is available |
|
| 245 | - * in all your subdomain use this dot before the domain name for example ".mysite.com". |
|
| 246 | - * leave empty if you want use the default configuration |
|
| 247 | - */ |
|
| 248 | - $config['session_cookie_domain'] = ''; |
|
| 241 | + /** |
|
| 242 | + * Session cookie domain |
|
| 243 | + * |
|
| 244 | + * The domain of your website that the cookie is available if you want the cookie is available |
|
| 245 | + * in all your subdomain use this dot before the domain name for example ".mysite.com". |
|
| 246 | + * leave empty if you want use the default configuration |
|
| 247 | + */ |
|
| 248 | + $config['session_cookie_domain'] = ''; |
|
| 249 | 249 | |
| 250 | - /** |
|
| 251 | - * Session cookie secure |
|
| 252 | - * |
|
| 253 | - * If your website use SSL i.e https, you set "true" for this configuration, so the cookie |
|
| 254 | - * is available only if the website use the secure connection else set this value to "false" |
|
| 255 | - */ |
|
| 256 | - $config['session_cookie_secure'] = false; |
|
| 250 | + /** |
|
| 251 | + * Session cookie secure |
|
| 252 | + * |
|
| 253 | + * If your website use SSL i.e https, you set "true" for this configuration, so the cookie |
|
| 254 | + * is available only if the website use the secure connection else set this value to "false" |
|
| 255 | + */ |
|
| 256 | + $config['session_cookie_secure'] = false; |
|
| 257 | 257 | |
| 258 | 258 | |
| 259 | - /*+---------------------------------------------------------------+ |
|
| 259 | + /*+---------------------------------------------------------------+ |
|
| 260 | 260 | * CSRF configuration section |
| 261 | 261 | +------------------------------------------------------------------+ |
| 262 | 262 | */ |
| 263 | 263 | |
| 264 | - /** |
|
| 265 | - * CSRF status |
|
| 266 | - * |
|
| 267 | - * if you would to use the CSRF (that we recommand you), set this key to true |
|
| 268 | - */ |
|
| 269 | - $config['csrf_enable'] = false; |
|
| 264 | + /** |
|
| 265 | + * CSRF status |
|
| 266 | + * |
|
| 267 | + * if you would to use the CSRF (that we recommand you), set this key to true |
|
| 268 | + */ |
|
| 269 | + $config['csrf_enable'] = false; |
|
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * CSRF key |
|
| 273 | - * |
|
| 274 | - * the key used to store the csrf data |
|
| 275 | - */ |
|
| 276 | - $config['csrf_key'] = 'csrf_key'; |
|
| 271 | + /** |
|
| 272 | + * CSRF key |
|
| 273 | + * |
|
| 274 | + * the key used to store the csrf data |
|
| 275 | + */ |
|
| 276 | + $config['csrf_key'] = 'csrf_key'; |
|
| 277 | 277 | |
| 278 | - /** |
|
| 279 | - * CSRF expire |
|
| 280 | - * |
|
| 281 | - * expire time in seconds of the CSRF data |
|
| 282 | - */ |
|
| 283 | - $config['csrf_expire'] = 120; |
|
| 278 | + /** |
|
| 279 | + * CSRF expire |
|
| 280 | + * |
|
| 281 | + * expire time in seconds of the CSRF data |
|
| 282 | + */ |
|
| 283 | + $config['csrf_expire'] = 120; |
|
| 284 | 284 | |
| 285 | 285 | |
| 286 | - /*+---------------------------------------------------------------+ |
|
| 286 | + /*+---------------------------------------------------------------+ |
|
| 287 | 287 | * Cache configuration section |
| 288 | 288 | +------------------------------------------------------------------+ |
| 289 | 289 | */ |
| 290 | 290 | |
| 291 | - /** |
|
| 292 | - * Cache status |
|
| 293 | - * |
|
| 294 | - * If you would to use the cache functionnality set this value to true |
|
| 295 | - */ |
|
| 296 | - $config['cache_enable'] = false; |
|
| 291 | + /** |
|
| 292 | + * Cache status |
|
| 293 | + * |
|
| 294 | + * If you would to use the cache functionnality set this value to true |
|
| 295 | + */ |
|
| 296 | + $config['cache_enable'] = false; |
|
| 297 | 297 | |
| 298 | - /** |
|
| 299 | - * Cache Time To Live |
|
| 300 | - * |
|
| 301 | - * expire time in seconds of the cache data |
|
| 302 | - */ |
|
| 303 | - $config['cache_ttl'] = 120; //in second |
|
| 298 | + /** |
|
| 299 | + * Cache Time To Live |
|
| 300 | + * |
|
| 301 | + * expire time in seconds of the cache data |
|
| 302 | + */ |
|
| 303 | + $config['cache_ttl'] = 120; //in second |
|
| 304 | 304 | |
| 305 | - /** |
|
| 306 | - * Cache handler class |
|
| 307 | - * |
|
| 308 | - * The cache handler class inside (CORE_CLASSES_CACHE_PATH, LIBRARY_PATH) directories that implements |
|
| 309 | - * the interface "CacheInterface" that we will use to manage the cache. |
|
| 310 | - * currently the possible values are "FileCache", "ApcCache". |
|
| 311 | - */ |
|
| 312 | - $config['cache_handler'] = 'FileCache'; |
|
| 305 | + /** |
|
| 306 | + * Cache handler class |
|
| 307 | + * |
|
| 308 | + * The cache handler class inside (CORE_CLASSES_CACHE_PATH, LIBRARY_PATH) directories that implements |
|
| 309 | + * the interface "CacheInterface" that we will use to manage the cache. |
|
| 310 | + * currently the possible values are "FileCache", "ApcCache". |
|
| 311 | + */ |
|
| 312 | + $config['cache_handler'] = 'FileCache'; |
|
| 313 | 313 | |
| 314 | 314 | |
| 315 | - /*+---------------------------------------------------------------+ |
|
| 315 | + /*+---------------------------------------------------------------+ |
|
| 316 | 316 | * White list IP access configuration section |
| 317 | 317 | +------------------------------------------------------------------+ |
| 318 | 318 | */ |
| 319 | 319 | |
| 320 | - /** |
|
| 321 | - * White list ip status |
|
| 322 | - * |
|
| 323 | - * if you would to use the white list ip access, set this key to true |
|
| 324 | - */ |
|
| 325 | - $config['white_list_ip_enable'] = false; |
|
| 320 | + /** |
|
| 321 | + * White list ip status |
|
| 322 | + * |
|
| 323 | + * if you would to use the white list ip access, set this key to true |
|
| 324 | + */ |
|
| 325 | + $config['white_list_ip_enable'] = false; |
|
| 326 | 326 | |
| 327 | - /** |
|
| 328 | - * White listed ip addresses |
|
| 329 | - * |
|
| 330 | - * add the allowed ip address list to access this application. |
|
| 331 | - * You can use the wildcard address |
|
| 332 | - * @example: '18.90.09.*', '10.*.*.*', '*' |
|
| 333 | - * |
|
| 334 | - */ |
|
| 335 | - $config['white_list_ip_addresses'] = array('127.0.0.1', '::1'); |
|
| 327 | + /** |
|
| 328 | + * White listed ip addresses |
|
| 329 | + * |
|
| 330 | + * add the allowed ip address list to access this application. |
|
| 331 | + * You can use the wildcard address |
|
| 332 | + * @example: '18.90.09.*', '10.*.*.*', '*' |
|
| 333 | + * |
|
| 334 | + */ |
|
| 335 | + $config['white_list_ip_addresses'] = array('127.0.0.1', '::1'); |
|
| 336 | 336 | |
| 337 | - |
|
| 338 | 337 | \ No newline at end of file |
| 338 | + |
|
| 339 | 339 | \ No newline at end of file |
@@ -156,8 +156,7 @@ |
||
| 156 | 156 | $this->updateQueryBuilderAndRunnerProperties(); |
| 157 | 157 | |
| 158 | 158 | return is_object($this->pdo); |
| 159 | - } |
|
| 160 | - catch (PDOException $e){ |
|
| 159 | + } catch (PDOException $e){ |
|
| 161 | 160 | $this->logger->fatal($e->getMessage()); |
| 162 | 161 | show_error('Cannot connect to Database.'); |
| 163 | 162 | return false; |
@@ -1,113 +1,113 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | defined('ROOT_PATH') || exit('Access denied'); |
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 26 | - class Database extends BaseClass{ |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | + class Database extends BaseClass{ |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * The PDO instance |
|
| 30 | - * @var object |
|
| 31 | - */ |
|
| 28 | + /** |
|
| 29 | + * The PDO instance |
|
| 30 | + * @var object |
|
| 31 | + */ |
|
| 32 | 32 | private $pdo = null; |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * The database name used for the application |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - private $databaseName = null; |
|
| 34 | + /** |
|
| 35 | + * The database name used for the application |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + private $databaseName = null; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * The number of rows returned by the last query |
|
| 42 | - * @var int |
|
| 43 | - */ |
|
| 40 | + /** |
|
| 41 | + * The number of rows returned by the last query |
|
| 42 | + * @var int |
|
| 43 | + */ |
|
| 44 | 44 | private $numRows = 0; |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * The last insert id for the primary key column that have auto increment or sequence |
|
| 48 | - * @var mixed |
|
| 49 | - */ |
|
| 46 | + /** |
|
| 47 | + * The last insert id for the primary key column that have auto increment or sequence |
|
| 48 | + * @var mixed |
|
| 49 | + */ |
|
| 50 | 50 | private $insertId = null; |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * The full SQL query statment after build for each command |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 52 | + /** |
|
| 53 | + * The full SQL query statment after build for each command |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | 56 | private $query = null; |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * The result returned for the last query |
|
| 60 | - * @var mixed |
|
| 61 | - */ |
|
| 58 | + /** |
|
| 59 | + * The result returned for the last query |
|
| 60 | + * @var mixed |
|
| 61 | + */ |
|
| 62 | 62 | private $result = array(); |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * The cache default time to live in second. 0 means no need to use the cache feature |
|
| 66 | - * @var int |
|
| 67 | - */ |
|
| 68 | - private $cacheTtl = 0; |
|
| 64 | + /** |
|
| 65 | + * The cache default time to live in second. 0 means no need to use the cache feature |
|
| 66 | + * @var int |
|
| 67 | + */ |
|
| 68 | + private $cacheTtl = 0; |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * The cache current time to live. 0 means no need to use the cache feature |
|
| 72 | - * @var int |
|
| 73 | - */ |
|
| 70 | + /** |
|
| 71 | + * The cache current time to live. 0 means no need to use the cache feature |
|
| 72 | + * @var int |
|
| 73 | + */ |
|
| 74 | 74 | private $temporaryCacheTtl = 0; |
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * The number of executed query for the current request |
|
| 78 | - * @var int |
|
| 79 | - */ |
|
| 76 | + /** |
|
| 77 | + * The number of executed query for the current request |
|
| 78 | + * @var int |
|
| 79 | + */ |
|
| 80 | 80 | private $queryCount = 0; |
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * The default data to be used in the statments query INSERT, UPDATE |
|
| 84 | - * @var array |
|
| 85 | - */ |
|
| 82 | + /** |
|
| 83 | + * The default data to be used in the statments query INSERT, UPDATE |
|
| 84 | + * @var array |
|
| 85 | + */ |
|
| 86 | 86 | private $data = array(); |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * The database configuration |
|
| 90 | - * @var array |
|
| 91 | - */ |
|
| 88 | + /** |
|
| 89 | + * The database configuration |
|
| 90 | + * @var array |
|
| 91 | + */ |
|
| 92 | 92 | private $config = array(); |
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | - * The cache instance |
|
| 96 | - * @var object |
|
| 97 | - */ |
|
| 95 | + * The cache instance |
|
| 96 | + * @var object |
|
| 97 | + */ |
|
| 98 | 98 | private $cacheInstance = null; |
| 99 | 99 | |
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * The DatabaseQueryBuilder instance |
|
| 103 | - * @var object |
|
| 104 | - */ |
|
| 101 | + /** |
|
| 102 | + * The DatabaseQueryBuilder instance |
|
| 103 | + * @var object |
|
| 104 | + */ |
|
| 105 | 105 | protected $queryBuilder = null; |
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | - * The DatabaseQueryRunner instance |
|
| 109 | - * @var object |
|
| 110 | - */ |
|
| 108 | + * The DatabaseQueryRunner instance |
|
| 109 | + * @var object |
|
| 110 | + */ |
|
| 111 | 111 | protected $queryRunner = null; |
| 112 | 112 | |
| 113 | 113 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | public function __construct($overwriteConfig = array(), $autoConnect = true){ |
| 120 | 120 | parent::__construct(); |
| 121 | 121 | |
| 122 | - //Set DatabaseQueryBuilder instance to use |
|
| 122 | + //Set DatabaseQueryBuilder instance to use |
|
| 123 | 123 | $this->setDependencyInstanceFromParamOrCreate('queryBuilder', null, 'DatabaseQueryBuilder', 'classes/database'); |
| 124 | 124 | |
| 125 | 125 | //Set DatabaseQueryRunner instance to use |
@@ -137,8 +137,8 @@ discard block |
||
| 137 | 137 | * @return bool |
| 138 | 138 | */ |
| 139 | 139 | public function connect(){ |
| 140 | - $config = $this->getDatabaseConfiguration(); |
|
| 141 | - if (! empty($config)){ |
|
| 140 | + $config = $this->getDatabaseConfiguration(); |
|
| 141 | + if (! empty($config)){ |
|
| 142 | 142 | try{ |
| 143 | 143 | $this->pdo = new PDO($this->getDsnValueFromConfig(), $config['username'], $config['password']); |
| 144 | 144 | $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'"); |
@@ -149,14 +149,14 @@ discard block |
||
| 149 | 149 | $this->updateQueryBuilderAndRunnerProperties(); |
| 150 | 150 | |
| 151 | 151 | return is_object($this->pdo); |
| 152 | - } |
|
| 153 | - catch (PDOException $e){ |
|
| 152 | + } |
|
| 153 | + catch (PDOException $e){ |
|
| 154 | 154 | $this->logger->fatal($e->getMessage()); |
| 155 | 155 | show_error('Cannot connect to Database.'); |
| 156 | 156 | return false; |
| 157 | - } |
|
| 158 | - } |
|
| 159 | - return false; |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + return false; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @return int |
| 166 | 166 | */ |
| 167 | 167 | public function numRows(){ |
| 168 | - return $this->numRows; |
|
| 168 | + return $this->numRows; |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | * @return mixed |
| 174 | 174 | */ |
| 175 | 175 | public function insertId(){ |
| 176 | - return $this->insertId; |
|
| 176 | + return $this->insertId; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | |
@@ -184,13 +184,13 @@ discard block |
||
| 184 | 184 | * @return mixed the query SQL string or the record result |
| 185 | 185 | */ |
| 186 | 186 | public function get($returnSQLQueryOrResultType = false){ |
| 187 | - $this->queryBuilder->limit(1); |
|
| 188 | - $query = $this->getAll(true); |
|
| 189 | - if ($returnSQLQueryOrResultType === true){ |
|
| 187 | + $this->queryBuilder->limit(1); |
|
| 188 | + $query = $this->getAll(true); |
|
| 189 | + if ($returnSQLQueryOrResultType === true){ |
|
| 190 | 190 | return $query; |
| 191 | - } else { |
|
| 191 | + } else { |
|
| 192 | 192 | return $this->query($query, false, $returnSQLQueryOrResultType == 'array'); |
| 193 | - } |
|
| 193 | + } |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -200,11 +200,11 @@ discard block |
||
| 200 | 200 | * @return mixed the query SQL string or the record result |
| 201 | 201 | */ |
| 202 | 202 | public function getAll($returnSQLQueryOrResultType = false){ |
| 203 | - $query = $this->queryBuilder->getQuery(); |
|
| 204 | - if ($returnSQLQueryOrResultType === true){ |
|
| 205 | - return $query; |
|
| 206 | - } |
|
| 207 | - return $this->query($query, true, $returnSQLQueryOrResultType == 'array'); |
|
| 203 | + $query = $this->queryBuilder->getQuery(); |
|
| 204 | + if ($returnSQLQueryOrResultType === true){ |
|
| 205 | + return $query; |
|
| 206 | + } |
|
| 207 | + return $this->query($query, true, $returnSQLQueryOrResultType == 'array'); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -214,19 +214,19 @@ discard block |
||
| 214 | 214 | * @return mixed the insert id of the new record or null |
| 215 | 215 | */ |
| 216 | 216 | public function insert($data = array(), $escape = true){ |
| 217 | - if (empty($data) && ! empty($this->data)){ |
|
| 217 | + if (empty($data) && ! empty($this->data)){ |
|
| 218 | 218 | //as when using $this->setData() may be the data already escaped |
| 219 | 219 | $escape = false; |
| 220 | 220 | $data = $this->data; |
| 221 | - } |
|
| 222 | - $query = $this->queryBuilder->insert($data, $escape)->getQuery(); |
|
| 223 | - $result = $this->query($query); |
|
| 224 | - if ($result){ |
|
| 221 | + } |
|
| 222 | + $query = $this->queryBuilder->insert($data, $escape)->getQuery(); |
|
| 223 | + $result = $this->query($query); |
|
| 224 | + if ($result){ |
|
| 225 | 225 | $this->insertId = $this->pdo->lastInsertId(); |
| 226 | - //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned |
|
| 226 | + //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned |
|
| 227 | 227 | return ! ($this->insertId) ? true : $this->insertId; |
| 228 | - } |
|
| 229 | - return false; |
|
| 228 | + } |
|
| 229 | + return false; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -236,13 +236,13 @@ discard block |
||
| 236 | 236 | * @return mixed the update status |
| 237 | 237 | */ |
| 238 | 238 | public function update($data = array(), $escape = true){ |
| 239 | - if (empty($data) && ! empty($this->data)){ |
|
| 239 | + if (empty($data) && ! empty($this->data)){ |
|
| 240 | 240 | //as when using $this->setData() may be the data already escaped |
| 241 | 241 | $escape = false; |
| 242 | 242 | $data = $this->data; |
| 243 | - } |
|
| 244 | - $query = $this->queryBuilder->update($data, $escape)->getQuery(); |
|
| 245 | - return $this->query($query); |
|
| 243 | + } |
|
| 244 | + $query = $this->queryBuilder->update($data, $escape)->getQuery(); |
|
| 245 | + return $this->query($query); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -250,8 +250,8 @@ discard block |
||
| 250 | 250 | * @return mixed the delete status |
| 251 | 251 | */ |
| 252 | 252 | public function delete(){ |
| 253 | - $query = $this->queryBuilder->delete()->getQuery(); |
|
| 254 | - return $this->query($query); |
|
| 253 | + $query = $this->queryBuilder->delete()->getQuery(); |
|
| 254 | + return $this->query($query); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | /** |
@@ -260,17 +260,17 @@ discard block |
||
| 260 | 260 | * @return object the current Database instance |
| 261 | 261 | */ |
| 262 | 262 | public function setCache($ttl = 0){ |
| 263 | - $this->cacheTtl = $ttl; |
|
| 264 | - $this->temporaryCacheTtl = $ttl; |
|
| 265 | - return $this; |
|
| 263 | + $this->cacheTtl = $ttl; |
|
| 264 | + $this->temporaryCacheTtl = $ttl; |
|
| 265 | + return $this; |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - /** |
|
| 269 | - * Enabled cache temporary for the current query not globally |
|
| 270 | - * @param integer $ttl the cache time to live in second |
|
| 271 | - * @return object the current Database instance |
|
| 272 | - */ |
|
| 273 | - public function cached($ttl = 0){ |
|
| 268 | + /** |
|
| 269 | + * Enabled cache temporary for the current query not globally |
|
| 270 | + * @param integer $ttl the cache time to live in second |
|
| 271 | + * @return object the current Database instance |
|
| 272 | + */ |
|
| 273 | + public function cached($ttl = 0){ |
|
| 274 | 274 | $this->temporaryCacheTtl = $ttl; |
| 275 | 275 | return $this; |
| 276 | 276 | } |
@@ -283,11 +283,11 @@ discard block |
||
| 283 | 283 | * need escaped |
| 284 | 284 | */ |
| 285 | 285 | public function escape($data, $escaped = true){ |
| 286 | - $data = trim($data); |
|
| 287 | - if($escaped){ |
|
| 286 | + $data = trim($data); |
|
| 287 | + if($escaped){ |
|
| 288 | 288 | return $this->pdo->quote($data); |
| 289 | - } |
|
| 290 | - return $data; |
|
| 289 | + } |
|
| 290 | + return $data; |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | * @return int |
| 296 | 296 | */ |
| 297 | 297 | public function queryCount(){ |
| 298 | - return $this->queryCount; |
|
| 298 | + return $this->queryCount; |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | /** |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | * @return string |
| 304 | 304 | */ |
| 305 | 305 | public function getQuery(){ |
| 306 | - return $this->query; |
|
| 306 | + return $this->query; |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | * @return string |
| 312 | 312 | */ |
| 313 | 313 | public function getDatabaseName(){ |
| 314 | - return $this->databaseName; |
|
| 314 | + return $this->databaseName; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
@@ -319,44 +319,44 @@ discard block |
||
| 319 | 319 | * @return object |
| 320 | 320 | */ |
| 321 | 321 | public function getPdo(){ |
| 322 | - return $this->pdo; |
|
| 322 | + return $this->pdo; |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /** |
| 326 | 326 | * Set the PDO instance |
| 327 | 327 | * @param object $pdo the pdo object |
| 328 | - * @return object Database |
|
| 328 | + * @return object Database |
|
| 329 | 329 | */ |
| 330 | 330 | public function setPdo(PDO $pdo){ |
| 331 | - $this->pdo = $pdo; |
|
| 332 | - return $this; |
|
| 331 | + $this->pdo = $pdo; |
|
| 332 | + return $this; |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - /** |
|
| 336 | - * Return the cache instance |
|
| 337 | - * @return CacheInterface |
|
| 338 | - */ |
|
| 335 | + /** |
|
| 336 | + * Return the cache instance |
|
| 337 | + * @return CacheInterface |
|
| 338 | + */ |
|
| 339 | 339 | public function getCacheInstance(){ |
| 340 | - return $this->cacheInstance; |
|
| 340 | + return $this->cacheInstance; |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | /** |
| 344 | 344 | * Set the cache instance |
| 345 | 345 | * @param CacheInterface $cache the cache object |
| 346 | - * @return object Database |
|
| 346 | + * @return object Database |
|
| 347 | 347 | */ |
| 348 | 348 | public function setCacheInstance($cache){ |
| 349 | - $this->cacheInstance = $cache; |
|
| 350 | - return $this; |
|
| 349 | + $this->cacheInstance = $cache; |
|
| 350 | + return $this; |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | |
| 354 | - /** |
|
| 355 | - * Return the DatabaseQueryBuilder instance |
|
| 356 | - * @return object DatabaseQueryBuilder |
|
| 357 | - */ |
|
| 354 | + /** |
|
| 355 | + * Return the DatabaseQueryBuilder instance |
|
| 356 | + * @return object DatabaseQueryBuilder |
|
| 357 | + */ |
|
| 358 | 358 | public function getQueryBuilder(){ |
| 359 | - return $this->queryBuilder; |
|
| 359 | + return $this->queryBuilder; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | /** |
@@ -364,8 +364,8 @@ discard block |
||
| 364 | 364 | * @param object DatabaseQueryBuilder $queryBuilder the DatabaseQueryBuilder object |
| 365 | 365 | */ |
| 366 | 366 | public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder){ |
| 367 | - $this->queryBuilder = $queryBuilder; |
|
| 368 | - return $this; |
|
| 367 | + $this->queryBuilder = $queryBuilder; |
|
| 368 | + return $this; |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | /** |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | * @return object DatabaseQueryRunner |
| 374 | 374 | */ |
| 375 | 375 | public function getQueryRunner(){ |
| 376 | - return $this->queryRunner; |
|
| 376 | + return $this->queryRunner; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -381,8 +381,8 @@ discard block |
||
| 381 | 381 | * @param object DatabaseQueryRunner $queryRunner the DatabaseQueryRunner object |
| 382 | 382 | */ |
| 383 | 383 | public function setQueryRunner(DatabaseQueryRunner $queryRunner){ |
| 384 | - $this->queryRunner = $queryRunner; |
|
| 385 | - return $this; |
|
| 384 | + $this->queryRunner = $queryRunner; |
|
| 385 | + return $this; |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | * @return array |
| 391 | 391 | */ |
| 392 | 392 | public function getData(){ |
| 393 | - return $this->data; |
|
| 393 | + return $this->data; |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -401,62 +401,62 @@ discard block |
||
| 401 | 401 | * @return object the current Database instance |
| 402 | 402 | */ |
| 403 | 403 | public function setData($key, $value = null, $escape = true){ |
| 404 | - if (is_array($key)){ |
|
| 405 | - foreach($key as $k => $v){ |
|
| 406 | - $this->setData($k, $v, $escape); |
|
| 407 | - } |
|
| 408 | - } else { |
|
| 404 | + if (is_array($key)){ |
|
| 405 | + foreach($key as $k => $v){ |
|
| 406 | + $this->setData($k, $v, $escape); |
|
| 407 | + } |
|
| 408 | + } else { |
|
| 409 | 409 | $this->data[$key] = $this->escape($value, $escape); |
| 410 | - } |
|
| 411 | - return $this; |
|
| 410 | + } |
|
| 411 | + return $this; |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - /** |
|
| 415 | - * Execute an SQL query |
|
| 416 | - * @param string $query the query SQL string |
|
| 417 | - * @param boolean $returnAsList indicate whether to return all record or just one row |
|
| 418 | - * @param boolean $returnAsArray return the result as array or not |
|
| 419 | - * @return mixed the query result |
|
| 420 | - */ |
|
| 414 | + /** |
|
| 415 | + * Execute an SQL query |
|
| 416 | + * @param string $query the query SQL string |
|
| 417 | + * @param boolean $returnAsList indicate whether to return all record or just one row |
|
| 418 | + * @param boolean $returnAsArray return the result as array or not |
|
| 419 | + * @return mixed the query result |
|
| 420 | + */ |
|
| 421 | 421 | public function query($query, $returnAsList = true, $returnAsArray = false){ |
| 422 | - $this->reset(); |
|
| 423 | - $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query)); |
|
| 424 | - //If is the SELECT query |
|
| 425 | - $isSqlSELECTQuery = stristr($this->query, 'SELECT'); |
|
| 422 | + $this->reset(); |
|
| 423 | + $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query)); |
|
| 424 | + //If is the SELECT query |
|
| 425 | + $isSqlSELECTQuery = stristr($this->query, 'SELECT'); |
|
| 426 | 426 | |
| 427 | - //cache expire time |
|
| 428 | - $cacheExpire = $this->temporaryCacheTtl; |
|
| 427 | + //cache expire time |
|
| 428 | + $cacheExpire = $this->temporaryCacheTtl; |
|
| 429 | 429 | |
| 430 | - //return to the initial cache time |
|
| 431 | - $this->temporaryCacheTtl = $this->cacheTtl; |
|
| 430 | + //return to the initial cache time |
|
| 431 | + $this->temporaryCacheTtl = $this->cacheTtl; |
|
| 432 | 432 | |
| 433 | - //config for cache |
|
| 434 | - $cacheEnable = get_config('cache_enable'); |
|
| 433 | + //config for cache |
|
| 434 | + $cacheEnable = get_config('cache_enable'); |
|
| 435 | 435 | |
| 436 | - //the database cache content |
|
| 437 | - $cacheContent = null; |
|
| 436 | + //the database cache content |
|
| 437 | + $cacheContent = null; |
|
| 438 | 438 | |
| 439 | - //if can use cache feature for this query |
|
| 440 | - $dbCacheStatus = $cacheEnable && $cacheExpire > 0; |
|
| 439 | + //if can use cache feature for this query |
|
| 440 | + $dbCacheStatus = $cacheEnable && $cacheExpire > 0; |
|
| 441 | 441 | |
| 442 | - if ($dbCacheStatus && $isSqlSELECTQuery){ |
|
| 443 | - $this->logger->info('The cache is enabled for this query, try to get result from cache'); |
|
| 444 | - $cacheContent = $this->getCacheContentForQuery($query, $returnAsList, $returnAsArray); |
|
| 445 | - } |
|
| 442 | + if ($dbCacheStatus && $isSqlSELECTQuery){ |
|
| 443 | + $this->logger->info('The cache is enabled for this query, try to get result from cache'); |
|
| 444 | + $cacheContent = $this->getCacheContentForQuery($query, $returnAsList, $returnAsArray); |
|
| 445 | + } |
|
| 446 | 446 | |
| 447 | - if (!$cacheContent){ |
|
| 448 | - //count the number of query execution to server |
|
| 447 | + if (!$cacheContent){ |
|
| 448 | + //count the number of query execution to server |
|
| 449 | 449 | $this->queryCount++; |
| 450 | 450 | |
| 451 | 451 | $queryResult = $this->queryRunner->setQuery($query) |
| 452 | - ->setReturnType($returnAsList) |
|
| 453 | - ->setReturnAsArray($returnAsArray) |
|
| 454 | - ->execute(); |
|
| 452 | + ->setReturnType($returnAsList) |
|
| 453 | + ->setReturnAsArray($returnAsArray) |
|
| 454 | + ->execute(); |
|
| 455 | 455 | |
| 456 | 456 | if (!is_object($queryResult)){ |
| 457 | - $this->result = false; |
|
| 458 | - $this->numRows = 0; |
|
| 459 | - return $this->result; |
|
| 457 | + $this->result = false; |
|
| 458 | + $this->numRows = 0; |
|
| 459 | + return $this->result; |
|
| 460 | 460 | } |
| 461 | 461 | $this->result = $queryResult->getResult(); |
| 462 | 462 | $this->numRows = $queryResult->getNumRows(); |
@@ -464,72 +464,72 @@ discard block |
||
| 464 | 464 | $key = $this->getCacheKeyForQuery($this->query, $returnAsList, $returnAsArray); |
| 465 | 465 | $this->setCacheContentForQuery($this->query, $key, $this->result, $cacheExpire); |
| 466 | 466 | } |
| 467 | - } else if ($isSqlSELECTQuery){ |
|
| 468 | - $this->logger->info('The result for query [' .$this->query. '] already cached use it'); |
|
| 469 | - $this->result = $cacheContent; |
|
| 470 | - $this->numRows = count($this->result); |
|
| 471 | - } |
|
| 472 | - return $this->result; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * Setting the database configuration using the configuration file and additional configuration from param |
|
| 477 | - * @param array $overwriteConfig the additional configuration to overwrite with the existing one |
|
| 478 | - * @param boolean $useConfigFile whether to use database configuration file |
|
| 479 | - * @param boolean $autoConnect whether to connect to database after set the configuration |
|
| 480 | - * @return object Database |
|
| 481 | - */ |
|
| 467 | + } else if ($isSqlSELECTQuery){ |
|
| 468 | + $this->logger->info('The result for query [' .$this->query. '] already cached use it'); |
|
| 469 | + $this->result = $cacheContent; |
|
| 470 | + $this->numRows = count($this->result); |
|
| 471 | + } |
|
| 472 | + return $this->result; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * Setting the database configuration using the configuration file and additional configuration from param |
|
| 477 | + * @param array $overwriteConfig the additional configuration to overwrite with the existing one |
|
| 478 | + * @param boolean $useConfigFile whether to use database configuration file |
|
| 479 | + * @param boolean $autoConnect whether to connect to database after set the configuration |
|
| 480 | + * @return object Database |
|
| 481 | + */ |
|
| 482 | 482 | public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true, $autoConnect = false){ |
| 483 | - $db = array(); |
|
| 484 | - if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')){ |
|
| 485 | - //here don't use require_once because somewhere user can create database instance directly |
|
| 486 | - require CONFIG_PATH . 'database.php'; |
|
| 487 | - } |
|
| 483 | + $db = array(); |
|
| 484 | + if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')){ |
|
| 485 | + //here don't use require_once because somewhere user can create database instance directly |
|
| 486 | + require CONFIG_PATH . 'database.php'; |
|
| 487 | + } |
|
| 488 | 488 | |
| 489 | - //merge with the parameter |
|
| 490 | - $db = array_merge($db, $overwriteConfig); |
|
| 489 | + //merge with the parameter |
|
| 490 | + $db = array_merge($db, $overwriteConfig); |
|
| 491 | 491 | |
| 492 | - //get the default configuration |
|
| 493 | - $config = $this->getDatabaseDefaultConfiguration(); |
|
| 492 | + //get the default configuration |
|
| 493 | + $config = $this->getDatabaseDefaultConfiguration(); |
|
| 494 | 494 | |
| 495 | - $config = array_merge($config, $db); |
|
| 496 | - //determine the port using the hostname like localhost:3307 |
|
| 497 | - //hostname will be "localhost", and port "3307" |
|
| 498 | - $p = explode(':', $config['hostname']); |
|
| 499 | - if (count($p) >= 2){ |
|
| 500 | - $config['hostname'] = $p[0]; |
|
| 501 | - $config['port'] = $p[1]; |
|
| 502 | - } |
|
| 495 | + $config = array_merge($config, $db); |
|
| 496 | + //determine the port using the hostname like localhost:3307 |
|
| 497 | + //hostname will be "localhost", and port "3307" |
|
| 498 | + $p = explode(':', $config['hostname']); |
|
| 499 | + if (count($p) >= 2){ |
|
| 500 | + $config['hostname'] = $p[0]; |
|
| 501 | + $config['port'] = $p[1]; |
|
| 502 | + } |
|
| 503 | 503 | |
| 504 | - $this->databaseName = $config['database']; |
|
| 505 | - $this->config = $config; |
|
| 506 | - $this->logger->info( |
|
| 507 | - 'The database configuration are listed below: ' |
|
| 508 | - . stringfy_vars(array_merge( |
|
| 509 | - $this->config, |
|
| 510 | - array('password' => string_hidden($this->config['password'])) |
|
| 511 | - )) |
|
| 512 | - ); |
|
| 513 | - if($autoConnect){ |
|
| 514 | - //Now connect to the database |
|
| 515 | - $this->connect(); |
|
| 516 | - } |
|
| 517 | - return $this; |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - /** |
|
| 521 | - * Return the database configuration |
|
| 522 | - * @return array |
|
| 523 | - */ |
|
| 504 | + $this->databaseName = $config['database']; |
|
| 505 | + $this->config = $config; |
|
| 506 | + $this->logger->info( |
|
| 507 | + 'The database configuration are listed below: ' |
|
| 508 | + . stringfy_vars(array_merge( |
|
| 509 | + $this->config, |
|
| 510 | + array('password' => string_hidden($this->config['password'])) |
|
| 511 | + )) |
|
| 512 | + ); |
|
| 513 | + if($autoConnect){ |
|
| 514 | + //Now connect to the database |
|
| 515 | + $this->connect(); |
|
| 516 | + } |
|
| 517 | + return $this; |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + /** |
|
| 521 | + * Return the database configuration |
|
| 522 | + * @return array |
|
| 523 | + */ |
|
| 524 | 524 | public function getDatabaseConfiguration(){ |
| 525 | - return $this->config; |
|
| 525 | + return $this->config; |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
| 529 | 529 | * Close the connexion |
| 530 | 530 | */ |
| 531 | 531 | public function close(){ |
| 532 | - $this->pdo = null; |
|
| 532 | + $this->pdo = null; |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | /** |
@@ -537,16 +537,16 @@ discard block |
||
| 537 | 537 | * @return array |
| 538 | 538 | */ |
| 539 | 539 | protected function getDatabaseDefaultConfiguration(){ |
| 540 | - return array( |
|
| 541 | - 'driver' => '', |
|
| 542 | - 'username' => '', |
|
| 543 | - 'password' => '', |
|
| 544 | - 'database' => '', |
|
| 545 | - 'hostname' => 'localhost', |
|
| 546 | - 'charset' => 'utf8', |
|
| 547 | - 'collation' => 'utf8_general_ci', |
|
| 548 | - 'prefix' => '', |
|
| 549 | - 'port' => '' |
|
| 540 | + return array( |
|
| 541 | + 'driver' => '', |
|
| 542 | + 'username' => '', |
|
| 543 | + 'password' => '', |
|
| 544 | + 'database' => '', |
|
| 545 | + 'hostname' => 'localhost', |
|
| 546 | + 'charset' => 'utf8', |
|
| 547 | + 'collation' => 'utf8_general_ci', |
|
| 548 | + 'prefix' => '', |
|
| 549 | + 'port' => '' |
|
| 550 | 550 | ); |
| 551 | 551 | } |
| 552 | 552 | |
@@ -555,18 +555,18 @@ discard block |
||
| 555 | 555 | * @return void |
| 556 | 556 | */ |
| 557 | 557 | protected function updateQueryBuilderAndRunnerProperties(){ |
| 558 | - //update queryBuilder with some properties needed |
|
| 559 | - if (is_object($this->queryBuilder)){ |
|
| 558 | + //update queryBuilder with some properties needed |
|
| 559 | + if (is_object($this->queryBuilder)){ |
|
| 560 | 560 | $this->queryBuilder->setDriver($this->config['driver']) |
| 561 | - ->setPrefix($this->config['prefix']) |
|
| 562 | - ->setPdo($this->pdo); |
|
| 563 | - } |
|
| 561 | + ->setPrefix($this->config['prefix']) |
|
| 562 | + ->setPdo($this->pdo); |
|
| 563 | + } |
|
| 564 | 564 | |
| 565 | - //update queryRunner with some properties needed |
|
| 566 | - if (is_object($this->queryRunner)){ |
|
| 565 | + //update queryRunner with some properties needed |
|
| 566 | + if (is_object($this->queryRunner)){ |
|
| 567 | 567 | $this->queryRunner->setDriver($this->config['driver']) |
| 568 | - ->setPdo($this->pdo); |
|
| 569 | - } |
|
| 568 | + ->setPdo($this->pdo); |
|
| 569 | + } |
|
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | |
@@ -575,21 +575,21 @@ discard block |
||
| 575 | 575 | * @return string|null the DSN string or null if can not find it |
| 576 | 576 | */ |
| 577 | 577 | protected function getDsnValueFromConfig(){ |
| 578 | - $dsn = null; |
|
| 579 | - $config = $this->getDatabaseConfiguration(); |
|
| 580 | - if (! empty($config)){ |
|
| 578 | + $dsn = null; |
|
| 579 | + $config = $this->getDatabaseConfiguration(); |
|
| 580 | + if (! empty($config)){ |
|
| 581 | 581 | $driver = $config['driver']; |
| 582 | 582 | $driverDsnMap = array( |
| 583 | - 'mysql' => $this->getDsnValueForDriver('mysql'), |
|
| 584 | - 'pgsql' => $this->getDsnValueForDriver('pgsql'), |
|
| 585 | - 'sqlite' => $this->getDsnValueForDriver('sqlite'), |
|
| 586 | - 'oracle' => $this->getDsnValueForDriver('oracle') |
|
| 587 | - ); |
|
| 583 | + 'mysql' => $this->getDsnValueForDriver('mysql'), |
|
| 584 | + 'pgsql' => $this->getDsnValueForDriver('pgsql'), |
|
| 585 | + 'sqlite' => $this->getDsnValueForDriver('sqlite'), |
|
| 586 | + 'oracle' => $this->getDsnValueForDriver('oracle') |
|
| 587 | + ); |
|
| 588 | 588 | if (isset($driverDsnMap[$driver])){ |
| 589 | - $dsn = $driverDsnMap[$driver]; |
|
| 589 | + $dsn = $driverDsnMap[$driver]; |
|
| 590 | 590 | } |
| 591 | - } |
|
| 592 | - return $dsn; |
|
| 591 | + } |
|
| 592 | + return $dsn; |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | /** |
@@ -598,32 +598,32 @@ discard block |
||
| 598 | 598 | * @return string|null the dsn name |
| 599 | 599 | */ |
| 600 | 600 | protected function getDsnValueForDriver($driver){ |
| 601 | - $dsn = ''; |
|
| 602 | - $config = $this->getDatabaseConfiguration(); |
|
| 603 | - if (empty($config)){ |
|
| 601 | + $dsn = ''; |
|
| 602 | + $config = $this->getDatabaseConfiguration(); |
|
| 603 | + if (empty($config)){ |
|
| 604 | 604 | return null; |
| 605 | - } |
|
| 606 | - switch ($driver) { |
|
| 605 | + } |
|
| 606 | + switch ($driver) { |
|
| 607 | 607 | case 'mysql': |
| 608 | 608 | case 'pgsql': |
| 609 | 609 | $port = ''; |
| 610 | - if (! empty($config['port'])) { |
|
| 610 | + if (! empty($config['port'])) { |
|
| 611 | 611 | $port = 'port=' . $config['port'] . ';'; |
| 612 | - } |
|
| 613 | - $dsn = $driver . ':host=' . $config['hostname'] . ';' . $port . 'dbname=' . $config['database']; |
|
| 614 | - break; |
|
| 612 | + } |
|
| 613 | + $dsn = $driver . ':host=' . $config['hostname'] . ';' . $port . 'dbname=' . $config['database']; |
|
| 614 | + break; |
|
| 615 | 615 | case 'sqlite': |
| 616 | 616 | $dsn = 'sqlite:' . $config['database']; |
| 617 | - break; |
|
| 618 | - case 'oracle': |
|
| 617 | + break; |
|
| 618 | + case 'oracle': |
|
| 619 | 619 | $port = ''; |
| 620 | - if (! empty($config['port'])) { |
|
| 620 | + if (! empty($config['port'])) { |
|
| 621 | 621 | $port = ':' . $config['port']; |
| 622 | - } |
|
| 623 | - $dsn = 'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database']; |
|
| 624 | - break; |
|
| 625 | - } |
|
| 626 | - return $dsn; |
|
| 622 | + } |
|
| 623 | + $dsn = 'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database']; |
|
| 624 | + break; |
|
| 625 | + } |
|
| 626 | + return $dsn; |
|
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | /** |
@@ -635,11 +635,11 @@ discard block |
||
| 635 | 635 | protected function getCacheContentForQuery($query, $returnAsList, $returnAsArray){ |
| 636 | 636 | $cacheKey = $this->getCacheKeyForQuery($query, $returnAsList, $returnAsArray); |
| 637 | 637 | if (! is_object($this->cacheInstance)){ |
| 638 | - //can not call method with reference in argument |
|
| 639 | - //like $this->setCacheInstance(& get_instance()->cache); |
|
| 640 | - //use temporary variable |
|
| 641 | - $instance = & get_instance()->cache; |
|
| 642 | - $this->cacheInstance = $instance; |
|
| 638 | + //can not call method with reference in argument |
|
| 639 | + //like $this->setCacheInstance(& get_instance()->cache); |
|
| 640 | + //use temporary variable |
|
| 641 | + $instance = & get_instance()->cache; |
|
| 642 | + $this->cacheInstance = $instance; |
|
| 643 | 643 | } |
| 644 | 644 | return $this->cacheInstance->get($cacheKey); |
| 645 | 645 | } |
@@ -651,27 +651,27 @@ discard block |
||
| 651 | 651 | * @param mixed $result the query result to save |
| 652 | 652 | * @param int $expire the cache TTL |
| 653 | 653 | */ |
| 654 | - protected function setCacheContentForQuery($query, $key, $result, $expire){ |
|
| 654 | + protected function setCacheContentForQuery($query, $key, $result, $expire){ |
|
| 655 | 655 | $this->logger->info('Save the result for query [' .$query. '] into cache for future use'); |
| 656 | 656 | if (! is_object($this->cacheInstance)){ |
| 657 | - //can not call method with reference in argument |
|
| 658 | - //like $this->setCacheInstance(& get_instance()->cache); |
|
| 659 | - //use temporary variable |
|
| 660 | - $instance = & get_instance()->cache; |
|
| 661 | - $this->cacheInstance = $instance; |
|
| 662 | - } |
|
| 657 | + //can not call method with reference in argument |
|
| 658 | + //like $this->setCacheInstance(& get_instance()->cache); |
|
| 659 | + //use temporary variable |
|
| 660 | + $instance = & get_instance()->cache; |
|
| 661 | + $this->cacheInstance = $instance; |
|
| 662 | + } |
|
| 663 | 663 | $this->cacheInstance->set($key, $result, $expire); |
| 664 | - } |
|
| 664 | + } |
|
| 665 | 665 | |
| 666 | 666 | |
| 667 | - /** |
|
| 668 | - * Return the cache key for the given query |
|
| 669 | - * @see Database::query |
|
| 670 | - * |
|
| 671 | - * @return string |
|
| 672 | - */ |
|
| 667 | + /** |
|
| 668 | + * Return the cache key for the given query |
|
| 669 | + * @see Database::query |
|
| 670 | + * |
|
| 671 | + * @return string |
|
| 672 | + */ |
|
| 673 | 673 | protected function getCacheKeyForQuery($query, $returnAsList, $returnAsArray){ |
| 674 | - return md5($query . $returnAsList . $returnAsArray); |
|
| 674 | + return md5($query . $returnAsList . $returnAsArray); |
|
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | |
@@ -679,20 +679,20 @@ discard block |
||
| 679 | 679 | * Reset the database class attributs to the initail values before each query. |
| 680 | 680 | */ |
| 681 | 681 | private function reset(){ |
| 682 | - //query builder reset |
|
| 683 | - $this->queryBuilder->reset(); |
|
| 684 | - $this->numRows = 0; |
|
| 685 | - $this->insertId = null; |
|
| 686 | - $this->query = null; |
|
| 687 | - $this->result = array(); |
|
| 688 | - $this->data = array(); |
|
| 682 | + //query builder reset |
|
| 683 | + $this->queryBuilder->reset(); |
|
| 684 | + $this->numRows = 0; |
|
| 685 | + $this->insertId = null; |
|
| 686 | + $this->query = null; |
|
| 687 | + $this->result = array(); |
|
| 688 | + $this->data = array(); |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | /** |
| 692 | 692 | * The class destructor |
| 693 | 693 | */ |
| 694 | 694 | public function __destruct(){ |
| 695 | - $this->pdo = null; |
|
| 695 | + $this->pdo = null; |
|
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | } |
@@ -23,92 +23,92 @@ discard block |
||
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | - class Database extends BaseClass{ |
|
| 26 | + class Database extends BaseClass { |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * The PDO instance |
| 30 | 30 | * @var object |
| 31 | 31 | */ |
| 32 | - private $pdo = null; |
|
| 32 | + private $pdo = null; |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * The database name used for the application |
| 36 | 36 | * @var string |
| 37 | 37 | */ |
| 38 | - private $databaseName = null; |
|
| 38 | + private $databaseName = null; |
|
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * The number of rows returned by the last query |
| 42 | 42 | * @var int |
| 43 | 43 | */ |
| 44 | - private $numRows = 0; |
|
| 44 | + private $numRows = 0; |
|
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * The last insert id for the primary key column that have auto increment or sequence |
| 48 | 48 | * @var mixed |
| 49 | 49 | */ |
| 50 | - private $insertId = null; |
|
| 50 | + private $insertId = null; |
|
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * The full SQL query statment after build for each command |
| 54 | 54 | * @var string |
| 55 | 55 | */ |
| 56 | - private $query = null; |
|
| 56 | + private $query = null; |
|
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * The result returned for the last query |
| 60 | 60 | * @var mixed |
| 61 | 61 | */ |
| 62 | - private $result = array(); |
|
| 62 | + private $result = array(); |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * The cache default time to live in second. 0 means no need to use the cache feature |
| 66 | 66 | * @var int |
| 67 | 67 | */ |
| 68 | - private $cacheTtl = 0; |
|
| 68 | + private $cacheTtl = 0; |
|
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * The cache current time to live. 0 means no need to use the cache feature |
| 72 | 72 | * @var int |
| 73 | 73 | */ |
| 74 | - private $temporaryCacheTtl = 0; |
|
| 74 | + private $temporaryCacheTtl = 0; |
|
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | 77 | * The number of executed query for the current request |
| 78 | 78 | * @var int |
| 79 | 79 | */ |
| 80 | - private $queryCount = 0; |
|
| 80 | + private $queryCount = 0; |
|
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * The default data to be used in the statments query INSERT, UPDATE |
| 84 | 84 | * @var array |
| 85 | 85 | */ |
| 86 | - private $data = array(); |
|
| 86 | + private $data = array(); |
|
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * The database configuration |
| 90 | 90 | * @var array |
| 91 | 91 | */ |
| 92 | - private $config = array(); |
|
| 92 | + private $config = array(); |
|
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | 95 | * The cache instance |
| 96 | 96 | * @var object |
| 97 | 97 | */ |
| 98 | - private $cacheInstance = null; |
|
| 98 | + private $cacheInstance = null; |
|
| 99 | 99 | |
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * The DatabaseQueryBuilder instance |
| 103 | 103 | * @var object |
| 104 | 104 | */ |
| 105 | - protected $queryBuilder = null; |
|
| 105 | + protected $queryBuilder = null; |
|
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | 108 | * The DatabaseQueryRunner instance |
| 109 | 109 | * @var object |
| 110 | 110 | */ |
| 111 | - protected $queryRunner = null; |
|
| 111 | + protected $queryRunner = null; |
|
| 112 | 112 | |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * @param array $overwriteConfig the config to overwrite with the config set in database.php |
| 117 | 117 | * @param boolean $autoConnect whether to connect to database automatically |
| 118 | 118 | */ |
| 119 | - public function __construct($overwriteConfig = array(), $autoConnect = true){ |
|
| 119 | + public function __construct($overwriteConfig = array(), $autoConnect = true) { |
|
| 120 | 120 | parent::__construct(); |
| 121 | 121 | |
| 122 | 122 | //Set DatabaseQueryBuilder instance to use |
@@ -136,10 +136,10 @@ discard block |
||
| 136 | 136 | * This is used to connect to database |
| 137 | 137 | * @return bool |
| 138 | 138 | */ |
| 139 | - public function connect(){ |
|
| 139 | + public function connect() { |
|
| 140 | 140 | $config = $this->getDatabaseConfiguration(); |
| 141 | - if (! empty($config)){ |
|
| 142 | - try{ |
|
| 141 | + if (!empty($config)) { |
|
| 142 | + try { |
|
| 143 | 143 | $this->pdo = new PDO($this->getDsnValueFromConfig(), $config['username'], $config['password']); |
| 144 | 144 | $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'"); |
| 145 | 145 | $this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'"); |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | |
| 151 | 151 | return is_object($this->pdo); |
| 152 | 152 | } |
| 153 | - catch (PDOException $e){ |
|
| 153 | + catch (PDOException $e) { |
|
| 154 | 154 | $this->logger->fatal($e->getMessage()); |
| 155 | 155 | show_error('Cannot connect to Database.'); |
| 156 | 156 | return false; |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | * Return the number of rows returned by the current query |
| 165 | 165 | * @return int |
| 166 | 166 | */ |
| 167 | - public function numRows(){ |
|
| 167 | + public function numRows() { |
|
| 168 | 168 | return $this->numRows; |
| 169 | 169 | } |
| 170 | 170 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * Return the last insert id value |
| 173 | 173 | * @return mixed |
| 174 | 174 | */ |
| 175 | - public function insertId(){ |
|
| 175 | + public function insertId() { |
|
| 176 | 176 | return $this->insertId; |
| 177 | 177 | } |
| 178 | 178 | |
@@ -183,10 +183,10 @@ discard block |
||
| 183 | 183 | * If is string will determine the result type "array" or "object" |
| 184 | 184 | * @return mixed the query SQL string or the record result |
| 185 | 185 | */ |
| 186 | - public function get($returnSQLQueryOrResultType = false){ |
|
| 186 | + public function get($returnSQLQueryOrResultType = false) { |
|
| 187 | 187 | $this->queryBuilder->limit(1); |
| 188 | 188 | $query = $this->getAll(true); |
| 189 | - if ($returnSQLQueryOrResultType === true){ |
|
| 189 | + if ($returnSQLQueryOrResultType === true) { |
|
| 190 | 190 | return $query; |
| 191 | 191 | } else { |
| 192 | 192 | return $this->query($query, false, $returnSQLQueryOrResultType == 'array'); |
@@ -199,9 +199,9 @@ discard block |
||
| 199 | 199 | * If is string will determine the result type "array" or "object" |
| 200 | 200 | * @return mixed the query SQL string or the record result |
| 201 | 201 | */ |
| 202 | - public function getAll($returnSQLQueryOrResultType = false){ |
|
| 202 | + public function getAll($returnSQLQueryOrResultType = false) { |
|
| 203 | 203 | $query = $this->queryBuilder->getQuery(); |
| 204 | - if ($returnSQLQueryOrResultType === true){ |
|
| 204 | + if ($returnSQLQueryOrResultType === true) { |
|
| 205 | 205 | return $query; |
| 206 | 206 | } |
| 207 | 207 | return $this->query($query, true, $returnSQLQueryOrResultType == 'array'); |
@@ -213,18 +213,18 @@ discard block |
||
| 213 | 213 | * @param boolean $escape whether to escape or not the values |
| 214 | 214 | * @return mixed the insert id of the new record or null |
| 215 | 215 | */ |
| 216 | - public function insert($data = array(), $escape = true){ |
|
| 217 | - if (empty($data) && ! empty($this->data)){ |
|
| 216 | + public function insert($data = array(), $escape = true) { |
|
| 217 | + if (empty($data) && !empty($this->data)) { |
|
| 218 | 218 | //as when using $this->setData() may be the data already escaped |
| 219 | 219 | $escape = false; |
| 220 | 220 | $data = $this->data; |
| 221 | 221 | } |
| 222 | 222 | $query = $this->queryBuilder->insert($data, $escape)->getQuery(); |
| 223 | 223 | $result = $this->query($query); |
| 224 | - if ($result){ |
|
| 224 | + if ($result) { |
|
| 225 | 225 | $this->insertId = $this->pdo->lastInsertId(); |
| 226 | 226 | //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned |
| 227 | - return ! ($this->insertId) ? true : $this->insertId; |
|
| 227 | + return !($this->insertId) ? true : $this->insertId; |
|
| 228 | 228 | } |
| 229 | 229 | return false; |
| 230 | 230 | } |
@@ -235,8 +235,8 @@ discard block |
||
| 235 | 235 | * @param boolean $escape whether to escape or not the values |
| 236 | 236 | * @return mixed the update status |
| 237 | 237 | */ |
| 238 | - public function update($data = array(), $escape = true){ |
|
| 239 | - if (empty($data) && ! empty($this->data)){ |
|
| 238 | + public function update($data = array(), $escape = true) { |
|
| 239 | + if (empty($data) && !empty($this->data)) { |
|
| 240 | 240 | //as when using $this->setData() may be the data already escaped |
| 241 | 241 | $escape = false; |
| 242 | 242 | $data = $this->data; |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | * Delete the record in database |
| 250 | 250 | * @return mixed the delete status |
| 251 | 251 | */ |
| 252 | - public function delete(){ |
|
| 252 | + public function delete() { |
|
| 253 | 253 | $query = $this->queryBuilder->delete()->getQuery(); |
| 254 | 254 | return $this->query($query); |
| 255 | 255 | } |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | * @param integer $ttl the cache time to live in second |
| 260 | 260 | * @return object the current Database instance |
| 261 | 261 | */ |
| 262 | - public function setCache($ttl = 0){ |
|
| 262 | + public function setCache($ttl = 0) { |
|
| 263 | 263 | $this->cacheTtl = $ttl; |
| 264 | 264 | $this->temporaryCacheTtl = $ttl; |
| 265 | 265 | return $this; |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @param integer $ttl the cache time to live in second |
| 271 | 271 | * @return object the current Database instance |
| 272 | 272 | */ |
| 273 | - public function cached($ttl = 0){ |
|
| 273 | + public function cached($ttl = 0) { |
|
| 274 | 274 | $this->temporaryCacheTtl = $ttl; |
| 275 | 275 | return $this; |
| 276 | 276 | } |
@@ -282,9 +282,9 @@ discard block |
||
| 282 | 282 | * @return mixed the data after escaped or the same data if no |
| 283 | 283 | * need escaped |
| 284 | 284 | */ |
| 285 | - public function escape($data, $escaped = true){ |
|
| 285 | + public function escape($data, $escaped = true) { |
|
| 286 | 286 | $data = trim($data); |
| 287 | - if($escaped){ |
|
| 287 | + if ($escaped) { |
|
| 288 | 288 | return $this->pdo->quote($data); |
| 289 | 289 | } |
| 290 | 290 | return $data; |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | * Return the number query executed count for the current request |
| 295 | 295 | * @return int |
| 296 | 296 | */ |
| 297 | - public function queryCount(){ |
|
| 297 | + public function queryCount() { |
|
| 298 | 298 | return $this->queryCount; |
| 299 | 299 | } |
| 300 | 300 | |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * Return the current query SQL string |
| 303 | 303 | * @return string |
| 304 | 304 | */ |
| 305 | - public function getQuery(){ |
|
| 305 | + public function getQuery() { |
|
| 306 | 306 | return $this->query; |
| 307 | 307 | } |
| 308 | 308 | |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | * Return the application database name |
| 311 | 311 | * @return string |
| 312 | 312 | */ |
| 313 | - public function getDatabaseName(){ |
|
| 313 | + public function getDatabaseName() { |
|
| 314 | 314 | return $this->databaseName; |
| 315 | 315 | } |
| 316 | 316 | |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | * Return the PDO instance |
| 319 | 319 | * @return object |
| 320 | 320 | */ |
| 321 | - public function getPdo(){ |
|
| 321 | + public function getPdo() { |
|
| 322 | 322 | return $this->pdo; |
| 323 | 323 | } |
| 324 | 324 | |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | * @param object $pdo the pdo object |
| 328 | 328 | * @return object Database |
| 329 | 329 | */ |
| 330 | - public function setPdo(PDO $pdo){ |
|
| 330 | + public function setPdo(PDO $pdo) { |
|
| 331 | 331 | $this->pdo = $pdo; |
| 332 | 332 | return $this; |
| 333 | 333 | } |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | * Return the cache instance |
| 337 | 337 | * @return CacheInterface |
| 338 | 338 | */ |
| 339 | - public function getCacheInstance(){ |
|
| 339 | + public function getCacheInstance() { |
|
| 340 | 340 | return $this->cacheInstance; |
| 341 | 341 | } |
| 342 | 342 | |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | * @param CacheInterface $cache the cache object |
| 346 | 346 | * @return object Database |
| 347 | 347 | */ |
| 348 | - public function setCacheInstance($cache){ |
|
| 348 | + public function setCacheInstance($cache) { |
|
| 349 | 349 | $this->cacheInstance = $cache; |
| 350 | 350 | return $this; |
| 351 | 351 | } |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | * Return the DatabaseQueryBuilder instance |
| 356 | 356 | * @return object DatabaseQueryBuilder |
| 357 | 357 | */ |
| 358 | - public function getQueryBuilder(){ |
|
| 358 | + public function getQueryBuilder() { |
|
| 359 | 359 | return $this->queryBuilder; |
| 360 | 360 | } |
| 361 | 361 | |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | * Set the DatabaseQueryBuilder instance |
| 364 | 364 | * @param object DatabaseQueryBuilder $queryBuilder the DatabaseQueryBuilder object |
| 365 | 365 | */ |
| 366 | - public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder){ |
|
| 366 | + public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder) { |
|
| 367 | 367 | $this->queryBuilder = $queryBuilder; |
| 368 | 368 | return $this; |
| 369 | 369 | } |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | * Return the DatabaseQueryRunner instance |
| 373 | 373 | * @return object DatabaseQueryRunner |
| 374 | 374 | */ |
| 375 | - public function getQueryRunner(){ |
|
| 375 | + public function getQueryRunner() { |
|
| 376 | 376 | return $this->queryRunner; |
| 377 | 377 | } |
| 378 | 378 | |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | * Set the DatabaseQueryRunner instance |
| 381 | 381 | * @param object DatabaseQueryRunner $queryRunner the DatabaseQueryRunner object |
| 382 | 382 | */ |
| 383 | - public function setQueryRunner(DatabaseQueryRunner $queryRunner){ |
|
| 383 | + public function setQueryRunner(DatabaseQueryRunner $queryRunner) { |
|
| 384 | 384 | $this->queryRunner = $queryRunner; |
| 385 | 385 | return $this; |
| 386 | 386 | } |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | * Return the data to be used for insert, update, etc. |
| 390 | 390 | * @return array |
| 391 | 391 | */ |
| 392 | - public function getData(){ |
|
| 392 | + public function getData() { |
|
| 393 | 393 | return $this->data; |
| 394 | 394 | } |
| 395 | 395 | |
@@ -400,9 +400,9 @@ discard block |
||
| 400 | 400 | * @param boolean $escape whether to escape or not the $value |
| 401 | 401 | * @return object the current Database instance |
| 402 | 402 | */ |
| 403 | - public function setData($key, $value = null, $escape = true){ |
|
| 404 | - if (is_array($key)){ |
|
| 405 | - foreach($key as $k => $v){ |
|
| 403 | + public function setData($key, $value = null, $escape = true) { |
|
| 404 | + if (is_array($key)) { |
|
| 405 | + foreach ($key as $k => $v) { |
|
| 406 | 406 | $this->setData($k, $v, $escape); |
| 407 | 407 | } |
| 408 | 408 | } else { |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | * @param boolean $returnAsArray return the result as array or not |
| 419 | 419 | * @return mixed the query result |
| 420 | 420 | */ |
| 421 | - public function query($query, $returnAsList = true, $returnAsArray = false){ |
|
| 421 | + public function query($query, $returnAsList = true, $returnAsArray = false) { |
|
| 422 | 422 | $this->reset(); |
| 423 | 423 | $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query)); |
| 424 | 424 | //If is the SELECT query |
@@ -439,12 +439,12 @@ discard block |
||
| 439 | 439 | //if can use cache feature for this query |
| 440 | 440 | $dbCacheStatus = $cacheEnable && $cacheExpire > 0; |
| 441 | 441 | |
| 442 | - if ($dbCacheStatus && $isSqlSELECTQuery){ |
|
| 442 | + if ($dbCacheStatus && $isSqlSELECTQuery) { |
|
| 443 | 443 | $this->logger->info('The cache is enabled for this query, try to get result from cache'); |
| 444 | 444 | $cacheContent = $this->getCacheContentForQuery($query, $returnAsList, $returnAsArray); |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - if (!$cacheContent){ |
|
| 447 | + if (!$cacheContent) { |
|
| 448 | 448 | //count the number of query execution to server |
| 449 | 449 | $this->queryCount++; |
| 450 | 450 | |
@@ -453,19 +453,19 @@ discard block |
||
| 453 | 453 | ->setReturnAsArray($returnAsArray) |
| 454 | 454 | ->execute(); |
| 455 | 455 | |
| 456 | - if (!is_object($queryResult)){ |
|
| 456 | + if (!is_object($queryResult)) { |
|
| 457 | 457 | $this->result = false; |
| 458 | 458 | $this->numRows = 0; |
| 459 | 459 | return $this->result; |
| 460 | 460 | } |
| 461 | 461 | $this->result = $queryResult->getResult(); |
| 462 | 462 | $this->numRows = $queryResult->getNumRows(); |
| 463 | - if ($isSqlSELECTQuery && $dbCacheStatus){ |
|
| 463 | + if ($isSqlSELECTQuery && $dbCacheStatus) { |
|
| 464 | 464 | $key = $this->getCacheKeyForQuery($this->query, $returnAsList, $returnAsArray); |
| 465 | 465 | $this->setCacheContentForQuery($this->query, $key, $this->result, $cacheExpire); |
| 466 | 466 | } |
| 467 | - } else if ($isSqlSELECTQuery){ |
|
| 468 | - $this->logger->info('The result for query [' .$this->query. '] already cached use it'); |
|
| 467 | + } else if ($isSqlSELECTQuery) { |
|
| 468 | + $this->logger->info('The result for query [' . $this->query . '] already cached use it'); |
|
| 469 | 469 | $this->result = $cacheContent; |
| 470 | 470 | $this->numRows = count($this->result); |
| 471 | 471 | } |
@@ -479,9 +479,9 @@ discard block |
||
| 479 | 479 | * @param boolean $autoConnect whether to connect to database after set the configuration |
| 480 | 480 | * @return object Database |
| 481 | 481 | */ |
| 482 | - public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true, $autoConnect = false){ |
|
| 482 | + public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true, $autoConnect = false) { |
|
| 483 | 483 | $db = array(); |
| 484 | - if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')){ |
|
| 484 | + if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')) { |
|
| 485 | 485 | //here don't use require_once because somewhere user can create database instance directly |
| 486 | 486 | require CONFIG_PATH . 'database.php'; |
| 487 | 487 | } |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | //determine the port using the hostname like localhost:3307 |
| 497 | 497 | //hostname will be "localhost", and port "3307" |
| 498 | 498 | $p = explode(':', $config['hostname']); |
| 499 | - if (count($p) >= 2){ |
|
| 499 | + if (count($p) >= 2) { |
|
| 500 | 500 | $config['hostname'] = $p[0]; |
| 501 | 501 | $config['port'] = $p[1]; |
| 502 | 502 | } |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | array('password' => string_hidden($this->config['password'])) |
| 511 | 511 | )) |
| 512 | 512 | ); |
| 513 | - if($autoConnect){ |
|
| 513 | + if ($autoConnect) { |
|
| 514 | 514 | //Now connect to the database |
| 515 | 515 | $this->connect(); |
| 516 | 516 | } |
@@ -521,14 +521,14 @@ discard block |
||
| 521 | 521 | * Return the database configuration |
| 522 | 522 | * @return array |
| 523 | 523 | */ |
| 524 | - public function getDatabaseConfiguration(){ |
|
| 524 | + public function getDatabaseConfiguration() { |
|
| 525 | 525 | return $this->config; |
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
| 529 | 529 | * Close the connexion |
| 530 | 530 | */ |
| 531 | - public function close(){ |
|
| 531 | + public function close() { |
|
| 532 | 532 | $this->pdo = null; |
| 533 | 533 | } |
| 534 | 534 | |
@@ -536,7 +536,7 @@ discard block |
||
| 536 | 536 | * Return the database default configuration |
| 537 | 537 | * @return array |
| 538 | 538 | */ |
| 539 | - protected function getDatabaseDefaultConfiguration(){ |
|
| 539 | + protected function getDatabaseDefaultConfiguration() { |
|
| 540 | 540 | return array( |
| 541 | 541 | 'driver' => '', |
| 542 | 542 | 'username' => '', |
@@ -554,16 +554,16 @@ discard block |
||
| 554 | 554 | * Update the DatabaseQueryBuilder and DatabaseQueryRunner properties |
| 555 | 555 | * @return void |
| 556 | 556 | */ |
| 557 | - protected function updateQueryBuilderAndRunnerProperties(){ |
|
| 557 | + protected function updateQueryBuilderAndRunnerProperties() { |
|
| 558 | 558 | //update queryBuilder with some properties needed |
| 559 | - if (is_object($this->queryBuilder)){ |
|
| 559 | + if (is_object($this->queryBuilder)) { |
|
| 560 | 560 | $this->queryBuilder->setDriver($this->config['driver']) |
| 561 | 561 | ->setPrefix($this->config['prefix']) |
| 562 | 562 | ->setPdo($this->pdo); |
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | //update queryRunner with some properties needed |
| 566 | - if (is_object($this->queryRunner)){ |
|
| 566 | + if (is_object($this->queryRunner)) { |
|
| 567 | 567 | $this->queryRunner->setDriver($this->config['driver']) |
| 568 | 568 | ->setPdo($this->pdo); |
| 569 | 569 | } |
@@ -574,10 +574,10 @@ discard block |
||
| 574 | 574 | * This method is used to get the PDO DSN string using the configured driver |
| 575 | 575 | * @return string|null the DSN string or null if can not find it |
| 576 | 576 | */ |
| 577 | - protected function getDsnValueFromConfig(){ |
|
| 577 | + protected function getDsnValueFromConfig() { |
|
| 578 | 578 | $dsn = null; |
| 579 | 579 | $config = $this->getDatabaseConfiguration(); |
| 580 | - if (! empty($config)){ |
|
| 580 | + if (!empty($config)) { |
|
| 581 | 581 | $driver = $config['driver']; |
| 582 | 582 | $driverDsnMap = array( |
| 583 | 583 | 'mysql' => $this->getDsnValueForDriver('mysql'), |
@@ -585,7 +585,7 @@ discard block |
||
| 585 | 585 | 'sqlite' => $this->getDsnValueForDriver('sqlite'), |
| 586 | 586 | 'oracle' => $this->getDsnValueForDriver('oracle') |
| 587 | 587 | ); |
| 588 | - if (isset($driverDsnMap[$driver])){ |
|
| 588 | + if (isset($driverDsnMap[$driver])) { |
|
| 589 | 589 | $dsn = $driverDsnMap[$driver]; |
| 590 | 590 | } |
| 591 | 591 | } |
@@ -597,17 +597,17 @@ discard block |
||
| 597 | 597 | * @param string $driver the driver name |
| 598 | 598 | * @return string|null the dsn name |
| 599 | 599 | */ |
| 600 | - protected function getDsnValueForDriver($driver){ |
|
| 600 | + protected function getDsnValueForDriver($driver) { |
|
| 601 | 601 | $dsn = ''; |
| 602 | 602 | $config = $this->getDatabaseConfiguration(); |
| 603 | - if (empty($config)){ |
|
| 603 | + if (empty($config)) { |
|
| 604 | 604 | return null; |
| 605 | 605 | } |
| 606 | 606 | switch ($driver) { |
| 607 | 607 | case 'mysql': |
| 608 | 608 | case 'pgsql': |
| 609 | 609 | $port = ''; |
| 610 | - if (! empty($config['port'])) { |
|
| 610 | + if (!empty($config['port'])) { |
|
| 611 | 611 | $port = 'port=' . $config['port'] . ';'; |
| 612 | 612 | } |
| 613 | 613 | $dsn = $driver . ':host=' . $config['hostname'] . ';' . $port . 'dbname=' . $config['database']; |
@@ -617,10 +617,10 @@ discard block |
||
| 617 | 617 | break; |
| 618 | 618 | case 'oracle': |
| 619 | 619 | $port = ''; |
| 620 | - if (! empty($config['port'])) { |
|
| 620 | + if (!empty($config['port'])) { |
|
| 621 | 621 | $port = ':' . $config['port']; |
| 622 | 622 | } |
| 623 | - $dsn = 'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database']; |
|
| 623 | + $dsn = 'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database']; |
|
| 624 | 624 | break; |
| 625 | 625 | } |
| 626 | 626 | return $dsn; |
@@ -632,9 +632,9 @@ discard block |
||
| 632 | 632 | * |
| 633 | 633 | * @return mixed |
| 634 | 634 | */ |
| 635 | - protected function getCacheContentForQuery($query, $returnAsList, $returnAsArray){ |
|
| 635 | + protected function getCacheContentForQuery($query, $returnAsList, $returnAsArray) { |
|
| 636 | 636 | $cacheKey = $this->getCacheKeyForQuery($query, $returnAsList, $returnAsArray); |
| 637 | - if (! is_object($this->cacheInstance)){ |
|
| 637 | + if (!is_object($this->cacheInstance)) { |
|
| 638 | 638 | //can not call method with reference in argument |
| 639 | 639 | //like $this->setCacheInstance(& get_instance()->cache); |
| 640 | 640 | //use temporary variable |
@@ -651,9 +651,9 @@ discard block |
||
| 651 | 651 | * @param mixed $result the query result to save |
| 652 | 652 | * @param int $expire the cache TTL |
| 653 | 653 | */ |
| 654 | - protected function setCacheContentForQuery($query, $key, $result, $expire){ |
|
| 655 | - $this->logger->info('Save the result for query [' .$query. '] into cache for future use'); |
|
| 656 | - if (! is_object($this->cacheInstance)){ |
|
| 654 | + protected function setCacheContentForQuery($query, $key, $result, $expire) { |
|
| 655 | + $this->logger->info('Save the result for query [' . $query . '] into cache for future use'); |
|
| 656 | + if (!is_object($this->cacheInstance)) { |
|
| 657 | 657 | //can not call method with reference in argument |
| 658 | 658 | //like $this->setCacheInstance(& get_instance()->cache); |
| 659 | 659 | //use temporary variable |
@@ -670,7 +670,7 @@ discard block |
||
| 670 | 670 | * |
| 671 | 671 | * @return string |
| 672 | 672 | */ |
| 673 | - protected function getCacheKeyForQuery($query, $returnAsList, $returnAsArray){ |
|
| 673 | + protected function getCacheKeyForQuery($query, $returnAsList, $returnAsArray) { |
|
| 674 | 674 | return md5($query . $returnAsList . $returnAsArray); |
| 675 | 675 | } |
| 676 | 676 | |
@@ -678,7 +678,7 @@ discard block |
||
| 678 | 678 | /** |
| 679 | 679 | * Reset the database class attributs to the initail values before each query. |
| 680 | 680 | */ |
| 681 | - private function reset(){ |
|
| 681 | + private function reset() { |
|
| 682 | 682 | //query builder reset |
| 683 | 683 | $this->queryBuilder->reset(); |
| 684 | 684 | $this->numRows = 0; |
@@ -691,7 +691,7 @@ discard block |
||
| 691 | 691 | /** |
| 692 | 692 | * The class destructor |
| 693 | 693 | */ |
| 694 | - public function __destruct(){ |
|
| 694 | + public function __destruct() { |
|
| 695 | 695 | $this->pdo = null; |
| 696 | 696 | } |
| 697 | 697 | |