@@ -1,127 +1,127 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework created using the concept of codeigniter with bootstrap twitter |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework created using the concept of codeigniter with bootstrap twitter |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * This file contains the connection information to your database, this file is read when you load the "Database" library. |
|
| 29 | - * You will find all its configuration parameters at your web hosting. |
|
| 30 | - */ |
|
| 27 | + /** |
|
| 28 | + * This file contains the connection information to your database, this file is read when you load the "Database" library. |
|
| 29 | + * You will find all its configuration parameters at your web hosting. |
|
| 30 | + */ |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * The type or driver of your database. |
|
| 34 | - * |
|
| 35 | - * Note: the "Database" library uses the PHP PDO extension to interact with your database, |
|
| 36 | - * so most of the PDO supported drivers namely: mysql, pgsql, sqlite, oracle are accepted. |
|
| 37 | - * For example : |
|
| 38 | - * |
|
| 39 | - * $db['driver'] = 'mysql'; // for MySQL Database |
|
| 40 | - * or |
|
| 41 | - * $db['driver'] = 'pgsql'; // for PostgreSQL Database |
|
| 42 | - * or |
|
| 43 | - * $db['driver'] = 'sqlite'; // for SQLite Database |
|
| 44 | - * or |
|
| 45 | - * $db['driver'] = 'oracle'; // for Oracle Database |
|
| 46 | - * |
|
| 47 | - */ |
|
| 48 | - $db['driver'] = 'mysql'; |
|
| 32 | + /** |
|
| 33 | + * The type or driver of your database. |
|
| 34 | + * |
|
| 35 | + * Note: the "Database" library uses the PHP PDO extension to interact with your database, |
|
| 36 | + * so most of the PDO supported drivers namely: mysql, pgsql, sqlite, oracle are accepted. |
|
| 37 | + * For example : |
|
| 38 | + * |
|
| 39 | + * $db['driver'] = 'mysql'; // for MySQL Database |
|
| 40 | + * or |
|
| 41 | + * $db['driver'] = 'pgsql'; // for PostgreSQL Database |
|
| 42 | + * or |
|
| 43 | + * $db['driver'] = 'sqlite'; // for SQLite Database |
|
| 44 | + * or |
|
| 45 | + * $db['driver'] = 'oracle'; // for Oracle Database |
|
| 46 | + * |
|
| 47 | + */ |
|
| 48 | + $db['driver'] = 'mysql'; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * The address of your database server |
|
| 52 | - * |
|
| 53 | - * It can be a domain name or IP address, for example: |
|
| 54 | - * $db['hostname'] = 'localhost'; |
|
| 55 | - * or |
|
| 56 | - * $db['hostname'] = 'mysql.host.com'; |
|
| 57 | - * or |
|
| 58 | - * $db['hostname'] = '187.15.14.17'; |
|
| 59 | - * * or if port is not a standart port |
|
| 60 | - * $db['hostname'] = 'mydb.server.com:6356'; |
|
| 61 | - */ |
|
| 62 | - $db['hostname'] = 'localhost'; |
|
| 50 | + /** |
|
| 51 | + * The address of your database server |
|
| 52 | + * |
|
| 53 | + * It can be a domain name or IP address, for example: |
|
| 54 | + * $db['hostname'] = 'localhost'; |
|
| 55 | + * or |
|
| 56 | + * $db['hostname'] = 'mysql.host.com'; |
|
| 57 | + * or |
|
| 58 | + * $db['hostname'] = '187.15.14.17'; |
|
| 59 | + * * or if port is not a standart port |
|
| 60 | + * $db['hostname'] = 'mydb.server.com:6356'; |
|
| 61 | + */ |
|
| 62 | + $db['hostname'] = 'localhost'; |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * The username of your database server |
|
| 66 | - * for example : |
|
| 67 | - * |
|
| 68 | - * $db['username'] = 'root'; |
|
| 69 | - * or |
|
| 70 | - * $db['username'] = 'myusername'; |
|
| 71 | - */ |
|
| 72 | - $db['username'] = 'root'; |
|
| 64 | + /** |
|
| 65 | + * The username of your database server |
|
| 66 | + * for example : |
|
| 67 | + * |
|
| 68 | + * $db['username'] = 'root'; |
|
| 69 | + * or |
|
| 70 | + * $db['username'] = 'myusername'; |
|
| 71 | + */ |
|
| 72 | + $db['username'] = 'root'; |
|
| 73 | 73 | |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * The password of your database server. |
|
| 77 | - * |
|
| 78 | - * Note: Some configuration settings on some database management systems do not allow |
|
| 79 | - * connection with a user without password, so it is recommended to set a password for this user for a security measure. |
|
| 80 | - * for example : |
|
| 81 | - * |
|
| 82 | - * $db['password'] = ''; //for an empty password, this is the case most often, if you are in local, ie for the user "root". |
|
| 83 | - * or |
|
| 84 | - * $db['password'] = 'M@5CUR3P@$$W0rd'; |
|
| 85 | - */ |
|
| 86 | - $db['password'] = ''; |
|
| 75 | + /** |
|
| 76 | + * The password of your database server. |
|
| 77 | + * |
|
| 78 | + * Note: Some configuration settings on some database management systems do not allow |
|
| 79 | + * connection with a user without password, so it is recommended to set a password for this user for a security measure. |
|
| 80 | + * for example : |
|
| 81 | + * |
|
| 82 | + * $db['password'] = ''; //for an empty password, this is the case most often, if you are in local, ie for the user "root". |
|
| 83 | + * or |
|
| 84 | + * $db['password'] = 'M@5CUR3P@$$W0rd'; |
|
| 85 | + */ |
|
| 86 | + $db['password'] = ''; |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * The name of your database |
|
| 90 | - * |
|
| 91 | - * for example : |
|
| 92 | - * |
|
| 93 | - * $db['database'] = 'database_name'; |
|
| 94 | - */ |
|
| 95 | - $db['database'] = ''; |
|
| 88 | + /** |
|
| 89 | + * The name of your database |
|
| 90 | + * |
|
| 91 | + * for example : |
|
| 92 | + * |
|
| 93 | + * $db['database'] = 'database_name'; |
|
| 94 | + */ |
|
| 95 | + $db['database'] = ''; |
|
| 96 | 96 | |
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * The character set that will be used by the database server. |
|
| 100 | - * for example : |
|
| 101 | - * |
|
| 102 | - * $db['charset'] = 'utf8'; |
|
| 103 | - */ |
|
| 104 | - $db['charset'] = 'utf8'; |
|
| 98 | + /** |
|
| 99 | + * The character set that will be used by the database server. |
|
| 100 | + * for example : |
|
| 101 | + * |
|
| 102 | + * $db['charset'] = 'utf8'; |
|
| 103 | + */ |
|
| 104 | + $db['charset'] = 'utf8'; |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * In addition to the character set, a certain database management system allows you to |
|
| 108 | - * choose how the data will be classified (ORDER BY) by what is called a "COLLATE". |
|
| 109 | - * This makes it possible, for example, to answer the classic problem of case sensitivity. |
|
| 110 | - * for example : |
|
| 111 | - * $db['collation'] = 'utf8_general_ci'; |
|
| 112 | - */ |
|
| 113 | - $db['collation'] = 'utf8_general_ci'; |
|
| 106 | + /** |
|
| 107 | + * In addition to the character set, a certain database management system allows you to |
|
| 108 | + * choose how the data will be classified (ORDER BY) by what is called a "COLLATE". |
|
| 109 | + * This makes it possible, for example, to answer the classic problem of case sensitivity. |
|
| 110 | + * for example : |
|
| 111 | + * $db['collation'] = 'utf8_general_ci'; |
|
| 112 | + */ |
|
| 113 | + $db['collation'] = 'utf8_general_ci'; |
|
| 114 | 114 | |
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * If your tables in your database contain prefixes, this is the case most on some application, |
|
| 118 | - * to avoid the conflict of name of the tables between different database, |
|
| 119 | - * it is possible to define prefixes for the tables. |
|
| 120 | - * for example : |
|
| 121 | - * |
|
| 122 | - * $db['prefix'] = 'pf_'; |
|
| 123 | - * or |
|
| 124 | - * |
|
| 125 | - * $db['prefix'] = 'my_db_'; |
|
| 126 | - */ |
|
| 127 | - $db['prefix'] = ''; |
|
| 128 | 116 | \ No newline at end of file |
| 117 | + /** |
|
| 118 | + * If your tables in your database contain prefixes, this is the case most on some application, |
|
| 119 | + * to avoid the conflict of name of the tables between different database, |
|
| 120 | + * it is possible to define prefixes for the tables. |
|
| 121 | + * for example : |
|
| 122 | + * |
|
| 123 | + * $db['prefix'] = 'pf_'; |
|
| 124 | + * or |
|
| 125 | + * |
|
| 126 | + * $db['prefix'] = 'my_db_'; |
|
| 127 | + */ |
|
| 128 | + $db['prefix'] = ''; |
|
| 129 | 129 | \ No newline at end of file |
@@ -1,88 +1,88 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework created using the concept of codeigniter with bootstrap twitter |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework created using the concept of codeigniter with bootstrap twitter |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * This file contains the configuration of your routes that is to say that links to your URLs. |
|
| 29 | - * The index of the $route array contains the url address to capture and the value contains |
|
| 30 | - * the name of the module, controller and the method to call. |
|
| 31 | - * For example : |
|
| 32 | - * |
|
| 33 | - * $route['/users/login'] = 'moduleUsers#UsersController@login_action'; |
|
| 34 | - * |
|
| 35 | - * it means, if the user type in the address bar an URL like http://yoursite.com/users/login, |
|
| 36 | - * that will call the module "moduleUsers", the controller "UsersController" and the method "login_action". |
|
| 37 | - * Note 1: it is recommended that each index in the $route array start with a slash "/" |
|
| 38 | - * otherwise on some system this will not work. |
|
| 39 | - * Note 2: to define the default controller route (homepage) of your application you use only the index "/" |
|
| 40 | - * for example the following route represents the homepage: |
|
| 41 | - * |
|
| 42 | - * $route['/'] = 'Home'; //only the controller or module name |
|
| 43 | - * |
|
| 44 | - * $route['/'] = 'Home@index'; //only the controller or module name with the method |
|
| 45 | - * |
|
| 46 | - * $route['/'] = 'module#Home@index'; //with module name, controller and method |
|
| 47 | - * |
|
| 48 | - * Note 3: If the method is not specified then the "index" method will be used as |
|
| 49 | - * default method. For example in the case of our homepage, this will be able to make: |
|
| 50 | - * |
|
| 51 | - * $route['/'] = 'Home'; |
|
| 52 | - * |
|
| 53 | - * Note 4: All methods called must have "public" visibility if you know the principle of |
|
| 54 | - * Object Oriented Programming, you know what visibility means (public, protected, private). |
|
| 55 | - * |
|
| 56 | - * In the index of your route, you can use the markers (:num), (:alpha), (:alnum) and (:any) which correspond |
|
| 57 | - * respectively to the regular expression [0-9], [a-zA-Z], [a-zA-Z0-9] and. *. |
|
| 58 | - * For example : |
|
| 59 | - * |
|
| 60 | - * - $route['/profile/(:num)'] = 'UsersController@profile'; => http://yoursite.com/profile/4 will be captured but |
|
| 61 | - * http://yoursite.com/profile/a will not captured. |
|
| 62 | - * |
|
| 63 | - * - $route['/profile/(:alpha)'] = 'UsersController@profile'; => http://yoursite.com/profile/a will be captured |
|
| 64 | - * but http://yoursite.com/profile/1457 will not captured. |
|
| 65 | - * |
|
| 66 | - * - $route['/profile/(:alnum)'] = 'UsersController@profile'; => http://yoursite.com/profile/4a, |
|
| 67 | - * http://yoursite.com/profile/7 will be captured but http://yoursite.com/profile/7-dangerous will not captured. |
|
| 68 | - * |
|
| 69 | - * - $route['/(:any)'] = 'ArticleController@read'; => http://yoursite.com/1-my-super-article, |
|
| 70 | - * http://yoursite.com/7, will be captured. |
|
| 71 | - * |
|
| 72 | - * Note 5: The order of definition of each route is important. |
|
| 73 | - * For example, the following definitions work: |
|
| 74 | - * |
|
| 75 | - * $route['/article/add'] = 'Article@add'; |
|
| 76 | - * $route['article/(:any)'] = 'Article@read'; |
|
| 77 | - * |
|
| 78 | - * however, the following definitions does not work as intended |
|
| 79 | - * |
|
| 80 | - * $route['article/(:any)'] = 'Article@read'; |
|
| 81 | - * $route['/article/add'] = 'Article@add'; |
|
| 82 | - * |
|
| 83 | - */ |
|
| 27 | + /** |
|
| 28 | + * This file contains the configuration of your routes that is to say that links to your URLs. |
|
| 29 | + * The index of the $route array contains the url address to capture and the value contains |
|
| 30 | + * the name of the module, controller and the method to call. |
|
| 31 | + * For example : |
|
| 32 | + * |
|
| 33 | + * $route['/users/login'] = 'moduleUsers#UsersController@login_action'; |
|
| 34 | + * |
|
| 35 | + * it means, if the user type in the address bar an URL like http://yoursite.com/users/login, |
|
| 36 | + * that will call the module "moduleUsers", the controller "UsersController" and the method "login_action". |
|
| 37 | + * Note 1: it is recommended that each index in the $route array start with a slash "/" |
|
| 38 | + * otherwise on some system this will not work. |
|
| 39 | + * Note 2: to define the default controller route (homepage) of your application you use only the index "/" |
|
| 40 | + * for example the following route represents the homepage: |
|
| 41 | + * |
|
| 42 | + * $route['/'] = 'Home'; //only the controller or module name |
|
| 43 | + * |
|
| 44 | + * $route['/'] = 'Home@index'; //only the controller or module name with the method |
|
| 45 | + * |
|
| 46 | + * $route['/'] = 'module#Home@index'; //with module name, controller and method |
|
| 47 | + * |
|
| 48 | + * Note 3: If the method is not specified then the "index" method will be used as |
|
| 49 | + * default method. For example in the case of our homepage, this will be able to make: |
|
| 50 | + * |
|
| 51 | + * $route['/'] = 'Home'; |
|
| 52 | + * |
|
| 53 | + * Note 4: All methods called must have "public" visibility if you know the principle of |
|
| 54 | + * Object Oriented Programming, you know what visibility means (public, protected, private). |
|
| 55 | + * |
|
| 56 | + * In the index of your route, you can use the markers (:num), (:alpha), (:alnum) and (:any) which correspond |
|
| 57 | + * respectively to the regular expression [0-9], [a-zA-Z], [a-zA-Z0-9] and. *. |
|
| 58 | + * For example : |
|
| 59 | + * |
|
| 60 | + * - $route['/profile/(:num)'] = 'UsersController@profile'; => http://yoursite.com/profile/4 will be captured but |
|
| 61 | + * http://yoursite.com/profile/a will not captured. |
|
| 62 | + * |
|
| 63 | + * - $route['/profile/(:alpha)'] = 'UsersController@profile'; => http://yoursite.com/profile/a will be captured |
|
| 64 | + * but http://yoursite.com/profile/1457 will not captured. |
|
| 65 | + * |
|
| 66 | + * - $route['/profile/(:alnum)'] = 'UsersController@profile'; => http://yoursite.com/profile/4a, |
|
| 67 | + * http://yoursite.com/profile/7 will be captured but http://yoursite.com/profile/7-dangerous will not captured. |
|
| 68 | + * |
|
| 69 | + * - $route['/(:any)'] = 'ArticleController@read'; => http://yoursite.com/1-my-super-article, |
|
| 70 | + * http://yoursite.com/7, will be captured. |
|
| 71 | + * |
|
| 72 | + * Note 5: The order of definition of each route is important. |
|
| 73 | + * For example, the following definitions work: |
|
| 74 | + * |
|
| 75 | + * $route['/article/add'] = 'Article@add'; |
|
| 76 | + * $route['article/(:any)'] = 'Article@read'; |
|
| 77 | + * |
|
| 78 | + * however, the following definitions does not work as intended |
|
| 79 | + * |
|
| 80 | + * $route['article/(:any)'] = 'Article@read'; |
|
| 81 | + * $route['/article/add'] = 'Article@add'; |
|
| 82 | + * |
|
| 83 | + */ |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * The default route like your home page |
|
| 87 | - */ |
|
| 88 | - $route['/'] = 'Home'; |
|
| 89 | 85 | \ No newline at end of file |
| 86 | + /** |
|
| 87 | + * The default route like your home page |
|
| 88 | + */ |
|
| 89 | + $route['/'] = 'Home'; |
|
| 90 | 90 | \ No newline at end of file |
@@ -1,90 +1,90 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework created using the concept of codeigniter with bootstrap twitter |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework created using the concept of codeigniter with bootstrap twitter |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * This file contains the pagination library configuration of your application |
|
| 29 | - */ |
|
| 27 | + /** |
|
| 28 | + * This file contains the pagination library configuration of your application |
|
| 29 | + */ |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Number of pagination digit |
|
| 33 | - */ |
|
| 34 | - $config['nb_link'] = 10; |
|
| 31 | + /** |
|
| 32 | + * Number of pagination digit |
|
| 33 | + */ |
|
| 34 | + $config['nb_link'] = 10; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * The pagination. |
|
| 38 | - * |
|
| 39 | - * Represents the number of data to display per page. |
|
| 40 | - * Note: this value must be strictly greater than zero (0) |
|
| 41 | - */ |
|
| 42 | - $config['pagination_per_page'] = 10; |
|
| 36 | + /** |
|
| 37 | + * The pagination. |
|
| 38 | + * |
|
| 39 | + * Represents the number of data to display per page. |
|
| 40 | + * Note: this value must be strictly greater than zero (0) |
|
| 41 | + */ |
|
| 42 | + $config['pagination_per_page'] = 10; |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * The query string name used to fetch the current page |
|
| 47 | - */ |
|
| 48 | - $config['page_query_string_name'] = 'page'; |
|
| 45 | + /** |
|
| 46 | + * The query string name used to fetch the current page |
|
| 47 | + */ |
|
| 48 | + $config['page_query_string_name'] = 'page'; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * The opened and closed tag for active link |
|
| 52 | - */ |
|
| 53 | - $config['active_link_open'] = '<li class = "active"><a href = "#">'; |
|
| 54 | - $config['active_link_close'] = '</a></li>'; |
|
| 50 | + /** |
|
| 51 | + * The opened and closed tag for active link |
|
| 52 | + */ |
|
| 53 | + $config['active_link_open'] = '<li class = "active"><a href = "#">'; |
|
| 54 | + $config['active_link_close'] = '</a></li>'; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * The opened and closed tag for previous link |
|
| 58 | - */ |
|
| 59 | - $config['previous_open'] = '<li>'; |
|
| 60 | - $config['previous_close'] = '</li>'; |
|
| 56 | + /** |
|
| 57 | + * The opened and closed tag for previous link |
|
| 58 | + */ |
|
| 59 | + $config['previous_open'] = '<li>'; |
|
| 60 | + $config['previous_close'] = '</li>'; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * The opened and closed tag for next link |
|
| 64 | - */ |
|
| 65 | - $config['next_open'] = '<li>'; |
|
| 66 | - $config['next_close'] = '</li>'; |
|
| 62 | + /** |
|
| 63 | + * The opened and closed tag for next link |
|
| 64 | + */ |
|
| 65 | + $config['next_open'] = '<li>'; |
|
| 66 | + $config['next_close'] = '</li>'; |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * The displayed text for previous and next link |
|
| 71 | - */ |
|
| 72 | - $config['previous_text'] = '««'; |
|
| 73 | - $config['next_text'] = '»»'; |
|
| 69 | + /** |
|
| 70 | + * The displayed text for previous and next link |
|
| 71 | + */ |
|
| 72 | + $config['previous_text'] = '««'; |
|
| 73 | + $config['next_text'] = '»»'; |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * The opened and closed tag for the pagination bloc |
|
| 77 | - */ |
|
| 78 | - $config['pagination_open'] = '<ul class = "pagination">'; |
|
| 79 | - $config['pagination_close'] = '</ul>'; |
|
| 75 | + /** |
|
| 76 | + * The opened and closed tag for the pagination bloc |
|
| 77 | + */ |
|
| 78 | + $config['pagination_open'] = '<ul class = "pagination">'; |
|
| 79 | + $config['pagination_close'] = '</ul>'; |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * The opened and closed tag for each link digit |
|
| 83 | - */ |
|
| 84 | - $config['digit_open'] = '<li>'; |
|
| 85 | - $config['digit_close'] = '</li>'; |
|
| 81 | + /** |
|
| 82 | + * The opened and closed tag for each link digit |
|
| 83 | + */ |
|
| 84 | + $config['digit_open'] = '<li>'; |
|
| 85 | + $config['digit_close'] = '</li>'; |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * The HTML attributes to use in each link |
|
| 89 | - */ |
|
| 90 | - $config['attributes'] = array(); |
|
| 91 | 87 | \ No newline at end of file |
| 88 | + /** |
|
| 89 | + * The HTML attributes to use in each link |
|
| 90 | + */ |
|
| 91 | + $config['attributes'] = array(); |
|
| 92 | 92 | \ No newline at end of file |
@@ -1,260 +1,260 @@ |
||
| 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 | - /** |
|
| 117 | - * The path to the directory of core classes for the model used by the system. |
|
| 118 | - * |
|
| 119 | - * It contains PHP classes for the models. |
|
| 120 | - */ |
|
| 121 | - define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS); |
|
| 116 | + /** |
|
| 117 | + * The path to the directory of core classes for the model used by the system. |
|
| 118 | + * |
|
| 119 | + * It contains PHP classes for the models. |
|
| 120 | + */ |
|
| 121 | + define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS); |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * The path to the directory of functions or helper systems. |
|
| 125 | - * |
|
| 126 | - * It contains PHP functions that perform a particular task: character string processing, URL, etc. |
|
| 127 | - */ |
|
| 128 | - define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS); |
|
| 123 | + /** |
|
| 124 | + * The path to the directory of functions or helper systems. |
|
| 125 | + * |
|
| 126 | + * It contains PHP functions that perform a particular task: character string processing, URL, etc. |
|
| 127 | + */ |
|
| 128 | + define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS); |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * The path to the core directory of languages files. |
|
| 132 | - * |
|
| 133 | - */ |
|
| 134 | - define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS); |
|
| 130 | + /** |
|
| 131 | + * The path to the core directory of languages files. |
|
| 132 | + * |
|
| 133 | + */ |
|
| 134 | + define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS); |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * The path to the system library directory. |
|
| 138 | - * |
|
| 139 | - * Which contains the libraries most often used in your web application, as for the |
|
| 140 | - * core directory it is advisable to put it out of the root directory of your application. |
|
| 141 | - */ |
|
| 142 | - define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS); |
|
| 136 | + /** |
|
| 137 | + * The path to the system library directory. |
|
| 138 | + * |
|
| 139 | + * Which contains the libraries most often used in your web application, as for the |
|
| 140 | + * core directory it is advisable to put it out of the root directory of your application. |
|
| 141 | + */ |
|
| 142 | + define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS); |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * The path to the system view directory. |
|
| 146 | - * |
|
| 147 | - * That contains the views used for the system, such as error messages, and so on. |
|
| 148 | - */ |
|
| 149 | - define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS); |
|
| 144 | + /** |
|
| 145 | + * The path to the system view directory. |
|
| 146 | + * |
|
| 147 | + * That contains the views used for the system, such as error messages, and so on. |
|
| 148 | + */ |
|
| 149 | + define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS); |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * The path to the directory of your PHP personal functions or helper. |
|
| 153 | - * |
|
| 154 | - * It contains your PHP functions that perform a particular task: utilities, etc. |
|
| 155 | - * Note: Do not put your personal functions or helpers in the system functions directory, |
|
| 156 | - * because if you update the system you may lose them. |
|
| 157 | - */ |
|
| 158 | - define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS); |
|
| 151 | + /** |
|
| 152 | + * The path to the directory of your PHP personal functions or helper. |
|
| 153 | + * |
|
| 154 | + * It contains your PHP functions that perform a particular task: utilities, etc. |
|
| 155 | + * Note: Do not put your personal functions or helpers in the system functions directory, |
|
| 156 | + * because if you update the system you may lose them. |
|
| 157 | + */ |
|
| 158 | + define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS); |
|
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * The path to the app directory of personal language. |
|
| 162 | - * |
|
| 163 | - * This feature is not yet available. |
|
| 164 | - * You can help us do this if you are nice or wish to see the developed framework. |
|
| 165 | - */ |
|
| 166 | - define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS); |
|
| 160 | + /** |
|
| 161 | + * The path to the app directory of personal language. |
|
| 162 | + * |
|
| 163 | + * This feature is not yet available. |
|
| 164 | + * You can help us do this if you are nice or wish to see the developed framework. |
|
| 165 | + */ |
|
| 166 | + define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS); |
|
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * The path to the directory of your personal libraries |
|
| 170 | - * |
|
| 171 | - * It contains your PHP classes, package, etc. |
|
| 172 | - * Note: you should not put your personal libraries in the system library directory, |
|
| 173 | - * because it is recalled in case of updating the system you might have surprises. |
|
| 174 | - */ |
|
| 175 | - define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS); |
|
| 168 | + /** |
|
| 169 | + * The path to the directory of your personal libraries |
|
| 170 | + * |
|
| 171 | + * It contains your PHP classes, package, etc. |
|
| 172 | + * Note: you should not put your personal libraries in the system library directory, |
|
| 173 | + * because it is recalled in case of updating the system you might have surprises. |
|
| 174 | + */ |
|
| 175 | + define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS); |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * The path to the directory that contains the log files. |
|
| 179 | - * |
|
| 180 | - * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, |
|
| 181 | - * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more |
|
| 182 | - * details see the documentation of your web server. |
|
| 183 | - * Example for Unix or linux with apache web server: |
|
| 184 | - * # chmod -R 700 /path/to/your/logs/directory/ |
|
| 185 | - * # chown -R www-data:www-data /path/to/your/logs/directory/ |
|
| 186 | - */ |
|
| 187 | - define('LOGS_PATH', ROOT_PATH . 'logs' . DS); |
|
| 177 | + /** |
|
| 178 | + * The path to the directory that contains the log files. |
|
| 179 | + * |
|
| 180 | + * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, |
|
| 181 | + * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more |
|
| 182 | + * details see the documentation of your web server. |
|
| 183 | + * Example for Unix or linux with apache web server: |
|
| 184 | + * # chmod -R 700 /path/to/your/logs/directory/ |
|
| 185 | + * # chown -R www-data:www-data /path/to/your/logs/directory/ |
|
| 186 | + */ |
|
| 187 | + define('LOGS_PATH', ROOT_PATH . 'logs' . DS); |
|
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * The path to the modules directory. |
|
| 191 | - * |
|
| 192 | - * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
|
| 193 | - * in HMVC architecture (hierichical, controllers, models, views). |
|
| 194 | - */ |
|
| 195 | - define('MODULE_PATH', ROOT_PATH . 'modules' . DS); |
|
| 189 | + /** |
|
| 190 | + * The path to the modules directory. |
|
| 191 | + * |
|
| 192 | + * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
|
| 193 | + * in HMVC architecture (hierichical, controllers, models, views). |
|
| 194 | + */ |
|
| 195 | + define('MODULE_PATH', ROOT_PATH . 'modules' . DS); |
|
| 196 | 196 | |
| 197 | - /** |
|
| 198 | - * The path to the directory of sources external to your application. |
|
| 199 | - * |
|
| 200 | - * If you have already used "composer" you know what that means. |
|
| 201 | - */ |
|
| 202 | - define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS); |
|
| 197 | + /** |
|
| 198 | + * The path to the directory of sources external to your application. |
|
| 199 | + * |
|
| 200 | + * If you have already used "composer" you know what that means. |
|
| 201 | + */ |
|
| 202 | + define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS); |
|
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * The front controller of your application. |
|
| 206 | - * |
|
| 207 | - * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of |
|
| 208 | - * your application by using the rewrite module URL of your web server . |
|
| 209 | - * For example, under apache web server, there is a configuration example file that is located at the root |
|
| 210 | - * of your framework folder : "htaccess.txt" rename it to ".htaccess". |
|
| 211 | - */ |
|
| 212 | - define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); |
|
| 204 | + /** |
|
| 205 | + * The front controller of your application. |
|
| 206 | + * |
|
| 207 | + * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of |
|
| 208 | + * your application by using the rewrite module URL of your web server . |
|
| 209 | + * For example, under apache web server, there is a configuration example file that is located at the root |
|
| 210 | + * of your framework folder : "htaccess.txt" rename it to ".htaccess". |
|
| 211 | + */ |
|
| 212 | + define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); |
|
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * Check if user run the application under CLI |
|
| 216 | - */ |
|
| 217 | - define('IS_CLI', stripos('cli', php_sapi_name()) !== false); |
|
| 214 | + /** |
|
| 215 | + * Check if user run the application under CLI |
|
| 216 | + */ |
|
| 217 | + define('IS_CLI', stripos('cli', php_sapi_name()) !== false); |
|
| 218 | 218 | |
| 219 | - /** |
|
| 220 | - * The environment of your application (production, test, development). |
|
| 221 | - * |
|
| 222 | - * if your application is still in development you use the value "development" |
|
| 223 | - * so you will have the display of the error messages, etc. |
|
| 224 | - * Once you finish the development of your application that is to put it online |
|
| 225 | - * you change this value to "production" or "testing", in this case there will be deactivation of error messages, |
|
| 226 | - * the loading of the system, will be fast. |
|
| 227 | - */ |
|
| 228 | - define('ENVIRONMENT', 'development'); |
|
| 219 | + /** |
|
| 220 | + * The environment of your application (production, test, development). |
|
| 221 | + * |
|
| 222 | + * if your application is still in development you use the value "development" |
|
| 223 | + * so you will have the display of the error messages, etc. |
|
| 224 | + * Once you finish the development of your application that is to put it online |
|
| 225 | + * you change this value to "production" or "testing", in this case there will be deactivation of error messages, |
|
| 226 | + * the loading of the system, will be fast. |
|
| 227 | + */ |
|
| 228 | + define('ENVIRONMENT', 'development'); |
|
| 229 | 229 | |
| 230 | - /* ---------------------------------------------------------------------------------- */ |
|
| 231 | - /////////////////////////////////////////////////////////////////////////////////////// |
|
| 232 | - /******************** DO NOT CHANGE THE LINES BELOW *********************************/ |
|
| 233 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 230 | + /* ---------------------------------------------------------------------------------- */ |
|
| 231 | + /////////////////////////////////////////////////////////////////////////////////////// |
|
| 232 | + /******************** DO NOT CHANGE THE LINES BELOW *********************************/ |
|
| 233 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 234 | 234 | |
| 235 | - switch (ENVIRONMENT) { |
|
| 236 | - case 'development': |
|
| 237 | - error_reporting(-1); |
|
| 238 | - ini_set('display_errors', 1); |
|
| 239 | - break; |
|
| 240 | - case 'testing': |
|
| 241 | - case 'production': |
|
| 242 | - ini_set('display_errors', 0); |
|
| 243 | - if (version_compare(PHP_VERSION, '5.3', '>=')) { |
|
| 244 | - error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); |
|
| 245 | - } |
|
| 246 | - else{ |
|
| 247 | - error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
|
| 248 | - } |
|
| 249 | - break; |
|
| 250 | - default: |
|
| 251 | - header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); |
|
| 252 | - echo 'The application environment is not set correctly.'; |
|
| 253 | - exit(1); |
|
| 254 | - } |
|
| 235 | + switch (ENVIRONMENT) { |
|
| 236 | + case 'development': |
|
| 237 | + error_reporting(-1); |
|
| 238 | + ini_set('display_errors', 1); |
|
| 239 | + break; |
|
| 240 | + case 'testing': |
|
| 241 | + case 'production': |
|
| 242 | + ini_set('display_errors', 0); |
|
| 243 | + if (version_compare(PHP_VERSION, '5.3', '>=')) { |
|
| 244 | + error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); |
|
| 245 | + } |
|
| 246 | + else{ |
|
| 247 | + error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
|
| 248 | + } |
|
| 249 | + break; |
|
| 250 | + default: |
|
| 251 | + header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); |
|
| 252 | + echo 'The application environment is not set correctly.'; |
|
| 253 | + exit(1); |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - /** |
|
| 257 | - * let's go. |
|
| 258 | - * Everything is OK now we launch our application. |
|
| 259 | - */ |
|
| 260 | - require_once CORE_PATH . 'bootstrap.php'; |
|
| 261 | 256 | \ No newline at end of file |
| 257 | + /** |
|
| 258 | + * let's go. |
|
| 259 | + * Everything is OK now we launch our application. |
|
| 260 | + */ |
|
| 261 | + require_once CORE_PATH . 'bootstrap.php'; |
|
| 262 | 262 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | 4 | * TNH Framework |
| 5 | 5 | * |
| 6 | 6 | * A simple PHP framework using HMVC architecture |
@@ -22,321 +22,321 @@ discard block |
||
| 22 | 22 | * You should have received a copy of the GNU General Public License |
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | - */ |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - class Module{ |
|
| 27 | + class Module{ |
|
| 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 | - * logger instance |
|
| 37 | - * @var Log |
|
| 38 | - */ |
|
| 39 | - private static $logger; |
|
| 35 | + /** |
|
| 36 | + * logger instance |
|
| 37 | + * @var Log |
|
| 38 | + */ |
|
| 39 | + private static $logger; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * The signleton of the logger |
|
| 43 | - * @return Object the Log instance |
|
| 44 | - */ |
|
| 45 | - private static function getLogger(){ |
|
| 46 | - if(self::$logger == null){ |
|
| 47 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 48 | - self::$logger[0]->setLogger('Library::Module'); |
|
| 49 | - } |
|
| 50 | - return self::$logger[0]; |
|
| 51 | - } |
|
| 41 | + /** |
|
| 42 | + * The signleton of the logger |
|
| 43 | + * @return Object the Log instance |
|
| 44 | + */ |
|
| 45 | + private static function getLogger(){ |
|
| 46 | + if(self::$logger == null){ |
|
| 47 | + self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 48 | + self::$logger[0]->setLogger('Library::Module'); |
|
| 49 | + } |
|
| 50 | + return self::$logger[0]; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Initialise the module list by scanning the directory MODULE_PATH |
|
| 55 | - */ |
|
| 56 | - public function init(){ |
|
| 57 | - $logger = self::getLogger(); |
|
| 58 | - $logger->debug('Check if the application contains the modules ...'); |
|
| 59 | - $moduleDir = opendir(MODULE_PATH); |
|
| 60 | - if(is_resource($moduleDir)){ |
|
| 61 | - while(($module = readdir($moduleDir)) !== false){ |
|
| 62 | - if(preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){ |
|
| 63 | - self::$list[] = $module; |
|
| 64 | - } |
|
| 65 | - else{ |
|
| 66 | - $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name'); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - closedir($moduleDir); |
|
| 70 | - } |
|
| 71 | - ksort(self::$list); |
|
| 53 | + /** |
|
| 54 | + * Initialise the module list by scanning the directory MODULE_PATH |
|
| 55 | + */ |
|
| 56 | + public function init(){ |
|
| 57 | + $logger = self::getLogger(); |
|
| 58 | + $logger->debug('Check if the application contains the modules ...'); |
|
| 59 | + $moduleDir = opendir(MODULE_PATH); |
|
| 60 | + if(is_resource($moduleDir)){ |
|
| 61 | + while(($module = readdir($moduleDir)) !== false){ |
|
| 62 | + if(preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){ |
|
| 63 | + self::$list[] = $module; |
|
| 64 | + } |
|
| 65 | + else{ |
|
| 66 | + $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name'); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + closedir($moduleDir); |
|
| 70 | + } |
|
| 71 | + ksort(self::$list); |
|
| 72 | 72 | |
| 73 | - if(self::hasModule()){ |
|
| 74 | - $logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']'); |
|
| 75 | - } |
|
| 76 | - } |
|
| 73 | + if(self::hasModule()){ |
|
| 74 | + $logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']'); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Get the list of the custom autoload configuration from module if exists |
|
| 80 | - * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values |
|
| 81 | - */ |
|
| 82 | - public static function getModulesAutoloadConfig(){ |
|
| 83 | - $logger = self::getLogger(); |
|
| 84 | - if(! self::hasModule()){ |
|
| 85 | - $logger->info('No module was loaded skipping.'); |
|
| 86 | - return false; |
|
| 87 | - } |
|
| 88 | - $autoloads = array(); |
|
| 89 | - $autoloads['libraries'] = array(); |
|
| 90 | - $autoloads['config'] = array(); |
|
| 91 | - $autoloads['models'] = array(); |
|
| 92 | - $autoloads['functions'] = array(); |
|
| 93 | - $autoloads['languages'] = array(); |
|
| 78 | + /** |
|
| 79 | + * Get the list of the custom autoload configuration from module if exists |
|
| 80 | + * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values |
|
| 81 | + */ |
|
| 82 | + public static function getModulesAutoloadConfig(){ |
|
| 83 | + $logger = self::getLogger(); |
|
| 84 | + if(! self::hasModule()){ |
|
| 85 | + $logger->info('No module was loaded skipping.'); |
|
| 86 | + return false; |
|
| 87 | + } |
|
| 88 | + $autoloads = array(); |
|
| 89 | + $autoloads['libraries'] = array(); |
|
| 90 | + $autoloads['config'] = array(); |
|
| 91 | + $autoloads['models'] = array(); |
|
| 92 | + $autoloads['functions'] = array(); |
|
| 93 | + $autoloads['languages'] = array(); |
|
| 94 | 94 | |
| 95 | - foreach (self::$list as $module) { |
|
| 96 | - $file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php'; |
|
| 97 | - if(file_exists($file)){ |
|
| 98 | - $autoload = array(); |
|
| 99 | - require_once $file; |
|
| 100 | - if(! empty($autoload) && is_array($autoload)){ |
|
| 101 | - $autoloads = array_merge_recursive($autoloads, $autoload); |
|
| 102 | - unset($autoload); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - return $autoloads; |
|
| 107 | - } |
|
| 95 | + foreach (self::$list as $module) { |
|
| 96 | + $file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php'; |
|
| 97 | + if(file_exists($file)){ |
|
| 98 | + $autoload = array(); |
|
| 99 | + require_once $file; |
|
| 100 | + if(! empty($autoload) && is_array($autoload)){ |
|
| 101 | + $autoloads = array_merge_recursive($autoloads, $autoload); |
|
| 102 | + unset($autoload); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + return $autoloads; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Get the list of the custom routes configuration from module if exists |
|
| 111 | - * @return array|boolean the routes list or false if no module contains the routes configuration |
|
| 112 | - */ |
|
| 113 | - public static function getModulesRoutes(){ |
|
| 114 | - $logger = self::getLogger(); |
|
| 115 | - if(! self::hasModule()){ |
|
| 116 | - $logger->info('No module was loaded skipping.'); |
|
| 117 | - return false; |
|
| 118 | - } |
|
| 119 | - $routes = array(); |
|
| 120 | - foreach (self::$list as $module) { |
|
| 121 | - $file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php'; |
|
| 122 | - if(file_exists($file)){ |
|
| 123 | - $route = array(); |
|
| 124 | - require_once $file; |
|
| 125 | - if(! empty($route) && is_array($route)){ |
|
| 126 | - $routes = array_merge($routes, $route); |
|
| 127 | - unset($route); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - return $routes; |
|
| 132 | - } |
|
| 109 | + /** |
|
| 110 | + * Get the list of the custom routes configuration from module if exists |
|
| 111 | + * @return array|boolean the routes list or false if no module contains the routes configuration |
|
| 112 | + */ |
|
| 113 | + public static function getModulesRoutes(){ |
|
| 114 | + $logger = self::getLogger(); |
|
| 115 | + if(! self::hasModule()){ |
|
| 116 | + $logger->info('No module was loaded skipping.'); |
|
| 117 | + return false; |
|
| 118 | + } |
|
| 119 | + $routes = array(); |
|
| 120 | + foreach (self::$list as $module) { |
|
| 121 | + $file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php'; |
|
| 122 | + if(file_exists($file)){ |
|
| 123 | + $route = array(); |
|
| 124 | + require_once $file; |
|
| 125 | + if(! empty($route) && is_array($route)){ |
|
| 126 | + $routes = array_merge($routes, $route); |
|
| 127 | + unset($route); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + return $routes; |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * Check if in module list can have this controller |
|
| 137 | - * @param string $class the controller class |
|
| 138 | - * @param string $module the module name |
|
| 139 | - * @return boolean|string false or null if no module have this controller, path the full path of the controller |
|
| 140 | - */ |
|
| 141 | - public static function findControllerFullPath($class, $module = null){ |
|
| 142 | - $logger = self::getLogger(); |
|
| 143 | - if(! self::hasModule()){ |
|
| 144 | - $logger->info('No module was loaded skiping.'); |
|
| 145 | - return false; |
|
| 146 | - } |
|
| 147 | - $class = str_ireplace('.php', '', $class); |
|
| 148 | - $class = ucfirst($class); |
|
| 149 | - $classFile = $class.'.php'; |
|
| 150 | - $logger->debug('Checking the controller [' . $class . '] in module [' .$module. '] ...'); |
|
| 151 | - $filePath = MODULE_PATH . $module . DS . 'controllers' . DS . $classFile; |
|
| 152 | - if(file_exists($filePath)){ |
|
| 153 | - $logger->info('Found controller [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 154 | - return $filePath; |
|
| 155 | - } |
|
| 156 | - else{ |
|
| 157 | - $logger->info('Controller [' . $class . '] does not exist in the module [' .$module. ']'); |
|
| 158 | - return false; |
|
| 159 | - } |
|
| 160 | - } |
|
| 135 | + /** |
|
| 136 | + * Check if in module list can have this controller |
|
| 137 | + * @param string $class the controller class |
|
| 138 | + * @param string $module the module name |
|
| 139 | + * @return boolean|string false or null if no module have this controller, path the full path of the controller |
|
| 140 | + */ |
|
| 141 | + public static function findControllerFullPath($class, $module = null){ |
|
| 142 | + $logger = self::getLogger(); |
|
| 143 | + if(! self::hasModule()){ |
|
| 144 | + $logger->info('No module was loaded skiping.'); |
|
| 145 | + return false; |
|
| 146 | + } |
|
| 147 | + $class = str_ireplace('.php', '', $class); |
|
| 148 | + $class = ucfirst($class); |
|
| 149 | + $classFile = $class.'.php'; |
|
| 150 | + $logger->debug('Checking the controller [' . $class . '] in module [' .$module. '] ...'); |
|
| 151 | + $filePath = MODULE_PATH . $module . DS . 'controllers' . DS . $classFile; |
|
| 152 | + if(file_exists($filePath)){ |
|
| 153 | + $logger->info('Found controller [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 154 | + return $filePath; |
|
| 155 | + } |
|
| 156 | + else{ |
|
| 157 | + $logger->info('Controller [' . $class . '] does not exist in the module [' .$module. ']'); |
|
| 158 | + return false; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * Check if in module list can have this model |
|
| 164 | - * @param string $class the model class |
|
| 165 | - * @param string $module the module name |
|
| 166 | - * @return boolean|string false or null if no module have this model, return the full path of this model |
|
| 167 | - */ |
|
| 168 | - public static function findModelFullPath($class, $module = null){ |
|
| 169 | - $logger = self::getLogger(); |
|
| 170 | - if(! self::hasModule()){ |
|
| 171 | - $logger->info('No module was loaded skiping.'); |
|
| 172 | - return false; |
|
| 173 | - } |
|
| 174 | - $class = str_ireplace('.php', '', $class); |
|
| 175 | - $class = ucfirst($class); |
|
| 176 | - $classFile = $class.'.php'; |
|
| 177 | - $logger->debug('Checking model [' . $class . '] in module [' .$module. '] ...'); |
|
| 178 | - $filePath = MODULE_PATH . $module . DS . 'models' . DS . $classFile; |
|
| 179 | - if(file_exists($filePath)){ |
|
| 180 | - $logger->info('Found model [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 181 | - return $filePath; |
|
| 182 | - } |
|
| 183 | - else{ |
|
| 184 | - $logger->info('Model [' . $class . '] does not exist in the module [' .$module. ']'); |
|
| 185 | - return false; |
|
| 186 | - } |
|
| 187 | - } |
|
| 162 | + /** |
|
| 163 | + * Check if in module list can have this model |
|
| 164 | + * @param string $class the model class |
|
| 165 | + * @param string $module the module name |
|
| 166 | + * @return boolean|string false or null if no module have this model, return the full path of this model |
|
| 167 | + */ |
|
| 168 | + public static function findModelFullPath($class, $module = null){ |
|
| 169 | + $logger = self::getLogger(); |
|
| 170 | + if(! self::hasModule()){ |
|
| 171 | + $logger->info('No module was loaded skiping.'); |
|
| 172 | + return false; |
|
| 173 | + } |
|
| 174 | + $class = str_ireplace('.php', '', $class); |
|
| 175 | + $class = ucfirst($class); |
|
| 176 | + $classFile = $class.'.php'; |
|
| 177 | + $logger->debug('Checking model [' . $class . '] in module [' .$module. '] ...'); |
|
| 178 | + $filePath = MODULE_PATH . $module . DS . 'models' . DS . $classFile; |
|
| 179 | + if(file_exists($filePath)){ |
|
| 180 | + $logger->info('Found model [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 181 | + return $filePath; |
|
| 182 | + } |
|
| 183 | + else{ |
|
| 184 | + $logger->info('Model [' . $class . '] does not exist in the module [' .$module. ']'); |
|
| 185 | + return false; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * Check if in module list can have this config |
|
| 191 | - * @param string $configuration the config name |
|
| 192 | - * @param string $module the module name |
|
| 193 | - * @return boolean|string false or null if no module have this configuration, return the full path of this configuration |
|
| 194 | - */ |
|
| 195 | - public static function findConfigFullPath($configuration, $module = null){ |
|
| 196 | - $logger = self::getLogger(); |
|
| 197 | - if(! self::hasModule()){ |
|
| 198 | - $logger->info('No module was loaded skiping.'); |
|
| 199 | - return false; |
|
| 200 | - } |
|
| 201 | - $configuration = str_ireplace('.php', '', $configuration); |
|
| 202 | - $file = $configuration.'.php'; |
|
| 203 | - $logger->debug('Checking configuration [' . $configuration . '] in module [' .$module. '] ...'); |
|
| 204 | - $filePath = MODULE_PATH . $module . DS . 'config' . DS . $file; |
|
| 205 | - if(file_exists($filePath)){ |
|
| 206 | - $logger->info('Found configuration [' . $configuration . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 207 | - return $filePath; |
|
| 208 | - } |
|
| 209 | - else{ |
|
| 210 | - $logger->info('Configuration [' . $configuration . '] does not exist in the module [' .$module. ']'); |
|
| 211 | - return false; |
|
| 212 | - } |
|
| 213 | - } |
|
| 189 | + /** |
|
| 190 | + * Check if in module list can have this config |
|
| 191 | + * @param string $configuration the config name |
|
| 192 | + * @param string $module the module name |
|
| 193 | + * @return boolean|string false or null if no module have this configuration, return the full path of this configuration |
|
| 194 | + */ |
|
| 195 | + public static function findConfigFullPath($configuration, $module = null){ |
|
| 196 | + $logger = self::getLogger(); |
|
| 197 | + if(! self::hasModule()){ |
|
| 198 | + $logger->info('No module was loaded skiping.'); |
|
| 199 | + return false; |
|
| 200 | + } |
|
| 201 | + $configuration = str_ireplace('.php', '', $configuration); |
|
| 202 | + $file = $configuration.'.php'; |
|
| 203 | + $logger->debug('Checking configuration [' . $configuration . '] in module [' .$module. '] ...'); |
|
| 204 | + $filePath = MODULE_PATH . $module . DS . 'config' . DS . $file; |
|
| 205 | + if(file_exists($filePath)){ |
|
| 206 | + $logger->info('Found configuration [' . $configuration . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 207 | + return $filePath; |
|
| 208 | + } |
|
| 209 | + else{ |
|
| 210 | + $logger->info('Configuration [' . $configuration . '] does not exist in the module [' .$module. ']'); |
|
| 211 | + return false; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * Check if in module list can have this helper |
|
| 217 | - * @param string $helper the helper name |
|
| 218 | - * @param string $module the module name |
|
| 219 | - * @return boolean|string false or null if no module have this helper, return the full path of this helper |
|
| 220 | - */ |
|
| 221 | - public static function findFunctionFullPath($helper, $module = null){ |
|
| 222 | - $logger = self::getLogger(); |
|
| 223 | - if(! self::hasModule()){ |
|
| 224 | - $logger->info('No module was loaded skiping.'); |
|
| 225 | - return false; |
|
| 226 | - } |
|
| 227 | - $helper = str_ireplace('.php', '', $helper); |
|
| 228 | - $helper = str_ireplace('function_', '', $helper); |
|
| 229 | - $file = 'function_'.$helper.'.php'; |
|
| 230 | - $logger->debug('Checking helper [' . $helper . '] in module [' .$module. '] ...'); |
|
| 231 | - $filePath = MODULE_PATH . $module . DS . 'functions' . DS . $file; |
|
| 232 | - if(file_exists($filePath)){ |
|
| 233 | - $logger->info('Found helper [' . $helper . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 234 | - return $filePath; |
|
| 235 | - } |
|
| 236 | - else{ |
|
| 237 | - $logger->info('Helper [' . $helper . '] does not exist in the module [' .$module. ']'); |
|
| 238 | - return false; |
|
| 239 | - } |
|
| 240 | - } |
|
| 215 | + /** |
|
| 216 | + * Check if in module list can have this helper |
|
| 217 | + * @param string $helper the helper name |
|
| 218 | + * @param string $module the module name |
|
| 219 | + * @return boolean|string false or null if no module have this helper, return the full path of this helper |
|
| 220 | + */ |
|
| 221 | + public static function findFunctionFullPath($helper, $module = null){ |
|
| 222 | + $logger = self::getLogger(); |
|
| 223 | + if(! self::hasModule()){ |
|
| 224 | + $logger->info('No module was loaded skiping.'); |
|
| 225 | + return false; |
|
| 226 | + } |
|
| 227 | + $helper = str_ireplace('.php', '', $helper); |
|
| 228 | + $helper = str_ireplace('function_', '', $helper); |
|
| 229 | + $file = 'function_'.$helper.'.php'; |
|
| 230 | + $logger->debug('Checking helper [' . $helper . '] in module [' .$module. '] ...'); |
|
| 231 | + $filePath = MODULE_PATH . $module . DS . 'functions' . DS . $file; |
|
| 232 | + if(file_exists($filePath)){ |
|
| 233 | + $logger->info('Found helper [' . $helper . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 234 | + return $filePath; |
|
| 235 | + } |
|
| 236 | + else{ |
|
| 237 | + $logger->info('Helper [' . $helper . '] does not exist in the module [' .$module. ']'); |
|
| 238 | + return false; |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | 242 | |
| 243 | - /** |
|
| 244 | - * Check if in module list can have this library |
|
| 245 | - * @param string $class the library name |
|
| 246 | - * @param string $module the module name |
|
| 247 | - * @return boolean|string false or null if no module have this library, return the full path of this library |
|
| 248 | - */ |
|
| 249 | - public static function findLibraryFullPath($class, $module = null){ |
|
| 250 | - $logger = self::getLogger(); |
|
| 251 | - if(! self::hasModule()){ |
|
| 252 | - $logger->info('No module was loaded skiping.'); |
|
| 253 | - return false; |
|
| 254 | - } |
|
| 255 | - $class = str_ireplace('.php', '', $class); |
|
| 256 | - $file = $class.'.php'; |
|
| 257 | - $logger->debug('Checking library [' . $class . '] in module [' .$module. '] ...'); |
|
| 258 | - $filePath = MODULE_PATH . $module . DS . 'libraries' . DS . $file; |
|
| 259 | - if(file_exists($filePath)){ |
|
| 260 | - $logger->info('Found library [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 261 | - return $filePath; |
|
| 262 | - } |
|
| 263 | - else{ |
|
| 264 | - $logger->info('Library [' . $class . '] does not exist in the module [' .$module. ']'); |
|
| 265 | - return false; |
|
| 266 | - } |
|
| 267 | - } |
|
| 243 | + /** |
|
| 244 | + * Check if in module list can have this library |
|
| 245 | + * @param string $class the library name |
|
| 246 | + * @param string $module the module name |
|
| 247 | + * @return boolean|string false or null if no module have this library, return the full path of this library |
|
| 248 | + */ |
|
| 249 | + public static function findLibraryFullPath($class, $module = null){ |
|
| 250 | + $logger = self::getLogger(); |
|
| 251 | + if(! self::hasModule()){ |
|
| 252 | + $logger->info('No module was loaded skiping.'); |
|
| 253 | + return false; |
|
| 254 | + } |
|
| 255 | + $class = str_ireplace('.php', '', $class); |
|
| 256 | + $file = $class.'.php'; |
|
| 257 | + $logger->debug('Checking library [' . $class . '] in module [' .$module. '] ...'); |
|
| 258 | + $filePath = MODULE_PATH . $module . DS . 'libraries' . DS . $file; |
|
| 259 | + if(file_exists($filePath)){ |
|
| 260 | + $logger->info('Found library [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 261 | + return $filePath; |
|
| 262 | + } |
|
| 263 | + else{ |
|
| 264 | + $logger->info('Library [' . $class . '] does not exist in the module [' .$module. ']'); |
|
| 265 | + return false; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | 269 | |
| 270 | - /** |
|
| 271 | - * Check if in module list can have this view |
|
| 272 | - * @param string $view the view path |
|
| 273 | - * @param string $module the module name to check |
|
| 274 | - * @return boolean|string false or null if no module have this view, path the full path of the view |
|
| 275 | - */ |
|
| 276 | - public static function findViewFullPath($view, $module = null){ |
|
| 277 | - $logger = self::getLogger(); |
|
| 278 | - if(! self::hasModule()){ |
|
| 279 | - $logger->info('No module was loaded skiping.'); |
|
| 280 | - return false; |
|
| 281 | - } |
|
| 282 | - $view = str_ireplace('.php', '', $view); |
|
| 283 | - $view = trim($view, '/\\'); |
|
| 284 | - $view = str_ireplace('/', DS, $view); |
|
| 285 | - $viewFile = $view . '.php'; |
|
| 286 | - $logger->debug('Checking view [' . $view . '] in module [' .$module. '] ...'); |
|
| 287 | - $filePath = MODULE_PATH . $module . DS . 'views' . DS . $viewFile; |
|
| 288 | - if(file_exists($filePath)){ |
|
| 289 | - $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 290 | - return $filePath; |
|
| 291 | - } |
|
| 292 | - else{ |
|
| 293 | - $logger->info('View [' . $view . '] does not exist in the module [' .$module. ']'); |
|
| 294 | - return false; |
|
| 295 | - } |
|
| 296 | - } |
|
| 270 | + /** |
|
| 271 | + * Check if in module list can have this view |
|
| 272 | + * @param string $view the view path |
|
| 273 | + * @param string $module the module name to check |
|
| 274 | + * @return boolean|string false or null if no module have this view, path the full path of the view |
|
| 275 | + */ |
|
| 276 | + public static function findViewFullPath($view, $module = null){ |
|
| 277 | + $logger = self::getLogger(); |
|
| 278 | + if(! self::hasModule()){ |
|
| 279 | + $logger->info('No module was loaded skiping.'); |
|
| 280 | + return false; |
|
| 281 | + } |
|
| 282 | + $view = str_ireplace('.php', '', $view); |
|
| 283 | + $view = trim($view, '/\\'); |
|
| 284 | + $view = str_ireplace('/', DS, $view); |
|
| 285 | + $viewFile = $view . '.php'; |
|
| 286 | + $logger->debug('Checking view [' . $view . '] in module [' .$module. '] ...'); |
|
| 287 | + $filePath = MODULE_PATH . $module . DS . 'views' . DS . $viewFile; |
|
| 288 | + if(file_exists($filePath)){ |
|
| 289 | + $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 290 | + return $filePath; |
|
| 291 | + } |
|
| 292 | + else{ |
|
| 293 | + $logger->info('View [' . $view . '] does not exist in the module [' .$module. ']'); |
|
| 294 | + return false; |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | 297 | |
| 298 | - /** |
|
| 299 | - * Check if in module list can have this language |
|
| 300 | - * @param string $language the language name |
|
| 301 | - * @param string $module the module name |
|
| 302 | - * @param string $appLang the application language like 'en', 'fr' |
|
| 303 | - * @return boolean|string false or null if no module have this language, return the full path of this language |
|
| 304 | - */ |
|
| 305 | - public static function findLanguageFullPath($language, $module = null, $appLang){ |
|
| 306 | - $logger = self::getLogger(); |
|
| 307 | - if(! self::hasModule()){ |
|
| 308 | - $logger->info('No module was loaded skiping.'); |
|
| 309 | - return false; |
|
| 310 | - } |
|
| 311 | - $language = str_ireplace('.php', '', $language); |
|
| 312 | - $language = str_ireplace('lang_', '', $language); |
|
| 313 | - $file = 'lang_'.$language.'.php'; |
|
| 314 | - $logger->debug('Checking language [' . $language . '] in module [' .$module. '] ...'); |
|
| 315 | - $filePath = MODULE_PATH . $module . DS . 'lang' . DS . $appLang . DS . $file; |
|
| 316 | - if(file_exists($filePath)){ |
|
| 317 | - $logger->info('Found language [' . $language . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 318 | - return $filePath; |
|
| 319 | - } |
|
| 320 | - else{ |
|
| 321 | - $logger->info('Language [' . $language . '] does not exist in the module [' .$module. ']'); |
|
| 322 | - return false; |
|
| 323 | - } |
|
| 324 | - } |
|
| 298 | + /** |
|
| 299 | + * Check if in module list can have this language |
|
| 300 | + * @param string $language the language name |
|
| 301 | + * @param string $module the module name |
|
| 302 | + * @param string $appLang the application language like 'en', 'fr' |
|
| 303 | + * @return boolean|string false or null if no module have this language, return the full path of this language |
|
| 304 | + */ |
|
| 305 | + public static function findLanguageFullPath($language, $module = null, $appLang){ |
|
| 306 | + $logger = self::getLogger(); |
|
| 307 | + if(! self::hasModule()){ |
|
| 308 | + $logger->info('No module was loaded skiping.'); |
|
| 309 | + return false; |
|
| 310 | + } |
|
| 311 | + $language = str_ireplace('.php', '', $language); |
|
| 312 | + $language = str_ireplace('lang_', '', $language); |
|
| 313 | + $file = 'lang_'.$language.'.php'; |
|
| 314 | + $logger->debug('Checking language [' . $language . '] in module [' .$module. '] ...'); |
|
| 315 | + $filePath = MODULE_PATH . $module . DS . 'lang' . DS . $appLang . DS . $file; |
|
| 316 | + if(file_exists($filePath)){ |
|
| 317 | + $logger->info('Found language [' . $language . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
| 318 | + return $filePath; |
|
| 319 | + } |
|
| 320 | + else{ |
|
| 321 | + $logger->info('Language [' . $language . '] does not exist in the module [' .$module. ']'); |
|
| 322 | + return false; |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | 325 | |
| 326 | - /** |
|
| 327 | - * Get the list of module loaded |
|
| 328 | - * @return array the module list |
|
| 329 | - */ |
|
| 330 | - public static function getModuleList(){ |
|
| 331 | - return self::$list; |
|
| 332 | - } |
|
| 326 | + /** |
|
| 327 | + * Get the list of module loaded |
|
| 328 | + * @return array the module list |
|
| 329 | + */ |
|
| 330 | + public static function getModuleList(){ |
|
| 331 | + return self::$list; |
|
| 332 | + } |
|
| 333 | 333 | |
| 334 | - /** |
|
| 335 | - * Check if the application has an module |
|
| 336 | - * @return boolean |
|
| 337 | - */ |
|
| 338 | - public static function hasModule(){ |
|
| 339 | - return !empty(self::$list); |
|
| 340 | - } |
|
| 334 | + /** |
|
| 335 | + * Check if the application has an module |
|
| 336 | + * @return boolean |
|
| 337 | + */ |
|
| 338 | + public static function hasModule(){ |
|
| 339 | + return !empty(self::$list); |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | - } |
|
| 342 | + } |
|
@@ -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,161 +1,161 @@ |
||
| 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{ |
|
| 27 | + class Security{ |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * The logger instance |
|
| 31 | - * @var Log |
|
| 32 | - */ |
|
| 33 | - private static $logger; |
|
| 29 | + /** |
|
| 30 | + * The logger instance |
|
| 31 | + * @var Log |
|
| 32 | + */ |
|
| 33 | + private static $logger; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Get the logger singleton instance |
|
| 37 | - * @return Log the logger instance |
|
| 38 | - */ |
|
| 39 | - private static function getLogger(){ |
|
| 40 | - if(self::$logger == null){ |
|
| 41 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 42 | - self::$logger[0]->setLogger('Library::Security'); |
|
| 43 | - } |
|
| 44 | - return self::$logger[0]; |
|
| 45 | - } |
|
| 35 | + /** |
|
| 36 | + * Get the logger singleton instance |
|
| 37 | + * @return Log the logger instance |
|
| 38 | + */ |
|
| 39 | + private static function getLogger(){ |
|
| 40 | + if(self::$logger == null){ |
|
| 41 | + self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 42 | + self::$logger[0]->setLogger('Library::Security'); |
|
| 43 | + } |
|
| 44 | + return self::$logger[0]; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * This method is used to generate the CSRF token |
|
| 50 | - * @return string the generated CSRF token |
|
| 51 | - */ |
|
| 52 | - public static function generateCSRF(){ |
|
| 53 | - $logger = self::getLogger(); |
|
| 54 | - $logger->debug('Generation of CSRF ...'); |
|
| 48 | + /** |
|
| 49 | + * This method is used to generate the CSRF token |
|
| 50 | + * @return string the generated CSRF token |
|
| 51 | + */ |
|
| 52 | + public static function generateCSRF(){ |
|
| 53 | + $logger = self::getLogger(); |
|
| 54 | + $logger->debug('Generation of CSRF ...'); |
|
| 55 | 55 | |
| 56 | - $key = get_config('csrf_key', 'csrf_key'); |
|
| 57 | - $expire = get_config('csrf_expire', 60); |
|
| 58 | - $keyExpire = 'csrf_expire'; |
|
| 59 | - $currentTime = time(); |
|
| 60 | - if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){ |
|
| 61 | - $logger->info('The CSRF token not yet expire just return it'); |
|
| 62 | - return Session::get($key); |
|
| 63 | - } |
|
| 64 | - else{ |
|
| 65 | - $newTime = $currentTime + $expire; |
|
| 66 | - $token = sha1(uniqid()) . sha1(uniqid()); |
|
| 67 | - $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']'); |
|
| 68 | - Session::set($keyExpire, $newTime); |
|
| 69 | - Session::set($key, $token); |
|
| 70 | - return Session::get($key); |
|
| 71 | - } |
|
| 72 | - } |
|
| 56 | + $key = get_config('csrf_key', 'csrf_key'); |
|
| 57 | + $expire = get_config('csrf_expire', 60); |
|
| 58 | + $keyExpire = 'csrf_expire'; |
|
| 59 | + $currentTime = time(); |
|
| 60 | + if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){ |
|
| 61 | + $logger->info('The CSRF token not yet expire just return it'); |
|
| 62 | + return Session::get($key); |
|
| 63 | + } |
|
| 64 | + else{ |
|
| 65 | + $newTime = $currentTime + $expire; |
|
| 66 | + $token = sha1(uniqid()) . sha1(uniqid()); |
|
| 67 | + $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']'); |
|
| 68 | + Session::set($keyExpire, $newTime); |
|
| 69 | + Session::set($key, $token); |
|
| 70 | + return Session::get($key); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * This method is used to check the CSRF if is valid, not yet expire, etc. |
|
| 76 | - * @return boolean true if valid, false if not valid |
|
| 77 | - */ |
|
| 78 | - public static function validateCSRF(){ |
|
| 79 | - $logger = self::getLogger(); |
|
| 80 | - $logger->debug('Validation of CSRF ...'); |
|
| 74 | + /** |
|
| 75 | + * This method is used to check the CSRF if is valid, not yet expire, etc. |
|
| 76 | + * @return boolean true if valid, false if not valid |
|
| 77 | + */ |
|
| 78 | + public static function validateCSRF(){ |
|
| 79 | + $logger = self::getLogger(); |
|
| 80 | + $logger->debug('Validation of CSRF ...'); |
|
| 81 | 81 | |
| 82 | - $key = get_config('csrf_key', 'csrf_key'); |
|
| 83 | - $expire = get_config('csrf_expire', 60); |
|
| 84 | - $keyExpire = 'csrf_expire'; |
|
| 85 | - $currentTime = time(); |
|
| 86 | - $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. ']'); |
|
| 87 | - if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){ |
|
| 88 | - $logger->warning('The CSRF session data is not valide'); |
|
| 89 | - return false; |
|
| 90 | - } |
|
| 91 | - else{ |
|
| 92 | - //perform form data |
|
| 93 | - //need use request->query() for best retrieve |
|
| 94 | - //super instance |
|
| 95 | - $obj = & get_instance(); |
|
| 96 | - $token = $obj->request->query($key); |
|
| 97 | - if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){ |
|
| 98 | - $logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job'); |
|
| 99 | - return false; |
|
| 100 | - } |
|
| 101 | - else{ |
|
| 102 | - $logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue'); |
|
| 103 | - //remove the token from session |
|
| 104 | - Session::clear($key); |
|
| 105 | - Session::clear($keyExpire); |
|
| 106 | - return true; |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - } |
|
| 82 | + $key = get_config('csrf_key', 'csrf_key'); |
|
| 83 | + $expire = get_config('csrf_expire', 60); |
|
| 84 | + $keyExpire = 'csrf_expire'; |
|
| 85 | + $currentTime = time(); |
|
| 86 | + $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. ']'); |
|
| 87 | + if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){ |
|
| 88 | + $logger->warning('The CSRF session data is not valide'); |
|
| 89 | + return false; |
|
| 90 | + } |
|
| 91 | + else{ |
|
| 92 | + //perform form data |
|
| 93 | + //need use request->query() for best retrieve |
|
| 94 | + //super instance |
|
| 95 | + $obj = & get_instance(); |
|
| 96 | + $token = $obj->request->query($key); |
|
| 97 | + if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){ |
|
| 98 | + $logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job'); |
|
| 99 | + return false; |
|
| 100 | + } |
|
| 101 | + else{ |
|
| 102 | + $logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue'); |
|
| 103 | + //remove the token from session |
|
| 104 | + Session::clear($key); |
|
| 105 | + Session::clear($keyExpire); |
|
| 106 | + return true; |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * This method is used to check the whitelist IP address access |
|
| 113 | - */ |
|
| 114 | - public static function checkWhiteListIpAccess(){ |
|
| 115 | - $logger = self::getLogger(); |
|
| 116 | - $logger->debug('Validation of the IP address access ...'); |
|
| 117 | - $logger->debug('Check if whitelist IP access is enabled in the configuration ...'); |
|
| 118 | - $isEnable = get_config('white_list_ip_enable', false); |
|
| 119 | - if($isEnable){ |
|
| 120 | - $logger->info('Whitelist IP access is enabled in the configuration'); |
|
| 121 | - $list = get_config('white_list_ip_addresses', array()); |
|
| 122 | - if(! empty($list)){ |
|
| 123 | - //Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing |
|
| 124 | - require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
|
| 125 | - $ip = get_ip(); |
|
| 126 | - if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){ |
|
| 127 | - $logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP'); |
|
| 128 | - //wildcard to access all ip address |
|
| 129 | - return; |
|
| 130 | - } |
|
| 131 | - else{ |
|
| 132 | - // go through all whitelisted ips |
|
| 133 | - foreach ($list as $ipaddr) { |
|
| 134 | - // find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*") |
|
| 135 | - $wildcardPosition = strpos($ipaddr, '*'); |
|
| 136 | - if ($wildcardPosition === false) { |
|
| 137 | - // no wild card in whitelisted ip --continue searching |
|
| 138 | - continue; |
|
| 139 | - } |
|
| 140 | - // cut ip at the position where we got the wild card on the whitelisted ip |
|
| 141 | - // and add the wold card to get the same pattern |
|
| 142 | - if (substr($ip, 0, $wildcardPosition) . '*' === $ipaddr) { |
|
| 143 | - // f.e. we got |
|
| 144 | - // ip "127.0.0.1" |
|
| 145 | - // whitelisted ip "127.0.*" |
|
| 146 | - // then we compared "127.0.*" with "127.0.*" |
|
| 147 | - // return success |
|
| 148 | - $logger->info('IP address ' . $ip . ' allowed using the wildcard like "x.x.x.*"'); |
|
| 149 | - return; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - $logger->warning('IP address ' . $ip . ' is not allowed to access to this application'); |
|
| 153 | - show_error('Access to this application is not allowed'); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - else{ |
|
| 158 | - $logger->info('Whitelist IP access is not enabled in the configuration, ignore checking'); |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - } |
|
| 111 | + /** |
|
| 112 | + * This method is used to check the whitelist IP address access |
|
| 113 | + */ |
|
| 114 | + public static function checkWhiteListIpAccess(){ |
|
| 115 | + $logger = self::getLogger(); |
|
| 116 | + $logger->debug('Validation of the IP address access ...'); |
|
| 117 | + $logger->debug('Check if whitelist IP access is enabled in the configuration ...'); |
|
| 118 | + $isEnable = get_config('white_list_ip_enable', false); |
|
| 119 | + if($isEnable){ |
|
| 120 | + $logger->info('Whitelist IP access is enabled in the configuration'); |
|
| 121 | + $list = get_config('white_list_ip_addresses', array()); |
|
| 122 | + if(! empty($list)){ |
|
| 123 | + //Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing |
|
| 124 | + require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
|
| 125 | + $ip = get_ip(); |
|
| 126 | + if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){ |
|
| 127 | + $logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP'); |
|
| 128 | + //wildcard to access all ip address |
|
| 129 | + return; |
|
| 130 | + } |
|
| 131 | + else{ |
|
| 132 | + // go through all whitelisted ips |
|
| 133 | + foreach ($list as $ipaddr) { |
|
| 134 | + // find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*") |
|
| 135 | + $wildcardPosition = strpos($ipaddr, '*'); |
|
| 136 | + if ($wildcardPosition === false) { |
|
| 137 | + // no wild card in whitelisted ip --continue searching |
|
| 138 | + continue; |
|
| 139 | + } |
|
| 140 | + // cut ip at the position where we got the wild card on the whitelisted ip |
|
| 141 | + // and add the wold card to get the same pattern |
|
| 142 | + if (substr($ip, 0, $wildcardPosition) . '*' === $ipaddr) { |
|
| 143 | + // f.e. we got |
|
| 144 | + // ip "127.0.0.1" |
|
| 145 | + // whitelisted ip "127.0.*" |
|
| 146 | + // then we compared "127.0.*" with "127.0.*" |
|
| 147 | + // return success |
|
| 148 | + $logger->info('IP address ' . $ip . ' allowed using the wildcard like "x.x.x.*"'); |
|
| 149 | + return; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + $logger->warning('IP address ' . $ip . ' is not allowed to access to this application'); |
|
| 153 | + show_error('Access to this application is not allowed'); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + else{ |
|
| 158 | + $logger->info('Whitelist IP access is not enabled in the configuration, ignore checking'); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + } |
|
@@ -1,43 +1,43 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | defined('ROOT_PATH') || exit('Access denied'); |
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 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 DatabaseQueryResult{ |
|
| 27 | + class DatabaseQueryResult{ |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * The database query result |
|
| 31 | - * @var mixed |
|
| 32 | - */ |
|
| 33 | - private $result = null; |
|
| 29 | + /** |
|
| 30 | + * The database query result |
|
| 31 | + * @var mixed |
|
| 32 | + */ |
|
| 33 | + private $result = null; |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * The number of rows returned by the last query |
|
| 38 | - * @var int |
|
| 39 | - */ |
|
| 40 | - private $numRows = 0; |
|
| 36 | + /** |
|
| 37 | + * The number of rows returned by the last query |
|
| 38 | + * @var int |
|
| 39 | + */ |
|
| 40 | + private $numRows = 0; |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -51,24 +51,24 @@ discard block |
||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Return the query result |
|
| 56 | - * |
|
| 57 | - * @return mixed |
|
| 58 | - */ |
|
| 54 | + /** |
|
| 55 | + * Return the query result |
|
| 56 | + * |
|
| 57 | + * @return mixed |
|
| 58 | + */ |
|
| 59 | 59 | public function getResult(){ |
| 60 | - return $this->result; |
|
| 60 | + return $this->result; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * Set the query result |
| 65 | 65 | * @param mixed $result the query result |
| 66 | 66 | * |
| 67 | - * @return object DatabaseQueryResult |
|
| 67 | + * @return object DatabaseQueryResult |
|
| 68 | 68 | */ |
| 69 | 69 | public function setResult($result){ |
| 70 | - $this->result = $result; |
|
| 71 | - return $this; |
|
| 70 | + $this->result = $result; |
|
| 71 | + return $this; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -77,18 +77,18 @@ discard block |
||
| 77 | 77 | * @return int |
| 78 | 78 | */ |
| 79 | 79 | public function getNumRows(){ |
| 80 | - return $this->numRows; |
|
| 80 | + return $this->numRows; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
| 84 | 84 | * Set the number of rows returned by the query |
| 85 | 85 | * @param int $numRows the number of rows returned |
| 86 | 86 | * |
| 87 | - * @return object DatabaseQueryResult |
|
| 87 | + * @return object DatabaseQueryResult |
|
| 88 | 88 | */ |
| 89 | 89 | public function setNumRows($numRows){ |
| 90 | - $this->numRows = $numRows; |
|
| 91 | - return $this; |
|
| 90 | + $this->numRows = $numRows; |
|
| 91 | + return $this; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | } |
@@ -1,108 +1,108 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | defined('ROOT_PATH') || exit('Access denied'); |
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 26 | - class DatabaseQueryBuilder{ |
|
| 27 | - /** |
|
| 28 | - * The SQL SELECT statment |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - private $select = '*'; |
|
| 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 DatabaseQueryBuilder{ |
|
| 27 | + /** |
|
| 28 | + * The SQL SELECT statment |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + private $select = '*'; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * The SQL FROM statment |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 37 | - private $from = null; |
|
| 33 | + /** |
|
| 34 | + * The SQL FROM statment |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | + private $from = null; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * The SQL WHERE statment |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 43 | - private $where = null; |
|
| 39 | + /** |
|
| 40 | + * The SQL WHERE statment |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | + private $where = null; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * The SQL LIMIT statment |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - private $limit = null; |
|
| 45 | + /** |
|
| 46 | + * The SQL LIMIT statment |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + private $limit = null; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * The SQL JOIN statment |
|
| 53 | - * @var string |
|
| 54 | - */ |
|
| 55 | - private $join = null; |
|
| 51 | + /** |
|
| 52 | + * The SQL JOIN statment |
|
| 53 | + * @var string |
|
| 54 | + */ |
|
| 55 | + private $join = null; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * The SQL ORDER BY statment |
|
| 59 | - * @var string |
|
| 60 | - */ |
|
| 61 | - private $orderBy = null; |
|
| 57 | + /** |
|
| 58 | + * The SQL ORDER BY statment |
|
| 59 | + * @var string |
|
| 60 | + */ |
|
| 61 | + private $orderBy = null; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * The SQL GROUP BY statment |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 67 | - private $groupBy = null; |
|
| 63 | + /** |
|
| 64 | + * The SQL GROUP BY statment |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | + private $groupBy = null; |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * The SQL HAVING statment |
|
| 71 | - * @var string |
|
| 72 | - */ |
|
| 73 | - private $having = null; |
|
| 69 | + /** |
|
| 70 | + * The SQL HAVING statment |
|
| 71 | + * @var string |
|
| 72 | + */ |
|
| 73 | + private $having = null; |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * The full SQL query statment after build for each command |
|
| 77 | - * @var string |
|
| 78 | - */ |
|
| 79 | - private $query = null; |
|
| 75 | + /** |
|
| 76 | + * The full SQL query statment after build for each command |
|
| 77 | + * @var string |
|
| 78 | + */ |
|
| 79 | + private $query = null; |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * The list of SQL valid operators |
|
| 83 | - * @var array |
|
| 84 | - */ |
|
| 81 | + /** |
|
| 82 | + * The list of SQL valid operators |
|
| 83 | + * @var array |
|
| 84 | + */ |
|
| 85 | 85 | private $operatorList = array('=','!=','<','>','<=','>=','<>'); |
| 86 | 86 | |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * The prefix used in each database table |
|
| 90 | - * @var string |
|
| 91 | - */ |
|
| 88 | + /** |
|
| 89 | + * The prefix used in each database table |
|
| 90 | + * @var string |
|
| 91 | + */ |
|
| 92 | 92 | private $prefix = null; |
| 93 | 93 | |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | - * The PDO instance |
|
| 97 | - * @var object |
|
| 98 | - */ |
|
| 96 | + * The PDO instance |
|
| 97 | + * @var object |
|
| 98 | + */ |
|
| 99 | 99 | private $pdo = null; |
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * The database driver name used |
|
| 103 | - * @var string |
|
| 104 | - */ |
|
| 105 | - private $driver = null; |
|
| 101 | + /** |
|
| 102 | + * The database driver name used |
|
| 103 | + * @var string |
|
| 104 | + */ |
|
| 105 | + private $driver = null; |
|
| 106 | 106 | |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | public function __construct(PDO $pdo = null){ |
| 113 | 113 | if (is_object($pdo)){ |
| 114 | - $this->setPdo($pdo); |
|
| 114 | + $this->setPdo($pdo); |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
@@ -121,16 +121,16 @@ discard block |
||
| 121 | 121 | * @return object the current DatabaseQueryBuilder instance |
| 122 | 122 | */ |
| 123 | 123 | public function from($table){ |
| 124 | - if (is_array($table)){ |
|
| 124 | + if (is_array($table)){ |
|
| 125 | 125 | $froms = ''; |
| 126 | 126 | foreach($table as $key){ |
| 127 | - $froms .= $this->getPrefix() . $key . ', '; |
|
| 127 | + $froms .= $this->getPrefix() . $key . ', '; |
|
| 128 | 128 | } |
| 129 | 129 | $this->from = rtrim($froms, ', '); |
| 130 | - } else { |
|
| 130 | + } else { |
|
| 131 | 131 | $this->from = $this->getPrefix() . $table; |
| 132 | - } |
|
| 133 | - return $this; |
|
| 132 | + } |
|
| 133 | + return $this; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -139,9 +139,9 @@ discard block |
||
| 139 | 139 | * @return object the current DatabaseQueryBuilder instance |
| 140 | 140 | */ |
| 141 | 141 | public function select($fields){ |
| 142 | - $select = (is_array($fields) ? implode(', ', $fields) : $fields); |
|
| 143 | - $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select); |
|
| 144 | - return $this; |
|
| 142 | + $select = (is_array($fields) ? implode(', ', $fields) : $fields); |
|
| 143 | + $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select); |
|
| 144 | + return $this; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -150,19 +150,19 @@ discard block |
||
| 150 | 150 | * @return object the current DatabaseQueryBuilder instance |
| 151 | 151 | */ |
| 152 | 152 | public function distinct($field){ |
| 153 | - $distinct = ' DISTINCT ' . $field; |
|
| 154 | - $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct); |
|
| 155 | - return $this; |
|
| 153 | + $distinct = ' DISTINCT ' . $field; |
|
| 154 | + $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct); |
|
| 155 | + return $this; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * Set the SQL function COUNT in SELECT statment |
|
| 160 | - * @param string $field the field name |
|
| 161 | - * @param string $name if is not null represent the alias used for this field in the result |
|
| 162 | - * @return object the current DatabaseQueryBuilder instance |
|
| 163 | - */ |
|
| 158 | + /** |
|
| 159 | + * Set the SQL function COUNT in SELECT statment |
|
| 160 | + * @param string $field the field name |
|
| 161 | + * @param string $name if is not null represent the alias used for this field in the result |
|
| 162 | + * @return object the current DatabaseQueryBuilder instance |
|
| 163 | + */ |
|
| 164 | 164 | public function count($field = '*', $name = null){ |
| 165 | - return $this->select_min_max_sum_count_avg('COUNT', $field, $name); |
|
| 165 | + return $this->select_min_max_sum_count_avg('COUNT', $field, $name); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * @return object the current DatabaseQueryBuilder instance |
| 173 | 173 | */ |
| 174 | 174 | public function min($field, $name = null){ |
| 175 | - return $this->select_min_max_sum_count_avg('MIN', $field, $name); |
|
| 175 | + return $this->select_min_max_sum_count_avg('MIN', $field, $name); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * @return object the current DatabaseQueryBuilder instance |
| 183 | 183 | */ |
| 184 | 184 | public function max($field, $name = null){ |
| 185 | - return $this->select_min_max_sum_count_avg('MAX', $field, $name); |
|
| 185 | + return $this->select_min_max_sum_count_avg('MAX', $field, $name); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | * @return object the current DatabaseQueryBuilder instance |
| 193 | 193 | */ |
| 194 | 194 | public function sum($field, $name = null){ |
| 195 | - return $this->select_min_max_sum_count_avg('SUM', $field, $name); |
|
| 195 | + return $this->select_min_max_sum_count_avg('SUM', $field, $name); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | /** |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @return object the current DatabaseQueryBuilder instance |
| 203 | 203 | */ |
| 204 | 204 | public function avg($field, $name = null){ |
| 205 | - return $this->select_min_max_sum_count_avg('AVG', $field, $name); |
|
| 205 | + return $this->select_min_max_sum_count_avg('AVG', $field, $name); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | |
@@ -216,20 +216,20 @@ 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 | - } |
|
| 229 | - else{ |
|
| 228 | + } |
|
| 229 | + else{ |
|
| 230 | 230 | $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
| 231 | - } |
|
| 232 | - return $this; |
|
| 231 | + } |
|
| 232 | + return $this; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | * @return object the current DatabaseQueryBuilder instance |
| 239 | 239 | */ |
| 240 | 240 | public function innerJoin($table, $field1, $op = null, $field2 = ''){ |
| 241 | - return $this->join($table, $field1, $op, $field2, 'INNER '); |
|
| 241 | + return $this->join($table, $field1, $op, $field2, 'INNER '); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -247,16 +247,16 @@ discard block |
||
| 247 | 247 | * @return object the current DatabaseQueryBuilder instance |
| 248 | 248 | */ |
| 249 | 249 | public function leftJoin($table, $field1, $op = null, $field2 = ''){ |
| 250 | - return $this->join($table, $field1, $op, $field2, 'LEFT '); |
|
| 251 | - } |
|
| 250 | + return $this->join($table, $field1, $op, $field2, 'LEFT '); |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 253 | + /** |
|
| 254 | 254 | * Set the SQL RIGHT JOIN statment |
| 255 | 255 | * @see DatabaseQueryBuilder::join() |
| 256 | 256 | * @return object the current DatabaseQueryBuilder instance |
| 257 | 257 | */ |
| 258 | 258 | public function rightJoin($table, $field1, $op = null, $field2 = ''){ |
| 259 | - return $this->join($table, $field1, $op, $field2, 'RIGHT '); |
|
| 259 | + return $this->join($table, $field1, $op, $field2, 'RIGHT '); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | * @return object the current DatabaseQueryBuilder instance |
| 266 | 266 | */ |
| 267 | 267 | public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){ |
| 268 | - return $this->join($table, $field1, $op, $field2, 'FULL OUTER '); |
|
| 268 | + return $this->join($table, $field1, $op, $field2, 'FULL OUTER '); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | * @return object the current DatabaseQueryBuilder instance |
| 275 | 275 | */ |
| 276 | 276 | public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){ |
| 277 | - return $this->join($table, $field1, $op, $field2, 'LEFT OUTER '); |
|
| 277 | + return $this->join($table, $field1, $op, $field2, 'LEFT OUTER '); |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | /** |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * @return object the current DatabaseQueryBuilder instance |
| 284 | 284 | */ |
| 285 | 285 | public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){ |
| 286 | - return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER '); |
|
| 286 | + return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER '); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | /** |
@@ -293,14 +293,14 @@ discard block |
||
| 293 | 293 | * @return object the current DatabaseQueryBuilder instance |
| 294 | 294 | */ |
| 295 | 295 | public function whereIsNull($field, $andOr = 'AND'){ |
| 296 | - if (is_array($field)){ |
|
| 296 | + if (is_array($field)){ |
|
| 297 | 297 | foreach($field as $f){ |
| 298 | - $this->whereIsNull($f, $andOr); |
|
| 298 | + $this->whereIsNull($f, $andOr); |
|
| 299 | 299 | } |
| 300 | - } else { |
|
| 301 | - $this->setWhereStr($field.' IS NULL ', $andOr); |
|
| 302 | - } |
|
| 303 | - return $this; |
|
| 300 | + } else { |
|
| 301 | + $this->setWhereStr($field.' IS NULL ', $andOr); |
|
| 302 | + } |
|
| 303 | + return $this; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -310,14 +310,14 @@ discard block |
||
| 310 | 310 | * @return object the current DatabaseQueryBuilder instance |
| 311 | 311 | */ |
| 312 | 312 | public function whereIsNotNull($field, $andOr = 'AND'){ |
| 313 | - if (is_array($field)){ |
|
| 313 | + if (is_array($field)){ |
|
| 314 | 314 | foreach($field as $f){ |
| 315 | - $this->whereIsNotNull($f, $andOr); |
|
| 315 | + $this->whereIsNotNull($f, $andOr); |
|
| 316 | + } |
|
| 317 | + } else { |
|
| 318 | + $this->setWhereStr($field.' IS NOT NULL ', $andOr); |
|
| 316 | 319 | } |
| 317 | - } else { |
|
| 318 | - $this->setWhereStr($field.' IS NOT NULL ', $andOr); |
|
| 319 | - } |
|
| 320 | - return $this; |
|
| 320 | + return $this; |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
@@ -331,19 +331,19 @@ discard block |
||
| 331 | 331 | * @return object the current DatabaseQueryBuilder instance |
| 332 | 332 | */ |
| 333 | 333 | public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){ |
| 334 | - $whereStr = ''; |
|
| 335 | - if (is_array($where)){ |
|
| 334 | + $whereStr = ''; |
|
| 335 | + if (is_array($where)){ |
|
| 336 | 336 | $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape); |
| 337 | - } |
|
| 338 | - else{ |
|
| 337 | + } |
|
| 338 | + else{ |
|
| 339 | 339 | if (is_array($op)){ |
| 340 | - $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape); |
|
| 340 | + $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape); |
|
| 341 | 341 | } else { |
| 342 | - $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape = true); |
|
| 342 | + $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape = true); |
|
| 343 | + } |
|
| 343 | 344 | } |
| 344 | - } |
|
| 345 | - $this->setWhereStr($whereStr, $andOr); |
|
| 346 | - return $this; |
|
| 345 | + $this->setWhereStr($whereStr, $andOr); |
|
| 346 | + return $this; |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | * @return object the current DatabaseQueryBuilder instance |
| 353 | 353 | */ |
| 354 | 354 | public function orWhere($where, $op = null, $val = null, $escape = true){ |
| 355 | - return $this->where($where, $op, $val, '', 'OR', $escape); |
|
| 355 | + return $this->where($where, $op, $val, '', 'OR', $escape); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | * @return object the current DatabaseQueryBuilder instance |
| 363 | 363 | */ |
| 364 | 364 | public function notWhere($where, $op = null, $val = null, $escape = true){ |
| 365 | - return $this->where($where, $op, $val, 'NOT ', 'AND', $escape); |
|
| 365 | + return $this->where($where, $op, $val, 'NOT ', 'AND', $escape); |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | /** |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | * @return object the current DatabaseQueryBuilder instance |
| 372 | 372 | */ |
| 373 | 373 | public function orNotWhere($where, $op = null, $val = null, $escape = true){ |
| 374 | - return $this->where($where, $op, $val, 'NOT ', 'OR', $escape); |
|
| 374 | + return $this->where($where, $op, $val, 'NOT ', 'OR', $escape); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
@@ -381,16 +381,16 @@ discard block |
||
| 381 | 381 | * @return object the current DatabaseQueryBuilder instance |
| 382 | 382 | */ |
| 383 | 383 | public function groupStart($type = '', $andOr = ' AND'){ |
| 384 | - if (empty($this->where)){ |
|
| 384 | + if (empty($this->where)){ |
|
| 385 | 385 | $this->where = $type . ' ('; |
| 386 | - } else { |
|
| 387 | - if (substr(trim($this->where), -1) == '('){ |
|
| 386 | + } else { |
|
| 387 | + if (substr(trim($this->where), -1) == '('){ |
|
| 388 | 388 | $this->where .= $type . ' ('; |
| 389 | - } else { |
|
| 390 | - $this->where .= $andOr . ' ' . $type . ' ('; |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - return $this; |
|
| 389 | + } else { |
|
| 390 | + $this->where .= $andOr . ' ' . $type . ' ('; |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + return $this; |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | * @return object the current DatabaseQueryBuilder instance |
| 400 | 400 | */ |
| 401 | 401 | public function notGroupStart(){ |
| 402 | - return $this->groupStart('NOT'); |
|
| 402 | + return $this->groupStart('NOT'); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -408,16 +408,16 @@ discard block |
||
| 408 | 408 | * @return object the current DatabaseQueryBuilder instance |
| 409 | 409 | */ |
| 410 | 410 | public function orGroupStart(){ |
| 411 | - return $this->groupStart('', ' OR'); |
|
| 411 | + return $this->groupStart('', ' OR'); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - /** |
|
| 415 | - * Set the opened parenthesis for the complex SQL query using OR for separator and NOT for type |
|
| 416 | - * @see DatabaseQueryBuilder::groupStart() |
|
| 417 | - * @return object the current DatabaseQueryBuilder instance |
|
| 418 | - */ |
|
| 414 | + /** |
|
| 415 | + * Set the opened parenthesis for the complex SQL query using OR for separator and NOT for type |
|
| 416 | + * @see DatabaseQueryBuilder::groupStart() |
|
| 417 | + * @return object the current DatabaseQueryBuilder instance |
|
| 418 | + */ |
|
| 419 | 419 | public function orNotGroupStart(){ |
| 420 | - return $this->groupStart('NOT', ' OR'); |
|
| 420 | + return $this->groupStart('NOT', ' OR'); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -425,8 +425,8 @@ discard block |
||
| 425 | 425 | * @return object the current DatabaseQueryBuilder instance |
| 426 | 426 | */ |
| 427 | 427 | public function groupEnd(){ |
| 428 | - $this->where .= ')'; |
|
| 429 | - return $this; |
|
| 428 | + $this->where .= ')'; |
|
| 429 | + return $this; |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | /** |
@@ -439,17 +439,17 @@ discard block |
||
| 439 | 439 | * @return object the current DatabaseQueryBuilder instance |
| 440 | 440 | */ |
| 441 | 441 | public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){ |
| 442 | - $_keys = array(); |
|
| 443 | - foreach ($keys as $k => $v){ |
|
| 442 | + $_keys = array(); |
|
| 443 | + foreach ($keys as $k => $v){ |
|
| 444 | 444 | if (is_null($v)){ |
| 445 | - $v = ''; |
|
| 445 | + $v = ''; |
|
| 446 | 446 | } |
| 447 | 447 | $_keys[] = (is_numeric($v) ? $v : $this->escape($v, $escape)); |
| 448 | - } |
|
| 449 | - $keys = implode(', ', $_keys); |
|
| 450 | - $whereStr = $field . ' ' . $type . ' IN (' . $keys . ')'; |
|
| 451 | - $this->setWhereStr($whereStr, $andOr); |
|
| 452 | - return $this; |
|
| 448 | + } |
|
| 449 | + $keys = implode(', ', $_keys); |
|
| 450 | + $whereStr = $field . ' ' . $type . ' IN (' . $keys . ')'; |
|
| 451 | + $this->setWhereStr($whereStr, $andOr); |
|
| 452 | + return $this; |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | /** |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | * @return object the current DatabaseQueryBuilder instance |
| 459 | 459 | */ |
| 460 | 460 | public function notIn($field, array $keys, $escape = true){ |
| 461 | - return $this->in($field, $keys, 'NOT ', 'AND', $escape); |
|
| 461 | + return $this->in($field, $keys, 'NOT ', 'AND', $escape); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | /** |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | * @return object the current DatabaseQueryBuilder instance |
| 468 | 468 | */ |
| 469 | 469 | public function orIn($field, array $keys, $escape = true){ |
| 470 | - return $this->in($field, $keys, '', 'OR', $escape); |
|
| 470 | + return $this->in($field, $keys, '', 'OR', $escape); |
|
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | /** |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | * @return object the current DatabaseQueryBuilder instance |
| 477 | 477 | */ |
| 478 | 478 | public function orNotIn($field, array $keys, $escape = true){ |
| 479 | - return $this->in($field, $keys, 'NOT ', 'OR', $escape); |
|
| 479 | + return $this->in($field, $keys, 'NOT ', 'OR', $escape); |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | /** |
@@ -490,15 +490,15 @@ discard block |
||
| 490 | 490 | * @return object the current DatabaseQueryBuilder instance |
| 491 | 491 | */ |
| 492 | 492 | public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){ |
| 493 | - if (is_null($value1)){ |
|
| 493 | + if (is_null($value1)){ |
|
| 494 | 494 | $value1 = ''; |
| 495 | - } |
|
| 496 | - if (is_null($value2)){ |
|
| 495 | + } |
|
| 496 | + if (is_null($value2)){ |
|
| 497 | 497 | $value2 = ''; |
| 498 | - } |
|
| 499 | - $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape); |
|
| 500 | - $this->setWhereStr($whereStr, $andOr); |
|
| 501 | - return $this; |
|
| 498 | + } |
|
| 499 | + $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape); |
|
| 500 | + $this->setWhereStr($whereStr, $andOr); |
|
| 501 | + return $this; |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | /** |
@@ -507,7 +507,7 @@ discard block |
||
| 507 | 507 | * @return object the current DatabaseQueryBuilder instance |
| 508 | 508 | */ |
| 509 | 509 | public function notBetween($field, $value1, $value2, $escape = true){ |
| 510 | - return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape); |
|
| 510 | + return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | /** |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | * @return object the current DatabaseQueryBuilder instance |
| 517 | 517 | */ |
| 518 | 518 | public function orBetween($field, $value1, $value2, $escape = true){ |
| 519 | - return $this->between($field, $value1, $value2, '', 'OR', $escape); |
|
| 519 | + return $this->between($field, $value1, $value2, '', 'OR', $escape); |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | /** |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | * @return object the current DatabaseQueryBuilder instance |
| 526 | 526 | */ |
| 527 | 527 | public function orNotBetween($field, $value1, $value2, $escape = true){ |
| 528 | - return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape); |
|
| 528 | + return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape); |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | /** |
@@ -538,11 +538,11 @@ discard block |
||
| 538 | 538 | * @return object the current DatabaseQueryBuilder instance |
| 539 | 539 | */ |
| 540 | 540 | public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){ |
| 541 | - if (empty($data)){ |
|
| 541 | + if (empty($data)){ |
|
| 542 | 542 | $data = ''; |
| 543 | - } |
|
| 544 | - $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr); |
|
| 545 | - return $this; |
|
| 543 | + } |
|
| 544 | + $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr); |
|
| 545 | + return $this; |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | /** |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | * @return object the current DatabaseQueryBuilder instance |
| 552 | 552 | */ |
| 553 | 553 | public function orLike($field, $data, $escape = true){ |
| 554 | - return $this->like($field, $data, '', 'OR', $escape); |
|
| 554 | + return $this->like($field, $data, '', 'OR', $escape); |
|
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | /** |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | * @return object the current DatabaseQueryBuilder instance |
| 561 | 561 | */ |
| 562 | 562 | public function notLike($field, $data, $escape = true){ |
| 563 | - return $this->like($field, $data, 'NOT ', 'AND', $escape); |
|
| 563 | + return $this->like($field, $data, 'NOT ', 'AND', $escape); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /** |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | * @return object the current DatabaseQueryBuilder instance |
| 570 | 570 | */ |
| 571 | 571 | public function orNotLike($field, $data, $escape = true){ |
| 572 | - return $this->like($field, $data, 'NOT ', 'OR', $escape); |
|
| 572 | + return $this->like($field, $data, 'NOT ', 'OR', $escape); |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
@@ -580,16 +580,16 @@ discard block |
||
| 580 | 580 | * @return object the current DatabaseQueryBuilder instance |
| 581 | 581 | */ |
| 582 | 582 | public function limit($limit, $limitEnd = null){ |
| 583 | - if (empty($limit)){ |
|
| 583 | + if (empty($limit)){ |
|
| 584 | 584 | $limit = 0; |
| 585 | - } |
|
| 586 | - if (! is_null($limitEnd)){ |
|
| 585 | + } |
|
| 586 | + if (! is_null($limitEnd)){ |
|
| 587 | 587 | $this->limit = $limit . ', ' . $limitEnd; |
| 588 | - } |
|
| 589 | - else{ |
|
| 588 | + } |
|
| 589 | + else{ |
|
| 590 | 590 | $this->limit = $limit; |
| 591 | - } |
|
| 592 | - return $this; |
|
| 591 | + } |
|
| 592 | + return $this; |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | /** |
@@ -599,15 +599,15 @@ discard block |
||
| 599 | 599 | * @return object the current DatabaseQueryBuilder instance |
| 600 | 600 | */ |
| 601 | 601 | public function orderBy($orderBy, $orderDir = ' ASC'){ |
| 602 | - if (stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
|
| 602 | + if (stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
|
| 603 | 603 | $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy; |
| 604 | - } |
|
| 605 | - else{ |
|
| 604 | + } |
|
| 605 | + else{ |
|
| 606 | 606 | $this->orderBy = empty($this->orderBy) |
| 607 | - ? ($orderBy . ' ' . strtoupper($orderDir)) |
|
| 608 | - : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
|
| 609 | - } |
|
| 610 | - return $this; |
|
| 607 | + ? ($orderBy . ' ' . strtoupper($orderDir)) |
|
| 608 | + : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
|
| 609 | + } |
|
| 610 | + return $this; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -616,13 +616,13 @@ discard block |
||
| 616 | 616 | * @return object the current DatabaseQueryBuilder instance |
| 617 | 617 | */ |
| 618 | 618 | public function groupBy($field){ |
| 619 | - if (is_array($field)){ |
|
| 619 | + if (is_array($field)){ |
|
| 620 | 620 | $this->groupBy = implode(', ', $field); |
| 621 | - } |
|
| 622 | - else{ |
|
| 621 | + } |
|
| 622 | + else{ |
|
| 623 | 623 | $this->groupBy = $field; |
| 624 | - } |
|
| 625 | - return $this; |
|
| 624 | + } |
|
| 625 | + return $this; |
|
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | /** |
@@ -634,22 +634,22 @@ discard block |
||
| 634 | 634 | * @return object the current DatabaseQueryBuilder instance |
| 635 | 635 | */ |
| 636 | 636 | public function having($field, $op = null, $val = null, $escape = true){ |
| 637 | - if (is_array($op)){ |
|
| 637 | + if (is_array($op)){ |
|
| 638 | 638 | $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape); |
| 639 | - } |
|
| 640 | - else if (! in_array($op, $this->operatorList)){ |
|
| 639 | + } |
|
| 640 | + else if (! in_array($op, $this->operatorList)){ |
|
| 641 | 641 | if (is_null($op)){ |
| 642 | - $op = ''; |
|
| 642 | + $op = ''; |
|
| 643 | 643 | } |
| 644 | 644 | $this->having = $field . ' > ' . ($this->escape($op, $escape)); |
| 645 | - } |
|
| 646 | - else{ |
|
| 645 | + } |
|
| 646 | + else{ |
|
| 647 | 647 | if (is_null($val)){ |
| 648 | - $val = ''; |
|
| 648 | + $val = ''; |
|
| 649 | 649 | } |
| 650 | 650 | $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape)); |
| 651 | - } |
|
| 652 | - return $this; |
|
| 651 | + } |
|
| 652 | + return $this; |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | /** |
@@ -659,12 +659,12 @@ discard block |
||
| 659 | 659 | * @return object the current DatabaseQueryBuilder instance |
| 660 | 660 | */ |
| 661 | 661 | public function insert($data = array(), $escape = true){ |
| 662 | - $columns = array_keys($data); |
|
| 663 | - $column = implode(', ', $columns); |
|
| 664 | - $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data)); |
|
| 662 | + $columns = array_keys($data); |
|
| 663 | + $column = implode(', ', $columns); |
|
| 664 | + $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data)); |
|
| 665 | 665 | |
| 666 | - $this->query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')'; |
|
| 667 | - return $this; |
|
| 666 | + $this->query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')'; |
|
| 667 | + return $this; |
|
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | /** |
@@ -674,25 +674,25 @@ discard block |
||
| 674 | 674 | * @return object the current DatabaseQueryBuilder instance |
| 675 | 675 | */ |
| 676 | 676 | public function update($data = array(), $escape = true){ |
| 677 | - $query = 'UPDATE ' . $this->from . ' SET '; |
|
| 678 | - $values = array(); |
|
| 679 | - foreach ($data as $column => $val){ |
|
| 677 | + $query = 'UPDATE ' . $this->from . ' SET '; |
|
| 678 | + $values = array(); |
|
| 679 | + foreach ($data as $column => $val){ |
|
| 680 | 680 | $values[] = $column . ' = ' . ($this->escape($val, $escape)); |
| 681 | - } |
|
| 682 | - $query .= implode(', ', $values); |
|
| 683 | - if (! empty($this->where)){ |
|
| 681 | + } |
|
| 682 | + $query .= implode(', ', $values); |
|
| 683 | + if (! empty($this->where)){ |
|
| 684 | 684 | $query .= ' WHERE ' . $this->where; |
| 685 | - } |
|
| 685 | + } |
|
| 686 | 686 | |
| 687 | - if (! empty($this->orderBy)){ |
|
| 687 | + if (! empty($this->orderBy)){ |
|
| 688 | 688 | $query .= ' ORDER BY ' . $this->orderBy; |
| 689 | - } |
|
| 689 | + } |
|
| 690 | 690 | |
| 691 | - if (! empty($this->limit)){ |
|
| 691 | + if (! empty($this->limit)){ |
|
| 692 | 692 | $query .= ' LIMIT ' . $this->limit; |
| 693 | - } |
|
| 694 | - $this->query = $query; |
|
| 695 | - return $this; |
|
| 693 | + } |
|
| 694 | + $this->query = $query; |
|
| 695 | + return $this; |
|
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | /** |
@@ -700,25 +700,25 @@ discard block |
||
| 700 | 700 | * @return object the current DatabaseQueryBuilder instance |
| 701 | 701 | */ |
| 702 | 702 | public function delete(){ |
| 703 | - $query = 'DELETE FROM ' . $this->from; |
|
| 704 | - $isTruncate = $query; |
|
| 705 | - if (! empty($this->where)){ |
|
| 706 | - $query .= ' WHERE ' . $this->where; |
|
| 707 | - } |
|
| 703 | + $query = 'DELETE FROM ' . $this->from; |
|
| 704 | + $isTruncate = $query; |
|
| 705 | + if (! empty($this->where)){ |
|
| 706 | + $query .= ' WHERE ' . $this->where; |
|
| 707 | + } |
|
| 708 | 708 | |
| 709 | - if (! empty($this->orderBy)){ |
|
| 710 | - $query .= ' ORDER BY ' . $this->orderBy; |
|
| 711 | - } |
|
| 709 | + if (! empty($this->orderBy)){ |
|
| 710 | + $query .= ' ORDER BY ' . $this->orderBy; |
|
| 711 | + } |
|
| 712 | 712 | |
| 713 | - if (! empty($this->limit)){ |
|
| 714 | - $query .= ' LIMIT ' . $this->limit; |
|
| 715 | - } |
|
| 713 | + if (! empty($this->limit)){ |
|
| 714 | + $query .= ' LIMIT ' . $this->limit; |
|
| 715 | + } |
|
| 716 | 716 | |
| 717 | - if ($isTruncate == $query && $this->driver != 'sqlite'){ |
|
| 718 | - $query = 'TRUNCATE TABLE ' . $this->from; |
|
| 719 | - } |
|
| 720 | - $this->query = $query; |
|
| 721 | - return $this; |
|
| 717 | + if ($isTruncate == $query && $this->driver != 'sqlite'){ |
|
| 718 | + $query = 'TRUNCATE TABLE ' . $this->from; |
|
| 719 | + } |
|
| 720 | + $this->query = $query; |
|
| 721 | + return $this; |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | /** |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | * @return mixed the data after escaped or the same data if not |
| 729 | 729 | */ |
| 730 | 730 | public function escape($data, $escaped = true){ |
| 731 | - return $escaped |
|
| 731 | + return $escaped |
|
| 732 | 732 | ? $this->getPdo()->quote(trim($data)) |
| 733 | 733 | : $data; |
| 734 | 734 | } |
@@ -739,126 +739,126 @@ discard block |
||
| 739 | 739 | * @return string |
| 740 | 740 | */ |
| 741 | 741 | public function getQuery(){ |
| 742 | - //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now |
|
| 743 | - if(empty($this->query)){ |
|
| 744 | - $query = 'SELECT ' . $this->select . ' FROM ' . $this->from; |
|
| 745 | - if (! empty($this->join)){ |
|
| 746 | - $query .= $this->join; |
|
| 747 | - } |
|
| 742 | + //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now |
|
| 743 | + if(empty($this->query)){ |
|
| 744 | + $query = 'SELECT ' . $this->select . ' FROM ' . $this->from; |
|
| 745 | + if (! empty($this->join)){ |
|
| 746 | + $query .= $this->join; |
|
| 747 | + } |
|
| 748 | 748 | |
| 749 | - if (! empty($this->where)){ |
|
| 750 | - $query .= ' WHERE ' . $this->where; |
|
| 751 | - } |
|
| 749 | + if (! empty($this->where)){ |
|
| 750 | + $query .= ' WHERE ' . $this->where; |
|
| 751 | + } |
|
| 752 | 752 | |
| 753 | - if (! empty($this->groupBy)){ |
|
| 754 | - $query .= ' GROUP BY ' . $this->groupBy; |
|
| 755 | - } |
|
| 753 | + if (! empty($this->groupBy)){ |
|
| 754 | + $query .= ' GROUP BY ' . $this->groupBy; |
|
| 755 | + } |
|
| 756 | 756 | |
| 757 | - if (! empty($this->having)){ |
|
| 758 | - $query .= ' HAVING ' . $this->having; |
|
| 759 | - } |
|
| 757 | + if (! empty($this->having)){ |
|
| 758 | + $query .= ' HAVING ' . $this->having; |
|
| 759 | + } |
|
| 760 | 760 | |
| 761 | - if (! empty($this->orderBy)){ |
|
| 762 | - $query .= ' ORDER BY ' . $this->orderBy; |
|
| 763 | - } |
|
| 761 | + if (! empty($this->orderBy)){ |
|
| 762 | + $query .= ' ORDER BY ' . $this->orderBy; |
|
| 763 | + } |
|
| 764 | 764 | |
| 765 | - if (! empty($this->limit)){ |
|
| 766 | - $query .= ' LIMIT ' . $this->limit; |
|
| 767 | - } |
|
| 768 | - $this->query = $query; |
|
| 769 | - } |
|
| 770 | - return $this->query; |
|
| 765 | + if (! empty($this->limit)){ |
|
| 766 | + $query .= ' LIMIT ' . $this->limit; |
|
| 767 | + } |
|
| 768 | + $this->query = $query; |
|
| 769 | + } |
|
| 770 | + return $this->query; |
|
| 771 | 771 | } |
| 772 | 772 | |
| 773 | 773 | |
| 774 | - /** |
|
| 775 | - * Return the PDO instance |
|
| 776 | - * @return object |
|
| 777 | - */ |
|
| 774 | + /** |
|
| 775 | + * Return the PDO instance |
|
| 776 | + * @return object |
|
| 777 | + */ |
|
| 778 | 778 | public function getPdo(){ |
| 779 | - return $this->pdo; |
|
| 779 | + return $this->pdo; |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | /** |
| 783 | 783 | * Set the PDO instance |
| 784 | 784 | * @param PDO $pdo the pdo object |
| 785 | - * @return object DatabaseQueryBuilder |
|
| 785 | + * @return object DatabaseQueryBuilder |
|
| 786 | 786 | */ |
| 787 | 787 | public function setPdo(PDO $pdo = null){ |
| 788 | - $this->pdo = $pdo; |
|
| 789 | - return $this; |
|
| 788 | + $this->pdo = $pdo; |
|
| 789 | + return $this; |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | - /** |
|
| 793 | - * Return the database table prefix |
|
| 794 | - * @return string |
|
| 795 | - */ |
|
| 792 | + /** |
|
| 793 | + * Return the database table prefix |
|
| 794 | + * @return string |
|
| 795 | + */ |
|
| 796 | 796 | public function getPrefix(){ |
| 797 | - return $this->prefix; |
|
| 797 | + return $this->prefix; |
|
| 798 | 798 | } |
| 799 | 799 | |
| 800 | 800 | /** |
| 801 | 801 | * Set the database table prefix |
| 802 | 802 | * @param string $prefix the new prefix |
| 803 | - * @return object DatabaseQueryBuilder |
|
| 803 | + * @return object DatabaseQueryBuilder |
|
| 804 | 804 | */ |
| 805 | 805 | public function setPrefix($prefix){ |
| 806 | - $this->prefix = $prefix; |
|
| 807 | - return $this; |
|
| 806 | + $this->prefix = $prefix; |
|
| 807 | + return $this; |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | - /** |
|
| 811 | - * Return the database driver |
|
| 812 | - * @return string |
|
| 813 | - */ |
|
| 810 | + /** |
|
| 811 | + * Return the database driver |
|
| 812 | + * @return string |
|
| 813 | + */ |
|
| 814 | 814 | public function getDriver(){ |
| 815 | - return $this->driver; |
|
| 815 | + return $this->driver; |
|
| 816 | 816 | } |
| 817 | 817 | |
| 818 | 818 | /** |
| 819 | 819 | * Set the database driver |
| 820 | 820 | * @param string $driver the new driver |
| 821 | - * @return object DatabaseQueryBuilder |
|
| 821 | + * @return object DatabaseQueryBuilder |
|
| 822 | 822 | */ |
| 823 | 823 | public function setDriver($driver){ |
| 824 | - $this->driver = $driver; |
|
| 825 | - return $this; |
|
| 824 | + $this->driver = $driver; |
|
| 825 | + return $this; |
|
| 826 | 826 | } |
| 827 | 827 | |
| 828 | - /** |
|
| 829 | - * Reset the DatabaseQueryBuilder class attributs to the initial values before each query. |
|
| 830 | - * @return object the current DatabaseQueryBuilder instance |
|
| 831 | - */ |
|
| 828 | + /** |
|
| 829 | + * Reset the DatabaseQueryBuilder class attributs to the initial values before each query. |
|
| 830 | + * @return object the current DatabaseQueryBuilder instance |
|
| 831 | + */ |
|
| 832 | 832 | public function reset(){ |
| 833 | - $this->select = '*'; |
|
| 834 | - $this->from = null; |
|
| 835 | - $this->where = null; |
|
| 836 | - $this->limit = null; |
|
| 837 | - $this->orderBy = null; |
|
| 838 | - $this->groupBy = null; |
|
| 839 | - $this->having = null; |
|
| 840 | - $this->join = null; |
|
| 841 | - $this->query = null; |
|
| 842 | - return $this; |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - /** |
|
| 846 | - * Get the SQL HAVING clause when operator argument is an array |
|
| 847 | - * @see DatabaseQueryBuilder::having |
|
| 848 | - * |
|
| 849 | - * @return string |
|
| 850 | - */ |
|
| 833 | + $this->select = '*'; |
|
| 834 | + $this->from = null; |
|
| 835 | + $this->where = null; |
|
| 836 | + $this->limit = null; |
|
| 837 | + $this->orderBy = null; |
|
| 838 | + $this->groupBy = null; |
|
| 839 | + $this->having = null; |
|
| 840 | + $this->join = null; |
|
| 841 | + $this->query = null; |
|
| 842 | + return $this; |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + /** |
|
| 846 | + * Get the SQL HAVING clause when operator argument is an array |
|
| 847 | + * @see DatabaseQueryBuilder::having |
|
| 848 | + * |
|
| 849 | + * @return string |
|
| 850 | + */ |
|
| 851 | 851 | protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true){ |
| 852 | 852 | $x = explode('?', $field); |
| 853 | 853 | $w = ''; |
| 854 | 854 | foreach($x as $k => $v){ |
| 855 | - if (!empty($v)){ |
|
| 855 | + if (!empty($v)){ |
|
| 856 | 856 | if (! isset($op[$k])){ |
| 857 | - $op[$k] = ''; |
|
| 857 | + $op[$k] = ''; |
|
| 858 | + } |
|
| 859 | + $w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : ''); |
|
| 860 | + } |
|
| 858 | 861 | } |
| 859 | - $w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : ''); |
|
| 860 | - } |
|
| 861 | - } |
|
| 862 | 862 | return $w; |
| 863 | 863 | } |
| 864 | 864 | |
@@ -870,35 +870,35 @@ discard block |
||
| 870 | 870 | * @return string |
| 871 | 871 | */ |
| 872 | 872 | protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){ |
| 873 | - $_where = array(); |
|
| 874 | - foreach ($where as $column => $data){ |
|
| 873 | + $_where = array(); |
|
| 874 | + foreach ($where as $column => $data){ |
|
| 875 | 875 | if (is_null($data)){ |
| 876 | - $data = ''; |
|
| 876 | + $data = ''; |
|
| 877 | 877 | } |
| 878 | 878 | $_where[] = $type . $column . ' = ' . ($this->escape($data, $escape)); |
| 879 | - } |
|
| 880 | - $where = implode(' '.$andOr.' ', $_where); |
|
| 881 | - return $where; |
|
| 879 | + } |
|
| 880 | + $where = implode(' '.$andOr.' ', $_where); |
|
| 881 | + return $where; |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | - /** |
|
| 885 | - * Get the SQL WHERE clause when operator argument is an array |
|
| 886 | - * @see DatabaseQueryBuilder::where |
|
| 887 | - * |
|
| 888 | - * @return string |
|
| 889 | - */ |
|
| 884 | + /** |
|
| 885 | + * Get the SQL WHERE clause when operator argument is an array |
|
| 886 | + * @see DatabaseQueryBuilder::where |
|
| 887 | + * |
|
| 888 | + * @return string |
|
| 889 | + */ |
|
| 890 | 890 | protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){ |
| 891 | - $x = explode('?', $where); |
|
| 892 | - $w = ''; |
|
| 893 | - foreach($x as $k => $v){ |
|
| 891 | + $x = explode('?', $where); |
|
| 892 | + $w = ''; |
|
| 893 | + foreach($x as $k => $v){ |
|
| 894 | 894 | if (! empty($v)){ |
| 895 | 895 | if (isset($op[$k]) && is_null($op[$k])){ |
| 896 | - $op[$k] = ''; |
|
| 896 | + $op[$k] = ''; |
|
| 897 | 897 | } |
| 898 | 898 | $w .= $type . $v . (isset($op[$k]) ? ($this->escape($op[$k], $escape)) : ''); |
| 899 | 899 | } |
| 900 | - } |
|
| 901 | - return $w; |
|
| 900 | + } |
|
| 901 | + return $w; |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | /** |
@@ -908,53 +908,53 @@ discard block |
||
| 908 | 908 | * @return string |
| 909 | 909 | */ |
| 910 | 910 | protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){ |
| 911 | - $w = ''; |
|
| 912 | - if (! in_array((string)$op, $this->operatorList)){ |
|
| 913 | - if (is_null($op)){ |
|
| 911 | + $w = ''; |
|
| 912 | + if (! in_array((string)$op, $this->operatorList)){ |
|
| 913 | + if (is_null($op)){ |
|
| 914 | 914 | $op = ''; |
| 915 | - } |
|
| 916 | - $w = $type . $where . ' = ' . ($this->escape($op, $escape)); |
|
| 915 | + } |
|
| 916 | + $w = $type . $where . ' = ' . ($this->escape($op, $escape)); |
|
| 917 | 917 | } else { |
| 918 | - if (is_null($val)){ |
|
| 918 | + if (is_null($val)){ |
|
| 919 | 919 | $val = ''; |
| 920 | - } |
|
| 921 | - $w = $type . $where . $op . ($this->escape($val, $escape)); |
|
| 920 | + } |
|
| 921 | + $w = $type . $where . $op . ($this->escape($val, $escape)); |
|
| 922 | 922 | } |
| 923 | 923 | return $w; |
| 924 | - } |
|
| 925 | - |
|
| 926 | - /** |
|
| 927 | - * Set the $this->where property |
|
| 928 | - * @param string $whereStr the WHERE clause string |
|
| 929 | - * @param string $andOr the separator type used 'AND', 'OR', etc. |
|
| 930 | - */ |
|
| 931 | - protected function setWhereStr($whereStr, $andOr = 'AND'){ |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + /** |
|
| 927 | + * Set the $this->where property |
|
| 928 | + * @param string $whereStr the WHERE clause string |
|
| 929 | + * @param string $andOr the separator type used 'AND', 'OR', etc. |
|
| 930 | + */ |
|
| 931 | + protected function setWhereStr($whereStr, $andOr = 'AND'){ |
|
| 932 | 932 | if (empty($this->where)){ |
| 933 | - $this->where = $whereStr; |
|
| 933 | + $this->where = $whereStr; |
|
| 934 | 934 | } else { |
| 935 | - if (substr(trim($this->where), -1) == '('){ |
|
| 935 | + if (substr(trim($this->where), -1) == '('){ |
|
| 936 | 936 | $this->where = $this->where . ' ' . $whereStr; |
| 937 | - } else { |
|
| 937 | + } else { |
|
| 938 | 938 | $this->where = $this->where . ' '.$andOr.' ' . $whereStr; |
| 939 | - } |
|
| 939 | + } |
|
| 940 | + } |
|
| 940 | 941 | } |
| 941 | - } |
|
| 942 | 942 | |
| 943 | 943 | |
| 944 | - /** |
|
| 945 | - * Set the SQL SELECT for function MIN, MAX, SUM, AVG, COUNT, AVG |
|
| 946 | - * @param string $clause the clause type like MIN, MAX, etc. |
|
| 947 | - * @see DatabaseQueryBuilder::min |
|
| 948 | - * @see DatabaseQueryBuilder::max |
|
| 949 | - * @see DatabaseQueryBuilder::sum |
|
| 950 | - * @see DatabaseQueryBuilder::count |
|
| 951 | - * @see DatabaseQueryBuilder::avg |
|
| 952 | - * @return object |
|
| 953 | - */ |
|
| 944 | + /** |
|
| 945 | + * Set the SQL SELECT for function MIN, MAX, SUM, AVG, COUNT, AVG |
|
| 946 | + * @param string $clause the clause type like MIN, MAX, etc. |
|
| 947 | + * @see DatabaseQueryBuilder::min |
|
| 948 | + * @see DatabaseQueryBuilder::max |
|
| 949 | + * @see DatabaseQueryBuilder::sum |
|
| 950 | + * @see DatabaseQueryBuilder::count |
|
| 951 | + * @see DatabaseQueryBuilder::avg |
|
| 952 | + * @return object |
|
| 953 | + */ |
|
| 954 | 954 | protected function select_min_max_sum_count_avg($clause, $field, $name = null){ |
| 955 | - $clause = strtoupper($clause); |
|
| 956 | - $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
|
| 957 | - $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
|
| 958 | - return $this; |
|
| 955 | + $clause = strtoupper($clause); |
|
| 956 | + $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
|
| 957 | + $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
|
| 958 | + return $this; |
|
| 959 | 959 | } |
| 960 | 960 | } |