@@ -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 | + } |
|
@@ -1,320 +1,320 @@ |
||
| 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 | - class Form{ |
|
| 28 | + class Form{ |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Generate the form opened tag |
|
| 32 | - * @param string $path the form action path |
|
| 33 | - * @param array $attributes the additional form attributes |
|
| 34 | - * @param string $method the form method like 'GET', 'POST' |
|
| 35 | - * @param string $enctype the form enctype like "multipart/form-data" |
|
| 36 | - * @return string the generated form html |
|
| 37 | - */ |
|
| 38 | - public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null){ |
|
| 39 | - if($path){ |
|
| 40 | - $path = Url::site_url($path); |
|
| 41 | - } |
|
| 42 | - $method = strtoupper($method); |
|
| 43 | - $str = null; |
|
| 44 | - $str .= '<form action = "'.$path.'" method = "'.$method.'"'; |
|
| 45 | - if(! empty($enctype)){ |
|
| 46 | - $str .= ' enctype = "'.$enctype.'" '; |
|
| 47 | - } |
|
| 48 | - if(! isset($attributes['accept-charset'])){ |
|
| 49 | - $attributes['accept-charset'] = get_config('charset', 'utf-8'); |
|
| 50 | - } |
|
| 51 | - $str .= attributes_to_string($attributes); |
|
| 52 | - $str .= '>'; |
|
| 53 | - //if CSRF is enabled in the configuration |
|
| 54 | - if(get_config('csrf_enable', false) && $method == 'POST'){ |
|
| 55 | - $csrfValue = Security::generateCSRF(); |
|
| 56 | - $csrfName = get_config('csrf_key', 'csrf_key'); |
|
| 57 | - $str .= static::hidden($csrfName, $csrfValue); |
|
| 58 | - } |
|
| 59 | - return $str; |
|
| 60 | - } |
|
| 30 | + /** |
|
| 31 | + * Generate the form opened tag |
|
| 32 | + * @param string $path the form action path |
|
| 33 | + * @param array $attributes the additional form attributes |
|
| 34 | + * @param string $method the form method like 'GET', 'POST' |
|
| 35 | + * @param string $enctype the form enctype like "multipart/form-data" |
|
| 36 | + * @return string the generated form html |
|
| 37 | + */ |
|
| 38 | + public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null){ |
|
| 39 | + if($path){ |
|
| 40 | + $path = Url::site_url($path); |
|
| 41 | + } |
|
| 42 | + $method = strtoupper($method); |
|
| 43 | + $str = null; |
|
| 44 | + $str .= '<form action = "'.$path.'" method = "'.$method.'"'; |
|
| 45 | + if(! empty($enctype)){ |
|
| 46 | + $str .= ' enctype = "'.$enctype.'" '; |
|
| 47 | + } |
|
| 48 | + if(! isset($attributes['accept-charset'])){ |
|
| 49 | + $attributes['accept-charset'] = get_config('charset', 'utf-8'); |
|
| 50 | + } |
|
| 51 | + $str .= attributes_to_string($attributes); |
|
| 52 | + $str .= '>'; |
|
| 53 | + //if CSRF is enabled in the configuration |
|
| 54 | + if(get_config('csrf_enable', false) && $method == 'POST'){ |
|
| 55 | + $csrfValue = Security::generateCSRF(); |
|
| 56 | + $csrfName = get_config('csrf_key', 'csrf_key'); |
|
| 57 | + $str .= static::hidden($csrfName, $csrfValue); |
|
| 58 | + } |
|
| 59 | + return $str; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Generate the form opened tag for multipart like to send a file |
|
| 64 | - * @see Form::open() for more details |
|
| 65 | - * @return string the generated multipart form html |
|
| 66 | - */ |
|
| 67 | - public static function openMultipart($path = null, array $attributes = array(), $method = 'POST'){ |
|
| 68 | - return self::open($path, $attributes, $method, 'multipart/form-data'); |
|
| 69 | - } |
|
| 62 | + /** |
|
| 63 | + * Generate the form opened tag for multipart like to send a file |
|
| 64 | + * @see Form::open() for more details |
|
| 65 | + * @return string the generated multipart form html |
|
| 66 | + */ |
|
| 67 | + public static function openMultipart($path = null, array $attributes = array(), $method = 'POST'){ |
|
| 68 | + return self::open($path, $attributes, $method, 'multipart/form-data'); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Generate the form close |
|
| 73 | - * @return string the form close html |
|
| 74 | - */ |
|
| 75 | - public static function close(){ |
|
| 76 | - return '</form>'; |
|
| 77 | - } |
|
| 71 | + /** |
|
| 72 | + * Generate the form close |
|
| 73 | + * @return string the form close html |
|
| 74 | + */ |
|
| 75 | + public static function close(){ |
|
| 76 | + return '</form>'; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Generate the form fieldset & legend |
|
| 81 | - * @param string $legend the legend tag value |
|
| 82 | - * @param array $fieldsetAttributes the fieldset additional HTML attributes |
|
| 83 | - * @param array $legendAttributes the legend additional HTML attributes. Is used only is $legend is not empty |
|
| 84 | - * @return string the generated fieldset value |
|
| 85 | - */ |
|
| 86 | - public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()){ |
|
| 87 | - $str = '<fieldset' . attributes_to_string($fieldsetAttributes) . '>'; |
|
| 88 | - if($legend){ |
|
| 89 | - $str .= '<legend' . attributes_to_string($legendAttributes) . '>'.$legend.'</legend>'; |
|
| 90 | - } |
|
| 91 | - return $str; |
|
| 92 | - } |
|
| 79 | + /** |
|
| 80 | + * Generate the form fieldset & legend |
|
| 81 | + * @param string $legend the legend tag value |
|
| 82 | + * @param array $fieldsetAttributes the fieldset additional HTML attributes |
|
| 83 | + * @param array $legendAttributes the legend additional HTML attributes. Is used only is $legend is not empty |
|
| 84 | + * @return string the generated fieldset value |
|
| 85 | + */ |
|
| 86 | + public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()){ |
|
| 87 | + $str = '<fieldset' . attributes_to_string($fieldsetAttributes) . '>'; |
|
| 88 | + if($legend){ |
|
| 89 | + $str .= '<legend' . attributes_to_string($legendAttributes) . '>'.$legend.'</legend>'; |
|
| 90 | + } |
|
| 91 | + return $str; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Generate the fieldset close tag |
|
| 96 | - * @return string the generated html for fieldset close |
|
| 97 | - */ |
|
| 98 | - public static function fieldsetClose(){ |
|
| 99 | - return '</fieldset>'; |
|
| 100 | - } |
|
| 94 | + /** |
|
| 95 | + * Generate the fieldset close tag |
|
| 96 | + * @return string the generated html for fieldset close |
|
| 97 | + */ |
|
| 98 | + public static function fieldsetClose(){ |
|
| 99 | + return '</fieldset>'; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Get the error message for the given form field name. |
|
| 104 | - * This use the form validation information to get the error information. |
|
| 105 | - * @param string $name the form field name |
|
| 106 | - * @return string the error message if exists and null if not |
|
| 107 | - */ |
|
| 108 | - public static function error($name){ |
|
| 109 | - $return = null; |
|
| 110 | - $obj = & get_instance(); |
|
| 111 | - if(isset($obj->formvalidation)){ |
|
| 112 | - $errors = $obj->formvalidation->returnErrors(); |
|
| 113 | - $error = isset($errors[$name]) ? $errors[$name] : null; |
|
| 114 | - if($error){ |
|
| 115 | - list($errorStart, $errorEnd) = $obj->formvalidation->getErrorDelimiter(); |
|
| 116 | - $return = $errorStart . $error . $errorEnd; |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - return $return; |
|
| 120 | - } |
|
| 102 | + /** |
|
| 103 | + * Get the error message for the given form field name. |
|
| 104 | + * This use the form validation information to get the error information. |
|
| 105 | + * @param string $name the form field name |
|
| 106 | + * @return string the error message if exists and null if not |
|
| 107 | + */ |
|
| 108 | + public static function error($name){ |
|
| 109 | + $return = null; |
|
| 110 | + $obj = & get_instance(); |
|
| 111 | + if(isset($obj->formvalidation)){ |
|
| 112 | + $errors = $obj->formvalidation->returnErrors(); |
|
| 113 | + $error = isset($errors[$name]) ? $errors[$name] : null; |
|
| 114 | + if($error){ |
|
| 115 | + list($errorStart, $errorEnd) = $obj->formvalidation->getErrorDelimiter(); |
|
| 116 | + $return = $errorStart . $error . $errorEnd; |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + return $return; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Get the form field value |
|
| 124 | - * @param string $name the form field name |
|
| 125 | - * @param mixed $default the default value if can not found the given form field name |
|
| 126 | - * @return mixed the form field value if is set, otherwise return the default value. |
|
| 127 | - */ |
|
| 128 | - public static function value($name, $default = null){ |
|
| 129 | - $value = get_instance()->request->query($name); |
|
| 130 | - return $value ? $value : $default; |
|
| 131 | - } |
|
| 122 | + /** |
|
| 123 | + * Get the form field value |
|
| 124 | + * @param string $name the form field name |
|
| 125 | + * @param mixed $default the default value if can not found the given form field name |
|
| 126 | + * @return mixed the form field value if is set, otherwise return the default value. |
|
| 127 | + */ |
|
| 128 | + public static function value($name, $default = null){ |
|
| 129 | + $value = get_instance()->request->query($name); |
|
| 130 | + return $value ? $value : $default; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * Generate the form label html content |
|
| 135 | - * @param string $label the title of the label |
|
| 136 | - * @param string $for the value of the label "for" attribute |
|
| 137 | - * @param array $attributes the additional attributes to be added |
|
| 138 | - * @return string the generated label html content |
|
| 139 | - */ |
|
| 140 | - public static function label($label, $for = '', array $attributes = array()){ |
|
| 141 | - $str = '<label'; |
|
| 142 | - if($for){ |
|
| 143 | - $str .= ' for = "'.$for.'"'; |
|
| 144 | - } |
|
| 145 | - $str .= attributes_to_string($attributes); |
|
| 146 | - $str .= '>'; |
|
| 147 | - $str .= $label.'</label>'; |
|
| 148 | - return $str; |
|
| 149 | - } |
|
| 133 | + /** |
|
| 134 | + * Generate the form label html content |
|
| 135 | + * @param string $label the title of the label |
|
| 136 | + * @param string $for the value of the label "for" attribute |
|
| 137 | + * @param array $attributes the additional attributes to be added |
|
| 138 | + * @return string the generated label html content |
|
| 139 | + */ |
|
| 140 | + public static function label($label, $for = '', array $attributes = array()){ |
|
| 141 | + $str = '<label'; |
|
| 142 | + if($for){ |
|
| 143 | + $str .= ' for = "'.$for.'"'; |
|
| 144 | + } |
|
| 145 | + $str .= attributes_to_string($attributes); |
|
| 146 | + $str .= '>'; |
|
| 147 | + $str .= $label.'</label>'; |
|
| 148 | + return $str; |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Generate the form field for input like "text", "email", "password", etc. |
|
| 153 | - * @param string $name the form field name |
|
| 154 | - * @param mixed $value the form field value to be set |
|
| 155 | - * @param array $attributes the additional attributes to be added in the form input |
|
| 156 | - * @param string $type the type of the form field (password, text, submit, button, etc.) |
|
| 157 | - * @return string the generated form field html content for the input |
|
| 158 | - */ |
|
| 159 | - public static function input($name, $value = null, array $attributes = array(), $type = 'text'){ |
|
| 160 | - $str = null; |
|
| 161 | - $str .= '<input name = "'.$name.'" value = "'.$value.'" type = "'.$type.'"'; |
|
| 162 | - $str .= attributes_to_string($attributes); |
|
| 163 | - $str .= '/>'; |
|
| 164 | - return $str; |
|
| 165 | - } |
|
| 151 | + /** |
|
| 152 | + * Generate the form field for input like "text", "email", "password", etc. |
|
| 153 | + * @param string $name the form field name |
|
| 154 | + * @param mixed $value the form field value to be set |
|
| 155 | + * @param array $attributes the additional attributes to be added in the form input |
|
| 156 | + * @param string $type the type of the form field (password, text, submit, button, etc.) |
|
| 157 | + * @return string the generated form field html content for the input |
|
| 158 | + */ |
|
| 159 | + public static function input($name, $value = null, array $attributes = array(), $type = 'text'){ |
|
| 160 | + $str = null; |
|
| 161 | + $str .= '<input name = "'.$name.'" value = "'.$value.'" type = "'.$type.'"'; |
|
| 162 | + $str .= attributes_to_string($attributes); |
|
| 163 | + $str .= '/>'; |
|
| 164 | + return $str; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Generate the form field for "text" |
|
| 169 | - * @see Form::input() for more details |
|
| 170 | - */ |
|
| 171 | - public static function text($name, $value = null, array $attributes = array()){ |
|
| 172 | - return self::input($name, $value, $attributes, 'text'); |
|
| 173 | - } |
|
| 167 | + /** |
|
| 168 | + * Generate the form field for "text" |
|
| 169 | + * @see Form::input() for more details |
|
| 170 | + */ |
|
| 171 | + public static function text($name, $value = null, array $attributes = array()){ |
|
| 172 | + return self::input($name, $value, $attributes, 'text'); |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * Generate the form field for "password" |
|
| 177 | - * @see Form::input() for more details |
|
| 178 | - */ |
|
| 179 | - public static function password($name, $value = null, array $attributes = array()){ |
|
| 180 | - return self::input($name, $value, $attributes, 'password'); |
|
| 181 | - } |
|
| 175 | + /** |
|
| 176 | + * Generate the form field for "password" |
|
| 177 | + * @see Form::input() for more details |
|
| 178 | + */ |
|
| 179 | + public static function password($name, $value = null, array $attributes = array()){ |
|
| 180 | + return self::input($name, $value, $attributes, 'password'); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * Generate the form field for "radio" |
|
| 185 | - * @see Form::input() for more details |
|
| 186 | - */ |
|
| 187 | - public static function radio($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 188 | - if($checked){ |
|
| 189 | - $attributes['checked'] = true; |
|
| 190 | - } |
|
| 191 | - return self::input($name, $value, $attributes, 'radio'); |
|
| 192 | - } |
|
| 183 | + /** |
|
| 184 | + * Generate the form field for "radio" |
|
| 185 | + * @see Form::input() for more details |
|
| 186 | + */ |
|
| 187 | + public static function radio($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 188 | + if($checked){ |
|
| 189 | + $attributes['checked'] = true; |
|
| 190 | + } |
|
| 191 | + return self::input($name, $value, $attributes, 'radio'); |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - /** |
|
| 195 | - * Generate the form field for "checkbox" |
|
| 196 | - * @see Form::input() for more details |
|
| 197 | - */ |
|
| 198 | - public static function checkbox($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 199 | - if($checked){ |
|
| 200 | - $attributes['checked'] = true; |
|
| 201 | - } |
|
| 202 | - return self::input($name, $value, $attributes, 'checkbox'); |
|
| 203 | - } |
|
| 194 | + /** |
|
| 195 | + * Generate the form field for "checkbox" |
|
| 196 | + * @see Form::input() for more details |
|
| 197 | + */ |
|
| 198 | + public static function checkbox($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 199 | + if($checked){ |
|
| 200 | + $attributes['checked'] = true; |
|
| 201 | + } |
|
| 202 | + return self::input($name, $value, $attributes, 'checkbox'); |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - /** |
|
| 206 | - * Generate the form field for "number" |
|
| 207 | - * @see Form::input() for more details |
|
| 208 | - */ |
|
| 209 | - public static function number($name, $value = null, array $attributes = array()){ |
|
| 210 | - return self::input($name, $value, $attributes, 'number'); |
|
| 211 | - } |
|
| 205 | + /** |
|
| 206 | + * Generate the form field for "number" |
|
| 207 | + * @see Form::input() for more details |
|
| 208 | + */ |
|
| 209 | + public static function number($name, $value = null, array $attributes = array()){ |
|
| 210 | + return self::input($name, $value, $attributes, 'number'); |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - /** |
|
| 214 | - * Generate the form field for "phone" |
|
| 215 | - * @see Form::input() for more details |
|
| 216 | - */ |
|
| 217 | - public static function phone($name, $value = null, array $attributes = array()){ |
|
| 218 | - return self::input($name, $value, $attributes, 'phone'); |
|
| 219 | - } |
|
| 213 | + /** |
|
| 214 | + * Generate the form field for "phone" |
|
| 215 | + * @see Form::input() for more details |
|
| 216 | + */ |
|
| 217 | + public static function phone($name, $value = null, array $attributes = array()){ |
|
| 218 | + return self::input($name, $value, $attributes, 'phone'); |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * Generate the form field for "email" |
|
| 223 | - * @see Form::input() for more details |
|
| 224 | - */ |
|
| 225 | - public static function email($name, $value = null, array $attributes = array()){ |
|
| 226 | - return self::input($name, $value, $attributes, 'email'); |
|
| 227 | - } |
|
| 221 | + /** |
|
| 222 | + * Generate the form field for "email" |
|
| 223 | + * @see Form::input() for more details |
|
| 224 | + */ |
|
| 225 | + public static function email($name, $value = null, array $attributes = array()){ |
|
| 226 | + return self::input($name, $value, $attributes, 'email'); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * Generate the form field for "search" |
|
| 231 | - * @see Form::input() for more details |
|
| 232 | - */ |
|
| 233 | - public static function search($name, $value = null, array $attributes = array()){ |
|
| 234 | - return self::input($name, $value, $attributes, 'search'); |
|
| 235 | - } |
|
| 229 | + /** |
|
| 230 | + * Generate the form field for "search" |
|
| 231 | + * @see Form::input() for more details |
|
| 232 | + */ |
|
| 233 | + public static function search($name, $value = null, array $attributes = array()){ |
|
| 234 | + return self::input($name, $value, $attributes, 'search'); |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - /** |
|
| 238 | - * Generate the form field for "hidden" |
|
| 239 | - * @see Form::input() for more details |
|
| 240 | - */ |
|
| 241 | - public static function hidden($name, $value = null, array $attributes = array()){ |
|
| 242 | - return self::input($name, $value, $attributes, 'hidden'); |
|
| 243 | - } |
|
| 237 | + /** |
|
| 238 | + * Generate the form field for "hidden" |
|
| 239 | + * @see Form::input() for more details |
|
| 240 | + */ |
|
| 241 | + public static function hidden($name, $value = null, array $attributes = array()){ |
|
| 242 | + return self::input($name, $value, $attributes, 'hidden'); |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * Generate the form field for "file" |
|
| 247 | - * @see Form::input() for more details |
|
| 248 | - */ |
|
| 249 | - public static function file($name, array $attributes = array()){ |
|
| 250 | - return self::input($name, null, $attributes, 'file'); |
|
| 251 | - } |
|
| 245 | + /** |
|
| 246 | + * Generate the form field for "file" |
|
| 247 | + * @see Form::input() for more details |
|
| 248 | + */ |
|
| 249 | + public static function file($name, array $attributes = array()){ |
|
| 250 | + return self::input($name, null, $attributes, 'file'); |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * Generate the form field for "button" |
|
| 255 | - * @see Form::input() for more details |
|
| 256 | - */ |
|
| 257 | - public static function button($name, $value = null, array $attributes = array()){ |
|
| 258 | - return self::input($name, $value, $attributes, 'button'); |
|
| 259 | - } |
|
| 253 | + /** |
|
| 254 | + * Generate the form field for "button" |
|
| 255 | + * @see Form::input() for more details |
|
| 256 | + */ |
|
| 257 | + public static function button($name, $value = null, array $attributes = array()){ |
|
| 258 | + return self::input($name, $value, $attributes, 'button'); |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - /** |
|
| 262 | - * Generate the form field for "reset" |
|
| 263 | - * @see Form::input() for more details |
|
| 264 | - */ |
|
| 265 | - public static function reset($name, $value = null, array $attributes = array()){ |
|
| 266 | - return self::input($name, $value, $attributes, 'reset'); |
|
| 267 | - } |
|
| 261 | + /** |
|
| 262 | + * Generate the form field for "reset" |
|
| 263 | + * @see Form::input() for more details |
|
| 264 | + */ |
|
| 265 | + public static function reset($name, $value = null, array $attributes = array()){ |
|
| 266 | + return self::input($name, $value, $attributes, 'reset'); |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * Generate the form field for "submit" |
|
| 271 | - * @see Form::input() for more details |
|
| 272 | - */ |
|
| 273 | - public static function submit($name, $value = null, array $attributes = array()){ |
|
| 274 | - return self::input($name, $value, $attributes, 'submit'); |
|
| 275 | - } |
|
| 269 | + /** |
|
| 270 | + * Generate the form field for "submit" |
|
| 271 | + * @see Form::input() for more details |
|
| 272 | + */ |
|
| 273 | + public static function submit($name, $value = null, array $attributes = array()){ |
|
| 274 | + return self::input($name, $value, $attributes, 'submit'); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - /** |
|
| 278 | - * Generate the form field for textarea |
|
| 279 | - * @param string $name the name of the textarea field |
|
| 280 | - * @param string $value the textarea field value |
|
| 281 | - * @param array $attributes the additional attributes to be added |
|
| 282 | - * @return string the generated textarea form html content |
|
| 283 | - */ |
|
| 284 | - public static function textarea($name, $value = '', array $attributes = array()){ |
|
| 285 | - $str = null; |
|
| 286 | - $str .= '<textarea name = "'.$name.'"'; |
|
| 287 | - $str .= attributes_to_string($attributes); |
|
| 288 | - $str .= '>'; |
|
| 289 | - $str .= $value.'</textarea>'; |
|
| 290 | - return $str; |
|
| 291 | - } |
|
| 277 | + /** |
|
| 278 | + * Generate the form field for textarea |
|
| 279 | + * @param string $name the name of the textarea field |
|
| 280 | + * @param string $value the textarea field value |
|
| 281 | + * @param array $attributes the additional attributes to be added |
|
| 282 | + * @return string the generated textarea form html content |
|
| 283 | + */ |
|
| 284 | + public static function textarea($name, $value = '', array $attributes = array()){ |
|
| 285 | + $str = null; |
|
| 286 | + $str .= '<textarea name = "'.$name.'"'; |
|
| 287 | + $str .= attributes_to_string($attributes); |
|
| 288 | + $str .= '>'; |
|
| 289 | + $str .= $value.'</textarea>'; |
|
| 290 | + return $str; |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * Generate the form field for select |
|
| 295 | - * @param string $name the name of the form field |
|
| 296 | - * @param mixed|array $values the values used to populate the "option" tags |
|
| 297 | - * @param mixed $selected the selected value in the option list |
|
| 298 | - * @param array $attributes the additional attribute to be added |
|
| 299 | - * @return string the generated form field html content for select |
|
| 300 | - */ |
|
| 301 | - public static function select($name, $values = null, $selected = null, array $attributes = array()){ |
|
| 302 | - if(! is_array($values)){ |
|
| 303 | - $values = array('' => $values); |
|
| 304 | - } |
|
| 305 | - $str = null; |
|
| 306 | - $str .= '<select name = "'.$name.'"'; |
|
| 307 | - $str .= attributes_to_string($attributes); |
|
| 308 | - $str .= '>'; |
|
| 309 | - foreach($values as $key => $val){ |
|
| 310 | - $select = ''; |
|
| 311 | - if($key == $selected){ |
|
| 312 | - $select = 'selected'; |
|
| 313 | - } |
|
| 314 | - $str .= '<option value = "'.$key.'" '.$select.'>'.$val.'</option>'; |
|
| 315 | - } |
|
| 316 | - $str .= '</select>'; |
|
| 317 | - return $str; |
|
| 318 | - } |
|
| 293 | + /** |
|
| 294 | + * Generate the form field for select |
|
| 295 | + * @param string $name the name of the form field |
|
| 296 | + * @param mixed|array $values the values used to populate the "option" tags |
|
| 297 | + * @param mixed $selected the selected value in the option list |
|
| 298 | + * @param array $attributes the additional attribute to be added |
|
| 299 | + * @return string the generated form field html content for select |
|
| 300 | + */ |
|
| 301 | + public static function select($name, $values = null, $selected = null, array $attributes = array()){ |
|
| 302 | + if(! is_array($values)){ |
|
| 303 | + $values = array('' => $values); |
|
| 304 | + } |
|
| 305 | + $str = null; |
|
| 306 | + $str .= '<select name = "'.$name.'"'; |
|
| 307 | + $str .= attributes_to_string($attributes); |
|
| 308 | + $str .= '>'; |
|
| 309 | + foreach($values as $key => $val){ |
|
| 310 | + $select = ''; |
|
| 311 | + if($key == $selected){ |
|
| 312 | + $select = 'selected'; |
|
| 313 | + } |
|
| 314 | + $str .= '<option value = "'.$key.'" '.$select.'>'.$val.'</option>'; |
|
| 315 | + } |
|
| 316 | + $str .= '</select>'; |
|
| 317 | + return $str; |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - } |
|
| 320 | + } |
|
@@ -1,151 +1,151 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use PHPUnit\Framework\TestCase; |
|
| 3 | + use PHPUnit\Framework\TestCase; |
|
| 4 | 4 | |
| 5 | - class RouterTest extends TestCase |
|
| 6 | - { |
|
| 5 | + class RouterTest extends TestCase |
|
| 6 | + { |
|
| 7 | 7 | |
| 8 | - public static function setUpBeforeClass() |
|
| 9 | - { |
|
| 8 | + public static function setUpBeforeClass() |
|
| 9 | + { |
|
| 10 | 10 | |
| 11 | - } |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public static function tearDownAfterClass() |
|
| 14 | - { |
|
| 13 | + public static function tearDownAfterClass() |
|
| 14 | + { |
|
| 15 | 15 | |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - protected function setUp() |
|
| 19 | - { |
|
| 20 | - } |
|
| 18 | + protected function setUp() |
|
| 19 | + { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - protected function tearDown() |
|
| 23 | - { |
|
| 24 | - } |
|
| 22 | + protected function tearDown() |
|
| 23 | + { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function testAutoUri() |
|
| 27 | - { |
|
| 26 | + public function testAutoUri() |
|
| 27 | + { |
|
| 28 | 28 | //when application run in CLI the first argument will be used as route URI |
| 29 | 29 | $_SERVER['argv'][1] = ''; |
| 30 | 30 | |
| 31 | 31 | $r = new Router(); |
| 32 | 32 | //remove all all config |
| 33 | 33 | $r->setRouteConfiguration(array(), false) |
| 34 | - ->setRouteUri() |
|
| 35 | - ->setRouteSegments() |
|
| 36 | - ->determineRouteParamsInformation(); |
|
| 34 | + ->setRouteUri() |
|
| 35 | + ->setRouteSegments() |
|
| 36 | + ->determineRouteParamsInformation(); |
|
| 37 | 37 | |
| 38 | 38 | $this->assertNull($r->getController()); |
| 39 | - $this->assertSame('index', $r->getMethod()); |
|
| 40 | - $this->assertSame(0, count($r->getArgs())); |
|
| 41 | - } |
|
| 39 | + $this->assertSame('index', $r->getMethod()); |
|
| 40 | + $this->assertSame(0, count($r->getArgs())); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | public function testCustomUri() |
| 44 | - { |
|
| 44 | + { |
|
| 45 | 45 | $r = new Router(); |
| 46 | 46 | $r->setRouteUri('users/profile/34/54') |
| 47 | - ->setRouteSegments() |
|
| 48 | - ->determineRouteParamsInformation(); |
|
| 47 | + ->setRouteSegments() |
|
| 48 | + ->determineRouteParamsInformation(); |
|
| 49 | 49 | $this->assertSame('users', $r->getController()); |
| 50 | - $this->assertSame('profile', $r->getMethod()); |
|
| 51 | - $this->assertSame(2, count($r->getArgs())); |
|
| 52 | - } |
|
| 50 | + $this->assertSame('profile', $r->getMethod()); |
|
| 51 | + $this->assertSame(2, count($r->getArgs())); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | public function testWithCustomConfigControllerMethod() |
| 55 | - { |
|
| 55 | + { |
|
| 56 | 56 | $r = new Router(); |
| 57 | 57 | $r->add('/foo/bar', 'fooController@fooMethod') |
| 58 | - ->setRouteUri('/foo/bar') |
|
| 59 | - ->setRouteSegments() |
|
| 60 | - ->determineRouteParamsInformation(); |
|
| 58 | + ->setRouteUri('/foo/bar') |
|
| 59 | + ->setRouteSegments() |
|
| 60 | + ->determineRouteParamsInformation(); |
|
| 61 | 61 | $this->assertSame('fooController', $r->getController()); |
| 62 | - $this->assertSame('fooMethod', $r->getMethod()); |
|
| 63 | - $this->assertSame(0, count($r->getArgs())); |
|
| 64 | - $this->assertNull($r->getModule()); |
|
| 65 | - } |
|
| 62 | + $this->assertSame('fooMethod', $r->getMethod()); |
|
| 63 | + $this->assertSame(0, count($r->getArgs())); |
|
| 64 | + $this->assertNull($r->getModule()); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | 67 | public function testWithCustomConfigModuleControllerMethod() |
| 68 | - { |
|
| 68 | + { |
|
| 69 | 69 | $r = new Router(); |
| 70 | 70 | $r->add('/foo/bar', 'fooModule#fooController@fooMethod') |
| 71 | - ->setRouteUri('/foo/bar') |
|
| 72 | - ->setRouteSegments() |
|
| 73 | - ->determineRouteParamsInformation(); |
|
| 71 | + ->setRouteUri('/foo/bar') |
|
| 72 | + ->setRouteSegments() |
|
| 73 | + ->determineRouteParamsInformation(); |
|
| 74 | 74 | $this->assertSame('fooController', $r->getController()); |
| 75 | - $this->assertSame('fooMethod', $r->getMethod()); |
|
| 76 | - $this->assertSame('fooModule', $r->getModule()); |
|
| 77 | - $this->assertSame(0, count($r->getArgs())); |
|
| 78 | - } |
|
| 75 | + $this->assertSame('fooMethod', $r->getMethod()); |
|
| 76 | + $this->assertSame('fooModule', $r->getModule()); |
|
| 77 | + $this->assertSame(0, count($r->getArgs())); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | 80 | public function testWithCustomConfigUsingAnyPattern() |
| 81 | - { |
|
| 81 | + { |
|
| 82 | 82 | $r = new Router(); |
| 83 | 83 | $r->add('/foo/(:any)', 'fooController@fooMethod') |
| 84 | - ->setRouteUri('/foo/bar123-baz') |
|
| 85 | - ->setRouteSegments() |
|
| 86 | - ->determineRouteParamsInformation(); |
|
| 84 | + ->setRouteUri('/foo/bar123-baz') |
|
| 85 | + ->setRouteSegments() |
|
| 86 | + ->determineRouteParamsInformation(); |
|
| 87 | 87 | $this->assertSame('fooController', $r->getController()); |
| 88 | - $this->assertSame('fooMethod', $r->getMethod()); |
|
| 89 | - $this->assertSame(1, count($r->getArgs())); |
|
| 88 | + $this->assertSame('fooMethod', $r->getMethod()); |
|
| 89 | + $this->assertSame(1, count($r->getArgs())); |
|
| 90 | 90 | $args = $r->getArgs(); |
| 91 | 91 | $this->assertSame('bar123-baz', $args[0]); |
| 92 | - } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - public function testWithCustomConfigUsingNumericPattern() |
|
| 95 | - { |
|
| 94 | + public function testWithCustomConfigUsingNumericPattern() |
|
| 95 | + { |
|
| 96 | 96 | $r = new Router(); |
| 97 | 97 | $r->add('/foo/(:num)', 'fooController@fooMethod') |
| 98 | - ->setRouteUri('/foo/34') |
|
| 99 | - ->setRouteSegments() |
|
| 100 | - ->determineRouteParamsInformation(); |
|
| 98 | + ->setRouteUri('/foo/34') |
|
| 99 | + ->setRouteSegments() |
|
| 100 | + ->determineRouteParamsInformation(); |
|
| 101 | 101 | $this->assertSame('fooController', $r->getController()); |
| 102 | - $this->assertSame('fooMethod', $r->getMethod()); |
|
| 103 | - $this->assertSame(1, count($r->getArgs())); |
|
| 102 | + $this->assertSame('fooMethod', $r->getMethod()); |
|
| 103 | + $this->assertSame(1, count($r->getArgs())); |
|
| 104 | 104 | $args = $r->getArgs(); |
| 105 | 105 | $this->assertSame('34', $args[0]); |
| 106 | - } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | 108 | public function testWithCustomConfigUsingAlphaPattern() |
| 109 | - { |
|
| 109 | + { |
|
| 110 | 110 | $r = new Router(); |
| 111 | 111 | $r->add('/foo/(:alpha)', 'fooController@fooMethod') |
| 112 | - ->setRouteUri('/foo/baz') |
|
| 113 | - ->setRouteSegments() |
|
| 114 | - ->determineRouteParamsInformation(); |
|
| 112 | + ->setRouteUri('/foo/baz') |
|
| 113 | + ->setRouteSegments() |
|
| 114 | + ->determineRouteParamsInformation(); |
|
| 115 | 115 | $this->assertSame('fooController', $r->getController()); |
| 116 | - $this->assertSame('fooMethod', $r->getMethod()); |
|
| 117 | - $this->assertSame(1, count($r->getArgs())); |
|
| 116 | + $this->assertSame('fooMethod', $r->getMethod()); |
|
| 117 | + $this->assertSame(1, count($r->getArgs())); |
|
| 118 | 118 | $args = $r->getArgs(); |
| 119 | 119 | $this->assertSame('baz', $args[0]); |
| 120 | - } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | 122 | public function testWithCustomConfigUsingAlphaNumericPattern() |
| 123 | - { |
|
| 123 | + { |
|
| 124 | 124 | $r = new Router(); |
| 125 | 125 | $r->add('/foo/(:alnum)', 'fooController@fooMethod') |
| 126 | - ->setRouteUri('/foo/baz123') |
|
| 127 | - ->setRouteSegments() |
|
| 128 | - ->determineRouteParamsInformation(); |
|
| 126 | + ->setRouteUri('/foo/baz123') |
|
| 127 | + ->setRouteSegments() |
|
| 128 | + ->determineRouteParamsInformation(); |
|
| 129 | 129 | $this->assertSame('fooController', $r->getController()); |
| 130 | - $this->assertSame('fooMethod', $r->getMethod()); |
|
| 131 | - $this->assertSame(1, count($r->getArgs())); |
|
| 130 | + $this->assertSame('fooMethod', $r->getMethod()); |
|
| 131 | + $this->assertSame(1, count($r->getArgs())); |
|
| 132 | 132 | $args = $r->getArgs(); |
| 133 | 133 | $this->assertSame('baz123', $args[0]); |
| 134 | - } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | 136 | public function testWithCustomConfigUsingMultiplePattern() |
| 137 | - { |
|
| 137 | + { |
|
| 138 | 138 | $r = new Router(); |
| 139 | 139 | $r->add('/foo/(:alpha)/(:num)', 'fooController@fooMethod') |
| 140 | - ->setRouteUri('/foo/baz/123') |
|
| 141 | - ->setRouteSegments() |
|
| 142 | - ->determineRouteParamsInformation(); |
|
| 140 | + ->setRouteUri('/foo/baz/123') |
|
| 141 | + ->setRouteSegments() |
|
| 142 | + ->determineRouteParamsInformation(); |
|
| 143 | 143 | $this->assertSame('fooController', $r->getController()); |
| 144 | - $this->assertSame('fooMethod', $r->getMethod()); |
|
| 145 | - $this->assertSame(2, count($r->getArgs())); |
|
| 144 | + $this->assertSame('fooMethod', $r->getMethod()); |
|
| 145 | + $this->assertSame(2, count($r->getArgs())); |
|
| 146 | 146 | $args = $r->getArgs(); |
| 147 | 147 | $this->assertSame('baz', $args[0]); |
| 148 | 148 | $this->assertSame('123', $args[1]); |
| 149 | - } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - } |
|
| 152 | 151 | \ No newline at end of file |
| 152 | + } |
|
| 153 | 153 | \ No newline at end of file |
@@ -1,31 +1,31 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use PHPUnit\Framework\TestCase; |
|
| 3 | + use PHPUnit\Framework\TestCase; |
|
| 4 | 4 | |
| 5 | - class DatabaseQueryBuilderTest extends TestCase |
|
| 6 | - { |
|
| 5 | + class DatabaseQueryBuilderTest extends TestCase |
|
| 6 | + { |
|
| 7 | 7 | |
| 8 | - public static function setUpBeforeClass() |
|
| 9 | - { |
|
| 8 | + public static function setUpBeforeClass() |
|
| 9 | + { |
|
| 10 | 10 | |
| 11 | - } |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public static function tearDownAfterClass() |
|
| 14 | - { |
|
| 13 | + public static function tearDownAfterClass() |
|
| 14 | + { |
|
| 15 | 15 | |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - protected function setUp() |
|
| 19 | - { |
|
| 20 | - } |
|
| 18 | + protected function setUp() |
|
| 19 | + { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - protected function tearDown() |
|
| 23 | - { |
|
| 24 | - } |
|
| 22 | + protected function tearDown() |
|
| 23 | + { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function testNotYet() |
|
| 27 | - { |
|
| 28 | - $this->markTestSkipped(); |
|
| 29 | - } |
|
| 26 | + public function testNotYet() |
|
| 27 | + { |
|
| 28 | + $this->markTestSkipped(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - } |
|
| 32 | 31 | \ No newline at end of file |
| 32 | + } |
|
| 33 | 33 | \ No newline at end of file |
@@ -1,31 +1,31 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use PHPUnit\Framework\TestCase; |
|
| 3 | + use PHPUnit\Framework\TestCase; |
|
| 4 | 4 | |
| 5 | - class DatabaseQueryResultTest extends TestCase |
|
| 6 | - { |
|
| 5 | + class DatabaseQueryResultTest extends TestCase |
|
| 6 | + { |
|
| 7 | 7 | |
| 8 | - public static function setUpBeforeClass() |
|
| 9 | - { |
|
| 8 | + public static function setUpBeforeClass() |
|
| 9 | + { |
|
| 10 | 10 | |
| 11 | - } |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public static function tearDownAfterClass() |
|
| 14 | - { |
|
| 13 | + public static function tearDownAfterClass() |
|
| 14 | + { |
|
| 15 | 15 | |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - protected function setUp() |
|
| 19 | - { |
|
| 20 | - } |
|
| 18 | + protected function setUp() |
|
| 19 | + { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - protected function tearDown() |
|
| 23 | - { |
|
| 24 | - } |
|
| 22 | + protected function tearDown() |
|
| 23 | + { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function testNotYet() |
|
| 27 | - { |
|
| 28 | - $this->markTestSkipped(); |
|
| 29 | - } |
|
| 26 | + public function testNotYet() |
|
| 27 | + { |
|
| 28 | + $this->markTestSkipped(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - } |
|
| 32 | 31 | \ No newline at end of file |
| 32 | + } |
|
| 33 | 33 | \ No newline at end of file |
@@ -1,31 +1,31 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use PHPUnit\Framework\TestCase; |
|
| 3 | + use PHPUnit\Framework\TestCase; |
|
| 4 | 4 | |
| 5 | - class DatabaseQueryRunnerTest extends TestCase |
|
| 6 | - { |
|
| 5 | + class DatabaseQueryRunnerTest extends TestCase |
|
| 6 | + { |
|
| 7 | 7 | |
| 8 | - public static function setUpBeforeClass() |
|
| 9 | - { |
|
| 8 | + public static function setUpBeforeClass() |
|
| 9 | + { |
|
| 10 | 10 | |
| 11 | - } |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public static function tearDownAfterClass() |
|
| 14 | - { |
|
| 13 | + public static function tearDownAfterClass() |
|
| 14 | + { |
|
| 15 | 15 | |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - protected function setUp() |
|
| 19 | - { |
|
| 20 | - } |
|
| 18 | + protected function setUp() |
|
| 19 | + { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - protected function tearDown() |
|
| 23 | - { |
|
| 24 | - } |
|
| 22 | + protected function tearDown() |
|
| 23 | + { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function testNotYet() |
|
| 27 | - { |
|
| 28 | - $this->markTestSkipped(); |
|
| 29 | - } |
|
| 26 | + public function testNotYet() |
|
| 27 | + { |
|
| 28 | + $this->markTestSkipped(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - } |
|
| 32 | 31 | \ No newline at end of file |
| 32 | + } |
|
| 33 | 33 | \ No newline at end of file |
@@ -1,69 +1,69 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use PHPUnit\Framework\TestCase; |
|
| 3 | + use PHPUnit\Framework\TestCase; |
|
| 4 | 4 | |
| 5 | - class FunctionUserAgentTest extends TestCase |
|
| 6 | - { |
|
| 5 | + class FunctionUserAgentTest extends TestCase |
|
| 6 | + { |
|
| 7 | 7 | |
| 8 | - public static function setUpBeforeClass() |
|
| 9 | - { |
|
| 8 | + public static function setUpBeforeClass() |
|
| 9 | + { |
|
| 10 | 10 | require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
| 11 | - } |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public function testLoopBack() |
|
| 14 | - { |
|
| 15 | - $this->assertEquals('127.0.0.1', get_ip()); |
|
| 16 | - } |
|
| 13 | + public function testLoopBack() |
|
| 14 | + { |
|
| 15 | + $this->assertEquals('127.0.0.1', get_ip()); |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | 18 | public function testServerRemoteAddr() |
| 19 | - { |
|
| 19 | + { |
|
| 20 | 20 | $ip = '182.23.24.56'; |
| 21 | 21 | $_SERVER['REMOTE_ADDR'] = $ip; |
| 22 | - $this->assertEquals($ip, get_ip()); |
|
| 23 | - } |
|
| 22 | + $this->assertEquals($ip, get_ip()); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | public function testServerHttpClientIp() |
| 26 | - { |
|
| 26 | + { |
|
| 27 | 27 | $ip = '192.168.24.1'; |
| 28 | 28 | $_SERVER['HTTP_CLIENT_IP'] = $ip; |
| 29 | - $this->assertEquals($ip, get_ip()); |
|
| 30 | - } |
|
| 29 | + $this->assertEquals($ip, get_ip()); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | public function testServerHttpXForwardedFor() |
| 33 | - { |
|
| 33 | + { |
|
| 34 | 34 | $ip = '172.18.2.1'; |
| 35 | 35 | $_SERVER['HTTP_X_FORWARDED_FOR'] = $ip; |
| 36 | - $this->assertEquals($ip, get_ip()); |
|
| 37 | - } |
|
| 36 | + $this->assertEquals($ip, get_ip()); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | public function testServerHttpXForwarded() |
| 40 | - { |
|
| 40 | + { |
|
| 41 | 41 | |
| 42 | 42 | $ip = '12.18.2.1'; |
| 43 | 43 | $_SERVER['HTTP_X_FORWARDED'] = $ip; |
| 44 | - $this->assertEquals($ip, get_ip()); |
|
| 45 | - } |
|
| 44 | + $this->assertEquals($ip, get_ip()); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | 47 | public function testServerHttpForwardedFor() |
| 48 | - { |
|
| 48 | + { |
|
| 49 | 49 | $ip = '198.180.2.1'; |
| 50 | 50 | $_SERVER['HTTP_FORWARDED_FOR'] = $ip; |
| 51 | - $this->assertEquals($ip, get_ip()); |
|
| 52 | - } |
|
| 51 | + $this->assertEquals($ip, get_ip()); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | public function testServerHttpForwarded() |
| 55 | - { |
|
| 55 | + { |
|
| 56 | 56 | $ip = '220.200.2.1'; |
| 57 | 57 | $_SERVER['HTTP_FORWARDED'] = $ip; |
| 58 | - $this->assertEquals($ip, get_ip()); |
|
| 59 | - } |
|
| 58 | + $this->assertEquals($ip, get_ip()); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - public function testManyIp() |
|
| 62 | - { |
|
| 61 | + public function testManyIp() |
|
| 62 | + { |
|
| 63 | 63 | $ips = '20.200.2.1, 192.168.34.4'; |
| 64 | 64 | $ip = '20.200.2.1'; |
| 65 | 65 | $_SERVER['REMOTE_ADDR'] = $ips; |
| 66 | - $this->assertEquals($ip, get_ip()); |
|
| 67 | - } |
|
| 66 | + $this->assertEquals($ip, get_ip()); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - } |
|
| 70 | 69 | \ No newline at end of file |
| 70 | + } |
|
| 71 | 71 | \ No newline at end of file |
@@ -1,287 +1,287 @@ |
||
| 1 | 1 | <?php |
| 2 | - /** |
|
| 3 | - * TNH Framework |
|
| 4 | - * |
|
| 5 | - * A simple PHP framework using HMVC architecture |
|
| 6 | - * |
|
| 7 | - * This content is released under the GNU GPL License (GPL) |
|
| 8 | - * |
|
| 9 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 10 | - * |
|
| 11 | - * This program is free software; you can redistribute it and/or |
|
| 12 | - * modify it under the terms of the GNU General Public License |
|
| 13 | - * as published by the Free Software Foundation; either version 3 |
|
| 14 | - * of the License, or (at your option) any later version. |
|
| 15 | - * |
|
| 16 | - * This program is distributed in the hope that it will be useful, |
|
| 17 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 18 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 19 | - * GNU General Public License for more details. |
|
| 20 | - * |
|
| 21 | - * You should have received a copy of the GNU General Public License |
|
| 22 | - * along with this program; if not, write to the Free Software |
|
| 23 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 24 | - */ |
|
| 2 | + /** |
|
| 3 | + * TNH Framework |
|
| 4 | + * |
|
| 5 | + * A simple PHP framework using HMVC architecture |
|
| 6 | + * |
|
| 7 | + * This content is released under the GNU GPL License (GPL) |
|
| 8 | + * |
|
| 9 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 10 | + * |
|
| 11 | + * This program is free software; you can redistribute it and/or |
|
| 12 | + * modify it under the terms of the GNU General Public License |
|
| 13 | + * as published by the Free Software Foundation; either version 3 |
|
| 14 | + * of the License, or (at your option) any later version. |
|
| 15 | + * |
|
| 16 | + * This program is distributed in the hope that it will be useful, |
|
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 19 | + * GNU General Public License for more details. |
|
| 20 | + * |
|
| 21 | + * You should have received a copy of the GNU General Public License |
|
| 22 | + * along with this program; if not, write to the Free Software |
|
| 23 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 24 | + */ |
|
| 25 | 25 | |
| 26 | - error_reporting(E_ALL | E_STRICT); |
|
| 27 | - ini_set('display_errors', 1); |
|
| 26 | + error_reporting(E_ALL | E_STRICT); |
|
| 27 | + ini_set('display_errors', 1); |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * the directory separator, under windows it is \ and unix, linux / |
|
| 31 | - */ |
|
| 32 | - define('DS', DIRECTORY_SEPARATOR); |
|
| 29 | + /** |
|
| 30 | + * the directory separator, under windows it is \ and unix, linux / |
|
| 31 | + */ |
|
| 32 | + define('DS', DIRECTORY_SEPARATOR); |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * The root directory of the application. |
|
| 36 | - * |
|
| 37 | - * you can place this directory outside of your web directory, for example "/home/your_app", etc. |
|
| 38 | - */ |
|
| 39 | - define('ROOT_PATH', dirname(realpath(__FILE__)) . DS . '..' . DS); |
|
| 34 | + /** |
|
| 35 | + * The root directory of the application. |
|
| 36 | + * |
|
| 37 | + * you can place this directory outside of your web directory, for example "/home/your_app", etc. |
|
| 38 | + */ |
|
| 39 | + define('ROOT_PATH', dirname(realpath(__FILE__)) . DS . '..' . DS); |
|
| 40 | 40 | |
| 41 | - //tests dir path |
|
| 42 | - define('TESTS_PATH', dirname(realpath(__FILE__)) . DS); |
|
| 41 | + //tests dir path |
|
| 42 | + define('TESTS_PATH', dirname(realpath(__FILE__)) . DS); |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * The path to the directory. |
|
| 46 | - * |
|
| 47 | - * That contains your static files (javascript, css, images, etc.) |
|
| 48 | - * Note: the path must be relative to the file index.php (the front-end controller). |
|
| 49 | - */ |
|
| 50 | - define('ASSETS_PATH', 'assets/'); |
|
| 44 | + /** |
|
| 45 | + * The path to the directory. |
|
| 46 | + * |
|
| 47 | + * That contains your static files (javascript, css, images, etc.) |
|
| 48 | + * Note: the path must be relative to the file index.php (the front-end controller). |
|
| 49 | + */ |
|
| 50 | + define('ASSETS_PATH', 'assets/'); |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * The path to the directory of your cache files. |
|
| 54 | - * |
|
| 55 | - * This feature is available currently for database and views. |
|
| 56 | - */ |
|
| 57 | - define('CACHE_PATH', ROOT_PATH . 'cache' . DS); |
|
| 52 | + /** |
|
| 53 | + * The path to the directory of your cache files. |
|
| 54 | + * |
|
| 55 | + * This feature is available currently for database and views. |
|
| 56 | + */ |
|
| 57 | + define('CACHE_PATH', ROOT_PATH . 'cache' . DS); |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Custom application path for tests |
|
| 61 | - */ |
|
| 62 | - define('APPS_PATH', TESTS_PATH .'hmvc' . DS); |
|
| 59 | + /** |
|
| 60 | + * Custom application path for tests |
|
| 61 | + */ |
|
| 62 | + define('APPS_PATH', TESTS_PATH .'hmvc' . DS); |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * The path to the controller directory of your application. |
|
| 66 | - * |
|
| 67 | - * If you already know the MVC architecture you know what a controller means; |
|
| 68 | - * it is he who makes the business logic of your application in general. |
|
| 69 | - */ |
|
| 70 | - define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS); |
|
| 64 | + /** |
|
| 65 | + * The path to the controller directory of your application. |
|
| 66 | + * |
|
| 67 | + * If you already know the MVC architecture you know what a controller means; |
|
| 68 | + * it is he who makes the business logic of your application in general. |
|
| 69 | + */ |
|
| 70 | + define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS); |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * The path to the directory of your model classes of your application. |
|
| 74 | - * |
|
| 75 | - * If you already know the MVC architecture you know what a model means; |
|
| 76 | - * it's the one who interacts with the database, in one word persistent data from your application. |
|
| 77 | - */ |
|
| 78 | - define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS); |
|
| 72 | + /** |
|
| 73 | + * The path to the directory of your model classes of your application. |
|
| 74 | + * |
|
| 75 | + * If you already know the MVC architecture you know what a model means; |
|
| 76 | + * it's the one who interacts with the database, in one word persistent data from your application. |
|
| 77 | + */ |
|
| 78 | + define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS); |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * The path to the directory of your views. |
|
| 82 | - * |
|
| 83 | - * If you already know the MVC architecture you know what a view means, |
|
| 84 | - * a view is just a user interface (html page, form, etc.) that is to say |
|
| 85 | - * everything displayed in the browser interface, etc. |
|
| 86 | - */ |
|
| 87 | - define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS); |
|
| 80 | + /** |
|
| 81 | + * The path to the directory of your views. |
|
| 82 | + * |
|
| 83 | + * If you already know the MVC architecture you know what a view means, |
|
| 84 | + * a view is just a user interface (html page, form, etc.) that is to say |
|
| 85 | + * everything displayed in the browser interface, etc. |
|
| 86 | + */ |
|
| 87 | + define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS); |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * The path to the configuration directory. |
|
| 91 | - * |
|
| 92 | - * That contains most of the configuration files for your |
|
| 93 | - * application (database, class loading file, functions, etc.) |
|
| 94 | - */ |
|
| 95 | - define('CONFIG_PATH', ROOT_PATH . 'config' . DS); |
|
| 89 | + /** |
|
| 90 | + * The path to the configuration directory. |
|
| 91 | + * |
|
| 92 | + * That contains most of the configuration files for your |
|
| 93 | + * application (database, class loading file, functions, etc.) |
|
| 94 | + */ |
|
| 95 | + define('CONFIG_PATH', ROOT_PATH . 'config' . DS); |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * The core directory |
|
| 99 | - * |
|
| 100 | - * It is recommended to put this folder out of the web directory of your server and |
|
| 101 | - * you should not change its content because in case of update you could lose the modified files. |
|
| 102 | - */ |
|
| 103 | - define('CORE_PATH', ROOT_PATH . 'core' . DS); |
|
| 97 | + /** |
|
| 98 | + * The core directory |
|
| 99 | + * |
|
| 100 | + * It is recommended to put this folder out of the web directory of your server and |
|
| 101 | + * you should not change its content because in case of update you could lose the modified files. |
|
| 102 | + */ |
|
| 103 | + define('CORE_PATH', ROOT_PATH . 'core' . DS); |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * The path to the directory of core classes that used by the system. |
|
| 107 | - * |
|
| 108 | - * It contains PHP classes that are used by the framework internally. |
|
| 109 | - */ |
|
| 110 | - define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS); |
|
| 105 | + /** |
|
| 106 | + * The path to the directory of core classes that used by the system. |
|
| 107 | + * |
|
| 108 | + * It contains PHP classes that are used by the framework internally. |
|
| 109 | + */ |
|
| 110 | + define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS); |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * The path to the directory of core classes for the cache used by the system. |
|
| 114 | - * |
|
| 115 | - * It contains PHP classes for the cache drivers. |
|
| 116 | - */ |
|
| 117 | - define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS); |
|
| 112 | + /** |
|
| 113 | + * The path to the directory of core classes for the cache used by the system. |
|
| 114 | + * |
|
| 115 | + * It contains PHP classes for the cache drivers. |
|
| 116 | + */ |
|
| 117 | + define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS); |
|
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | - * The path to the directory of core classes for the database used by the system. |
|
| 121 | - * |
|
| 122 | - * It contains PHP classes for the database library, drivers, etc. |
|
| 123 | - */ |
|
| 124 | - define('CORE_CLASSES_DATABASE_PATH', CORE_CLASSES_PATH . 'database' . DS); |
|
| 120 | + * The path to the directory of core classes for the database used by the system. |
|
| 121 | + * |
|
| 122 | + * It contains PHP classes for the database library, drivers, etc. |
|
| 123 | + */ |
|
| 124 | + define('CORE_CLASSES_DATABASE_PATH', CORE_CLASSES_PATH . 'database' . DS); |
|
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * The path to the directory of core classes for the model used by the system. |
|
| 128 | - * |
|
| 129 | - * It contains PHP classes for the models. |
|
| 130 | - */ |
|
| 131 | - define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS); |
|
| 126 | + /** |
|
| 127 | + * The path to the directory of core classes for the model used by the system. |
|
| 128 | + * |
|
| 129 | + * It contains PHP classes for the models. |
|
| 130 | + */ |
|
| 131 | + define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS); |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * The path to the directory of functions or helper systems. |
|
| 135 | - * |
|
| 136 | - * It contains PHP functions that perform a particular task: character string processing, URL, etc. |
|
| 137 | - */ |
|
| 138 | - define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS); |
|
| 133 | + /** |
|
| 134 | + * The path to the directory of functions or helper systems. |
|
| 135 | + * |
|
| 136 | + * It contains PHP functions that perform a particular task: character string processing, URL, etc. |
|
| 137 | + */ |
|
| 138 | + define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS); |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * The path to the core directory of languages files. |
|
| 142 | - * |
|
| 143 | - */ |
|
| 144 | - define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS); |
|
| 140 | + /** |
|
| 141 | + * The path to the core directory of languages files. |
|
| 142 | + * |
|
| 143 | + */ |
|
| 144 | + define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS); |
|
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * The path to the system library directory. |
|
| 148 | - * |
|
| 149 | - * Which contains the libraries most often used in your web application, as for the |
|
| 150 | - * core directory it is advisable to put it out of the root directory of your application. |
|
| 151 | - */ |
|
| 152 | - define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS); |
|
| 146 | + /** |
|
| 147 | + * The path to the system library directory. |
|
| 148 | + * |
|
| 149 | + * Which contains the libraries most often used in your web application, as for the |
|
| 150 | + * core directory it is advisable to put it out of the root directory of your application. |
|
| 151 | + */ |
|
| 152 | + define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS); |
|
| 153 | 153 | |
| 154 | - /** |
|
| 155 | - * The path to the system view directory. |
|
| 156 | - * |
|
| 157 | - * That contains the views used for the system, such as error messages, and so on. |
|
| 158 | - */ |
|
| 159 | - define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS); |
|
| 154 | + /** |
|
| 155 | + * The path to the system view directory. |
|
| 156 | + * |
|
| 157 | + * That contains the views used for the system, such as error messages, and so on. |
|
| 158 | + */ |
|
| 159 | + define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS); |
|
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * The path to the directory of your PHP personal functions or helper. |
|
| 163 | - * |
|
| 164 | - * It contains your PHP functions that perform a particular task: utilities, etc. |
|
| 165 | - * Note: Do not put your personal functions or helpers in the system functions directory, |
|
| 166 | - * because if you update the system you may lose them. |
|
| 167 | - */ |
|
| 168 | - define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS); |
|
| 161 | + /** |
|
| 162 | + * The path to the directory of your PHP personal functions or helper. |
|
| 163 | + * |
|
| 164 | + * It contains your PHP functions that perform a particular task: utilities, etc. |
|
| 165 | + * Note: Do not put your personal functions or helpers in the system functions directory, |
|
| 166 | + * because if you update the system you may lose them. |
|
| 167 | + */ |
|
| 168 | + define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS); |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * The path to the app directory of personal language. |
|
| 172 | - * |
|
| 173 | - * This feature is not yet available. |
|
| 174 | - * You can help us do this if you are nice or wish to see the developed framework. |
|
| 175 | - */ |
|
| 176 | - define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS); |
|
| 170 | + /** |
|
| 171 | + * The path to the app directory of personal language. |
|
| 172 | + * |
|
| 173 | + * This feature is not yet available. |
|
| 174 | + * You can help us do this if you are nice or wish to see the developed framework. |
|
| 175 | + */ |
|
| 176 | + define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS); |
|
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * The path to the directory of your personal libraries |
|
| 180 | - * |
|
| 181 | - * It contains your PHP classes, package, etc. |
|
| 182 | - * Note: you should not put your personal libraries in the system library directory, |
|
| 183 | - * because it is recalled in case of updating the system you might have surprises. |
|
| 184 | - */ |
|
| 185 | - define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS); |
|
| 178 | + /** |
|
| 179 | + * The path to the directory of your personal libraries |
|
| 180 | + * |
|
| 181 | + * It contains your PHP classes, package, etc. |
|
| 182 | + * Note: you should not put your personal libraries in the system library directory, |
|
| 183 | + * because it is recalled in case of updating the system you might have surprises. |
|
| 184 | + */ |
|
| 185 | + define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS); |
|
| 186 | 186 | |
| 187 | - /** |
|
| 188 | - * The path to the directory that contains the log files. |
|
| 189 | - * |
|
| 190 | - * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, |
|
| 191 | - * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more |
|
| 192 | - * details see the documentation of your web server. |
|
| 193 | - * Example for Unix or linux with apache web server: |
|
| 194 | - * # chmod -R 700 /path/to/your/logs/directory/ |
|
| 195 | - * # chown -R www-data:www-data /path/to/your/logs/directory/ |
|
| 196 | - */ |
|
| 197 | - define('LOGS_PATH', ROOT_PATH . 'logs' . DS); |
|
| 187 | + /** |
|
| 188 | + * The path to the directory that contains the log files. |
|
| 189 | + * |
|
| 190 | + * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, |
|
| 191 | + * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more |
|
| 192 | + * details see the documentation of your web server. |
|
| 193 | + * Example for Unix or linux with apache web server: |
|
| 194 | + * # chmod -R 700 /path/to/your/logs/directory/ |
|
| 195 | + * # chown -R www-data:www-data /path/to/your/logs/directory/ |
|
| 196 | + */ |
|
| 197 | + define('LOGS_PATH', ROOT_PATH . 'logs' . DS); |
|
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * The path to the modules directory. |
|
| 201 | - * |
|
| 202 | - * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
|
| 203 | - * in HMVC architecture (hierichical, controllers, models, views). |
|
| 204 | - */ |
|
| 205 | - define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS); |
|
| 199 | + /** |
|
| 200 | + * The path to the modules directory. |
|
| 201 | + * |
|
| 202 | + * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
|
| 203 | + * in HMVC architecture (hierichical, controllers, models, views). |
|
| 204 | + */ |
|
| 205 | + define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS); |
|
| 206 | 206 | |
| 207 | - /** |
|
| 208 | - * The path to the directory of sources external to your application. |
|
| 209 | - * |
|
| 210 | - * If you have already used "composer" you know what that means. |
|
| 211 | - */ |
|
| 212 | - define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS); |
|
| 207 | + /** |
|
| 208 | + * The path to the directory of sources external to your application. |
|
| 209 | + * |
|
| 210 | + * If you have already used "composer" you know what that means. |
|
| 211 | + */ |
|
| 212 | + define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS); |
|
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * The front controller of your application. |
|
| 216 | - * |
|
| 217 | - * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of |
|
| 218 | - * your application by using the rewrite module URL of your web server . |
|
| 219 | - * For example, under apache web server, there is a configuration example file that is located at the root |
|
| 220 | - * of your framework folder : "htaccess.txt" rename it to ".htaccess". |
|
| 221 | - */ |
|
| 222 | - define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); |
|
| 214 | + /** |
|
| 215 | + * The front controller of your application. |
|
| 216 | + * |
|
| 217 | + * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of |
|
| 218 | + * your application by using the rewrite module URL of your web server . |
|
| 219 | + * For example, under apache web server, there is a configuration example file that is located at the root |
|
| 220 | + * of your framework folder : "htaccess.txt" rename it to ".htaccess". |
|
| 221 | + */ |
|
| 222 | + define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); |
|
| 223 | 223 | |
| 224 | - /** |
|
| 225 | - * Check if user run the application under CLI |
|
| 226 | - */ |
|
| 227 | - define('IS_CLI', stripos('cli', php_sapi_name()) !== false); |
|
| 224 | + /** |
|
| 225 | + * Check if user run the application under CLI |
|
| 226 | + */ |
|
| 227 | + define('IS_CLI', stripos('cli', php_sapi_name()) !== false); |
|
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * The environment of your application (production, test, development). |
|
| 231 | - * |
|
| 232 | - * if your application is still in development you use the value "development" |
|
| 233 | - * so you will have the display of the error messages, etc. |
|
| 234 | - * Once you finish the development of your application that is to put it online |
|
| 235 | - * you change this value to "production" or "testing", in this case there will be deactivation of error messages, |
|
| 236 | - * the loading of the system, will be fast. |
|
| 237 | - */ |
|
| 238 | - define('ENVIRONMENT', 'testing'); |
|
| 229 | + /** |
|
| 230 | + * The environment of your application (production, test, development). |
|
| 231 | + * |
|
| 232 | + * if your application is still in development you use the value "development" |
|
| 233 | + * so you will have the display of the error messages, etc. |
|
| 234 | + * Once you finish the development of your application that is to put it online |
|
| 235 | + * you change this value to "production" or "testing", in this case there will be deactivation of error messages, |
|
| 236 | + * the loading of the system, will be fast. |
|
| 237 | + */ |
|
| 238 | + define('ENVIRONMENT', 'testing'); |
|
| 239 | 239 | |
| 240 | 240 | |
| 241 | - //Fix to allow test as if application is running in CLI mode $_SESSION global variable is not available |
|
| 242 | - $_SESSION = array(); |
|
| 241 | + //Fix to allow test as if application is running in CLI mode $_SESSION global variable is not available |
|
| 242 | + $_SESSION = array(); |
|
| 243 | 243 | |
| 244 | - //check for composer autoload file if exists include it |
|
| 245 | - if (file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 246 | - require_once VENDOR_PATH . 'autoload.php'; |
|
| 244 | + //check for composer autoload file if exists include it |
|
| 245 | + if (file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 246 | + require_once VENDOR_PATH . 'autoload.php'; |
|
| 247 | 247 | |
| 248 | - //define the class alias for vstream |
|
| 249 | - class_alias('org\bovigo\vfs\vfsStream', 'vfsStream'); |
|
| 250 | - class_alias('org\bovigo\vfs\vfsStreamDirectory', 'vfsStreamDirectory'); |
|
| 251 | - class_alias('org\bovigo\vfs\vfsStreamWrapper', 'vfsStreamWrapper'); |
|
| 248 | + //define the class alias for vstream |
|
| 249 | + class_alias('org\bovigo\vfs\vfsStream', 'vfsStream'); |
|
| 250 | + class_alias('org\bovigo\vfs\vfsStreamDirectory', 'vfsStreamDirectory'); |
|
| 251 | + class_alias('org\bovigo\vfs\vfsStreamWrapper', 'vfsStreamWrapper'); |
|
| 252 | 252 | |
| 253 | - } |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - //require autoloader for test |
|
| 256 | - require_once 'include/autoloader.php'; |
|
| 255 | + //require autoloader for test |
|
| 256 | + require_once 'include/autoloader.php'; |
|
| 257 | 257 | |
| 258 | 258 | |
| 259 | 259 | |
| 260 | - //grap from core/common.php functions and mock some functions for tests |
|
| 261 | - require_once 'include/common.php'; |
|
| 260 | + //grap from core/common.php functions and mock some functions for tests |
|
| 261 | + require_once 'include/common.php'; |
|
| 262 | 262 | |
| 263 | - //Some utilities functions, classes, etc. |
|
| 264 | - require_once 'include/testsUtil.php'; |
|
| 263 | + //Some utilities functions, classes, etc. |
|
| 264 | + require_once 'include/testsUtil.php'; |
|
| 265 | 265 | |
| 266 | - /** |
|
| 267 | - * Setting of the PHP error message handling function |
|
| 268 | - */ |
|
| 269 | - set_error_handler('php_error_handler'); |
|
| 266 | + /** |
|
| 267 | + * Setting of the PHP error message handling function |
|
| 268 | + */ |
|
| 269 | + set_error_handler('php_error_handler'); |
|
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * Setting of the PHP error exception handling function |
|
| 273 | - */ |
|
| 274 | - set_exception_handler('php_exception_handler'); |
|
| 271 | + /** |
|
| 272 | + * Setting of the PHP error exception handling function |
|
| 273 | + */ |
|
| 274 | + set_exception_handler('php_exception_handler'); |
|
| 275 | 275 | |
| 276 | - /** |
|
| 277 | - * Setting of the PHP shutdown handling function |
|
| 278 | - */ |
|
| 279 | - register_shutdown_function('php_shudown_handler'); |
|
| 276 | + /** |
|
| 277 | + * Setting of the PHP shutdown handling function |
|
| 278 | + */ |
|
| 279 | + register_shutdown_function('php_shudown_handler'); |
|
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * Register the tests autoload |
|
| 283 | - */ |
|
| 284 | - spl_autoload_register('tests_autoload'); |
|
| 281 | + /** |
|
| 282 | + * Register the tests autoload |
|
| 283 | + */ |
|
| 284 | + spl_autoload_register('tests_autoload'); |
|
| 285 | 285 | |
| 286 | 286 | |
| 287 | - |
|
| 288 | 287 | \ No newline at end of file |
| 288 | + |
|
| 289 | 289 | \ No newline at end of file |
@@ -1,312 +1,312 @@ |
||
| 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 FileCache implements CacheInterface{ |
|
| 27 | + class FileCache implements CacheInterface{ |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Whether to enable compression of the cache data file. |
|
| 31 | - * @var boolean |
|
| 32 | - */ |
|
| 33 | - private $compressCacheData = true; |
|
| 29 | + /** |
|
| 30 | + * Whether to enable compression of the cache data file. |
|
| 31 | + * @var boolean |
|
| 32 | + */ |
|
| 33 | + private $compressCacheData = true; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * The logger instance |
|
| 37 | - * @var Log |
|
| 38 | - */ |
|
| 39 | - private $logger; |
|
| 35 | + /** |
|
| 36 | + * The logger instance |
|
| 37 | + * @var Log |
|
| 38 | + */ |
|
| 39 | + private $logger; |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | - public function __construct(Log $logger = null){ |
|
| 43 | - if(! $this->isSupported()){ |
|
| 44 | - show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.'); |
|
| 45 | - } |
|
| 46 | - /** |
|
| 47 | - * instance of the Log class |
|
| 48 | - */ |
|
| 49 | - if(is_object($logger)){ |
|
| 50 | - $this->logger = $logger; |
|
| 51 | - } |
|
| 52 | - else{ |
|
| 53 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 54 | - $this->logger->setLogger('Library::FileCache'); |
|
| 55 | - } |
|
| 42 | + public function __construct(Log $logger = null){ |
|
| 43 | + if(! $this->isSupported()){ |
|
| 44 | + show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.'); |
|
| 45 | + } |
|
| 46 | + /** |
|
| 47 | + * instance of the Log class |
|
| 48 | + */ |
|
| 49 | + if(is_object($logger)){ |
|
| 50 | + $this->logger = $logger; |
|
| 51 | + } |
|
| 52 | + else{ |
|
| 53 | + $this->logger =& class_loader('Log', 'classes'); |
|
| 54 | + $this->logger->setLogger('Library::FileCache'); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - //if Zlib extension is not loaded set compressCacheData to false |
|
| 58 | - if(! extension_loaded('zlib')){ |
|
| 59 | - $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE'); |
|
| 60 | - $this->compressCacheData = false; |
|
| 61 | - } |
|
| 62 | - } |
|
| 57 | + //if Zlib extension is not loaded set compressCacheData to false |
|
| 58 | + if(! extension_loaded('zlib')){ |
|
| 59 | + $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE'); |
|
| 60 | + $this->compressCacheData = false; |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * This is used to get the cache data using the key |
|
| 66 | - * @param string $key the key to identify the cache data |
|
| 67 | - * @return mixed the cache data if exists else return false |
|
| 68 | - */ |
|
| 69 | - public function get($key){ |
|
| 70 | - $this->logger->debug('Getting cache data for key ['. $key .']'); |
|
| 71 | - $filePath = $this->getFilePath($key); |
|
| 72 | - if(! file_exists($filePath)){ |
|
| 73 | - $this->logger->info('No cache file found for the key ['. $key .'], return false'); |
|
| 74 | - return false; |
|
| 75 | - } |
|
| 76 | - $this->logger->info('The cache file [' .$filePath. '] for the key ['. $key .'] exists, check if the cache data is valid'); |
|
| 77 | - $handle = fopen($filePath,'r'); |
|
| 78 | - if(! is_resource($handle)){ |
|
| 79 | - $this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false'); |
|
| 80 | - return false; |
|
| 81 | - } |
|
| 82 | - // Getting a shared lock |
|
| 83 | - flock($handle, LOCK_SH); |
|
| 84 | - $data = file_get_contents($filePath); |
|
| 85 | - fclose($handle); |
|
| 86 | - $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
|
| 87 | - if (! $data) { |
|
| 88 | - $this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false'); |
|
| 89 | - // If unserializing somehow didn't work out, we'll delete the file |
|
| 90 | - unlink($filePath); |
|
| 91 | - return false; |
|
| 92 | - } |
|
| 93 | - if (time() > $data['expire']) { |
|
| 94 | - $this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']'); |
|
| 95 | - // Unlinking when the file was expired |
|
| 96 | - unlink($filePath); |
|
| 97 | - return false; |
|
| 98 | - } |
|
| 99 | - else{ |
|
| 100 | - $this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']'); |
|
| 101 | - return $data['data']; |
|
| 102 | - } |
|
| 103 | - } |
|
| 64 | + /** |
|
| 65 | + * This is used to get the cache data using the key |
|
| 66 | + * @param string $key the key to identify the cache data |
|
| 67 | + * @return mixed the cache data if exists else return false |
|
| 68 | + */ |
|
| 69 | + public function get($key){ |
|
| 70 | + $this->logger->debug('Getting cache data for key ['. $key .']'); |
|
| 71 | + $filePath = $this->getFilePath($key); |
|
| 72 | + if(! file_exists($filePath)){ |
|
| 73 | + $this->logger->info('No cache file found for the key ['. $key .'], return false'); |
|
| 74 | + return false; |
|
| 75 | + } |
|
| 76 | + $this->logger->info('The cache file [' .$filePath. '] for the key ['. $key .'] exists, check if the cache data is valid'); |
|
| 77 | + $handle = fopen($filePath,'r'); |
|
| 78 | + if(! is_resource($handle)){ |
|
| 79 | + $this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false'); |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 82 | + // Getting a shared lock |
|
| 83 | + flock($handle, LOCK_SH); |
|
| 84 | + $data = file_get_contents($filePath); |
|
| 85 | + fclose($handle); |
|
| 86 | + $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
|
| 87 | + if (! $data) { |
|
| 88 | + $this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false'); |
|
| 89 | + // If unserializing somehow didn't work out, we'll delete the file |
|
| 90 | + unlink($filePath); |
|
| 91 | + return false; |
|
| 92 | + } |
|
| 93 | + if (time() > $data['expire']) { |
|
| 94 | + $this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']'); |
|
| 95 | + // Unlinking when the file was expired |
|
| 96 | + unlink($filePath); |
|
| 97 | + return false; |
|
| 98 | + } |
|
| 99 | + else{ |
|
| 100 | + $this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']'); |
|
| 101 | + return $data['data']; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Save data to the cache |
|
| 108 | - * @param string $key the key to identify this cache data |
|
| 109 | - * @param mixed $data the cache data |
|
| 110 | - * @param integer $ttl the cache life time |
|
| 111 | - * @return boolean true if success otherwise will return false |
|
| 112 | - */ |
|
| 113 | - public function set($key, $data, $ttl = 0){ |
|
| 114 | - $expire = time() + $ttl; |
|
| 115 | - $this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
| 116 | - $filePath = $this->getFilePath($key); |
|
| 117 | - $handle = fopen($filePath,'w'); |
|
| 118 | - if(! is_resource($handle)){ |
|
| 119 | - $this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false'); |
|
| 120 | - return false; |
|
| 121 | - } |
|
| 122 | - flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed |
|
| 123 | - //Serializing along with the TTL |
|
| 124 | - $cacheData = serialize(array( |
|
| 125 | - 'mtime' => time(), |
|
| 126 | - 'expire' => $expire, |
|
| 127 | - 'data' => $data, |
|
| 128 | - 'ttl' => $ttl |
|
| 129 | - ) |
|
| 130 | - ); |
|
| 131 | - $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData); |
|
| 132 | - if(! $result){ |
|
| 133 | - $this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false'); |
|
| 134 | - fclose($handle); |
|
| 135 | - return false; |
|
| 136 | - } |
|
| 137 | - else{ |
|
| 138 | - $this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']'); |
|
| 139 | - fclose($handle); |
|
| 140 | - chmod($filePath, 0640); |
|
| 141 | - return true; |
|
| 142 | - } |
|
| 143 | - } |
|
| 106 | + /** |
|
| 107 | + * Save data to the cache |
|
| 108 | + * @param string $key the key to identify this cache data |
|
| 109 | + * @param mixed $data the cache data |
|
| 110 | + * @param integer $ttl the cache life time |
|
| 111 | + * @return boolean true if success otherwise will return false |
|
| 112 | + */ |
|
| 113 | + public function set($key, $data, $ttl = 0){ |
|
| 114 | + $expire = time() + $ttl; |
|
| 115 | + $this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
| 116 | + $filePath = $this->getFilePath($key); |
|
| 117 | + $handle = fopen($filePath,'w'); |
|
| 118 | + if(! is_resource($handle)){ |
|
| 119 | + $this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false'); |
|
| 120 | + return false; |
|
| 121 | + } |
|
| 122 | + flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed |
|
| 123 | + //Serializing along with the TTL |
|
| 124 | + $cacheData = serialize(array( |
|
| 125 | + 'mtime' => time(), |
|
| 126 | + 'expire' => $expire, |
|
| 127 | + 'data' => $data, |
|
| 128 | + 'ttl' => $ttl |
|
| 129 | + ) |
|
| 130 | + ); |
|
| 131 | + $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData); |
|
| 132 | + if(! $result){ |
|
| 133 | + $this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false'); |
|
| 134 | + fclose($handle); |
|
| 135 | + return false; |
|
| 136 | + } |
|
| 137 | + else{ |
|
| 138 | + $this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']'); |
|
| 139 | + fclose($handle); |
|
| 140 | + chmod($filePath, 0640); |
|
| 141 | + return true; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Delete the cache data for given key |
|
| 148 | - * @param string $key the key for cache to be deleted |
|
| 149 | - * @return boolean true if the cache is delete, false if can't delete |
|
| 150 | - * the cache or the cache with the given key not exist |
|
| 151 | - */ |
|
| 152 | - public function delete($key){ |
|
| 153 | - $this->logger->debug('Deleting of cache data for key [' .$key. ']'); |
|
| 154 | - $filePath = $this->getFilePath($key); |
|
| 155 | - $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']'); |
|
| 156 | - if(! file_exists($filePath)){ |
|
| 157 | - $this->logger->info('This cache file does not exists skipping'); |
|
| 158 | - return false; |
|
| 159 | - } |
|
| 160 | - else{ |
|
| 161 | - $this->logger->info('Found cache file [' .$filePath. '] remove it'); |
|
| 162 | - unlink($filePath); |
|
| 163 | - return true; |
|
| 164 | - } |
|
| 165 | - } |
|
| 146 | + /** |
|
| 147 | + * Delete the cache data for given key |
|
| 148 | + * @param string $key the key for cache to be deleted |
|
| 149 | + * @return boolean true if the cache is delete, false if can't delete |
|
| 150 | + * the cache or the cache with the given key not exist |
|
| 151 | + */ |
|
| 152 | + public function delete($key){ |
|
| 153 | + $this->logger->debug('Deleting of cache data for key [' .$key. ']'); |
|
| 154 | + $filePath = $this->getFilePath($key); |
|
| 155 | + $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']'); |
|
| 156 | + if(! file_exists($filePath)){ |
|
| 157 | + $this->logger->info('This cache file does not exists skipping'); |
|
| 158 | + return false; |
|
| 159 | + } |
|
| 160 | + else{ |
|
| 161 | + $this->logger->info('Found cache file [' .$filePath. '] remove it'); |
|
| 162 | + unlink($filePath); |
|
| 163 | + return true; |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Get the cache information for given key |
|
| 169 | - * @param string $key the key for cache to get the information for |
|
| 170 | - * @return boolean|array the cache information. The associative array and must contains the following information: |
|
| 171 | - * 'mtime' => creation time of the cache (Unix timestamp), |
|
| 172 | - * 'expire' => expiration time of the cache (Unix timestamp), |
|
| 173 | - * 'ttl' => the time to live of the cache in second |
|
| 174 | - */ |
|
| 175 | - public function getInfo($key){ |
|
| 176 | - $this->logger->debug('Getting of cache info for key [' .$key. ']'); |
|
| 177 | - $filePath = $this->getFilePath($key); |
|
| 178 | - $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']'); |
|
| 179 | - if(! file_exists($filePath)){ |
|
| 180 | - $this->logger->info('This cache file does not exists skipping'); |
|
| 181 | - return false; |
|
| 182 | - } |
|
| 183 | - $this->logger->info('Found cache file [' .$filePath. '] check the validity'); |
|
| 184 | - $data = file_get_contents($filePath); |
|
| 185 | - $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
|
| 186 | - if(! $data){ |
|
| 187 | - $this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']'); |
|
| 188 | - return false; |
|
| 189 | - } |
|
| 190 | - $this->logger->info('This cache data is OK check for expire'); |
|
| 191 | - if(isset($data['expire']) && $data['expire'] > time()){ |
|
| 192 | - $this->logger->info('This cache not yet expired return cache informations'); |
|
| 193 | - $info = array( |
|
| 194 | - 'mtime' => $data['mtime'], |
|
| 195 | - 'expire' => $data['expire'], |
|
| 196 | - 'ttl' => $data['ttl'] |
|
| 197 | - ); |
|
| 198 | - return $info; |
|
| 199 | - } |
|
| 200 | - $this->logger->info('This cache already expired return false'); |
|
| 201 | - return false; |
|
| 202 | - } |
|
| 167 | + /** |
|
| 168 | + * Get the cache information for given key |
|
| 169 | + * @param string $key the key for cache to get the information for |
|
| 170 | + * @return boolean|array the cache information. The associative array and must contains the following information: |
|
| 171 | + * 'mtime' => creation time of the cache (Unix timestamp), |
|
| 172 | + * 'expire' => expiration time of the cache (Unix timestamp), |
|
| 173 | + * 'ttl' => the time to live of the cache in second |
|
| 174 | + */ |
|
| 175 | + public function getInfo($key){ |
|
| 176 | + $this->logger->debug('Getting of cache info for key [' .$key. ']'); |
|
| 177 | + $filePath = $this->getFilePath($key); |
|
| 178 | + $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']'); |
|
| 179 | + if(! file_exists($filePath)){ |
|
| 180 | + $this->logger->info('This cache file does not exists skipping'); |
|
| 181 | + return false; |
|
| 182 | + } |
|
| 183 | + $this->logger->info('Found cache file [' .$filePath. '] check the validity'); |
|
| 184 | + $data = file_get_contents($filePath); |
|
| 185 | + $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
|
| 186 | + if(! $data){ |
|
| 187 | + $this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']'); |
|
| 188 | + return false; |
|
| 189 | + } |
|
| 190 | + $this->logger->info('This cache data is OK check for expire'); |
|
| 191 | + if(isset($data['expire']) && $data['expire'] > time()){ |
|
| 192 | + $this->logger->info('This cache not yet expired return cache informations'); |
|
| 193 | + $info = array( |
|
| 194 | + 'mtime' => $data['mtime'], |
|
| 195 | + 'expire' => $data['expire'], |
|
| 196 | + 'ttl' => $data['ttl'] |
|
| 197 | + ); |
|
| 198 | + return $info; |
|
| 199 | + } |
|
| 200 | + $this->logger->info('This cache already expired return false'); |
|
| 201 | + return false; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | 204 | |
| 205 | - /** |
|
| 206 | - * Used to delete expired cache data |
|
| 207 | - */ |
|
| 208 | - public function deleteExpiredCache(){ |
|
| 209 | - $this->logger->debug('Deleting of expired cache files'); |
|
| 210 | - $list = glob(CACHE_PATH . '*.cache'); |
|
| 211 | - if(! $list){ |
|
| 212 | - $this->logger->info('No cache files were found skipping'); |
|
| 213 | - } |
|
| 214 | - else{ |
|
| 215 | - $this->logger->info('Found [' . count($list) . '] cache files to remove if expired'); |
|
| 216 | - foreach ($list as $file) { |
|
| 217 | - $this->logger->debug('Processing the cache file [' . $file . ']'); |
|
| 218 | - $data = file_get_contents($file); |
|
| 219 | - $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
|
| 220 | - if(! $data){ |
|
| 221 | - $this->logger->warning('Can not unserialize the cache data for file [' . $file . ']'); |
|
| 222 | - } |
|
| 223 | - else if(time() > $data['expire']){ |
|
| 224 | - $this->logger->info('The cache data for file [' . $file . '] already expired remove it'); |
|
| 225 | - unlink($file); |
|
| 226 | - } |
|
| 227 | - else{ |
|
| 228 | - $this->logger->info('The cache data for file [' . $file . '] not yet expired skip it'); |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - } |
|
| 205 | + /** |
|
| 206 | + * Used to delete expired cache data |
|
| 207 | + */ |
|
| 208 | + public function deleteExpiredCache(){ |
|
| 209 | + $this->logger->debug('Deleting of expired cache files'); |
|
| 210 | + $list = glob(CACHE_PATH . '*.cache'); |
|
| 211 | + if(! $list){ |
|
| 212 | + $this->logger->info('No cache files were found skipping'); |
|
| 213 | + } |
|
| 214 | + else{ |
|
| 215 | + $this->logger->info('Found [' . count($list) . '] cache files to remove if expired'); |
|
| 216 | + foreach ($list as $file) { |
|
| 217 | + $this->logger->debug('Processing the cache file [' . $file . ']'); |
|
| 218 | + $data = file_get_contents($file); |
|
| 219 | + $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
|
| 220 | + if(! $data){ |
|
| 221 | + $this->logger->warning('Can not unserialize the cache data for file [' . $file . ']'); |
|
| 222 | + } |
|
| 223 | + else if(time() > $data['expire']){ |
|
| 224 | + $this->logger->info('The cache data for file [' . $file . '] already expired remove it'); |
|
| 225 | + unlink($file); |
|
| 226 | + } |
|
| 227 | + else{ |
|
| 228 | + $this->logger->info('The cache data for file [' . $file . '] not yet expired skip it'); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * Remove all file from cache folder |
|
| 236 | - */ |
|
| 237 | - public function clean(){ |
|
| 238 | - $this->logger->debug('Deleting of all cache files'); |
|
| 239 | - $list = glob(CACHE_PATH . '*.cache'); |
|
| 240 | - if(! $list){ |
|
| 241 | - $this->logger->info('No cache files were found skipping'); |
|
| 242 | - } |
|
| 243 | - else{ |
|
| 244 | - $this->logger->info('Found [' . count($list) . '] cache files to remove'); |
|
| 245 | - foreach ($list as $file) { |
|
| 246 | - $this->logger->debug('Processing the cache file [' . $file . ']'); |
|
| 247 | - unlink($file); |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - } |
|
| 234 | + /** |
|
| 235 | + * Remove all file from cache folder |
|
| 236 | + */ |
|
| 237 | + public function clean(){ |
|
| 238 | + $this->logger->debug('Deleting of all cache files'); |
|
| 239 | + $list = glob(CACHE_PATH . '*.cache'); |
|
| 240 | + if(! $list){ |
|
| 241 | + $this->logger->info('No cache files were found skipping'); |
|
| 242 | + } |
|
| 243 | + else{ |
|
| 244 | + $this->logger->info('Found [' . count($list) . '] cache files to remove'); |
|
| 245 | + foreach ($list as $file) { |
|
| 246 | + $this->logger->debug('Processing the cache file [' . $file . ']'); |
|
| 247 | + unlink($file); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | - /** |
|
| 253 | - * @return boolean |
|
| 254 | - */ |
|
| 255 | - public function isCompressCacheData(){ |
|
| 256 | - return $this->compressCacheData; |
|
| 257 | - } |
|
| 252 | + /** |
|
| 253 | + * @return boolean |
|
| 254 | + */ |
|
| 255 | + public function isCompressCacheData(){ |
|
| 256 | + return $this->compressCacheData; |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * @param boolean $compressCacheData |
|
| 261 | - * |
|
| 262 | - * @return object |
|
| 263 | - */ |
|
| 264 | - public function setCompressCacheData($status = true){ |
|
| 265 | - //if Zlib extension is not loaded set compressCacheData to false |
|
| 266 | - if($status === true && ! extension_loaded('zlib')){ |
|
| 259 | + /** |
|
| 260 | + * @param boolean $compressCacheData |
|
| 261 | + * |
|
| 262 | + * @return object |
|
| 263 | + */ |
|
| 264 | + public function setCompressCacheData($status = true){ |
|
| 265 | + //if Zlib extension is not loaded set compressCacheData to false |
|
| 266 | + if($status === true && ! extension_loaded('zlib')){ |
|
| 267 | 267 | |
| 268 | - $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE'); |
|
| 269 | - $this->compressCacheData = false; |
|
| 270 | - } |
|
| 271 | - else{ |
|
| 272 | - $this->compressCacheData = $status; |
|
| 273 | - } |
|
| 274 | - return $this; |
|
| 275 | - } |
|
| 268 | + $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE'); |
|
| 269 | + $this->compressCacheData = false; |
|
| 270 | + } |
|
| 271 | + else{ |
|
| 272 | + $this->compressCacheData = $status; |
|
| 273 | + } |
|
| 274 | + return $this; |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - /** |
|
| 278 | - * Check whether the cache feature for the handle is supported |
|
| 279 | - * |
|
| 280 | - * @return bool |
|
| 281 | - */ |
|
| 282 | - public function isSupported(){ |
|
| 283 | - return CACHE_PATH && is_dir(CACHE_PATH) && is_writable(CACHE_PATH); |
|
| 284 | - } |
|
| 277 | + /** |
|
| 278 | + * Check whether the cache feature for the handle is supported |
|
| 279 | + * |
|
| 280 | + * @return bool |
|
| 281 | + */ |
|
| 282 | + public function isSupported(){ |
|
| 283 | + return CACHE_PATH && is_dir(CACHE_PATH) && is_writable(CACHE_PATH); |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - /** |
|
| 287 | - * Return the Log instance |
|
| 288 | - * @return object |
|
| 289 | - */ |
|
| 290 | - public function getLogger(){ |
|
| 291 | - return $this->logger; |
|
| 292 | - } |
|
| 286 | + /** |
|
| 287 | + * Return the Log instance |
|
| 288 | + * @return object |
|
| 289 | + */ |
|
| 290 | + public function getLogger(){ |
|
| 291 | + return $this->logger; |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - /** |
|
| 295 | - * Set the log instance |
|
| 296 | - * @param Log $logger the log object |
|
| 297 | - */ |
|
| 298 | - public function setLogger(Log $logger){ |
|
| 299 | - $this->logger = $logger; |
|
| 300 | - return $this; |
|
| 301 | - } |
|
| 294 | + /** |
|
| 295 | + * Set the log instance |
|
| 296 | + * @param Log $logger the log object |
|
| 297 | + */ |
|
| 298 | + public function setLogger(Log $logger){ |
|
| 299 | + $this->logger = $logger; |
|
| 300 | + return $this; |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | - /** |
|
| 304 | - * Get the cache file full path for the given key |
|
| 305 | - * |
|
| 306 | - * @param string $key the cache item key |
|
| 307 | - * @return string the full cache file path for this key |
|
| 308 | - */ |
|
| 309 | - private function getFilePath($key){ |
|
| 310 | - return CACHE_PATH . md5($key) . '.cache'; |
|
| 311 | - } |
|
| 312 | - } |
|
| 303 | + /** |
|
| 304 | + * Get the cache file full path for the given key |
|
| 305 | + * |
|
| 306 | + * @param string $key the cache item key |
|
| 307 | + * @return string the full cache file path for this key |
|
| 308 | + */ |
|
| 309 | + private function getFilePath($key){ |
|
| 310 | + return CACHE_PATH . md5($key) . '.cache'; |
|
| 311 | + } |
|
| 312 | + } |
|