@@ -1,267 +1,267 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * TNH Framework |
|
4 | - * |
|
5 | - * A simple PHP framework using HMVC architecture |
|
6 | - * |
|
7 | - * This content is released under the GNU GPL License (GPL) |
|
8 | - * |
|
9 | - * Copyright (C) 2017 Tony NGUEREZA |
|
10 | - * |
|
11 | - * This program is free software; you can redistribute it and/or |
|
12 | - * modify it under the terms of the GNU General Public License |
|
13 | - * as published by the Free Software Foundation; either version 3 |
|
14 | - * of the License, or (at your option) any later version. |
|
15 | - * |
|
16 | - * This program is distributed in the hope that it will be useful, |
|
17 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 | - * GNU General Public License for more details. |
|
20 | - * |
|
21 | - * You should have received a copy of the GNU General Public License |
|
22 | - * along with this program; if not, write to the Free Software |
|
23 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
24 | - */ |
|
2 | + /** |
|
3 | + * TNH Framework |
|
4 | + * |
|
5 | + * A simple PHP framework using HMVC architecture |
|
6 | + * |
|
7 | + * This content is released under the GNU GPL License (GPL) |
|
8 | + * |
|
9 | + * Copyright (C) 2017 Tony NGUEREZA |
|
10 | + * |
|
11 | + * This program is free software; you can redistribute it and/or |
|
12 | + * modify it under the terms of the GNU General Public License |
|
13 | + * as published by the Free Software Foundation; either version 3 |
|
14 | + * of the License, or (at your option) any later version. |
|
15 | + * |
|
16 | + * This program is distributed in the hope that it will be useful, |
|
17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 | + * GNU General Public License for more details. |
|
20 | + * |
|
21 | + * You should have received a copy of the GNU General Public License |
|
22 | + * along with this program; if not, write to the Free Software |
|
23 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
24 | + */ |
|
25 | 25 | |
26 | - /** |
|
27 | - * the directory separator, under windows it is \ and unix, linux / |
|
28 | - */ |
|
29 | - define('DS', DIRECTORY_SEPARATOR); |
|
26 | + /** |
|
27 | + * the directory separator, under windows it is \ and unix, linux / |
|
28 | + */ |
|
29 | + define('DS', DIRECTORY_SEPARATOR); |
|
30 | 30 | |
31 | - /** |
|
32 | - * The root directory of the application. |
|
33 | - * |
|
34 | - * you can place this directory outside of your web directory, for example "/home/your_app", etc. |
|
35 | - */ |
|
36 | - define('ROOT_PATH', dirname(realpath(__FILE__)) . DS); |
|
31 | + /** |
|
32 | + * The root directory of the application. |
|
33 | + * |
|
34 | + * you can place this directory outside of your web directory, for example "/home/your_app", etc. |
|
35 | + */ |
|
36 | + define('ROOT_PATH', dirname(realpath(__FILE__)) . DS); |
|
37 | 37 | |
38 | - /** |
|
39 | - * The path to the directory. |
|
40 | - * |
|
41 | - * That contains your static files (javascript, css, images, etc.) |
|
42 | - * Note: the path must be relative to the file index.php (the front-end controller). |
|
43 | - */ |
|
44 | - define('ASSETS_PATH', 'assets/'); |
|
38 | + /** |
|
39 | + * The path to the directory. |
|
40 | + * |
|
41 | + * That contains your static files (javascript, css, images, etc.) |
|
42 | + * Note: the path must be relative to the file index.php (the front-end controller). |
|
43 | + */ |
|
44 | + define('ASSETS_PATH', 'assets/'); |
|
45 | 45 | |
46 | - /** |
|
47 | - * The path to the directory of your cache files. |
|
48 | - * |
|
49 | - * This feature is available currently for database and views. |
|
50 | - */ |
|
51 | - define('CACHE_PATH', ROOT_PATH . 'cache' . DS); |
|
46 | + /** |
|
47 | + * The path to the directory of your cache files. |
|
48 | + * |
|
49 | + * This feature is available currently for database and views. |
|
50 | + */ |
|
51 | + define('CACHE_PATH', ROOT_PATH . 'cache' . DS); |
|
52 | 52 | |
53 | - /** |
|
54 | - * The path to the application directory. |
|
55 | - * |
|
56 | - * It contains your most often used files that is to say which contains your files of the application, |
|
57 | - * in MVC architecture (controllers, models, views). |
|
58 | - */ |
|
59 | - define('APPS_PATH', ROOT_PATH . 'classes' . DS); |
|
53 | + /** |
|
54 | + * The path to the application directory. |
|
55 | + * |
|
56 | + * It contains your most often used files that is to say which contains your files of the application, |
|
57 | + * in MVC architecture (controllers, models, views). |
|
58 | + */ |
|
59 | + define('APPS_PATH', ROOT_PATH . 'classes' . DS); |
|
60 | 60 | |
61 | - /** |
|
62 | - * The path to the controller directory of your application. |
|
63 | - * |
|
64 | - * If you already know the MVC architecture you know what a controller means; |
|
65 | - * it is he who makes the business logic of your application in general. |
|
66 | - */ |
|
67 | - define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS); |
|
61 | + /** |
|
62 | + * The path to the controller directory of your application. |
|
63 | + * |
|
64 | + * If you already know the MVC architecture you know what a controller means; |
|
65 | + * it is he who makes the business logic of your application in general. |
|
66 | + */ |
|
67 | + define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS); |
|
68 | 68 | |
69 | - /** |
|
70 | - * The path to the directory of your model classes of your application. |
|
71 | - * |
|
72 | - * If you already know the MVC architecture you know what a model means; |
|
73 | - * it's the one who interacts with the database, in one word persistent data from your application. |
|
74 | - */ |
|
75 | - define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS); |
|
69 | + /** |
|
70 | + * The path to the directory of your model classes of your application. |
|
71 | + * |
|
72 | + * If you already know the MVC architecture you know what a model means; |
|
73 | + * it's the one who interacts with the database, in one word persistent data from your application. |
|
74 | + */ |
|
75 | + define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS); |
|
76 | 76 | |
77 | - /** |
|
78 | - * The path to the directory of your views. |
|
79 | - * |
|
80 | - * If you already know the MVC architecture you know what a view means, |
|
81 | - * a view is just a user interface (html page, form, etc.) that is to say |
|
82 | - * everything displayed in the browser interface, etc. |
|
83 | - */ |
|
84 | - define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS); |
|
77 | + /** |
|
78 | + * The path to the directory of your views. |
|
79 | + * |
|
80 | + * If you already know the MVC architecture you know what a view means, |
|
81 | + * a view is just a user interface (html page, form, etc.) that is to say |
|
82 | + * everything displayed in the browser interface, etc. |
|
83 | + */ |
|
84 | + define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS); |
|
85 | 85 | |
86 | - /** |
|
87 | - * The path to the configuration directory. |
|
88 | - * |
|
89 | - * That contains most of the configuration files for your |
|
90 | - * application (database, class loading file, functions, etc.) |
|
91 | - */ |
|
92 | - define('CONFIG_PATH', ROOT_PATH . 'config' . DS); |
|
86 | + /** |
|
87 | + * The path to the configuration directory. |
|
88 | + * |
|
89 | + * That contains most of the configuration files for your |
|
90 | + * application (database, class loading file, functions, etc.) |
|
91 | + */ |
|
92 | + define('CONFIG_PATH', ROOT_PATH . 'config' . DS); |
|
93 | 93 | |
94 | - /** |
|
95 | - * The core directory |
|
96 | - * |
|
97 | - * It is recommended to put this folder out of the web directory of your server and |
|
98 | - * you should not change its content because in case of update you could lose the modified files. |
|
99 | - */ |
|
100 | - define('CORE_PATH', ROOT_PATH . 'core' . DS); |
|
94 | + /** |
|
95 | + * The core directory |
|
96 | + * |
|
97 | + * It is recommended to put this folder out of the web directory of your server and |
|
98 | + * you should not change its content because in case of update you could lose the modified files. |
|
99 | + */ |
|
100 | + define('CORE_PATH', ROOT_PATH . 'core' . DS); |
|
101 | 101 | |
102 | - /** |
|
103 | - * The path to the directory of core classes that used by the system. |
|
104 | - * |
|
105 | - * It contains PHP classes that are used by the framework internally. |
|
106 | - */ |
|
107 | - define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS); |
|
102 | + /** |
|
103 | + * The path to the directory of core classes that used by the system. |
|
104 | + * |
|
105 | + * It contains PHP classes that are used by the framework internally. |
|
106 | + */ |
|
107 | + define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS); |
|
108 | 108 | |
109 | - /** |
|
110 | - * The path to the directory of core classes for the cache used by the system. |
|
111 | - * |
|
112 | - * It contains PHP classes for the cache drivers. |
|
113 | - */ |
|
114 | - define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS); |
|
109 | + /** |
|
110 | + * The path to the directory of core classes for the cache used by the system. |
|
111 | + * |
|
112 | + * It contains PHP classes for the cache drivers. |
|
113 | + */ |
|
114 | + define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS); |
|
115 | 115 | |
116 | 116 | /** |
117 | - * The path to the directory of core classes for the database used by the system. |
|
118 | - * |
|
119 | - * It contains PHP classes for the database library, drivers, etc. |
|
120 | - */ |
|
121 | - define('CORE_CLASSES_DATABASE_PATH', CORE_CLASSES_PATH . 'database' . DS); |
|
117 | + * The path to the directory of core classes for the database used by the system. |
|
118 | + * |
|
119 | + * It contains PHP classes for the database library, drivers, etc. |
|
120 | + */ |
|
121 | + define('CORE_CLASSES_DATABASE_PATH', CORE_CLASSES_PATH . 'database' . DS); |
|
122 | 122 | |
123 | - /** |
|
124 | - * The path to the directory of core classes for the model used by the system. |
|
125 | - * |
|
126 | - * It contains PHP classes for the models. |
|
127 | - */ |
|
128 | - define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS); |
|
123 | + /** |
|
124 | + * The path to the directory of core classes for the model used by the system. |
|
125 | + * |
|
126 | + * It contains PHP classes for the models. |
|
127 | + */ |
|
128 | + define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS); |
|
129 | 129 | |
130 | - /** |
|
131 | - * The path to the directory of functions or helper systems. |
|
132 | - * |
|
133 | - * It contains PHP functions that perform a particular task: character string processing, URL, etc. |
|
134 | - */ |
|
135 | - define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS); |
|
130 | + /** |
|
131 | + * The path to the directory of functions or helper systems. |
|
132 | + * |
|
133 | + * It contains PHP functions that perform a particular task: character string processing, URL, etc. |
|
134 | + */ |
|
135 | + define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS); |
|
136 | 136 | |
137 | - /** |
|
138 | - * The path to the core directory of languages files. |
|
139 | - * |
|
140 | - */ |
|
141 | - define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS); |
|
137 | + /** |
|
138 | + * The path to the core directory of languages files. |
|
139 | + * |
|
140 | + */ |
|
141 | + define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS); |
|
142 | 142 | |
143 | - /** |
|
144 | - * The path to the system library directory. |
|
145 | - * |
|
146 | - * Which contains the libraries most often used in your web application, as for the |
|
147 | - * core directory it is advisable to put it out of the root directory of your application. |
|
148 | - */ |
|
149 | - define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS); |
|
143 | + /** |
|
144 | + * The path to the system library directory. |
|
145 | + * |
|
146 | + * Which contains the libraries most often used in your web application, as for the |
|
147 | + * core directory it is advisable to put it out of the root directory of your application. |
|
148 | + */ |
|
149 | + define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS); |
|
150 | 150 | |
151 | - /** |
|
152 | - * The path to the system view directory. |
|
153 | - * |
|
154 | - * That contains the views used for the system, such as error messages, and so on. |
|
155 | - */ |
|
156 | - define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS); |
|
151 | + /** |
|
152 | + * The path to the system view directory. |
|
153 | + * |
|
154 | + * That contains the views used for the system, such as error messages, and so on. |
|
155 | + */ |
|
156 | + define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS); |
|
157 | 157 | |
158 | - /** |
|
159 | - * The path to the directory of your PHP personal functions or helper. |
|
160 | - * |
|
161 | - * It contains your PHP functions that perform a particular task: utilities, etc. |
|
162 | - * Note: Do not put your personal functions or helpers in the system functions directory, |
|
163 | - * because if you update the system you may lose them. |
|
164 | - */ |
|
165 | - define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS); |
|
158 | + /** |
|
159 | + * The path to the directory of your PHP personal functions or helper. |
|
160 | + * |
|
161 | + * It contains your PHP functions that perform a particular task: utilities, etc. |
|
162 | + * Note: Do not put your personal functions or helpers in the system functions directory, |
|
163 | + * because if you update the system you may lose them. |
|
164 | + */ |
|
165 | + define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS); |
|
166 | 166 | |
167 | - /** |
|
168 | - * The path to the app directory of personal language. |
|
169 | - * |
|
170 | - * This feature is not yet available. |
|
171 | - * You can help us do this if you are nice or wish to see the developed framework. |
|
172 | - */ |
|
173 | - define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS); |
|
167 | + /** |
|
168 | + * The path to the app directory of personal language. |
|
169 | + * |
|
170 | + * This feature is not yet available. |
|
171 | + * You can help us do this if you are nice or wish to see the developed framework. |
|
172 | + */ |
|
173 | + define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS); |
|
174 | 174 | |
175 | - /** |
|
176 | - * The path to the directory of your personal libraries |
|
177 | - * |
|
178 | - * It contains your PHP classes, package, etc. |
|
179 | - * Note: you should not put your personal libraries in the system library directory, |
|
180 | - * because it is recalled in case of updating the system you might have surprises. |
|
181 | - */ |
|
182 | - define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS); |
|
175 | + /** |
|
176 | + * The path to the directory of your personal libraries |
|
177 | + * |
|
178 | + * It contains your PHP classes, package, etc. |
|
179 | + * Note: you should not put your personal libraries in the system library directory, |
|
180 | + * because it is recalled in case of updating the system you might have surprises. |
|
181 | + */ |
|
182 | + define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS); |
|
183 | 183 | |
184 | - /** |
|
185 | - * The path to the directory that contains the log files. |
|
186 | - * |
|
187 | - * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, |
|
188 | - * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more |
|
189 | - * details see the documentation of your web server. |
|
190 | - * Example for Unix or linux with apache web server: |
|
191 | - * # chmod -R 700 /path/to/your/logs/directory/ |
|
192 | - * # chown -R www-data:www-data /path/to/your/logs/directory/ |
|
193 | - */ |
|
194 | - define('LOGS_PATH', ROOT_PATH . 'logs' . DS); |
|
184 | + /** |
|
185 | + * The path to the directory that contains the log files. |
|
186 | + * |
|
187 | + * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, |
|
188 | + * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more |
|
189 | + * details see the documentation of your web server. |
|
190 | + * Example for Unix or linux with apache web server: |
|
191 | + * # chmod -R 700 /path/to/your/logs/directory/ |
|
192 | + * # chown -R www-data:www-data /path/to/your/logs/directory/ |
|
193 | + */ |
|
194 | + define('LOGS_PATH', ROOT_PATH . 'logs' . DS); |
|
195 | 195 | |
196 | - /** |
|
197 | - * The path to the modules directory. |
|
198 | - * |
|
199 | - * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
|
200 | - * in HMVC architecture (hierichical, controllers, models, views). |
|
201 | - */ |
|
202 | - define('MODULE_PATH', ROOT_PATH . 'modules' . DS); |
|
196 | + /** |
|
197 | + * The path to the modules directory. |
|
198 | + * |
|
199 | + * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
|
200 | + * in HMVC architecture (hierichical, controllers, models, views). |
|
201 | + */ |
|
202 | + define('MODULE_PATH', ROOT_PATH . 'modules' . DS); |
|
203 | 203 | |
204 | - /** |
|
205 | - * The path to the directory of sources external to your application. |
|
206 | - * |
|
207 | - * If you have already used "composer" you know what that means. |
|
208 | - */ |
|
209 | - define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS); |
|
204 | + /** |
|
205 | + * The path to the directory of sources external to your application. |
|
206 | + * |
|
207 | + * If you have already used "composer" you know what that means. |
|
208 | + */ |
|
209 | + define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS); |
|
210 | 210 | |
211 | - /** |
|
212 | - * The front controller of your application. |
|
213 | - * |
|
214 | - * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of |
|
215 | - * your application by using the rewrite module URL of your web server . |
|
216 | - * For example, under apache web server, there is a configuration example file that is located at the root |
|
217 | - * of your framework folder : "htaccess.txt" rename it to ".htaccess". |
|
218 | - */ |
|
219 | - define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); |
|
211 | + /** |
|
212 | + * The front controller of your application. |
|
213 | + * |
|
214 | + * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of |
|
215 | + * your application by using the rewrite module URL of your web server . |
|
216 | + * For example, under apache web server, there is a configuration example file that is located at the root |
|
217 | + * of your framework folder : "htaccess.txt" rename it to ".htaccess". |
|
218 | + */ |
|
219 | + define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); |
|
220 | 220 | |
221 | - /** |
|
222 | - * Check if user run the application under CLI |
|
223 | - */ |
|
224 | - define('IS_CLI', stripos('cli', php_sapi_name()) !== false); |
|
221 | + /** |
|
222 | + * Check if user run the application under CLI |
|
223 | + */ |
|
224 | + define('IS_CLI', stripos('cli', php_sapi_name()) !== false); |
|
225 | 225 | |
226 | - /** |
|
227 | - * The environment of your application (production, test, development). |
|
228 | - * |
|
229 | - * if your application is still in development you use the value "development" |
|
230 | - * so you will have the display of the error messages, etc. |
|
231 | - * Once you finish the development of your application that is to put it online |
|
232 | - * you change this value to "production" or "testing", in this case there will be deactivation of error messages, |
|
233 | - * the loading of the system, will be fast. |
|
234 | - */ |
|
235 | - define('ENVIRONMENT', 'development'); |
|
226 | + /** |
|
227 | + * The environment of your application (production, test, development). |
|
228 | + * |
|
229 | + * if your application is still in development you use the value "development" |
|
230 | + * so you will have the display of the error messages, etc. |
|
231 | + * Once you finish the development of your application that is to put it online |
|
232 | + * you change this value to "production" or "testing", in this case there will be deactivation of error messages, |
|
233 | + * the loading of the system, will be fast. |
|
234 | + */ |
|
235 | + define('ENVIRONMENT', 'development'); |
|
236 | 236 | |
237 | - /* ---------------------------------------------------------------------------------- */ |
|
238 | - /////////////////////////////////////////////////////////////////////////////////////// |
|
239 | - /******************** DO NOT CHANGE THE LINES BELOW *********************************/ |
|
240 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
237 | + /* ---------------------------------------------------------------------------------- */ |
|
238 | + /////////////////////////////////////////////////////////////////////////////////////// |
|
239 | + /******************** DO NOT CHANGE THE LINES BELOW *********************************/ |
|
240 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
241 | 241 | |
242 | - switch (ENVIRONMENT) { |
|
243 | - case 'development': |
|
244 | - error_reporting(-1); |
|
245 | - ini_set('display_errors', 1); |
|
246 | - break; |
|
247 | - case 'testing': |
|
248 | - case 'production': |
|
249 | - ini_set('display_errors', 0); |
|
250 | - if (version_compare(PHP_VERSION, '5.3', '>=')) { |
|
251 | - error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); |
|
252 | - } |
|
253 | - else { |
|
254 | - error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
|
255 | - } |
|
256 | - break; |
|
257 | - default: |
|
258 | - header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); |
|
259 | - echo 'The application environment is not set correctly.'; |
|
260 | - exit(1); |
|
261 | - } |
|
242 | + switch (ENVIRONMENT) { |
|
243 | + case 'development': |
|
244 | + error_reporting(-1); |
|
245 | + ini_set('display_errors', 1); |
|
246 | + break; |
|
247 | + case 'testing': |
|
248 | + case 'production': |
|
249 | + ini_set('display_errors', 0); |
|
250 | + if (version_compare(PHP_VERSION, '5.3', '>=')) { |
|
251 | + error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); |
|
252 | + } |
|
253 | + else { |
|
254 | + error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
|
255 | + } |
|
256 | + break; |
|
257 | + default: |
|
258 | + header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); |
|
259 | + echo 'The application environment is not set correctly.'; |
|
260 | + exit(1); |
|
261 | + } |
|
262 | 262 | |
263 | - /** |
|
264 | - * let's go. |
|
265 | - * Everything is OK now we launch our application. |
|
266 | - */ |
|
267 | - require_once CORE_PATH . 'bootstrap.php'; |
|
268 | 263 | \ No newline at end of file |
264 | + /** |
|
265 | + * let's go. |
|
266 | + * Everything is OK now we launch our application. |
|
267 | + */ |
|
268 | + require_once CORE_PATH . 'bootstrap.php'; |
|
269 | 269 | \ No newline at end of file |
@@ -22,251 +22,251 @@ |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
23 | 23 | * along with this program; if not, write to the Free Software |
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | - */ |
|
25 | + */ |
|
26 | 26 | |
27 | - class Module extends BaseStaticClass { |
|
27 | + class Module extends BaseStaticClass { |
|
28 | 28 | |
29 | - /** |
|
30 | - * list of loaded module |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - private static $list = array(); |
|
29 | + /** |
|
30 | + * list of loaded module |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + private static $list = array(); |
|
34 | 34 | |
35 | - /** |
|
36 | - * Initialise the module list by scanning the directory MODULE_PATH |
|
37 | - */ |
|
38 | - public function init(){ |
|
39 | - $logger = self::getLogger(); |
|
40 | - $logger->debug('Check if the application contains the modules ...'); |
|
41 | - $moduleDir = opendir(MODULE_PATH); |
|
42 | - if (is_resource($moduleDir)){ |
|
43 | - while(($module = readdir($moduleDir)) !== false){ |
|
44 | - if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){ |
|
45 | - self::$list[] = $module; |
|
46 | - } else{ |
|
47 | - $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name'); |
|
48 | - } |
|
49 | - } |
|
50 | - closedir($moduleDir); |
|
51 | - } |
|
52 | - ksort(self::$list); |
|
35 | + /** |
|
36 | + * Initialise the module list by scanning the directory MODULE_PATH |
|
37 | + */ |
|
38 | + public function init(){ |
|
39 | + $logger = self::getLogger(); |
|
40 | + $logger->debug('Check if the application contains the modules ...'); |
|
41 | + $moduleDir = opendir(MODULE_PATH); |
|
42 | + if (is_resource($moduleDir)){ |
|
43 | + while(($module = readdir($moduleDir)) !== false){ |
|
44 | + if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){ |
|
45 | + self::$list[] = $module; |
|
46 | + } else{ |
|
47 | + $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name'); |
|
48 | + } |
|
49 | + } |
|
50 | + closedir($moduleDir); |
|
51 | + } |
|
52 | + ksort(self::$list); |
|
53 | 53 | |
54 | - if (! empty(self::$list)){ |
|
55 | - $logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']'); |
|
56 | - } |
|
57 | - } |
|
54 | + if (! empty(self::$list)){ |
|
55 | + $logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']'); |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * Add new module in the list |
|
62 | - * @param string $name the name of the module |
|
63 | - * |
|
64 | - * @return object the current instance |
|
65 | - */ |
|
66 | - public function add($name) { |
|
67 | - self::$list[] = $name; |
|
68 | - return $this; |
|
69 | - } |
|
60 | + /** |
|
61 | + * Add new module in the list |
|
62 | + * @param string $name the name of the module |
|
63 | + * |
|
64 | + * @return object the current instance |
|
65 | + */ |
|
66 | + public function add($name) { |
|
67 | + self::$list[] = $name; |
|
68 | + return $this; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Get the list of the custom autoload configuration from module if exists |
|
73 | - * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values |
|
74 | - */ |
|
75 | - public static function getModulesAutoloadConfig() { |
|
76 | - $logger = self::getLogger(); |
|
77 | - if (empty(self::$list)) { |
|
78 | - $logger->info('No module was loaded skipping.'); |
|
79 | - return false; |
|
80 | - } |
|
81 | - $autoloads = array(); |
|
82 | - $autoloads['libraries'] = array(); |
|
83 | - $autoloads['config'] = array(); |
|
84 | - $autoloads['models'] = array(); |
|
85 | - $autoloads['functions'] = array(); |
|
86 | - $autoloads['languages'] = array(); |
|
71 | + /** |
|
72 | + * Get the list of the custom autoload configuration from module if exists |
|
73 | + * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values |
|
74 | + */ |
|
75 | + public static function getModulesAutoloadConfig() { |
|
76 | + $logger = self::getLogger(); |
|
77 | + if (empty(self::$list)) { |
|
78 | + $logger->info('No module was loaded skipping.'); |
|
79 | + return false; |
|
80 | + } |
|
81 | + $autoloads = array(); |
|
82 | + $autoloads['libraries'] = array(); |
|
83 | + $autoloads['config'] = array(); |
|
84 | + $autoloads['models'] = array(); |
|
85 | + $autoloads['functions'] = array(); |
|
86 | + $autoloads['languages'] = array(); |
|
87 | 87 | |
88 | - foreach (self::$list as $module) { |
|
89 | - $file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php'; |
|
90 | - if (file_exists($file)) { |
|
91 | - $autoload = array(); |
|
92 | - require_once $file; |
|
93 | - if (!empty($autoload) && is_array($autoload)) { |
|
94 | - $autoloads = array_merge_recursive($autoloads, $autoload); |
|
95 | - unset($autoload); |
|
96 | - } |
|
97 | - } |
|
98 | - } |
|
99 | - return $autoloads; |
|
100 | - } |
|
88 | + foreach (self::$list as $module) { |
|
89 | + $file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php'; |
|
90 | + if (file_exists($file)) { |
|
91 | + $autoload = array(); |
|
92 | + require_once $file; |
|
93 | + if (!empty($autoload) && is_array($autoload)) { |
|
94 | + $autoloads = array_merge_recursive($autoloads, $autoload); |
|
95 | + unset($autoload); |
|
96 | + } |
|
97 | + } |
|
98 | + } |
|
99 | + return $autoloads; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Get the list of the custom routes configuration from module if exists |
|
104 | - * @return array|boolean the routes list or false if no module contains the routes configuration |
|
105 | - */ |
|
106 | - public static function getModulesRoutesConfig() { |
|
107 | - $logger = self::getLogger(); |
|
108 | - if (empty(self::$list)) { |
|
109 | - $logger->info('No module was loaded skipping.'); |
|
110 | - return false; |
|
111 | - } |
|
112 | - $routes = array(); |
|
113 | - foreach (self::$list as $module) { |
|
114 | - $file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php'; |
|
115 | - if (file_exists($file)) { |
|
116 | - $route = array(); |
|
117 | - require_once $file; |
|
118 | - if (!empty($route) && is_array($route)) { |
|
119 | - $routes = array_merge($routes, $route); |
|
120 | - unset($route); |
|
121 | - } |
|
122 | - } |
|
123 | - } |
|
124 | - return $routes; |
|
125 | - } |
|
102 | + /** |
|
103 | + * Get the list of the custom routes configuration from module if exists |
|
104 | + * @return array|boolean the routes list or false if no module contains the routes configuration |
|
105 | + */ |
|
106 | + public static function getModulesRoutesConfig() { |
|
107 | + $logger = self::getLogger(); |
|
108 | + if (empty(self::$list)) { |
|
109 | + $logger->info('No module was loaded skipping.'); |
|
110 | + return false; |
|
111 | + } |
|
112 | + $routes = array(); |
|
113 | + foreach (self::$list as $module) { |
|
114 | + $file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php'; |
|
115 | + if (file_exists($file)) { |
|
116 | + $route = array(); |
|
117 | + require_once $file; |
|
118 | + if (!empty($route) && is_array($route)) { |
|
119 | + $routes = array_merge($routes, $route); |
|
120 | + unset($route); |
|
121 | + } |
|
122 | + } |
|
123 | + } |
|
124 | + return $routes; |
|
125 | + } |
|
126 | 126 | |
127 | 127 | |
128 | - /** |
|
129 | - * Check if in module list can have this controller |
|
130 | - * @see Module::findClassInModuleFullFilePath |
|
131 | - * @return boolean|string false or null if no module have this controller, path the full path of the controller |
|
132 | - */ |
|
133 | - public static function findControllerFullPath($class, $module = null) { |
|
134 | - return self::findClassInModuleFullFilePath($class, $module, 'controllers'); |
|
135 | - } |
|
128 | + /** |
|
129 | + * Check if in module list can have this controller |
|
130 | + * @see Module::findClassInModuleFullFilePath |
|
131 | + * @return boolean|string false or null if no module have this controller, path the full path of the controller |
|
132 | + */ |
|
133 | + public static function findControllerFullPath($class, $module = null) { |
|
134 | + return self::findClassInModuleFullFilePath($class, $module, 'controllers'); |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Check if in module list can have this model |
|
139 | - * @see Module::findClassInModuleFullFilePath |
|
140 | - * @return boolean|string false or null if no module have this model, return the full path of this model |
|
141 | - */ |
|
142 | - public static function findModelFullPath($class, $module = null) { |
|
143 | - return self::findClassInModuleFullFilePath($class, $module, 'models'); |
|
144 | - } |
|
137 | + /** |
|
138 | + * Check if in module list can have this model |
|
139 | + * @see Module::findClassInModuleFullFilePath |
|
140 | + * @return boolean|string false or null if no module have this model, return the full path of this model |
|
141 | + */ |
|
142 | + public static function findModelFullPath($class, $module = null) { |
|
143 | + return self::findClassInModuleFullFilePath($class, $module, 'models'); |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Check if in module list can have this library |
|
148 | - * @see Module::findClassInModuleFullFilePath |
|
149 | - * @return boolean|string false or null if no module have this library, return the full path of this library |
|
150 | - */ |
|
151 | - public static function findLibraryFullPath($class, $module = null) { |
|
152 | - return self::findClassInModuleFullFilePath($class, $module, 'libraries'); |
|
153 | - } |
|
146 | + /** |
|
147 | + * Check if in module list can have this library |
|
148 | + * @see Module::findClassInModuleFullFilePath |
|
149 | + * @return boolean|string false or null if no module have this library, return the full path of this library |
|
150 | + */ |
|
151 | + public static function findLibraryFullPath($class, $module = null) { |
|
152 | + return self::findClassInModuleFullFilePath($class, $module, 'libraries'); |
|
153 | + } |
|
154 | 154 | |
155 | 155 | |
156 | - /** |
|
157 | - * Check if in module list can have this config |
|
158 | - * @see Module::findNonClassInModuleFullFilePath |
|
159 | - * @return boolean|string false or null if no module have this configuration, return the full path of this configuration |
|
160 | - */ |
|
161 | - public static function findConfigFullPath($configuration, $module = null) { |
|
162 | - return self::findNonClassInModuleFullFilePath($configuration, $module, 'config'); |
|
163 | - } |
|
156 | + /** |
|
157 | + * Check if in module list can have this config |
|
158 | + * @see Module::findNonClassInModuleFullFilePath |
|
159 | + * @return boolean|string false or null if no module have this configuration, return the full path of this configuration |
|
160 | + */ |
|
161 | + public static function findConfigFullPath($configuration, $module = null) { |
|
162 | + return self::findNonClassInModuleFullFilePath($configuration, $module, 'config'); |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * Check if in module list can have this helper |
|
167 | - * @see Module::findNonClassInModuleFullFilePath |
|
168 | - * @return boolean|string false or null if no module have this helper, return the full path of this helper |
|
169 | - */ |
|
170 | - public static function findFunctionFullPath($helper, $module = null) { |
|
171 | - return self::findNonClassInModuleFullFilePath($helper, $module, 'functions'); |
|
172 | - } |
|
165 | + /** |
|
166 | + * Check if in module list can have this helper |
|
167 | + * @see Module::findNonClassInModuleFullFilePath |
|
168 | + * @return boolean|string false or null if no module have this helper, return the full path of this helper |
|
169 | + */ |
|
170 | + public static function findFunctionFullPath($helper, $module = null) { |
|
171 | + return self::findNonClassInModuleFullFilePath($helper, $module, 'functions'); |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * Check if in module list can have this view |
|
176 | - * @see Module::findNonClassInModuleFullFilePath |
|
177 | - * @return boolean|string false or null if no module have this view, path the full path of the view |
|
178 | - */ |
|
179 | - public static function findViewFullPath($view, $module = null) { |
|
180 | - return self::findNonClassInModuleFullFilePath($view, $module, 'views'); |
|
181 | - } |
|
174 | + /** |
|
175 | + * Check if in module list can have this view |
|
176 | + * @see Module::findNonClassInModuleFullFilePath |
|
177 | + * @return boolean|string false or null if no module have this view, path the full path of the view |
|
178 | + */ |
|
179 | + public static function findViewFullPath($view, $module = null) { |
|
180 | + return self::findNonClassInModuleFullFilePath($view, $module, 'views'); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Check if in module list can have this language |
|
185 | - * @see Module::findNonClassInModuleFullFilePath |
|
186 | - * @return boolean|string false or null if no module have this language, return the full path of this language |
|
187 | - */ |
|
188 | - public static function findLanguageFullPath($language, $appLang, $module = null) { |
|
189 | - return self::findNonClassInModuleFullFilePath($language, $module, 'lang', $appLang); |
|
190 | - } |
|
183 | + /** |
|
184 | + * Check if in module list can have this language |
|
185 | + * @see Module::findNonClassInModuleFullFilePath |
|
186 | + * @return boolean|string false or null if no module have this language, return the full path of this language |
|
187 | + */ |
|
188 | + public static function findLanguageFullPath($language, $appLang, $module = null) { |
|
189 | + return self::findNonClassInModuleFullFilePath($language, $module, 'lang', $appLang); |
|
190 | + } |
|
191 | 191 | |
192 | - /** |
|
193 | - * Get the list of module loaded |
|
194 | - * @return array the module list |
|
195 | - */ |
|
196 | - public static function getModuleList() { |
|
197 | - return self::$list; |
|
198 | - } |
|
192 | + /** |
|
193 | + * Get the list of module loaded |
|
194 | + * @return array the module list |
|
195 | + */ |
|
196 | + public static function getModuleList() { |
|
197 | + return self::$list; |
|
198 | + } |
|
199 | 199 | |
200 | - /** |
|
201 | - * Check if the application has an module |
|
202 | - * @return boolean |
|
203 | - */ |
|
204 | - public static function hasModule() { |
|
205 | - return !empty(self::$list); |
|
206 | - } |
|
200 | + /** |
|
201 | + * Check if the application has an module |
|
202 | + * @return boolean |
|
203 | + */ |
|
204 | + public static function hasModule() { |
|
205 | + return !empty(self::$list); |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * Check if in module list can have the model, controller, library |
|
210 | - * @param string $class the class name of library, model, controller |
|
211 | - * @param string $module the module name |
|
212 | - * @param string $type the name of the type "controllers", "libraries", "models" |
|
213 | - * @return boolean|string false or null if no module |
|
214 | - * have this class, return the full path of the class |
|
215 | - */ |
|
216 | - protected static function findClassInModuleFullFilePath($class, $module, $type) { |
|
217 | - $logger = self::getLogger(); |
|
218 | - $class = str_ireplace('.php', '', $class); |
|
219 | - $class = ucfirst($class); |
|
220 | - $classFile = $class . '.php'; |
|
221 | - $logger->debug('Checking the class [' . $class . '] in module [' . $module . '] for [' . $type . '] ...'); |
|
222 | - $filePath = MODULE_PATH . $module . DS . $type . DS . $classFile; |
|
223 | - if (file_exists($filePath)) { |
|
224 | - $logger->info('Found class [' . $class . '] in module [' . $module . '] for [' . $type . '] the file path is [' . $filePath . ']'); |
|
225 | - return $filePath; |
|
226 | - } |
|
227 | - $logger->info('Class [' . $class . '] does not exist in the module [' . $module . '] for [' . $type . ']'); |
|
228 | - return false; |
|
229 | - } |
|
208 | + /** |
|
209 | + * Check if in module list can have the model, controller, library |
|
210 | + * @param string $class the class name of library, model, controller |
|
211 | + * @param string $module the module name |
|
212 | + * @param string $type the name of the type "controllers", "libraries", "models" |
|
213 | + * @return boolean|string false or null if no module |
|
214 | + * have this class, return the full path of the class |
|
215 | + */ |
|
216 | + protected static function findClassInModuleFullFilePath($class, $module, $type) { |
|
217 | + $logger = self::getLogger(); |
|
218 | + $class = str_ireplace('.php', '', $class); |
|
219 | + $class = ucfirst($class); |
|
220 | + $classFile = $class . '.php'; |
|
221 | + $logger->debug('Checking the class [' . $class . '] in module [' . $module . '] for [' . $type . '] ...'); |
|
222 | + $filePath = MODULE_PATH . $module . DS . $type . DS . $classFile; |
|
223 | + if (file_exists($filePath)) { |
|
224 | + $logger->info('Found class [' . $class . '] in module [' . $module . '] for [' . $type . '] the file path is [' . $filePath . ']'); |
|
225 | + return $filePath; |
|
226 | + } |
|
227 | + $logger->info('Class [' . $class . '] does not exist in the module [' . $module . '] for [' . $type . ']'); |
|
228 | + return false; |
|
229 | + } |
|
230 | 230 | |
231 | - /** |
|
232 | - * Check if in module list can have the config, view, helper, language |
|
233 | - * @param string $name the name of config, view, helper, language |
|
234 | - * @param string $module the module name |
|
235 | - * @param string $type the name of the type "config", "functions", "views", "lang" |
|
236 | - * @param string|null $appLang the application language. This is use only when $type = "lang" |
|
237 | - * @return boolean|string false or null if no module |
|
238 | - * have this resource, return the full path of the resource |
|
239 | - */ |
|
240 | - protected static function findNonClassInModuleFullFilePath($name, $module, $type, $appLang = null) { |
|
241 | - $logger = self::getLogger(); |
|
242 | - $name = str_ireplace('.php', '', $name); |
|
243 | - $file = $name . '.php'; |
|
244 | - $filePath = MODULE_PATH . $module . DS . $type . DS . $file; |
|
245 | - switch ($type) { |
|
246 | - case 'functions': |
|
247 | - $name = str_ireplace('function_', '', $name); |
|
248 | - $file = 'function_' . $name . '.php'; |
|
249 | - $filePath = MODULE_PATH . $module . DS . $type . DS . $file; |
|
250 | - break; |
|
251 | - case 'views': |
|
252 | - $name = trim($name, '/\\'); |
|
253 | - $name = str_ireplace('/', DS, $name); |
|
254 | - $file = $name . '.php'; |
|
255 | - $filePath = MODULE_PATH . $module . DS . $type . DS . $file; |
|
256 | - break; |
|
257 | - case 'lang': |
|
258 | - $name = str_ireplace('lang_', '', $name); |
|
259 | - $file = 'lang_' . $name . '.php'; |
|
260 | - $filePath = MODULE_PATH . $module . DS . $type . DS . $appLang . DS . $file; |
|
261 | - break; |
|
262 | - } |
|
263 | - $logger->debug('Checking resource [' . $name . '] in module [' . $module . '] for [' . $type . '] ...'); |
|
264 | - if (file_exists($filePath)) { |
|
265 | - $logger->info('Found resource [' . $name . '] in module [' . $module . '] for [' . $type . '] the file path is [' . $filePath . ']'); |
|
266 | - return $filePath; |
|
267 | - } |
|
268 | - $logger->info('Resource [' . $name . '] does not exist in the module [' . $module . '] for [' . $type . ']'); |
|
269 | - return false; |
|
270 | - } |
|
231 | + /** |
|
232 | + * Check if in module list can have the config, view, helper, language |
|
233 | + * @param string $name the name of config, view, helper, language |
|
234 | + * @param string $module the module name |
|
235 | + * @param string $type the name of the type "config", "functions", "views", "lang" |
|
236 | + * @param string|null $appLang the application language. This is use only when $type = "lang" |
|
237 | + * @return boolean|string false or null if no module |
|
238 | + * have this resource, return the full path of the resource |
|
239 | + */ |
|
240 | + protected static function findNonClassInModuleFullFilePath($name, $module, $type, $appLang = null) { |
|
241 | + $logger = self::getLogger(); |
|
242 | + $name = str_ireplace('.php', '', $name); |
|
243 | + $file = $name . '.php'; |
|
244 | + $filePath = MODULE_PATH . $module . DS . $type . DS . $file; |
|
245 | + switch ($type) { |
|
246 | + case 'functions': |
|
247 | + $name = str_ireplace('function_', '', $name); |
|
248 | + $file = 'function_' . $name . '.php'; |
|
249 | + $filePath = MODULE_PATH . $module . DS . $type . DS . $file; |
|
250 | + break; |
|
251 | + case 'views': |
|
252 | + $name = trim($name, '/\\'); |
|
253 | + $name = str_ireplace('/', DS, $name); |
|
254 | + $file = $name . '.php'; |
|
255 | + $filePath = MODULE_PATH . $module . DS . $type . DS . $file; |
|
256 | + break; |
|
257 | + case 'lang': |
|
258 | + $name = str_ireplace('lang_', '', $name); |
|
259 | + $file = 'lang_' . $name . '.php'; |
|
260 | + $filePath = MODULE_PATH . $module . DS . $type . DS . $appLang . DS . $file; |
|
261 | + break; |
|
262 | + } |
|
263 | + $logger->debug('Checking resource [' . $name . '] in module [' . $module . '] for [' . $type . '] ...'); |
|
264 | + if (file_exists($filePath)) { |
|
265 | + $logger->info('Found resource [' . $name . '] in module [' . $module . '] for [' . $type . '] the file path is [' . $filePath . ']'); |
|
266 | + return $filePath; |
|
267 | + } |
|
268 | + $logger->info('Resource [' . $name . '] does not exist in the module [' . $module . '] for [' . $type . ']'); |
|
269 | + return false; |
|
270 | + } |
|
271 | 271 | |
272 | - } |
|
272 | + } |
@@ -1,63 +1,63 @@ |
||
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 | - /** |
|
28 | - * This class represent the event detail to dispatch to correspond listener |
|
29 | - */ |
|
30 | - class EventInfo { |
|
27 | + /** |
|
28 | + * This class represent the event detail to dispatch to correspond listener |
|
29 | + */ |
|
30 | + class EventInfo { |
|
31 | 31 | |
32 | - /** |
|
33 | - * The event name |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $name; |
|
32 | + /** |
|
33 | + * The event name |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $name; |
|
37 | 37 | |
38 | - /** |
|
39 | - * The event data to send to the listeners |
|
40 | - * @var mixed |
|
41 | - */ |
|
42 | - public $payload; |
|
38 | + /** |
|
39 | + * The event data to send to the listeners |
|
40 | + * @var mixed |
|
41 | + */ |
|
42 | + public $payload; |
|
43 | 43 | |
44 | - /** |
|
45 | - * If the listeners need return the event after treatment or not, false means no need |
|
46 | - * return true need return the event. |
|
47 | - * @var boolean |
|
48 | - */ |
|
49 | - public $returnBack; |
|
44 | + /** |
|
45 | + * If the listeners need return the event after treatment or not, false means no need |
|
46 | + * return true need return the event. |
|
47 | + * @var boolean |
|
48 | + */ |
|
49 | + public $returnBack; |
|
50 | 50 | |
51 | - /** |
|
52 | - * This variable indicates if need stop the event propagation |
|
53 | - * @var boolean |
|
54 | - */ |
|
55 | - public $stop; |
|
51 | + /** |
|
52 | + * This variable indicates if need stop the event propagation |
|
53 | + * @var boolean |
|
54 | + */ |
|
55 | + public $stop; |
|
56 | 56 | |
57 | - public function __construct($name, $payload = array(), $returnBack = false, $stop = false) { |
|
58 | - $this->name = $name; |
|
59 | - $this->payload = $payload; |
|
60 | - $this->returnBack = $returnBack; |
|
61 | - $this->stop = $stop; |
|
62 | - } |
|
63 | - } |
|
57 | + public function __construct($name, $payload = array(), $returnBack = false, $stop = false) { |
|
58 | + $this->name = $name; |
|
59 | + $this->payload = $payload; |
|
60 | + $this->returnBack = $returnBack; |
|
61 | + $this->stop = $stop; |
|
62 | + } |
|
63 | + } |
@@ -1,135 +1,135 @@ |
||
1 | 1 | <?php |
2 | - defined('ROOT_PATH') or exit('Access denied'); |
|
3 | - /** |
|
4 | - * TNH Framework |
|
5 | - * |
|
6 | - * A simple PHP framework using HMVC architecture |
|
7 | - * |
|
8 | - * This content is released under the GNU GPL License (GPL) |
|
9 | - * |
|
10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
11 | - * |
|
12 | - * This program is free software; you can redistribute it and/or |
|
13 | - * modify it under the terms of the GNU General Public License |
|
14 | - * as published by the Free Software Foundation; either version 3 |
|
15 | - * of the License, or (at your option) any later version. |
|
16 | - * |
|
17 | - * This program is distributed in the hope that it will be useful, |
|
18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | - * GNU General Public License for more details. |
|
21 | - * |
|
22 | - * You should have received a copy of the GNU General Public License |
|
23 | - * along with this program; if not, write to the Free Software |
|
24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
25 | - */ |
|
2 | + defined('ROOT_PATH') or exit('Access denied'); |
|
3 | + /** |
|
4 | + * TNH Framework |
|
5 | + * |
|
6 | + * A simple PHP framework using HMVC architecture |
|
7 | + * |
|
8 | + * This content is released under the GNU GPL License (GPL) |
|
9 | + * |
|
10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
11 | + * |
|
12 | + * This program is free software; you can redistribute it and/or |
|
13 | + * modify it under the terms of the GNU General Public License |
|
14 | + * as published by the Free Software Foundation; either version 3 |
|
15 | + * of the License, or (at your option) any later version. |
|
16 | + * |
|
17 | + * This program is distributed in the hope that it will be useful, |
|
18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | + * GNU General Public License for more details. |
|
21 | + * |
|
22 | + * You should have received a copy of the GNU General Public License |
|
23 | + * along with this program; if not, write to the Free Software |
|
24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
25 | + */ |
|
26 | 26 | |
27 | - class Security extends BaseStaticClass { |
|
27 | + class Security extends BaseStaticClass { |
|
28 | 28 | |
29 | - /** |
|
30 | - * This method is used to generate the CSRF token |
|
31 | - * @return string the generated CSRF token |
|
32 | - */ |
|
33 | - public static function generateCSRF() { |
|
34 | - $logger = self::getLogger(); |
|
35 | - $logger->debug('Generation of CSRF ...'); |
|
29 | + /** |
|
30 | + * This method is used to generate the CSRF token |
|
31 | + * @return string the generated CSRF token |
|
32 | + */ |
|
33 | + public static function generateCSRF() { |
|
34 | + $logger = self::getLogger(); |
|
35 | + $logger->debug('Generation of CSRF ...'); |
|
36 | 36 | |
37 | - $key = get_config('csrf_key', 'csrf_key'); |
|
38 | - $expire = get_config('csrf_expire', 60); |
|
39 | - $keyExpire = 'csrf_expire'; |
|
40 | - $currentTime = time(); |
|
41 | - if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){ |
|
42 | - $logger->info('The CSRF token not yet expire just return it'); |
|
43 | - return Session::get($key); |
|
44 | - } else{ |
|
45 | - $newTime = $currentTime + $expire; |
|
46 | - $token = sha1(uniqid()) . sha1(uniqid()); |
|
47 | - $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']'); |
|
48 | - Session::set($keyExpire, $newTime); |
|
49 | - Session::set($key, $token); |
|
50 | - return Session::get($key); |
|
51 | - } |
|
52 | - } |
|
37 | + $key = get_config('csrf_key', 'csrf_key'); |
|
38 | + $expire = get_config('csrf_expire', 60); |
|
39 | + $keyExpire = 'csrf_expire'; |
|
40 | + $currentTime = time(); |
|
41 | + if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){ |
|
42 | + $logger->info('The CSRF token not yet expire just return it'); |
|
43 | + return Session::get($key); |
|
44 | + } else{ |
|
45 | + $newTime = $currentTime + $expire; |
|
46 | + $token = sha1(uniqid()) . sha1(uniqid()); |
|
47 | + $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']'); |
|
48 | + Session::set($keyExpire, $newTime); |
|
49 | + Session::set($key, $token); |
|
50 | + return Session::get($key); |
|
51 | + } |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * This method is used to check the CSRF if is valid, not yet expire, etc. |
|
56 | - * @return boolean true if valid, false if not valid |
|
57 | - */ |
|
58 | - public static function validateCSRF() { |
|
59 | - $logger = self::getLogger(); |
|
60 | - $logger->debug('Validation of CSRF ...'); |
|
54 | + /** |
|
55 | + * This method is used to check the CSRF if is valid, not yet expire, etc. |
|
56 | + * @return boolean true if valid, false if not valid |
|
57 | + */ |
|
58 | + public static function validateCSRF() { |
|
59 | + $logger = self::getLogger(); |
|
60 | + $logger->debug('Validation of CSRF ...'); |
|
61 | 61 | |
62 | - $key = get_config('csrf_key', 'csrf_key'); |
|
63 | - $expire = get_config('csrf_expire', 60); |
|
64 | - $keyExpire = 'csrf_expire'; |
|
65 | - $currentTime = time(); |
|
66 | - $logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . ']'); |
|
67 | - if (!Session::exists($key) || Session::get($keyExpire) <= $currentTime) { |
|
68 | - $logger->warning('The CSRF session data is not valide'); |
|
69 | - return false; |
|
70 | - } |
|
71 | - //perform form data |
|
72 | - //need use request->query() for best retrieve |
|
73 | - //super instance |
|
74 | - $obj = & get_instance(); |
|
75 | - $token = $obj->request->query($key); |
|
76 | - if (!$token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime) { |
|
77 | - $logger->warning('The CSRF data [' . $token . '] is not valide may be attacker do his job'); |
|
78 | - return false; |
|
79 | - } |
|
80 | - $logger->info('The CSRF data [' . $token . '] is valide the form data is safe continue'); |
|
81 | - //remove the token from session |
|
82 | - Session::clear($key); |
|
83 | - Session::clear($keyExpire); |
|
84 | - return true; |
|
85 | - } |
|
62 | + $key = get_config('csrf_key', 'csrf_key'); |
|
63 | + $expire = get_config('csrf_expire', 60); |
|
64 | + $keyExpire = 'csrf_expire'; |
|
65 | + $currentTime = time(); |
|
66 | + $logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . ']'); |
|
67 | + if (!Session::exists($key) || Session::get($keyExpire) <= $currentTime) { |
|
68 | + $logger->warning('The CSRF session data is not valide'); |
|
69 | + return false; |
|
70 | + } |
|
71 | + //perform form data |
|
72 | + //need use request->query() for best retrieve |
|
73 | + //super instance |
|
74 | + $obj = & get_instance(); |
|
75 | + $token = $obj->request->query($key); |
|
76 | + if (!$token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime) { |
|
77 | + $logger->warning('The CSRF data [' . $token . '] is not valide may be attacker do his job'); |
|
78 | + return false; |
|
79 | + } |
|
80 | + $logger->info('The CSRF data [' . $token . '] is valide the form data is safe continue'); |
|
81 | + //remove the token from session |
|
82 | + Session::clear($key); |
|
83 | + Session::clear($keyExpire); |
|
84 | + return true; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * This method is used to check the whitelist IP address access |
|
89 | - */ |
|
90 | - public static function checkWhiteListIpAccess(){ |
|
91 | - $logger = self::getLogger(); |
|
92 | - $logger->debug('Validation of the IP address access ...'); |
|
93 | - $logger->debug('Check if whitelist IP access is enabled in the configuration ...'); |
|
94 | - $isEnable = get_config('white_list_ip_enable', false); |
|
95 | - if($isEnable){ |
|
96 | - $logger->info('Whitelist IP access is enabled in the configuration'); |
|
97 | - $list = get_config('white_list_ip_addresses', array()); |
|
98 | - if(! empty($list)){ |
|
99 | - //Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing |
|
100 | - require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
|
101 | - $ip = get_ip(); |
|
102 | - if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){ |
|
103 | - $logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP'); |
|
104 | - //wildcard to access all ip address |
|
105 | - return; |
|
106 | - } else{ |
|
107 | - // go through all whitelisted ips |
|
108 | - foreach ($list as $ipaddr) { |
|
109 | - // find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*") |
|
110 | - $wildcardPosition = strpos($ipaddr, '*'); |
|
111 | - if ($wildcardPosition === false) { |
|
112 | - // no wild card in whitelisted ip --continue searching |
|
113 | - continue; |
|
114 | - } |
|
115 | - // cut ip at the position where we got the wild card on the whitelisted ip |
|
116 | - // and add the wold card to get the same pattern |
|
117 | - if (substr($ip, 0, $wildcardPosition) . '*' === $ipaddr) { |
|
118 | - // f.e. we got |
|
119 | - // ip "127.0.0.1" |
|
120 | - // whitelisted ip "127.0.*" |
|
121 | - // then we compared "127.0.*" with "127.0.*" |
|
122 | - // return success |
|
123 | - $logger->info('IP address ' . $ip . ' allowed using the wildcard like "x.x.x.*"'); |
|
124 | - return; |
|
125 | - } |
|
126 | - } |
|
127 | - $logger->warning('IP address ' . $ip . ' is not allowed to access to this application'); |
|
128 | - show_error('Access to this application is not allowed'); |
|
129 | - } |
|
130 | - } |
|
131 | - } else{ |
|
132 | - $logger->info('Whitelist IP access is not enabled in the configuration, ignore checking'); |
|
133 | - } |
|
134 | - } |
|
135 | - } |
|
87 | + /** |
|
88 | + * This method is used to check the whitelist IP address access |
|
89 | + */ |
|
90 | + public static function checkWhiteListIpAccess(){ |
|
91 | + $logger = self::getLogger(); |
|
92 | + $logger->debug('Validation of the IP address access ...'); |
|
93 | + $logger->debug('Check if whitelist IP access is enabled in the configuration ...'); |
|
94 | + $isEnable = get_config('white_list_ip_enable', false); |
|
95 | + if($isEnable){ |
|
96 | + $logger->info('Whitelist IP access is enabled in the configuration'); |
|
97 | + $list = get_config('white_list_ip_addresses', array()); |
|
98 | + if(! empty($list)){ |
|
99 | + //Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing |
|
100 | + require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
|
101 | + $ip = get_ip(); |
|
102 | + if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){ |
|
103 | + $logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP'); |
|
104 | + //wildcard to access all ip address |
|
105 | + return; |
|
106 | + } else{ |
|
107 | + // go through all whitelisted ips |
|
108 | + foreach ($list as $ipaddr) { |
|
109 | + // find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*") |
|
110 | + $wildcardPosition = strpos($ipaddr, '*'); |
|
111 | + if ($wildcardPosition === false) { |
|
112 | + // no wild card in whitelisted ip --continue searching |
|
113 | + continue; |
|
114 | + } |
|
115 | + // cut ip at the position where we got the wild card on the whitelisted ip |
|
116 | + // and add the wold card to get the same pattern |
|
117 | + if (substr($ip, 0, $wildcardPosition) . '*' === $ipaddr) { |
|
118 | + // f.e. we got |
|
119 | + // ip "127.0.0.1" |
|
120 | + // whitelisted ip "127.0.*" |
|
121 | + // then we compared "127.0.*" with "127.0.*" |
|
122 | + // return success |
|
123 | + $logger->info('IP address ' . $ip . ' allowed using the wildcard like "x.x.x.*"'); |
|
124 | + return; |
|
125 | + } |
|
126 | + } |
|
127 | + $logger->warning('IP address ' . $ip . ' is not allowed to access to this application'); |
|
128 | + show_error('Access to this application is not allowed'); |
|
129 | + } |
|
130 | + } |
|
131 | + } else{ |
|
132 | + $logger->info('Whitelist IP access is not enabled in the configuration, ignore checking'); |
|
133 | + } |
|
134 | + } |
|
135 | + } |
@@ -216,19 +216,19 @@ discard block |
||
216 | 216 | * @return object the current DatabaseQueryBuilder instance |
217 | 217 | */ |
218 | 218 | public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){ |
219 | - $on = $field1; |
|
220 | - $table = $this->getPrefix() . $table; |
|
221 | - if (! is_null($op)){ |
|
219 | + $on = $field1; |
|
220 | + $table = $this->getPrefix() . $table; |
|
221 | + if (! is_null($op)){ |
|
222 | 222 | $on = (! in_array($op, $this->operatorList) |
223 | - ? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) |
|
224 | - : ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2)); |
|
225 | - } |
|
226 | - if (empty($this->join)){ |
|
223 | + ? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) |
|
224 | + : ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2)); |
|
225 | + } |
|
226 | + if (empty($this->join)){ |
|
227 | 227 | $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
228 | - } else{ |
|
228 | + } else{ |
|
229 | 229 | $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
230 | - } |
|
231 | - return $this; |
|
230 | + } |
|
231 | + return $this; |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
@@ -330,18 +330,18 @@ discard block |
||
330 | 330 | * @return object the current DatabaseQueryBuilder instance |
331 | 331 | */ |
332 | 332 | public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){ |
333 | - $whereStr = ''; |
|
334 | - if (is_array($where)){ |
|
333 | + $whereStr = ''; |
|
334 | + if (is_array($where)){ |
|
335 | 335 | $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape); |
336 | - } else{ |
|
336 | + } else{ |
|
337 | 337 | if (is_array($op)){ |
338 | - $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape); |
|
338 | + $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape); |
|
339 | 339 | } else { |
340 | - $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape); |
|
340 | + $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape); |
|
341 | 341 | } |
342 | - } |
|
343 | - $this->setWhereStr($whereStr, $andOr); |
|
344 | - return $this; |
|
342 | + } |
|
343 | + $this->setWhereStr($whereStr, $andOr); |
|
344 | + return $this; |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
@@ -578,15 +578,15 @@ discard block |
||
578 | 578 | * @return object the current DatabaseQueryBuilder instance |
579 | 579 | */ |
580 | 580 | public function limit($limit, $limitEnd = null){ |
581 | - if (empty($limit)){ |
|
581 | + if (empty($limit)){ |
|
582 | 582 | $limit = 0; |
583 | - } |
|
584 | - if (! is_null($limitEnd)){ |
|
583 | + } |
|
584 | + if (! is_null($limitEnd)){ |
|
585 | 585 | $this->limit = $limit . ', ' . $limitEnd; |
586 | - } else{ |
|
586 | + } else{ |
|
587 | 587 | $this->limit = $limit; |
588 | - } |
|
589 | - return $this; |
|
588 | + } |
|
589 | + return $this; |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | /** |
@@ -596,14 +596,14 @@ discard block |
||
596 | 596 | * @return object the current DatabaseQueryBuilder instance |
597 | 597 | */ |
598 | 598 | public function orderBy($orderBy, $orderDir = ' ASC'){ |
599 | - if (stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
|
599 | + if (stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
|
600 | 600 | $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy; |
601 | - } else{ |
|
601 | + } else{ |
|
602 | 602 | $this->orderBy = empty($this->orderBy) |
603 | - ? ($orderBy . ' ' . strtoupper($orderDir)) |
|
604 | - : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
|
605 | - } |
|
606 | - return $this; |
|
603 | + ? ($orderBy . ' ' . strtoupper($orderDir)) |
|
604 | + : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
|
605 | + } |
|
606 | + return $this; |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -612,12 +612,12 @@ discard block |
||
612 | 612 | * @return object the current DatabaseQueryBuilder instance |
613 | 613 | */ |
614 | 614 | public function groupBy($field){ |
615 | - if (is_array($field)){ |
|
615 | + if (is_array($field)){ |
|
616 | 616 | $this->groupBy = implode(', ', $field); |
617 | - } else{ |
|
617 | + } else{ |
|
618 | 618 | $this->groupBy = $field; |
619 | - } |
|
620 | - return $this; |
|
619 | + } |
|
620 | + return $this; |
|
621 | 621 | } |
622 | 622 | |
623 | 623 | /** |
@@ -629,20 +629,20 @@ discard block |
||
629 | 629 | * @return object the current DatabaseQueryBuilder instance |
630 | 630 | */ |
631 | 631 | public function having($field, $op = null, $val = null, $escape = true){ |
632 | - if (is_array($op)){ |
|
632 | + if (is_array($op)){ |
|
633 | 633 | $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape); |
634 | - } else if (! in_array($op, $this->operatorList)){ |
|
634 | + } else if (! in_array($op, $this->operatorList)){ |
|
635 | 635 | if (is_null($op)){ |
636 | - $op = ''; |
|
636 | + $op = ''; |
|
637 | 637 | } |
638 | 638 | $this->having = $field . ' > ' . ($this->escape($op, $escape)); |
639 | - } else{ |
|
639 | + } else{ |
|
640 | 640 | if (is_null($val)){ |
641 | - $val = ''; |
|
641 | + $val = ''; |
|
642 | 642 | } |
643 | 643 | $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape)); |
644 | - } |
|
645 | - return $this; |
|
644 | + } |
|
645 | + return $this; |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | /** |
@@ -128,97 +128,97 @@ discard block |
||
128 | 128 | $responseTime = $this->benchmarkInstance->elapsedTime( |
129 | 129 | 'DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', |
130 | 130 | 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')' |
131 | - ); |
|
132 | - //TODO use the configuration value for the high response time currently is 1 second |
|
131 | + ); |
|
132 | + //TODO use the configuration value for the high response time currently is 1 second |
|
133 | 133 | if ($responseTime >= 1 ){ |
134 | 134 | $this->logger->warning( |
135 | 135 | 'High response time while processing database query [' . $this->query . ']. |
136 | 136 | The response time is [' .$responseTime. '] sec.' |
137 | - ); |
|
137 | + ); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | if ($this->pdoStatment !== false){ |
141 | - $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false; |
|
142 | - if($isSqlSELECTQuery){ |
|
143 | - $this->setResultForSelect(); |
|
144 | - } else{ |
|
145 | - $this->setResultForNonSelect(); |
|
146 | - } |
|
147 | - return $this->queryResult; |
|
141 | + $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false; |
|
142 | + if($isSqlSELECTQuery){ |
|
143 | + $this->setResultForSelect(); |
|
144 | + } else{ |
|
145 | + $this->setResultForNonSelect(); |
|
146 | + } |
|
147 | + return $this->queryResult; |
|
148 | 148 | } |
149 | 149 | $this->setQueryRunnerError(); |
150 | 150 | } |
151 | 151 | |
152 | - /** |
|
153 | - * Return the result for SELECT query |
|
154 | - * @see DatabaseQueryRunner::execute |
|
155 | - */ |
|
152 | + /** |
|
153 | + * Return the result for SELECT query |
|
154 | + * @see DatabaseQueryRunner::execute |
|
155 | + */ |
|
156 | 156 | protected function setResultForSelect(){ |
157 | - //if need return all result like list of record |
|
158 | - $result = null; |
|
159 | - $numRows = 0; |
|
160 | - $fetchMode = PDO::FETCH_OBJ; |
|
161 | - if($this->returnAsArray){ |
|
157 | + //if need return all result like list of record |
|
158 | + $result = null; |
|
159 | + $numRows = 0; |
|
160 | + $fetchMode = PDO::FETCH_OBJ; |
|
161 | + if($this->returnAsArray){ |
|
162 | 162 | $fetchMode = PDO::FETCH_ASSOC; |
163 | - } |
|
164 | - if ($this->returnAsList){ |
|
165 | - $result = $this->pdoStatment->fetchAll($fetchMode); |
|
166 | - } else{ |
|
167 | - $result = $this->pdoStatment->fetch($fetchMode); |
|
168 | - } |
|
169 | - //Sqlite and pgsql always return 0 when using rowCount() |
|
170 | - if (in_array($this->driver, array('sqlite', 'pgsql'))){ |
|
163 | + } |
|
164 | + if ($this->returnAsList){ |
|
165 | + $result = $this->pdoStatment->fetchAll($fetchMode); |
|
166 | + } else{ |
|
167 | + $result = $this->pdoStatment->fetch($fetchMode); |
|
168 | + } |
|
169 | + //Sqlite and pgsql always return 0 when using rowCount() |
|
170 | + if (in_array($this->driver, array('sqlite', 'pgsql'))){ |
|
171 | 171 | $numRows = count($result); |
172 | - } else{ |
|
172 | + } else{ |
|
173 | 173 | $numRows = $this->pdoStatment->rowCount(); |
174 | - } |
|
175 | - if(! is_object($this->queryResult)){ |
|
176 | - $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database'); |
|
177 | - } |
|
178 | - $this->queryResult->setResult($result); |
|
179 | - $this->queryResult->setNumRows($numRows); |
|
174 | + } |
|
175 | + if(! is_object($this->queryResult)){ |
|
176 | + $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database'); |
|
177 | + } |
|
178 | + $this->queryResult->setResult($result); |
|
179 | + $this->queryResult->setNumRows($numRows); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
183 | - * Return the result for non SELECT query |
|
184 | - * @see DatabaseQueryRunner::execute |
|
185 | - */ |
|
183 | + * Return the result for non SELECT query |
|
184 | + * @see DatabaseQueryRunner::execute |
|
185 | + */ |
|
186 | 186 | protected function setResultForNonSelect(){ |
187 | - //Sqlite and pgsql always return 0 when using rowCount() |
|
188 | - $result = false; |
|
189 | - $numRows = 0; |
|
190 | - if (in_array($this->driver, array('sqlite', 'pgsql'))){ |
|
187 | + //Sqlite and pgsql always return 0 when using rowCount() |
|
188 | + $result = false; |
|
189 | + $numRows = 0; |
|
190 | + if (in_array($this->driver, array('sqlite', 'pgsql'))){ |
|
191 | 191 | $result = true; //to test the result for the query like UPDATE, INSERT, DELETE |
192 | 192 | $numRows = 1; //TODO use the correct method to get the exact affected row |
193 | - } else{ |
|
194 | - //to test the result for the query like UPDATE, INSERT, DELETE |
|
195 | - $result = $this->pdoStatment->rowCount() >= 0; |
|
196 | - $numRows = $this->pdoStatment->rowCount(); |
|
197 | - } |
|
198 | - if(! is_object($this->queryResult)){ |
|
199 | - $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database'); |
|
200 | - } |
|
201 | - $this->queryResult->setResult($result); |
|
202 | - $this->queryResult->setNumRows($numRows); |
|
193 | + } else{ |
|
194 | + //to test the result for the query like UPDATE, INSERT, DELETE |
|
195 | + $result = $this->pdoStatment->rowCount() >= 0; |
|
196 | + $numRows = $this->pdoStatment->rowCount(); |
|
197 | + } |
|
198 | + if(! is_object($this->queryResult)){ |
|
199 | + $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database'); |
|
200 | + } |
|
201 | + $this->queryResult->setResult($result); |
|
202 | + $this->queryResult->setNumRows($numRows); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | |
206 | - /** |
|
206 | + /** |
|
207 | 207 | * Return the benchmark instance |
208 | 208 | * @return Benchmark |
209 | 209 | */ |
210 | 210 | public function getBenchmark() { |
211 | - return $this->benchmarkInstance; |
|
211 | + return $this->benchmarkInstance; |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | 215 | * Set the benchmark instance |
216 | 216 | * @param Benchmark $benchmark the benchmark object |
217 | - * @return object DatabaseQueryRunner |
|
217 | + * @return object DatabaseQueryRunner |
|
218 | 218 | */ |
219 | 219 | public function setBenchmark($benchmark) { |
220 | - $this->benchmarkInstance = $benchmark; |
|
221 | - return $this; |
|
220 | + $this->benchmarkInstance = $benchmark; |
|
221 | + return $this; |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -348,18 +348,18 @@ discard block |
||
348 | 348 | * @param object $logger the Log instance if not null |
349 | 349 | */ |
350 | 350 | protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
351 | - if ($logger !== null){ |
|
351 | + if ($logger !== null){ |
|
352 | 352 | $this->logger = $logger; |
353 | - } else{ |
|
354 | - $this->logger =& class_loader('Log', 'classes'); |
|
355 | - $this->logger->setLogger('Library::DatabaseQueryRunner'); |
|
356 | - } |
|
353 | + } else{ |
|
354 | + $this->logger =& class_loader('Log', 'classes'); |
|
355 | + $this->logger->setLogger('Library::DatabaseQueryRunner'); |
|
356 | + } |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | |
360 | 360 | /** |
361 | - * Reset the instance before run each query |
|
362 | - */ |
|
361 | + * Reset the instance before run each query |
|
362 | + */ |
|
363 | 363 | private function reset() { |
364 | 364 | $this->error = null; |
365 | 365 | $this->pdoStatment = null; |
@@ -149,13 +149,13 @@ |
||
149 | 149 | $this->updateQueryBuilderAndRunnerProperties(); |
150 | 150 | |
151 | 151 | return is_object($this->pdo); |
152 | - } catch (PDOException $e){ |
|
152 | + } catch (PDOException $e){ |
|
153 | 153 | $this->logger->fatal($e->getMessage()); |
154 | 154 | show_error('Cannot connect to Database.'); |
155 | 155 | return false; |
156 | - } |
|
157 | - } |
|
158 | - return false; |
|
156 | + } |
|
157 | + } |
|
158 | + return false; |
|
159 | 159 | } |
160 | 160 | |
161 | 161 |
@@ -1,147 +1,147 @@ |
||
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 | - */ |
|
26 | - class Session extends BaseStaticClass { |
|
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 | + class Session extends BaseStaticClass { |
|
27 | 27 | |
28 | - /** |
|
29 | - * The session flash key to use |
|
30 | - * @const |
|
31 | - */ |
|
32 | - const SESSION_FLASH_KEY = 'session_flash'; |
|
28 | + /** |
|
29 | + * The session flash key to use |
|
30 | + * @const |
|
31 | + */ |
|
32 | + const SESSION_FLASH_KEY = 'session_flash'; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Get the session item value |
|
36 | - * @param string $item the session item name to get |
|
37 | - * @param mixed $default the default value to use if can not find the session item in the list |
|
38 | - * @return mixed the session value if exist or the default value |
|
39 | - */ |
|
40 | - public static function get($item, $default = null) { |
|
41 | - $logger = self::getLogger(); |
|
42 | - $logger->debug('Getting session data for item [' . $item . '] ...'); |
|
43 | - if (array_key_exists($item, $_SESSION)) { |
|
44 | - $logger->info('Found session data for item [' . $item . '] the vaue is : [' . stringfy_vars($_SESSION[$item]) . ']'); |
|
45 | - return $_SESSION[$item]; |
|
46 | - } |
|
47 | - $logger->warning('Cannot find session item [' . $item . '] using the default value [' . $default . ']'); |
|
48 | - return $default; |
|
49 | - } |
|
34 | + /** |
|
35 | + * Get the session item value |
|
36 | + * @param string $item the session item name to get |
|
37 | + * @param mixed $default the default value to use if can not find the session item in the list |
|
38 | + * @return mixed the session value if exist or the default value |
|
39 | + */ |
|
40 | + public static function get($item, $default = null) { |
|
41 | + $logger = self::getLogger(); |
|
42 | + $logger->debug('Getting session data for item [' . $item . '] ...'); |
|
43 | + if (array_key_exists($item, $_SESSION)) { |
|
44 | + $logger->info('Found session data for item [' . $item . '] the vaue is : [' . stringfy_vars($_SESSION[$item]) . ']'); |
|
45 | + return $_SESSION[$item]; |
|
46 | + } |
|
47 | + $logger->warning('Cannot find session item [' . $item . '] using the default value [' . $default . ']'); |
|
48 | + return $default; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Set the session item value |
|
53 | - * @param string $item the session item name to set |
|
54 | - * @param mixed $value the session item value |
|
55 | - */ |
|
56 | - public static function set($item, $value) { |
|
57 | - $logger = self::getLogger(); |
|
58 | - $logger->debug('Setting session data for item [' . $item . '], value [' . stringfy_vars($value) . ']'); |
|
59 | - $_SESSION[$item] = $value; |
|
60 | - } |
|
51 | + /** |
|
52 | + * Set the session item value |
|
53 | + * @param string $item the session item name to set |
|
54 | + * @param mixed $value the session item value |
|
55 | + */ |
|
56 | + public static function set($item, $value) { |
|
57 | + $logger = self::getLogger(); |
|
58 | + $logger->debug('Setting session data for item [' . $item . '], value [' . stringfy_vars($value) . ']'); |
|
59 | + $_SESSION[$item] = $value; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Get the session flash item value |
|
64 | - * @param string $item the session flash item name to get |
|
65 | - * @param mixed $default the default value to use if can not find the session flash item in the list |
|
66 | - * @return mixed the session flash value if exist or the default value |
|
67 | - */ |
|
68 | - public static function getFlash($item, $default = null){ |
|
69 | - $logger = self::getLogger(); |
|
70 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
71 | - $return = array_key_exists($key, $_SESSION) ? |
|
72 | - ($_SESSION[$key]) : $default; |
|
73 | - if(array_key_exists($key, $_SESSION)){ |
|
74 | - unset($_SESSION[$key]); |
|
75 | - } else{ |
|
76 | - $logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']'); |
|
77 | - } |
|
78 | - return $return; |
|
79 | - } |
|
62 | + /** |
|
63 | + * Get the session flash item value |
|
64 | + * @param string $item the session flash item name to get |
|
65 | + * @param mixed $default the default value to use if can not find the session flash item in the list |
|
66 | + * @return mixed the session flash value if exist or the default value |
|
67 | + */ |
|
68 | + public static function getFlash($item, $default = null){ |
|
69 | + $logger = self::getLogger(); |
|
70 | + $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
71 | + $return = array_key_exists($key, $_SESSION) ? |
|
72 | + ($_SESSION[$key]) : $default; |
|
73 | + if(array_key_exists($key, $_SESSION)){ |
|
74 | + unset($_SESSION[$key]); |
|
75 | + } else{ |
|
76 | + $logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']'); |
|
77 | + } |
|
78 | + return $return; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Check whether the given session flash item exists |
|
83 | - * @param string $item the session flash item name |
|
84 | - * @return boolean |
|
85 | - */ |
|
86 | - public static function hasFlash($item) { |
|
87 | - $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
88 | - return array_key_exists($key, $_SESSION); |
|
89 | - } |
|
81 | + /** |
|
82 | + * Check whether the given session flash item exists |
|
83 | + * @param string $item the session flash item name |
|
84 | + * @return boolean |
|
85 | + */ |
|
86 | + public static function hasFlash($item) { |
|
87 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
88 | + return array_key_exists($key, $_SESSION); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Set the session flash item value |
|
93 | - * @param string $item the session flash item name to set |
|
94 | - * @param mixed $value the session flash item value |
|
95 | - */ |
|
96 | - public static function setFlash($item, $value) { |
|
97 | - $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
98 | - $_SESSION[$key] = $value; |
|
99 | - } |
|
91 | + /** |
|
92 | + * Set the session flash item value |
|
93 | + * @param string $item the session flash item name to set |
|
94 | + * @param mixed $value the session flash item value |
|
95 | + */ |
|
96 | + public static function setFlash($item, $value) { |
|
97 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
98 | + $_SESSION[$key] = $value; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Clear the session item in the list |
|
103 | - * @param string $item the session item name to be deleted |
|
104 | - */ |
|
105 | - public static function clear($item){ |
|
106 | - $logger = self::getLogger(); |
|
107 | - if(array_key_exists($item, $_SESSION)){ |
|
108 | - $logger->info('Deleting of session for item ['.$item.' ]'); |
|
109 | - unset($_SESSION[$item]); |
|
110 | - } else{ |
|
111 | - $logger->warning('Session item ['.$item.'] to be deleted does not exists'); |
|
112 | - } |
|
113 | - } |
|
101 | + /** |
|
102 | + * Clear the session item in the list |
|
103 | + * @param string $item the session item name to be deleted |
|
104 | + */ |
|
105 | + public static function clear($item){ |
|
106 | + $logger = self::getLogger(); |
|
107 | + if(array_key_exists($item, $_SESSION)){ |
|
108 | + $logger->info('Deleting of session for item ['.$item.' ]'); |
|
109 | + unset($_SESSION[$item]); |
|
110 | + } else{ |
|
111 | + $logger->warning('Session item ['.$item.'] to be deleted does not exists'); |
|
112 | + } |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Clear the session flash item in the list |
|
117 | - * @param string $item the session flash item name to be deleted |
|
118 | - */ |
|
119 | - public static function clearFlash($item){ |
|
120 | - $logger = self::getLogger(); |
|
121 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
122 | - if(array_key_exists($key, $_SESSION)){ |
|
123 | - $logger->info('Delete session flash for item ['.$item.']'); |
|
124 | - unset($_SESSION[$item]); |
|
125 | - } else{ |
|
126 | - $logger->warning('Dession flash item ['.$item.'] to be deleted does not exists'); |
|
127 | - } |
|
128 | - } |
|
115 | + /** |
|
116 | + * Clear the session flash item in the list |
|
117 | + * @param string $item the session flash item name to be deleted |
|
118 | + */ |
|
119 | + public static function clearFlash($item){ |
|
120 | + $logger = self::getLogger(); |
|
121 | + $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
122 | + if(array_key_exists($key, $_SESSION)){ |
|
123 | + $logger->info('Delete session flash for item ['.$item.']'); |
|
124 | + unset($_SESSION[$item]); |
|
125 | + } else{ |
|
126 | + $logger->warning('Dession flash item ['.$item.'] to be deleted does not exists'); |
|
127 | + } |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Check whether the given session item exists |
|
132 | - * @param string $item the session item name |
|
133 | - * @return boolean |
|
134 | - */ |
|
135 | - public static function exists($item) { |
|
136 | - return array_key_exists($item, $_SESSION); |
|
137 | - } |
|
130 | + /** |
|
131 | + * Check whether the given session item exists |
|
132 | + * @param string $item the session item name |
|
133 | + * @return boolean |
|
134 | + */ |
|
135 | + public static function exists($item) { |
|
136 | + return array_key_exists($item, $_SESSION); |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * Destroy all session data values |
|
141 | - */ |
|
142 | - public static function clearAll() { |
|
143 | - session_unset(); |
|
144 | - session_destroy(); |
|
145 | - } |
|
139 | + /** |
|
140 | + * Destroy all session data values |
|
141 | + */ |
|
142 | + public static function clearAll() { |
|
143 | + session_unset(); |
|
144 | + session_destroy(); |
|
145 | + } |
|
146 | 146 | |
147 | - } |
|
147 | + } |
@@ -1,148 +1,148 @@ |
||
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 | - } else{ |
|
66 | - $path .= $suffix; |
|
67 | - } |
|
68 | - } |
|
69 | - return $url . $path; |
|
70 | - } |
|
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 | + } else{ |
|
66 | + $path .= $suffix; |
|
67 | + } |
|
68 | + } |
|
69 | + return $url . $path; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Return the current site URL |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public static function current() { |
|
77 | - $current = '/'; |
|
78 | - $requestUri = get_instance()->request->requestUri(); |
|
79 | - if ($requestUri) { |
|
80 | - $current = $requestUri; |
|
81 | - } |
|
82 | - return static::domain() . $current; |
|
83 | - } |
|
72 | + /** |
|
73 | + * Return the current site URL |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public static function current() { |
|
77 | + $current = '/'; |
|
78 | + $requestUri = get_instance()->request->requestUri(); |
|
79 | + if ($requestUri) { |
|
80 | + $current = $requestUri; |
|
81 | + } |
|
82 | + return static::domain() . $current; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Generate a friendly text to use in link (slugs) |
|
87 | - * @param string $str the title or text to use to get the friendly text |
|
88 | - * @param string $separator the caracters separator |
|
89 | - * @param boolean $lowercase whether to set the final text to lowe case or not |
|
90 | - * @return string the friendly generated text |
|
91 | - */ |
|
92 | - public static function title($str = null, $separator = '-', $lowercase = true) { |
|
93 | - $str = trim($str); |
|
94 | - $from = array('ç', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'à', 'á', 'â', 'ã', 'ä', 'å', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'È', 'É', 'Ê', 'Ë', 'è', 'é', 'ê', 'ë', 'Ç', 'ç', 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï', 'Ù', 'Ú', 'Û', 'Ü', 'ù', 'ú', 'û', 'ü', 'ÿ', 'Ñ', 'ñ'); |
|
95 | - $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'); |
|
96 | - $str = str_replace($from, $to, $str); |
|
97 | - $str = preg_replace('#([^a-z0-9]+)#i', $separator, $str); |
|
98 | - $str = str_replace('--', $separator, $str); |
|
99 | - //if after process we get something like one-two-three-, need truncate the last separator "-" |
|
100 | - if (substr($str, -1) == $separator) { |
|
101 | - $str = substr($str, 0, -1); |
|
102 | - } |
|
103 | - if ($lowercase) { |
|
104 | - $str = strtolower($str); |
|
105 | - } |
|
106 | - return $str; |
|
107 | - } |
|
85 | + /** |
|
86 | + * Generate a friendly text to use in link (slugs) |
|
87 | + * @param string $str the title or text to use to get the friendly text |
|
88 | + * @param string $separator the caracters separator |
|
89 | + * @param boolean $lowercase whether to set the final text to lowe case or not |
|
90 | + * @return string the friendly generated text |
|
91 | + */ |
|
92 | + public static function title($str = null, $separator = '-', $lowercase = true) { |
|
93 | + $str = trim($str); |
|
94 | + $from = array('ç', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'à', 'á', 'â', 'ã', 'ä', 'å', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'È', 'É', 'Ê', 'Ë', 'è', 'é', 'ê', 'ë', 'Ç', 'ç', 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï', 'Ù', 'Ú', 'Û', 'Ü', 'ù', 'ú', 'û', 'ü', 'ÿ', 'Ñ', 'ñ'); |
|
95 | + $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'); |
|
96 | + $str = str_replace($from, $to, $str); |
|
97 | + $str = preg_replace('#([^a-z0-9]+)#i', $separator, $str); |
|
98 | + $str = str_replace('--', $separator, $str); |
|
99 | + //if after process we get something like one-two-three-, need truncate the last separator "-" |
|
100 | + if (substr($str, -1) == $separator) { |
|
101 | + $str = substr($str, 0, -1); |
|
102 | + } |
|
103 | + if ($lowercase) { |
|
104 | + $str = strtolower($str); |
|
105 | + } |
|
106 | + return $str; |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Get the current application domain with protocol |
|
111 | - * @return string the domain name |
|
112 | - */ |
|
113 | - public static function domain() { |
|
114 | - $domain = 'localhost'; |
|
115 | - $port = get_instance()->request->server('SERVER_PORT'); |
|
116 | - $protocol = 'http'; |
|
117 | - if (is_https()) { |
|
118 | - $protocol = 'https'; |
|
119 | - } |
|
109 | + /** |
|
110 | + * Get the current application domain with protocol |
|
111 | + * @return string the domain name |
|
112 | + */ |
|
113 | + public static function domain() { |
|
114 | + $domain = 'localhost'; |
|
115 | + $port = get_instance()->request->server('SERVER_PORT'); |
|
116 | + $protocol = 'http'; |
|
117 | + if (is_https()) { |
|
118 | + $protocol = 'https'; |
|
119 | + } |
|
120 | 120 | |
121 | - $domainserverVars = array( |
|
122 | - 'HTTP_HOST', |
|
123 | - 'SERVER_NAME', |
|
124 | - 'SERVER_ADDR' |
|
125 | - ); |
|
121 | + $domainserverVars = array( |
|
122 | + 'HTTP_HOST', |
|
123 | + 'SERVER_NAME', |
|
124 | + 'SERVER_ADDR' |
|
125 | + ); |
|
126 | 126 | |
127 | - foreach ($domainserverVars as $var) { |
|
128 | - $value = get_instance()->request->server($var); |
|
129 | - if ($value) { |
|
130 | - $domain = $value; |
|
131 | - break; |
|
132 | - } |
|
133 | - } |
|
127 | + foreach ($domainserverVars as $var) { |
|
128 | + $value = get_instance()->request->server($var); |
|
129 | + if ($value) { |
|
130 | + $domain = $value; |
|
131 | + break; |
|
132 | + } |
|
133 | + } |
|
134 | 134 | |
135 | - if ($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))) { |
|
136 | - $domain .= ':' . $port; |
|
137 | - } |
|
138 | - return $protocol . '://' . $domain; |
|
139 | - } |
|
135 | + if ($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))) { |
|
136 | + $domain .= ':' . $port; |
|
137 | + } |
|
138 | + return $protocol . '://' . $domain; |
|
139 | + } |
|
140 | 140 | |
141 | - /** |
|
142 | - * Get the current request query string |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public static function queryString() { |
|
146 | - return get_instance()->request->server('QUERY_STRING'); |
|
147 | - } |
|
148 | - } |
|
141 | + /** |
|
142 | + * Get the current request query string |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public static function queryString() { |
|
146 | + return get_instance()->request->server('QUERY_STRING'); |
|
147 | + } |
|
148 | + } |