@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * This class represent the event detail to dispatch to correspond listener |
| 29 | 29 | */ |
| 30 | - class EventInfo{ |
|
| 30 | + class EventInfo { |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * The event name |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public $stop; |
| 56 | 56 | |
| 57 | - public function __construct($name, $payload = array(), $returnBack = false, $stop = false){ |
|
| 57 | + public function __construct($name, $payload = array(), $returnBack = false, $stop = false) { |
|
| 58 | 58 | $this->name = $name; |
| 59 | 59 | $this->payload = $payload; |
| 60 | 60 | $this->returnBack = $returnBack; |
@@ -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 | + } |
|
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * also to dispatch the event |
| 30 | 30 | */ |
| 31 | 31 | |
| 32 | - class EventDispatcher{ |
|
| 32 | + class EventDispatcher { |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * The list of the registered listeners |
@@ -44,8 +44,8 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | private $logger; |
| 46 | 46 | |
| 47 | - public function __construct(){ |
|
| 48 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 47 | + public function __construct() { |
|
| 48 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 49 | 49 | $this->logger->setLogger('Library::EventDispatcher'); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -54,13 +54,13 @@ discard block |
||
| 54 | 54 | * @param string $eventName the name of the event to register for |
| 55 | 55 | * @param callable $listener the function or class method to receive the event information after dispatch |
| 56 | 56 | */ |
| 57 | - public function addListener($eventName, callable $listener){ |
|
| 58 | - $this->logger->debug('Adding new event listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']'); |
|
| 59 | - if(! isset($this->listeners[$eventName])){ |
|
| 57 | + public function addListener($eventName, callable $listener) { |
|
| 58 | + $this->logger->debug('Adding new event listener for the event name [' . $eventName . '], listener [' . stringfy_vars($listener) . ']'); |
|
| 59 | + if (!isset($this->listeners[$eventName])) { |
|
| 60 | 60 | $this->logger->info('This event does not have the registered event listener before, adding new one'); |
| 61 | 61 | $this->listeners[$eventName] = array(); |
| 62 | 62 | } |
| 63 | - else{ |
|
| 63 | + else { |
|
| 64 | 64 | $this->logger->info('This event already have the registered listener, add this listener to the list'); |
| 65 | 65 | } |
| 66 | 66 | $this->listeners[$eventName][] = $listener; |
@@ -71,19 +71,19 @@ discard block |
||
| 71 | 71 | * @param string $eventName the event name |
| 72 | 72 | * @param callable $listener the listener callback |
| 73 | 73 | */ |
| 74 | - public function removeListener($eventName, callable $listener){ |
|
| 75 | - $this->logger->debug('Removing of the event listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']'); |
|
| 76 | - if(isset($this->listeners[$eventName])){ |
|
| 74 | + public function removeListener($eventName, callable $listener) { |
|
| 75 | + $this->logger->debug('Removing of the event listener, the event name [' . $eventName . '], listener [' . stringfy_vars($listener) . ']'); |
|
| 76 | + if (isset($this->listeners[$eventName])) { |
|
| 77 | 77 | $this->logger->info('This event have the listeners, check if this listener exists'); |
| 78 | - if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){ |
|
| 79 | - $this->logger->info('Found the listener at index [' .$index. '] remove it'); |
|
| 78 | + if (false !== $index = array_search($listener, $this->listeners[$eventName], true)) { |
|
| 79 | + $this->logger->info('Found the listener at index [' . $index . '] remove it'); |
|
| 80 | 80 | unset($this->listeners[$eventName][$index]); |
| 81 | 81 | } |
| 82 | - else{ |
|
| 82 | + else { |
|
| 83 | 83 | $this->logger->info('Cannot found this listener in the event listener list'); |
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | - else{ |
|
| 86 | + else { |
|
| 87 | 87 | $this->logger->info('This event does not have this listener ignore remove'); |
| 88 | 88 | } |
| 89 | 89 | } |
@@ -93,13 +93,13 @@ discard block |
||
| 93 | 93 | * remove all listeners for this event |
| 94 | 94 | * @param string $eventName the event name |
| 95 | 95 | */ |
| 96 | - public function removeAllListener($eventName = null){ |
|
| 97 | - $this->logger->debug('Removing of all event listener, the event name [' .$eventName. ']'); |
|
| 98 | - if($eventName !== null && isset($this->listeners[$eventName])){ |
|
| 96 | + public function removeAllListener($eventName = null) { |
|
| 97 | + $this->logger->debug('Removing of all event listener, the event name [' . $eventName . ']'); |
|
| 98 | + if ($eventName !== null && isset($this->listeners[$eventName])) { |
|
| 99 | 99 | $this->logger->info('The event name is set of exist in the listener just remove all event listener for this event'); |
| 100 | 100 | unset($this->listeners[$eventName]); |
| 101 | 101 | } |
| 102 | - else{ |
|
| 102 | + else { |
|
| 103 | 103 | $this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener'); |
| 104 | 104 | $this->listeners = array(); |
| 105 | 105 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @param string $eventName the event name |
| 111 | 111 | * @return array the listeners for this event or empty array if this event does not contain any listener |
| 112 | 112 | */ |
| 113 | - public function getListeners($eventName){ |
|
| 113 | + public function getListeners($eventName) { |
|
| 114 | 114 | return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array(); |
| 115 | 115 | } |
| 116 | 116 | |
@@ -119,21 +119,21 @@ discard block |
||
| 119 | 119 | * @param mixed|object $event the event information |
| 120 | 120 | * @return void|object if event need return, will return the final EventInfo object. |
| 121 | 121 | */ |
| 122 | - public function dispatch($event){ |
|
| 123 | - if(! $event || !$event instanceof EventInfo){ |
|
| 122 | + public function dispatch($event) { |
|
| 123 | + if (!$event || !$event instanceof EventInfo) { |
|
| 124 | 124 | $this->logger->info('The event is not set or is not an instance of "EventInfo" create the default "EventInfo" object to use instead of.'); |
| 125 | 125 | $event = new EventInfo((string) $event); |
| 126 | 126 | } |
| 127 | - $this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']'); |
|
| 128 | - if(isset($event->stop) && $event->stop){ |
|
| 127 | + $this->logger->debug('Dispatch to the event listener, the event [' . stringfy_vars($event) . ']'); |
|
| 128 | + if (isset($event->stop) && $event->stop) { |
|
| 129 | 129 | $this->logger->info('This event need stopped, no need call any listener'); |
| 130 | 130 | return; |
| 131 | 131 | } |
| 132 | - if($event->returnBack){ |
|
| 132 | + if ($event->returnBack) { |
|
| 133 | 133 | $this->logger->info('This event need return back, return the result for future use'); |
| 134 | 134 | return $this->dispatchToListerners($event); |
| 135 | 135 | } |
| 136 | - else{ |
|
| 136 | + else { |
|
| 137 | 137 | $this->logger->info('This event no need return back the result, just dispatch it'); |
| 138 | 138 | $this->dispatchToListerners($event); |
| 139 | 139 | } |
@@ -144,38 +144,38 @@ discard block |
||
| 144 | 144 | * @param object EventInfo $event the event information |
| 145 | 145 | * @return void|object if event need return, will return the final EventInfo instance. |
| 146 | 146 | */ |
| 147 | - private function dispatchToListerners(EventInfo $event){ |
|
| 147 | + private function dispatchToListerners(EventInfo $event) { |
|
| 148 | 148 | $eBackup = $event; |
| 149 | 149 | $list = $this->getListeners($event->name); |
| 150 | - if(empty($list)){ |
|
| 151 | - $this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.'); |
|
| 152 | - if($event->returnBack){ |
|
| 150 | + if (empty($list)) { |
|
| 151 | + $this->logger->info('No event listener is registered for the event [' . $event->name . '] skipping.'); |
|
| 152 | + if ($event->returnBack) { |
|
| 153 | 153 | return $event; |
| 154 | 154 | } |
| 155 | 155 | return; |
| 156 | 156 | } |
| 157 | - else{ |
|
| 158 | - $this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list)); |
|
| 157 | + else { |
|
| 158 | + $this->logger->info('Found the registered event listener for the event [' . $event->name . '] the list are: ' . stringfy_vars($list)); |
|
| 159 | 159 | } |
| 160 | - foreach($list as $listener){ |
|
| 161 | - if($eBackup->returnBack){ |
|
| 160 | + foreach ($list as $listener) { |
|
| 161 | + if ($eBackup->returnBack) { |
|
| 162 | 162 | $returnedEvent = call_user_func_array($listener, array($event)); |
| 163 | - if($returnedEvent instanceof EventInfo){ |
|
| 163 | + if ($returnedEvent instanceof EventInfo) { |
|
| 164 | 164 | $event = $returnedEvent; |
| 165 | 165 | } |
| 166 | - else{ |
|
| 167 | - show_error('This event [' .$event->name. '] need you return the event object after processing'); |
|
| 166 | + else { |
|
| 167 | + show_error('This event [' . $event->name . '] need you return the event object after processing'); |
|
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | - else{ |
|
| 170 | + else { |
|
| 171 | 171 | call_user_func_array($listener, array($event)); |
| 172 | 172 | } |
| 173 | - if($event->stop){ |
|
| 173 | + if ($event->stop) { |
|
| 174 | 174 | break; |
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | //only test for original event may be during the flow some listeners change this parameter |
| 178 | - if($eBackup->returnBack){ |
|
| 178 | + if ($eBackup->returnBack) { |
|
| 179 | 179 | return $event; |
| 180 | 180 | } |
| 181 | 181 | } |
@@ -59,8 +59,7 @@ discard block |
||
| 59 | 59 | if(! isset($this->listeners[$eventName])){ |
| 60 | 60 | $this->logger->info('This event does not have the registered event listener before, adding new one'); |
| 61 | 61 | $this->listeners[$eventName] = array(); |
| 62 | - } |
|
| 63 | - else{ |
|
| 62 | + } else{ |
|
| 64 | 63 | $this->logger->info('This event already have the registered listener, add this listener to the list'); |
| 65 | 64 | } |
| 66 | 65 | $this->listeners[$eventName][] = $listener; |
@@ -78,12 +77,10 @@ discard block |
||
| 78 | 77 | if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){ |
| 79 | 78 | $this->logger->info('Found the listener at index [' .$index. '] remove it'); |
| 80 | 79 | unset($this->listeners[$eventName][$index]); |
| 81 | - } |
|
| 82 | - else{ |
|
| 80 | + } else{ |
|
| 83 | 81 | $this->logger->info('Cannot found this listener in the event listener list'); |
| 84 | 82 | } |
| 85 | - } |
|
| 86 | - else{ |
|
| 83 | + } else{ |
|
| 87 | 84 | $this->logger->info('This event does not have this listener ignore remove'); |
| 88 | 85 | } |
| 89 | 86 | } |
@@ -98,8 +95,7 @@ discard block |
||
| 98 | 95 | if($eventName !== null && isset($this->listeners[$eventName])){ |
| 99 | 96 | $this->logger->info('The event name is set of exist in the listener just remove all event listener for this event'); |
| 100 | 97 | unset($this->listeners[$eventName]); |
| 101 | - } |
|
| 102 | - else{ |
|
| 98 | + } else{ |
|
| 103 | 99 | $this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener'); |
| 104 | 100 | $this->listeners = array(); |
| 105 | 101 | } |
@@ -132,8 +128,7 @@ discard block |
||
| 132 | 128 | if($event->returnBack){ |
| 133 | 129 | $this->logger->info('This event need return back, return the result for future use'); |
| 134 | 130 | return $this->dispatchToListerners($event); |
| 135 | - } |
|
| 136 | - else{ |
|
| 131 | + } else{ |
|
| 137 | 132 | $this->logger->info('This event no need return back the result, just dispatch it'); |
| 138 | 133 | $this->dispatchToListerners($event); |
| 139 | 134 | } |
@@ -153,8 +148,7 @@ discard block |
||
| 153 | 148 | return $event; |
| 154 | 149 | } |
| 155 | 150 | return; |
| 156 | - } |
|
| 157 | - else{ |
|
| 151 | + } else{ |
|
| 158 | 152 | $this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list)); |
| 159 | 153 | } |
| 160 | 154 | foreach($list as $listener){ |
@@ -162,12 +156,10 @@ discard block |
||
| 162 | 156 | $returnedEvent = call_user_func_array($listener, array($event)); |
| 163 | 157 | if($returnedEvent instanceof EventInfo){ |
| 164 | 158 | $event = $returnedEvent; |
| 165 | - } |
|
| 166 | - else{ |
|
| 159 | + } else{ |
|
| 167 | 160 | show_error('This event [' .$event->name. '] need you return the event object after processing'); |
| 168 | 161 | } |
| 169 | - } |
|
| 170 | - else{ |
|
| 162 | + } else{ |
|
| 171 | 163 | call_user_func_array($listener, array($event)); |
| 172 | 164 | } |
| 173 | 165 | if($event->stop){ |
@@ -1,182 +1,182 @@ |
||
| 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 dispatcher management, permit to record the listener and |
|
| 29 | - * also to dispatch the event |
|
| 30 | - */ |
|
| 27 | + /** |
|
| 28 | + * This class represent the event dispatcher management, permit to record the listener and |
|
| 29 | + * also to dispatch the event |
|
| 30 | + */ |
|
| 31 | 31 | |
| 32 | - class EventDispatcher{ |
|
| 32 | + class EventDispatcher{ |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * The list of the registered listeners |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - private $listeners = array(); |
|
| 34 | + /** |
|
| 35 | + * The list of the registered listeners |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + private $listeners = array(); |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * The logger instance |
|
| 43 | - * @var Log |
|
| 44 | - */ |
|
| 45 | - private $logger; |
|
| 41 | + /** |
|
| 42 | + * The logger instance |
|
| 43 | + * @var Log |
|
| 44 | + */ |
|
| 45 | + private $logger; |
|
| 46 | 46 | |
| 47 | - public function __construct(){ |
|
| 48 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 49 | - $this->logger->setLogger('Library::EventDispatcher'); |
|
| 50 | - } |
|
| 47 | + public function __construct(){ |
|
| 48 | + $this->logger =& class_loader('Log', 'classes'); |
|
| 49 | + $this->logger->setLogger('Library::EventDispatcher'); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Register new listener |
|
| 54 | - * @param string $eventName the name of the event to register for |
|
| 55 | - * @param callable $listener the function or class method to receive the event information after dispatch |
|
| 56 | - */ |
|
| 57 | - public function addListener($eventName, callable $listener){ |
|
| 58 | - $this->logger->debug('Adding new event listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']'); |
|
| 59 | - if(! isset($this->listeners[$eventName])){ |
|
| 60 | - $this->logger->info('This event does not have the registered event listener before, adding new one'); |
|
| 61 | - $this->listeners[$eventName] = array(); |
|
| 62 | - } |
|
| 63 | - else{ |
|
| 64 | - $this->logger->info('This event already have the registered listener, add this listener to the list'); |
|
| 65 | - } |
|
| 66 | - $this->listeners[$eventName][] = $listener; |
|
| 67 | - } |
|
| 52 | + /** |
|
| 53 | + * Register new listener |
|
| 54 | + * @param string $eventName the name of the event to register for |
|
| 55 | + * @param callable $listener the function or class method to receive the event information after dispatch |
|
| 56 | + */ |
|
| 57 | + public function addListener($eventName, callable $listener){ |
|
| 58 | + $this->logger->debug('Adding new event listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']'); |
|
| 59 | + if(! isset($this->listeners[$eventName])){ |
|
| 60 | + $this->logger->info('This event does not have the registered event listener before, adding new one'); |
|
| 61 | + $this->listeners[$eventName] = array(); |
|
| 62 | + } |
|
| 63 | + else{ |
|
| 64 | + $this->logger->info('This event already have the registered listener, add this listener to the list'); |
|
| 65 | + } |
|
| 66 | + $this->listeners[$eventName][] = $listener; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Remove the event listener from list |
|
| 71 | - * @param string $eventName the event name |
|
| 72 | - * @param callable $listener the listener callback |
|
| 73 | - */ |
|
| 74 | - public function removeListener($eventName, callable $listener){ |
|
| 75 | - $this->logger->debug('Removing of the event listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']'); |
|
| 76 | - if(isset($this->listeners[$eventName])){ |
|
| 77 | - $this->logger->info('This event have the listeners, check if this listener exists'); |
|
| 78 | - if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){ |
|
| 79 | - $this->logger->info('Found the listener at index [' .$index. '] remove it'); |
|
| 80 | - unset($this->listeners[$eventName][$index]); |
|
| 81 | - } |
|
| 82 | - else{ |
|
| 83 | - $this->logger->info('Cannot found this listener in the event listener list'); |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - else{ |
|
| 87 | - $this->logger->info('This event does not have this listener ignore remove'); |
|
| 88 | - } |
|
| 89 | - } |
|
| 69 | + /** |
|
| 70 | + * Remove the event listener from list |
|
| 71 | + * @param string $eventName the event name |
|
| 72 | + * @param callable $listener the listener callback |
|
| 73 | + */ |
|
| 74 | + public function removeListener($eventName, callable $listener){ |
|
| 75 | + $this->logger->debug('Removing of the event listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']'); |
|
| 76 | + if(isset($this->listeners[$eventName])){ |
|
| 77 | + $this->logger->info('This event have the listeners, check if this listener exists'); |
|
| 78 | + if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){ |
|
| 79 | + $this->logger->info('Found the listener at index [' .$index. '] remove it'); |
|
| 80 | + unset($this->listeners[$eventName][$index]); |
|
| 81 | + } |
|
| 82 | + else{ |
|
| 83 | + $this->logger->info('Cannot found this listener in the event listener list'); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + else{ |
|
| 87 | + $this->logger->info('This event does not have this listener ignore remove'); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Remove all the event listener. If event name is null will remove all listeners, else will just |
|
| 93 | - * remove all listeners for this event |
|
| 94 | - * @param string $eventName the event name |
|
| 95 | - */ |
|
| 96 | - public function removeAllListener($eventName = null){ |
|
| 97 | - $this->logger->debug('Removing of all event listener, the event name [' .$eventName. ']'); |
|
| 98 | - if($eventName !== null && isset($this->listeners[$eventName])){ |
|
| 99 | - $this->logger->info('The event name is set of exist in the listener just remove all event listener for this event'); |
|
| 100 | - unset($this->listeners[$eventName]); |
|
| 101 | - } |
|
| 102 | - else{ |
|
| 103 | - $this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener'); |
|
| 104 | - $this->listeners = array(); |
|
| 105 | - } |
|
| 106 | - } |
|
| 91 | + /** |
|
| 92 | + * Remove all the event listener. If event name is null will remove all listeners, else will just |
|
| 93 | + * remove all listeners for this event |
|
| 94 | + * @param string $eventName the event name |
|
| 95 | + */ |
|
| 96 | + public function removeAllListener($eventName = null){ |
|
| 97 | + $this->logger->debug('Removing of all event listener, the event name [' .$eventName. ']'); |
|
| 98 | + if($eventName !== null && isset($this->listeners[$eventName])){ |
|
| 99 | + $this->logger->info('The event name is set of exist in the listener just remove all event listener for this event'); |
|
| 100 | + unset($this->listeners[$eventName]); |
|
| 101 | + } |
|
| 102 | + else{ |
|
| 103 | + $this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener'); |
|
| 104 | + $this->listeners = array(); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Get the list of listener for this event |
|
| 110 | - * @param string $eventName the event name |
|
| 111 | - * @return array the listeners for this event or empty array if this event does not contain any listener |
|
| 112 | - */ |
|
| 113 | - public function getListeners($eventName){ |
|
| 114 | - return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array(); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * Get the list of listener for this event |
|
| 110 | + * @param string $eventName the event name |
|
| 111 | + * @return array the listeners for this event or empty array if this event does not contain any listener |
|
| 112 | + */ |
|
| 113 | + public function getListeners($eventName){ |
|
| 114 | + return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array(); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Dispatch the event to the registered listeners. |
|
| 119 | - * @param mixed|object $event the event information |
|
| 120 | - * @return void|object if event need return, will return the final EventInfo object. |
|
| 121 | - */ |
|
| 122 | - public function dispatch($event){ |
|
| 123 | - if(! $event || !$event instanceof EventInfo){ |
|
| 124 | - $this->logger->info('The event is not set or is not an instance of "EventInfo" create the default "EventInfo" object to use instead of.'); |
|
| 125 | - $event = new EventInfo((string) $event); |
|
| 126 | - } |
|
| 127 | - $this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']'); |
|
| 128 | - if(isset($event->stop) && $event->stop){ |
|
| 129 | - $this->logger->info('This event need stopped, no need call any listener'); |
|
| 130 | - return; |
|
| 131 | - } |
|
| 132 | - if($event->returnBack){ |
|
| 133 | - $this->logger->info('This event need return back, return the result for future use'); |
|
| 134 | - return $this->dispatchToListerners($event); |
|
| 135 | - } |
|
| 136 | - else{ |
|
| 137 | - $this->logger->info('This event no need return back the result, just dispatch it'); |
|
| 138 | - $this->dispatchToListerners($event); |
|
| 139 | - } |
|
| 140 | - } |
|
| 117 | + /** |
|
| 118 | + * Dispatch the event to the registered listeners. |
|
| 119 | + * @param mixed|object $event the event information |
|
| 120 | + * @return void|object if event need return, will return the final EventInfo object. |
|
| 121 | + */ |
|
| 122 | + public function dispatch($event){ |
|
| 123 | + if(! $event || !$event instanceof EventInfo){ |
|
| 124 | + $this->logger->info('The event is not set or is not an instance of "EventInfo" create the default "EventInfo" object to use instead of.'); |
|
| 125 | + $event = new EventInfo((string) $event); |
|
| 126 | + } |
|
| 127 | + $this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']'); |
|
| 128 | + if(isset($event->stop) && $event->stop){ |
|
| 129 | + $this->logger->info('This event need stopped, no need call any listener'); |
|
| 130 | + return; |
|
| 131 | + } |
|
| 132 | + if($event->returnBack){ |
|
| 133 | + $this->logger->info('This event need return back, return the result for future use'); |
|
| 134 | + return $this->dispatchToListerners($event); |
|
| 135 | + } |
|
| 136 | + else{ |
|
| 137 | + $this->logger->info('This event no need return back the result, just dispatch it'); |
|
| 138 | + $this->dispatchToListerners($event); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Dispatch the event to the registered listeners. |
|
| 144 | - * @param object EventInfo $event the event information |
|
| 145 | - * @return void|object if event need return, will return the final EventInfo instance. |
|
| 146 | - */ |
|
| 147 | - private function dispatchToListerners(EventInfo $event){ |
|
| 148 | - $eBackup = $event; |
|
| 149 | - $list = $this->getListeners($event->name); |
|
| 150 | - if(empty($list)){ |
|
| 151 | - $this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.'); |
|
| 152 | - if($event->returnBack){ |
|
| 153 | - return $event; |
|
| 154 | - } |
|
| 155 | - return; |
|
| 156 | - } |
|
| 157 | - else{ |
|
| 158 | - $this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list)); |
|
| 159 | - } |
|
| 160 | - foreach($list as $listener){ |
|
| 161 | - if($eBackup->returnBack){ |
|
| 162 | - $returnedEvent = call_user_func_array($listener, array($event)); |
|
| 163 | - if($returnedEvent instanceof EventInfo){ |
|
| 164 | - $event = $returnedEvent; |
|
| 165 | - } |
|
| 166 | - else{ |
|
| 167 | - show_error('This event [' .$event->name. '] need you return the event object after processing'); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - else{ |
|
| 171 | - call_user_func_array($listener, array($event)); |
|
| 172 | - } |
|
| 173 | - if($event->stop){ |
|
| 174 | - break; |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - //only test for original event may be during the flow some listeners change this parameter |
|
| 178 | - if($eBackup->returnBack){ |
|
| 179 | - return $event; |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - } |
|
| 142 | + /** |
|
| 143 | + * Dispatch the event to the registered listeners. |
|
| 144 | + * @param object EventInfo $event the event information |
|
| 145 | + * @return void|object if event need return, will return the final EventInfo instance. |
|
| 146 | + */ |
|
| 147 | + private function dispatchToListerners(EventInfo $event){ |
|
| 148 | + $eBackup = $event; |
|
| 149 | + $list = $this->getListeners($event->name); |
|
| 150 | + if(empty($list)){ |
|
| 151 | + $this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.'); |
|
| 152 | + if($event->returnBack){ |
|
| 153 | + return $event; |
|
| 154 | + } |
|
| 155 | + return; |
|
| 156 | + } |
|
| 157 | + else{ |
|
| 158 | + $this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list)); |
|
| 159 | + } |
|
| 160 | + foreach($list as $listener){ |
|
| 161 | + if($eBackup->returnBack){ |
|
| 162 | + $returnedEvent = call_user_func_array($listener, array($event)); |
|
| 163 | + if($returnedEvent instanceof EventInfo){ |
|
| 164 | + $event = $returnedEvent; |
|
| 165 | + } |
|
| 166 | + else{ |
|
| 167 | + show_error('This event [' .$event->name. '] need you return the event object after processing'); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + else{ |
|
| 171 | + call_user_func_array($listener, array($event)); |
|
| 172 | + } |
|
| 173 | + if($event->stop){ |
|
| 174 | + break; |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + //only test for original event may be during the flow some listeners change this parameter |
|
| 178 | + if($eBackup->returnBack){ |
|
| 179 | + return $event; |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + } |
|
@@ -115,8 +115,7 @@ |
||
| 115 | 115 | protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
| 116 | 116 | if($logger !== null){ |
| 117 | 117 | $this->logger = $logger; |
| 118 | - } |
|
| 119 | - else{ |
|
| 118 | + } else{ |
|
| 120 | 119 | $this->logger =& class_loader('Log', 'classes'); |
| 121 | 120 | $this->logger->setLogger('MainController'); |
| 122 | 121 | } |
@@ -1,146 +1,146 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - class Controller{ |
|
| 27 | + class Controller{ |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * The name of the module if this controller belong to an module |
|
| 31 | - * @var string |
|
| 32 | - */ |
|
| 33 | - public $moduleName = null; |
|
| 29 | + /** |
|
| 30 | + * The name of the module if this controller belong to an module |
|
| 31 | + * @var string |
|
| 32 | + */ |
|
| 33 | + public $moduleName = null; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * The singleton of the super object |
|
| 37 | - * @var Controller |
|
| 38 | - */ |
|
| 39 | - private static $instance; |
|
| 35 | + /** |
|
| 36 | + * The singleton of the super object |
|
| 37 | + * @var Controller |
|
| 38 | + */ |
|
| 39 | + private static $instance; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * The logger instance |
|
| 43 | - * @var Log |
|
| 44 | - */ |
|
| 45 | - protected $logger; |
|
| 41 | + /** |
|
| 42 | + * The logger instance |
|
| 43 | + * @var Log |
|
| 44 | + */ |
|
| 45 | + protected $logger; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Class constructor |
|
| 49 | - * @param object $logger the Log instance to use if is null will create one |
|
| 50 | - */ |
|
| 51 | - public function __construct(Log $logger = null){ |
|
| 52 | - //setting the Log instance |
|
| 53 | - $this->setLoggerFromParamOrCreateNewInstance($logger); |
|
| 47 | + /** |
|
| 48 | + * Class constructor |
|
| 49 | + * @param object $logger the Log instance to use if is null will create one |
|
| 50 | + */ |
|
| 51 | + public function __construct(Log $logger = null){ |
|
| 52 | + //setting the Log instance |
|
| 53 | + $this->setLoggerFromParamOrCreateNewInstance($logger); |
|
| 54 | 54 | |
| 55 | - //instance of the super object |
|
| 56 | - self::$instance = & $this; |
|
| 55 | + //instance of the super object |
|
| 56 | + self::$instance = & $this; |
|
| 57 | 57 | |
| 58 | - //Load the resources loaded during the application bootstrap |
|
| 59 | - $this->logger->debug('Adding the loaded classes to the super instance'); |
|
| 60 | - foreach (class_loaded() as $var => $class){ |
|
| 61 | - $this->$var =& class_loader($class); |
|
| 62 | - } |
|
| 58 | + //Load the resources loaded during the application bootstrap |
|
| 59 | + $this->logger->debug('Adding the loaded classes to the super instance'); |
|
| 60 | + foreach (class_loaded() as $var => $class){ |
|
| 61 | + $this->$var =& class_loader($class); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - //set module using the router |
|
| 65 | - $this->setModuleNameFromRouter(); |
|
| 64 | + //set module using the router |
|
| 65 | + $this->setModuleNameFromRouter(); |
|
| 66 | 66 | |
| 67 | - //load the required resources |
|
| 68 | - $this->loadRequiredResources(); |
|
| 67 | + //load the required resources |
|
| 68 | + $this->loadRequiredResources(); |
|
| 69 | 69 | |
| 70 | - //set the cache using the configuration |
|
| 71 | - $this->setCacheFromParamOrConfig(null); |
|
| 70 | + //set the cache using the configuration |
|
| 71 | + $this->setCacheFromParamOrConfig(null); |
|
| 72 | 72 | |
| 73 | - //set application session configuration |
|
| 74 | - $this->logger->debug('Setting PHP application session handler'); |
|
| 75 | - set_session_config(); |
|
| 73 | + //set application session configuration |
|
| 74 | + $this->logger->debug('Setting PHP application session handler'); |
|
| 75 | + set_session_config(); |
|
| 76 | 76 | |
| 77 | - //dispatch the loaded instance of super controller event |
|
| 78 | - $this->eventdispatcher->dispatch('SUPER_CONTROLLER_CREATED'); |
|
| 79 | - } |
|
| 77 | + //dispatch the loaded instance of super controller event |
|
| 78 | + $this->eventdispatcher->dispatch('SUPER_CONTROLLER_CREATED'); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * This is a very useful method it's used to get the super object instance |
|
| 84 | - * @return Controller the super object instance |
|
| 85 | - */ |
|
| 86 | - public static function &get_instance(){ |
|
| 87 | - return self::$instance; |
|
| 88 | - } |
|
| 82 | + /** |
|
| 83 | + * This is a very useful method it's used to get the super object instance |
|
| 84 | + * @return Controller the super object instance |
|
| 85 | + */ |
|
| 86 | + public static function &get_instance(){ |
|
| 87 | + return self::$instance; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * This method is used to set the module name |
|
| 92 | - */ |
|
| 93 | - protected function setModuleNameFromRouter(){ |
|
| 94 | - //set the module using the router instance |
|
| 95 | - if(isset($this->router) && $this->router->getModule()){ |
|
| 96 | - $this->moduleName = $this->router->getModule(); |
|
| 97 | - } |
|
| 98 | - } |
|
| 90 | + /** |
|
| 91 | + * This method is used to set the module name |
|
| 92 | + */ |
|
| 93 | + protected function setModuleNameFromRouter(){ |
|
| 94 | + //set the module using the router instance |
|
| 95 | + if(isset($this->router) && $this->router->getModule()){ |
|
| 96 | + $this->moduleName = $this->router->getModule(); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Set the cache using the argument otherwise will use the configuration |
|
| 102 | - * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured |
|
| 103 | - */ |
|
| 104 | - protected function setCacheFromParamOrConfig(CacheInterface $cache = null){ |
|
| 105 | - $this->logger->debug('Setting the cache handler instance'); |
|
| 106 | - //set cache handler instance |
|
| 107 | - if(get_config('cache_enable', false)){ |
|
| 108 | - if ($cache !== null){ |
|
| 109 | - $this->cache = $cache; |
|
| 110 | - } else if (isset($this->{strtolower(get_config('cache_handler'))})){ |
|
| 111 | - $this->cache = $this->{strtolower(get_config('cache_handler'))}; |
|
| 112 | - unset($this->{strtolower(get_config('cache_handler'))}); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 100 | + /** |
|
| 101 | + * Set the cache using the argument otherwise will use the configuration |
|
| 102 | + * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured |
|
| 103 | + */ |
|
| 104 | + protected function setCacheFromParamOrConfig(CacheInterface $cache = null){ |
|
| 105 | + $this->logger->debug('Setting the cache handler instance'); |
|
| 106 | + //set cache handler instance |
|
| 107 | + if(get_config('cache_enable', false)){ |
|
| 108 | + if ($cache !== null){ |
|
| 109 | + $this->cache = $cache; |
|
| 110 | + } else if (isset($this->{strtolower(get_config('cache_handler'))})){ |
|
| 111 | + $this->cache = $this->{strtolower(get_config('cache_handler'))}; |
|
| 112 | + unset($this->{strtolower(get_config('cache_handler'))}); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Set the Log instance using argument or create new instance |
|
| 119 | - * @param object $logger the Log instance if not null |
|
| 120 | - */ |
|
| 121 | - protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
|
| 122 | - if($logger !== null){ |
|
| 123 | - $this->logger = $logger; |
|
| 124 | - } |
|
| 125 | - else{ |
|
| 126 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 127 | - $this->logger->setLogger('MainController'); |
|
| 128 | - } |
|
| 129 | - } |
|
| 117 | + /** |
|
| 118 | + * Set the Log instance using argument or create new instance |
|
| 119 | + * @param object $logger the Log instance if not null |
|
| 120 | + */ |
|
| 121 | + protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
|
| 122 | + if($logger !== null){ |
|
| 123 | + $this->logger = $logger; |
|
| 124 | + } |
|
| 125 | + else{ |
|
| 126 | + $this->logger =& class_loader('Log', 'classes'); |
|
| 127 | + $this->logger->setLogger('MainController'); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * This method is used to load the required resources for framework to work |
|
| 133 | - * @return void |
|
| 134 | - */ |
|
| 135 | - private function loadRequiredResources(){ |
|
| 136 | - $this->logger->debug('Loading the required classes into super instance'); |
|
| 137 | - $this->eventdispatcher =& class_loader('EventDispatcher', 'classes'); |
|
| 138 | - $this->loader =& class_loader('Loader', 'classes'); |
|
| 139 | - $this->lang =& class_loader('Lang', 'classes'); |
|
| 140 | - $this->request =& class_loader('Request', 'classes'); |
|
| 141 | - //dispatch the request instance created event |
|
| 142 | - $this->eventdispatcher->dispatch('REQUEST_CREATED'); |
|
| 143 | - $this->response =& class_loader('Response', 'classes', 'classes'); |
|
| 144 | - } |
|
| 131 | + /** |
|
| 132 | + * This method is used to load the required resources for framework to work |
|
| 133 | + * @return void |
|
| 134 | + */ |
|
| 135 | + private function loadRequiredResources(){ |
|
| 136 | + $this->logger->debug('Loading the required classes into super instance'); |
|
| 137 | + $this->eventdispatcher =& class_loader('EventDispatcher', 'classes'); |
|
| 138 | + $this->loader =& class_loader('Loader', 'classes'); |
|
| 139 | + $this->lang =& class_loader('Lang', 'classes'); |
|
| 140 | + $this->request =& class_loader('Request', 'classes'); |
|
| 141 | + //dispatch the request instance created event |
|
| 142 | + $this->eventdispatcher->dispatch('REQUEST_CREATED'); |
|
| 143 | + $this->response =& class_loader('Response', 'classes', 'classes'); |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - } |
|
| 146 | + } |
|
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - class Controller{ |
|
| 27 | + class Controller { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The name of the module if this controller belong to an module |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * Class constructor |
| 49 | 49 | * @param object $logger the Log instance to use if is null will create one |
| 50 | 50 | */ |
| 51 | - public function __construct(Log $logger = null){ |
|
| 51 | + public function __construct(Log $logger = null) { |
|
| 52 | 52 | //setting the Log instance |
| 53 | 53 | $this->setLoggerFromParamOrCreateNewInstance($logger); |
| 54 | 54 | |
@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | //Load the resources loaded during the application bootstrap |
| 59 | 59 | $this->logger->debug('Adding the loaded classes to the super instance'); |
| 60 | - foreach (class_loaded() as $var => $class){ |
|
| 61 | - $this->$var =& class_loader($class); |
|
| 60 | + foreach (class_loaded() as $var => $class) { |
|
| 61 | + $this->$var = & class_loader($class); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | //set module using the router |
@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | /** |
| 91 | 91 | * This method is used to set the module name |
| 92 | 92 | */ |
| 93 | - protected function setModuleNameFromRouter(){ |
|
| 93 | + protected function setModuleNameFromRouter() { |
|
| 94 | 94 | //set the module using the router instance |
| 95 | - if(isset($this->router) && $this->router->getModule()){ |
|
| 95 | + if (isset($this->router) && $this->router->getModule()) { |
|
| 96 | 96 | $this->moduleName = $this->router->getModule(); |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -101,13 +101,13 @@ discard block |
||
| 101 | 101 | * Set the cache using the argument otherwise will use the configuration |
| 102 | 102 | * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured |
| 103 | 103 | */ |
| 104 | - protected function setCacheFromParamOrConfig(CacheInterface $cache = null){ |
|
| 104 | + protected function setCacheFromParamOrConfig(CacheInterface $cache = null) { |
|
| 105 | 105 | $this->logger->debug('Setting the cache handler instance'); |
| 106 | 106 | //set cache handler instance |
| 107 | - if(get_config('cache_enable', false)){ |
|
| 108 | - if ($cache !== null){ |
|
| 107 | + if (get_config('cache_enable', false)) { |
|
| 108 | + if ($cache !== null) { |
|
| 109 | 109 | $this->cache = $cache; |
| 110 | - } else if (isset($this->{strtolower(get_config('cache_handler'))})){ |
|
| 110 | + } else if (isset($this->{strtolower(get_config('cache_handler'))})) { |
|
| 111 | 111 | $this->cache = $this->{strtolower(get_config('cache_handler'))}; |
| 112 | 112 | unset($this->{strtolower(get_config('cache_handler'))}); |
| 113 | 113 | } |
@@ -118,12 +118,12 @@ discard block |
||
| 118 | 118 | * Set the Log instance using argument or create new instance |
| 119 | 119 | * @param object $logger the Log instance if not null |
| 120 | 120 | */ |
| 121 | - protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
|
| 122 | - if($logger !== null){ |
|
| 121 | + protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) { |
|
| 122 | + if ($logger !== null) { |
|
| 123 | 123 | $this->logger = $logger; |
| 124 | 124 | } |
| 125 | - else{ |
|
| 126 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 125 | + else { |
|
| 126 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 127 | 127 | $this->logger->setLogger('MainController'); |
| 128 | 128 | } |
| 129 | 129 | } |
@@ -132,15 +132,15 @@ discard block |
||
| 132 | 132 | * This method is used to load the required resources for framework to work |
| 133 | 133 | * @return void |
| 134 | 134 | */ |
| 135 | - private function loadRequiredResources(){ |
|
| 135 | + private function loadRequiredResources() { |
|
| 136 | 136 | $this->logger->debug('Loading the required classes into super instance'); |
| 137 | - $this->eventdispatcher =& class_loader('EventDispatcher', 'classes'); |
|
| 138 | - $this->loader =& class_loader('Loader', 'classes'); |
|
| 139 | - $this->lang =& class_loader('Lang', 'classes'); |
|
| 140 | - $this->request =& class_loader('Request', 'classes'); |
|
| 137 | + $this->eventdispatcher = & class_loader('EventDispatcher', 'classes'); |
|
| 138 | + $this->loader = & class_loader('Loader', 'classes'); |
|
| 139 | + $this->lang = & class_loader('Lang', 'classes'); |
|
| 140 | + $this->request = & class_loader('Request', 'classes'); |
|
| 141 | 141 | //dispatch the request instance created event |
| 142 | 142 | $this->eventdispatcher->dispatch('REQUEST_CREATED'); |
| 143 | - $this->response =& class_loader('Response', 'classes', 'classes'); |
|
| 143 | + $this->response = & class_loader('Response', 'classes', 'classes'); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | } |
@@ -53,14 +53,14 @@ discard block |
||
| 53 | 53 | //put the first letter of class to upper case |
| 54 | 54 | $class = ucfirst($class); |
| 55 | 55 | static $classes = array(); |
| 56 | - if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){ |
|
| 56 | + if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log') { |
|
| 57 | 57 | return $classes[$class]; |
| 58 | 58 | } |
| 59 | 59 | $found = false; |
| 60 | 60 | foreach (array(ROOT_PATH, CORE_PATH) as $path) { |
| 61 | 61 | $file = $path . $dir . '/' . $class . '.php'; |
| 62 | - if (file_exists($file)){ |
|
| 63 | - if (class_exists($class, false) === false){ |
|
| 62 | + if (file_exists($file)) { |
|
| 63 | + if (class_exists($class, false) === false) { |
|
| 64 | 64 | require_once $file; |
| 65 | 65 | } |
| 66 | 66 | //already found |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | break; |
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | - if (! $found){ |
|
| 71 | + if (!$found) { |
|
| 72 | 72 | //can't use show_error() at this time because some dependencies not yet loaded |
| 73 | 73 | set_http_status_header(503); |
| 74 | 74 | echo 'Cannot find the class [' . $class . ']'; |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | /* |
| 79 | 79 | TODO use the best method to get the Log instance |
| 80 | 80 | */ |
| 81 | - if ($class == 'Log'){ |
|
| 81 | + if ($class == 'Log') { |
|
| 82 | 82 | //can't use the instruction like "return new Log()" |
| 83 | 83 | //because we need return the reference instance of the loaded class. |
| 84 | 84 | $log = new Log(); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | function & class_loaded($class = null){ |
| 104 | 104 | static $list = array(); |
| 105 | - if ($class !== null){ |
|
| 105 | + if ($class !== null) { |
|
| 106 | 106 | $list[strtolower($class)] = $class; |
| 107 | 107 | } |
| 108 | 108 | return $list; |
@@ -117,14 +117,14 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | function & load_configurations(array $overwrite_values = array()){ |
| 119 | 119 | static $config; |
| 120 | - if (empty($config)){ |
|
| 120 | + if (empty($config)) { |
|
| 121 | 121 | $file = CONFIG_PATH . 'config.php'; |
| 122 | 122 | $found = false; |
| 123 | - if (file_exists($file)){ |
|
| 123 | + if (file_exists($file)) { |
|
| 124 | 124 | require_once $file; |
| 125 | 125 | $found = true; |
| 126 | 126 | } |
| 127 | - if (! $found){ |
|
| 127 | + if (!$found) { |
|
| 128 | 128 | set_http_status_header(503); |
| 129 | 129 | echo 'Unable to find the configuration file [' . $file . ']'; |
| 130 | 130 | die(); |
@@ -144,9 +144,9 @@ discard block |
||
| 144 | 144 | * |
| 145 | 145 | * @return mixed the config value |
| 146 | 146 | */ |
| 147 | - function get_config($key, $default = null){ |
|
| 147 | + function get_config($key, $default = null) { |
|
| 148 | 148 | static $cfg; |
| 149 | - if (empty($cfg)){ |
|
| 149 | + if (empty($cfg)) { |
|
| 150 | 150 | $cfg[0] = & load_configurations(); |
| 151 | 151 | } |
| 152 | 152 | return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default; |
@@ -160,9 +160,9 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @codeCoverageIgnore |
| 162 | 162 | */ |
| 163 | - function save_to_log($level, $message, $logger = null){ |
|
| 164 | - $log =& class_loader('Log', 'classes'); |
|
| 165 | - if ($logger){ |
|
| 163 | + function save_to_log($level, $message, $logger = null) { |
|
| 164 | + $log = & class_loader('Log', 'classes'); |
|
| 165 | + if ($logger) { |
|
| 166 | 166 | $log->setLogger($logger); |
| 167 | 167 | } |
| 168 | 168 | $log->writeLog($message, $level); |
@@ -175,8 +175,8 @@ discard block |
||
| 175 | 175 | * |
| 176 | 176 | * @codeCoverageIgnore |
| 177 | 177 | */ |
| 178 | - function set_http_status_header($code = 200, $text = null){ |
|
| 179 | - if (empty($text)){ |
|
| 178 | + function set_http_status_header($code = 200, $text = null) { |
|
| 179 | + if (empty($text)) { |
|
| 180 | 180 | $http_status = array( |
| 181 | 181 | 100 => 'Continue', |
| 182 | 182 | 101 => 'Switching Protocols', |
@@ -224,18 +224,18 @@ discard block |
||
| 224 | 224 | 504 => 'Gateway Timeout', |
| 225 | 225 | 505 => 'HTTP Version Not Supported', |
| 226 | 226 | ); |
| 227 | - if (isset($http_status[$code])){ |
|
| 227 | + if (isset($http_status[$code])) { |
|
| 228 | 228 | $text = $http_status[$code]; |
| 229 | 229 | } |
| 230 | - else{ |
|
| 230 | + else { |
|
| 231 | 231 | show_error('No HTTP status text found for your code please check it.'); |
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - if (strpos(php_sapi_name(), 'cgi') === 0){ |
|
| 235 | + if (strpos(php_sapi_name(), 'cgi') === 0) { |
|
| 236 | 236 | header('Status: ' . $code . ' ' . $text, TRUE); |
| 237 | 237 | } |
| 238 | - else{ |
|
| 238 | + else { |
|
| 239 | 239 | $proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; |
| 240 | 240 | header($proto . ' ' . $code . ' ' . $text, TRUE, $code); |
| 241 | 241 | } |
@@ -250,13 +250,13 @@ discard block |
||
| 250 | 250 | * |
| 251 | 251 | * @codeCoverageIgnore |
| 252 | 252 | */ |
| 253 | - function show_error($msg, $title = 'error', $logging = true){ |
|
| 253 | + function show_error($msg, $title = 'error', $logging = true) { |
|
| 254 | 254 | $title = strtoupper($title); |
| 255 | 255 | $data = array(); |
| 256 | 256 | $data['error'] = $msg; |
| 257 | 257 | $data['title'] = $title; |
| 258 | - if ($logging){ |
|
| 259 | - save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR'); |
|
| 258 | + if ($logging) { |
|
| 259 | + save_to_log('error', '[' . $title . '] ' . strip_tags($msg), 'GLOBAL::ERROR'); |
|
| 260 | 260 | } |
| 261 | 261 | $response = & class_loader('Response', 'classes'); |
| 262 | 262 | $response->sendError($data); |
@@ -270,18 +270,18 @@ discard block |
||
| 270 | 270 | * |
| 271 | 271 | * @return boolean true if the web server uses the https protocol, false if not. |
| 272 | 272 | */ |
| 273 | - function is_https(){ |
|
| 273 | + function is_https() { |
|
| 274 | 274 | /* |
| 275 | 275 | * some servers pass the "HTTPS" parameter in the server variable, |
| 276 | 276 | * if is the case, check if the value is "on", "true", "1". |
| 277 | 277 | */ |
| 278 | - if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){ |
|
| 278 | + if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { |
|
| 279 | 279 | return true; |
| 280 | 280 | } |
| 281 | - else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
| 281 | + else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 282 | 282 | return true; |
| 283 | 283 | } |
| 284 | - else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
| 284 | + else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') { |
|
| 285 | 285 | return true; |
| 286 | 286 | } |
| 287 | 287 | return false; |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | * |
| 297 | 297 | * @return boolean true if is a valid URL address or false. |
| 298 | 298 | */ |
| 299 | - function is_url($url){ |
|
| 299 | + function is_url($url) { |
|
| 300 | 300 | return preg_match('/^(http|https|ftp):\/\/(.*)/', $url) == 1; |
| 301 | 301 | } |
| 302 | 302 | |
@@ -306,8 +306,8 @@ discard block |
||
| 306 | 306 | * @param string $controllerClass the controller class name to be loaded |
| 307 | 307 | * @codeCoverageIgnore |
| 308 | 308 | */ |
| 309 | - function autoload_controller($controllerClass){ |
|
| 310 | - if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){ |
|
| 309 | + function autoload_controller($controllerClass) { |
|
| 310 | + if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')) { |
|
| 311 | 311 | require_once $path; |
| 312 | 312 | } |
| 313 | 313 | } |
@@ -321,11 +321,11 @@ discard block |
||
| 321 | 321 | * |
| 322 | 322 | * @return boolean |
| 323 | 323 | */ |
| 324 | - function php_exception_handler($ex){ |
|
| 325 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
| 326 | - show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
| 324 | + function php_exception_handler($ex) { |
|
| 325 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { |
|
| 326 | + show_error('An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
| 327 | 327 | } |
| 328 | - else{ |
|
| 328 | + else { |
|
| 329 | 329 | save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception'); |
| 330 | 330 | } |
| 331 | 331 | return true; |
@@ -342,16 +342,16 @@ discard block |
||
| 342 | 342 | * |
| 343 | 343 | * @return boolean |
| 344 | 344 | */ |
| 345 | - function php_error_handler($errno , $errstr, $errfile , $errline){ |
|
| 345 | + function php_error_handler($errno, $errstr, $errfile, $errline) { |
|
| 346 | 346 | $isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno); |
| 347 | - if ($isError){ |
|
| 347 | + if ($isError) { |
|
| 348 | 348 | set_http_status_header(500); |
| 349 | 349 | } |
| 350 | - if (! (error_reporting() & $errno)) { |
|
| 350 | + if (!(error_reporting() & $errno)) { |
|
| 351 | 351 | save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ERROR'); |
| 352 | 352 | return; |
| 353 | 353 | } |
| 354 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
| 354 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { |
|
| 355 | 355 | $errorType = 'error'; |
| 356 | 356 | switch ($errno) { |
| 357 | 357 | case E_USER_ERROR: |
@@ -367,9 +367,9 @@ discard block |
||
| 367 | 367 | $errorType = 'error'; |
| 368 | 368 | break; |
| 369 | 369 | } |
| 370 | - show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
| 370 | + show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline . '</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
| 371 | 371 | } |
| 372 | - if ($isError){ |
|
| 372 | + if ($isError) { |
|
| 373 | 373 | die(); |
| 374 | 374 | } |
| 375 | 375 | return true; |
@@ -379,10 +379,10 @@ discard block |
||
| 379 | 379 | * This function is used to run in shutdown situation of the script |
| 380 | 380 | * @codeCoverageIgnore |
| 381 | 381 | */ |
| 382 | - function php_shudown_handler(){ |
|
| 382 | + function php_shudown_handler() { |
|
| 383 | 383 | $lastError = error_get_last(); |
| 384 | 384 | if (isset($lastError) && |
| 385 | - ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){ |
|
| 385 | + ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))) { |
|
| 386 | 386 | php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']); |
| 387 | 387 | } |
| 388 | 388 | } |
@@ -400,11 +400,11 @@ discard block |
||
| 400 | 400 | * |
| 401 | 401 | * @return string string of the HTML attribute. |
| 402 | 402 | */ |
| 403 | - function attributes_to_string(array $attributes){ |
|
| 403 | + function attributes_to_string(array $attributes) { |
|
| 404 | 404 | $str = ' '; |
| 405 | 405 | //we check that the array passed as an argument is not empty. |
| 406 | - if (! empty($attributes)){ |
|
| 407 | - foreach($attributes as $key => $value){ |
|
| 406 | + if (!empty($attributes)) { |
|
| 407 | + foreach ($attributes as $key => $value) { |
|
| 408 | 408 | $key = trim(htmlspecialchars($key)); |
| 409 | 409 | $value = trim(htmlspecialchars($value)); |
| 410 | 410 | /* |
@@ -414,10 +414,10 @@ discard block |
||
| 414 | 414 | * $attr = array('placeholder' => 'I am a "puple"') |
| 415 | 415 | * $str = attributes_to_string($attr); => placeholder = "I am a \"puple\"" |
| 416 | 416 | */ |
| 417 | - if ($value && strpos('"', $value) !== false){ |
|
| 417 | + if ($value && strpos('"', $value) !== false) { |
|
| 418 | 418 | $value = addslashes($value); |
| 419 | 419 | } |
| 420 | - $str .= $key.' = "'.$value.'" '; |
|
| 420 | + $str .= $key . ' = "' . $value . '" '; |
|
| 421 | 421 | } |
| 422 | 422 | } |
| 423 | 423 | //remove the space after using rtrim() |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | * |
| 434 | 434 | * @return string the stringfy value |
| 435 | 435 | */ |
| 436 | - function stringfy_vars($var){ |
|
| 436 | + function stringfy_vars($var) { |
|
| 437 | 437 | return print_r($var, true); |
| 438 | 438 | } |
| 439 | 439 | |
@@ -444,18 +444,18 @@ discard block |
||
| 444 | 444 | * |
| 445 | 445 | * @return mixed the sanitize value |
| 446 | 446 | */ |
| 447 | - function clean_input($str){ |
|
| 448 | - if (is_array($str)){ |
|
| 447 | + function clean_input($str) { |
|
| 448 | + if (is_array($str)) { |
|
| 449 | 449 | $str = array_map('clean_input', $str); |
| 450 | 450 | } |
| 451 | - else if (is_object($str)){ |
|
| 451 | + else if (is_object($str)) { |
|
| 452 | 452 | $obj = $str; |
| 453 | 453 | foreach ($str as $var => $value) { |
| 454 | 454 | $obj->$var = clean_input($value); |
| 455 | 455 | } |
| 456 | 456 | $str = $obj; |
| 457 | 457 | } |
| 458 | - else{ |
|
| 458 | + else { |
|
| 459 | 459 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
| 460 | 460 | } |
| 461 | 461 | return $str; |
@@ -473,11 +473,11 @@ discard block |
||
| 473 | 473 | * |
| 474 | 474 | * @return string the string with the hidden part. |
| 475 | 475 | */ |
| 476 | - function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
|
| 476 | + function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') { |
|
| 477 | 477 | //get the string length |
| 478 | 478 | $len = strlen($str); |
| 479 | 479 | //if str is empty |
| 480 | - if ($len <= 0){ |
|
| 480 | + if ($len <= 0) { |
|
| 481 | 481 | return str_repeat($hiddenChar, 6); |
| 482 | 482 | } |
| 483 | 483 | //if the length is less than startCount and endCount |
@@ -485,14 +485,14 @@ discard block |
||
| 485 | 485 | //or startCount is negative or endCount is negative |
| 486 | 486 | //return the full string hidden |
| 487 | 487 | |
| 488 | - if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){ |
|
| 488 | + if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) { |
|
| 489 | 489 | return str_repeat($hiddenChar, $len); |
| 490 | 490 | } |
| 491 | 491 | //the start non hidden string |
| 492 | 492 | $startNonHiddenStr = substr($str, 0, $startCount); |
| 493 | 493 | //the end non hidden string |
| 494 | 494 | $endNonHiddenStr = null; |
| 495 | - if ($endCount > 0){ |
|
| 495 | + if ($endCount > 0) { |
|
| 496 | 496 | $endNonHiddenStr = substr($str, - $endCount); |
| 497 | 497 | } |
| 498 | 498 | //the hidden string |
@@ -505,40 +505,40 @@ discard block |
||
| 505 | 505 | * This function is used to set the initial session config regarding the configuration |
| 506 | 506 | * @codeCoverageIgnore |
| 507 | 507 | */ |
| 508 | - function set_session_config(){ |
|
| 508 | + function set_session_config() { |
|
| 509 | 509 | //$_SESSION is not available on cli mode |
| 510 | - if (! IS_CLI){ |
|
| 511 | - $logger =& class_loader('Log', 'classes'); |
|
| 510 | + if (!IS_CLI) { |
|
| 511 | + $logger = & class_loader('Log', 'classes'); |
|
| 512 | 512 | $logger->setLogger('PHPSession'); |
| 513 | 513 | //set session params |
| 514 | 514 | $sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files |
| 515 | 515 | $sessionName = get_config('session_name'); |
| 516 | - if ($sessionName){ |
|
| 516 | + if ($sessionName) { |
|
| 517 | 517 | session_name($sessionName); |
| 518 | 518 | } |
| 519 | 519 | $logger->info('Session handler: ' . $sessionHandler); |
| 520 | 520 | $logger->info('Session name: ' . $sessionName); |
| 521 | 521 | |
| 522 | - if ($sessionHandler == 'files'){ |
|
| 522 | + if ($sessionHandler == 'files') { |
|
| 523 | 523 | $sessionSavePath = get_config('session_save_path'); |
| 524 | - if ($sessionSavePath){ |
|
| 525 | - if (! is_dir($sessionSavePath)){ |
|
| 524 | + if ($sessionSavePath) { |
|
| 525 | + if (!is_dir($sessionSavePath)) { |
|
| 526 | 526 | mkdir($sessionSavePath, 1773); |
| 527 | 527 | } |
| 528 | 528 | session_save_path($sessionSavePath); |
| 529 | 529 | $logger->info('Session save path: ' . $sessionSavePath); |
| 530 | 530 | } |
| 531 | 531 | } |
| 532 | - else if ($sessionHandler == 'database'){ |
|
| 532 | + else if ($sessionHandler == 'database') { |
|
| 533 | 533 | //load database session handle library |
| 534 | 534 | //Database Session handler Model |
| 535 | 535 | require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php'; |
| 536 | 536 | |
| 537 | - $DBS =& class_loader('DBSessionHandler', 'classes'); |
|
| 537 | + $DBS = & class_loader('DBSessionHandler', 'classes'); |
|
| 538 | 538 | session_set_save_handler($DBS, true); |
| 539 | 539 | $logger->info('session save path: ' . get_config('session_save_path')); |
| 540 | 540 | } |
| 541 | - else{ |
|
| 541 | + else { |
|
| 542 | 542 | show_error('Invalid session handler configuration'); |
| 543 | 543 | } |
| 544 | 544 | $lifetime = get_config('session_cookie_lifetime', 0); |
@@ -561,9 +561,9 @@ discard block |
||
| 561 | 561 | $logger->info('Session lifetime: ' . $lifetime); |
| 562 | 562 | $logger->info('Session cookie path: ' . $path); |
| 563 | 563 | $logger->info('Session domain: ' . $domain); |
| 564 | - $logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE')); |
|
| 564 | + $logger->info('Session is secure: ' . ($secure ? 'TRUE' : 'FALSE')); |
|
| 565 | 565 | |
| 566 | - if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){ |
|
| 566 | + if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()) { |
|
| 567 | 567 | $logger->info('Session not yet start, start it now'); |
| 568 | 568 | session_start(); |
| 569 | 569 | } |
@@ -226,16 +226,14 @@ discard block |
||
| 226 | 226 | ); |
| 227 | 227 | if (isset($http_status[$code])){ |
| 228 | 228 | $text = $http_status[$code]; |
| 229 | - } |
|
| 230 | - else{ |
|
| 229 | + } else{ |
|
| 231 | 230 | show_error('No HTTP status text found for your code please check it.'); |
| 232 | 231 | } |
| 233 | 232 | } |
| 234 | 233 | |
| 235 | 234 | if (strpos(php_sapi_name(), 'cgi') === 0){ |
| 236 | 235 | header('Status: ' . $code . ' ' . $text, TRUE); |
| 237 | - } |
|
| 238 | - else{ |
|
| 236 | + } else{ |
|
| 239 | 237 | $proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; |
| 240 | 238 | header($proto . ' ' . $code . ' ' . $text, TRUE, $code); |
| 241 | 239 | } |
@@ -277,11 +275,9 @@ discard block |
||
| 277 | 275 | */ |
| 278 | 276 | if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){ |
| 279 | 277 | return true; |
| 280 | - } |
|
| 281 | - else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
| 278 | + } else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
| 282 | 279 | return true; |
| 283 | - } |
|
| 284 | - else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
| 280 | + } else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
| 285 | 281 | return true; |
| 286 | 282 | } |
| 287 | 283 | return false; |
@@ -324,8 +320,7 @@ discard block |
||
| 324 | 320 | function php_exception_handler($ex){ |
| 325 | 321 | if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
| 326 | 322 | show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
| 327 | - } |
|
| 328 | - else{ |
|
| 323 | + } else{ |
|
| 329 | 324 | save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception'); |
| 330 | 325 | } |
| 331 | 326 | return true; |
@@ -447,15 +442,13 @@ discard block |
||
| 447 | 442 | function clean_input($str){ |
| 448 | 443 | if (is_array($str)){ |
| 449 | 444 | $str = array_map('clean_input', $str); |
| 450 | - } |
|
| 451 | - else if (is_object($str)){ |
|
| 445 | + } else if (is_object($str)){ |
|
| 452 | 446 | $obj = $str; |
| 453 | 447 | foreach ($str as $var => $value) { |
| 454 | 448 | $obj->$var = clean_input($value); |
| 455 | 449 | } |
| 456 | 450 | $str = $obj; |
| 457 | - } |
|
| 458 | - else{ |
|
| 451 | + } else{ |
|
| 459 | 452 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
| 460 | 453 | } |
| 461 | 454 | return $str; |
@@ -528,8 +521,7 @@ discard block |
||
| 528 | 521 | session_save_path($sessionSavePath); |
| 529 | 522 | $logger->info('Session save path: ' . $sessionSavePath); |
| 530 | 523 | } |
| 531 | - } |
|
| 532 | - else if ($sessionHandler == 'database'){ |
|
| 524 | + } else if ($sessionHandler == 'database'){ |
|
| 533 | 525 | //load database session handle library |
| 534 | 526 | //Database Session handler Model |
| 535 | 527 | require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php'; |
@@ -537,8 +529,7 @@ discard block |
||
| 537 | 529 | $DBS =& class_loader('DBSessionHandler', 'classes'); |
| 538 | 530 | session_set_save_handler($DBS, true); |
| 539 | 531 | $logger->info('session save path: ' . get_config('session_save_path')); |
| 540 | - } |
|
| 541 | - else{ |
|
| 532 | + } else{ |
|
| 542 | 533 | show_error('Invalid session handler configuration'); |
| 543 | 534 | } |
| 544 | 535 | $lifetime = get_config('session_cookie_lifetime', 0); |
@@ -1,585 +1,585 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @file common.php |
|
| 29 | - * |
|
| 30 | - * Contains most of the commons functions used by the system |
|
| 31 | - * |
|
| 32 | - * @package core |
|
| 33 | - * @author Tony NGUEREZA |
|
| 34 | - * @copyright Copyright (c) 2017 |
|
| 35 | - * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 36 | - * @link http://www.iacademy.cf |
|
| 37 | - * @version 1.0.0 |
|
| 38 | - * @filesource |
|
| 39 | - */ |
|
| 27 | + /** |
|
| 28 | + * @file common.php |
|
| 29 | + * |
|
| 30 | + * Contains most of the commons functions used by the system |
|
| 31 | + * |
|
| 32 | + * @package core |
|
| 33 | + * @author Tony NGUEREZA |
|
| 34 | + * @copyright Copyright (c) 2017 |
|
| 35 | + * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 36 | + * @link http://www.iacademy.cf |
|
| 37 | + * @version 1.0.0 |
|
| 38 | + * @filesource |
|
| 39 | + */ |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * This function is the class loader helper is used if the library "Loader" not yet loaded |
|
| 44 | - * he load the class once |
|
| 45 | - * @param string $class the class name to be loaded |
|
| 46 | - * @param string $dir the directory where to find the class |
|
| 47 | - * @param mixed $params the parameter to pass as argument to the constructor of the class |
|
| 48 | - * @codeCoverageIgnore |
|
| 49 | - * |
|
| 50 | - * @return object the instance of the loaded class |
|
| 51 | - */ |
|
| 52 | - function & class_loader($class, $dir = 'libraries', $params = null){ |
|
| 53 | - //put the first letter of class to upper case |
|
| 54 | - $class = ucfirst($class); |
|
| 55 | - static $classes = array(); |
|
| 56 | - if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){ |
|
| 57 | - return $classes[$class]; |
|
| 58 | - } |
|
| 59 | - $found = false; |
|
| 60 | - foreach (array(ROOT_PATH, CORE_PATH) as $path) { |
|
| 61 | - $file = $path . $dir . '/' . $class . '.php'; |
|
| 62 | - if (file_exists($file)){ |
|
| 63 | - if (class_exists($class, false) === false){ |
|
| 64 | - require_once $file; |
|
| 65 | - } |
|
| 66 | - //already found |
|
| 67 | - $found = true; |
|
| 68 | - break; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - if (! $found){ |
|
| 72 | - //can't use show_error() at this time because some dependencies not yet loaded |
|
| 73 | - set_http_status_header(503); |
|
| 74 | - echo 'Cannot find the class [' . $class . ']'; |
|
| 75 | - die(); |
|
| 76 | - } |
|
| 42 | + /** |
|
| 43 | + * This function is the class loader helper is used if the library "Loader" not yet loaded |
|
| 44 | + * he load the class once |
|
| 45 | + * @param string $class the class name to be loaded |
|
| 46 | + * @param string $dir the directory where to find the class |
|
| 47 | + * @param mixed $params the parameter to pass as argument to the constructor of the class |
|
| 48 | + * @codeCoverageIgnore |
|
| 49 | + * |
|
| 50 | + * @return object the instance of the loaded class |
|
| 51 | + */ |
|
| 52 | + function & class_loader($class, $dir = 'libraries', $params = null){ |
|
| 53 | + //put the first letter of class to upper case |
|
| 54 | + $class = ucfirst($class); |
|
| 55 | + static $classes = array(); |
|
| 56 | + if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){ |
|
| 57 | + return $classes[$class]; |
|
| 58 | + } |
|
| 59 | + $found = false; |
|
| 60 | + foreach (array(ROOT_PATH, CORE_PATH) as $path) { |
|
| 61 | + $file = $path . $dir . '/' . $class . '.php'; |
|
| 62 | + if (file_exists($file)){ |
|
| 63 | + if (class_exists($class, false) === false){ |
|
| 64 | + require_once $file; |
|
| 65 | + } |
|
| 66 | + //already found |
|
| 67 | + $found = true; |
|
| 68 | + break; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + if (! $found){ |
|
| 72 | + //can't use show_error() at this time because some dependencies not yet loaded |
|
| 73 | + set_http_status_header(503); |
|
| 74 | + echo 'Cannot find the class [' . $class . ']'; |
|
| 75 | + die(); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /* |
|
| 78 | + /* |
|
| 79 | 79 | TODO use the best method to get the Log instance |
| 80 | 80 | */ |
| 81 | - if ($class == 'Log'){ |
|
| 82 | - //can't use the instruction like "return new Log()" |
|
| 83 | - //because we need return the reference instance of the loaded class. |
|
| 84 | - $log = new Log(); |
|
| 85 | - return $log; |
|
| 86 | - } |
|
| 87 | - //track of loaded classes |
|
| 88 | - class_loaded($class); |
|
| 81 | + if ($class == 'Log'){ |
|
| 82 | + //can't use the instruction like "return new Log()" |
|
| 83 | + //because we need return the reference instance of the loaded class. |
|
| 84 | + $log = new Log(); |
|
| 85 | + return $log; |
|
| 86 | + } |
|
| 87 | + //track of loaded classes |
|
| 88 | + class_loaded($class); |
|
| 89 | 89 | |
| 90 | - //record the class instance |
|
| 91 | - $classes[$class] = isset($params) ? new $class($params) : new $class(); |
|
| 90 | + //record the class instance |
|
| 91 | + $classes[$class] = isset($params) ? new $class($params) : new $class(); |
|
| 92 | 92 | |
| 93 | - return $classes[$class]; |
|
| 94 | - } |
|
| 93 | + return $classes[$class]; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * This function is the helper to record the loaded classes |
|
| 98 | - * @param string $class the loaded class name |
|
| 99 | - * @codeCoverageIgnore |
|
| 100 | - * |
|
| 101 | - * @return array the list of the loaded classes |
|
| 102 | - */ |
|
| 103 | - function & class_loaded($class = null){ |
|
| 104 | - static $list = array(); |
|
| 105 | - if ($class !== null){ |
|
| 106 | - $list[strtolower($class)] = $class; |
|
| 107 | - } |
|
| 108 | - return $list; |
|
| 109 | - } |
|
| 96 | + /** |
|
| 97 | + * This function is the helper to record the loaded classes |
|
| 98 | + * @param string $class the loaded class name |
|
| 99 | + * @codeCoverageIgnore |
|
| 100 | + * |
|
| 101 | + * @return array the list of the loaded classes |
|
| 102 | + */ |
|
| 103 | + function & class_loaded($class = null){ |
|
| 104 | + static $list = array(); |
|
| 105 | + if ($class !== null){ |
|
| 106 | + $list[strtolower($class)] = $class; |
|
| 107 | + } |
|
| 108 | + return $list; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * This function is used to load the configurations in the case the "Config" library not yet loaded |
|
| 113 | - * @param array $overwrite_values if need overwrite the existing configuration |
|
| 114 | - * @codeCoverageIgnore |
|
| 115 | - * |
|
| 116 | - * @return array the configurations values |
|
| 117 | - */ |
|
| 118 | - function & load_configurations(array $overwrite_values = array()){ |
|
| 119 | - static $config; |
|
| 120 | - if (empty($config)){ |
|
| 121 | - $file = CONFIG_PATH . 'config.php'; |
|
| 122 | - $found = false; |
|
| 123 | - if (file_exists($file)){ |
|
| 124 | - require_once $file; |
|
| 125 | - $found = true; |
|
| 126 | - } |
|
| 127 | - if (! $found){ |
|
| 128 | - set_http_status_header(503); |
|
| 129 | - echo 'Unable to find the configuration file [' . $file . ']'; |
|
| 130 | - die(); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - foreach ($overwrite_values as $key => $value) { |
|
| 134 | - $config[$key] = $value; |
|
| 135 | - } |
|
| 136 | - return $config; |
|
| 137 | - } |
|
| 111 | + /** |
|
| 112 | + * This function is used to load the configurations in the case the "Config" library not yet loaded |
|
| 113 | + * @param array $overwrite_values if need overwrite the existing configuration |
|
| 114 | + * @codeCoverageIgnore |
|
| 115 | + * |
|
| 116 | + * @return array the configurations values |
|
| 117 | + */ |
|
| 118 | + function & load_configurations(array $overwrite_values = array()){ |
|
| 119 | + static $config; |
|
| 120 | + if (empty($config)){ |
|
| 121 | + $file = CONFIG_PATH . 'config.php'; |
|
| 122 | + $found = false; |
|
| 123 | + if (file_exists($file)){ |
|
| 124 | + require_once $file; |
|
| 125 | + $found = true; |
|
| 126 | + } |
|
| 127 | + if (! $found){ |
|
| 128 | + set_http_status_header(503); |
|
| 129 | + echo 'Unable to find the configuration file [' . $file . ']'; |
|
| 130 | + die(); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + foreach ($overwrite_values as $key => $value) { |
|
| 134 | + $config[$key] = $value; |
|
| 135 | + } |
|
| 136 | + return $config; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * This function is the helper to get the config value in case the "Config" library not yet loaded |
|
| 141 | - * @param string $key the config item to get the vale |
|
| 142 | - * @param mixed $default the default value to return if can't find the config item in the configuration |
|
| 143 | - * @test |
|
| 144 | - * |
|
| 145 | - * @return mixed the config value |
|
| 146 | - */ |
|
| 147 | - function get_config($key, $default = null){ |
|
| 148 | - static $cfg; |
|
| 149 | - if (empty($cfg)){ |
|
| 150 | - $cfg[0] = & load_configurations(); |
|
| 151 | - } |
|
| 152 | - return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default; |
|
| 153 | - } |
|
| 139 | + /** |
|
| 140 | + * This function is the helper to get the config value in case the "Config" library not yet loaded |
|
| 141 | + * @param string $key the config item to get the vale |
|
| 142 | + * @param mixed $default the default value to return if can't find the config item in the configuration |
|
| 143 | + * @test |
|
| 144 | + * |
|
| 145 | + * @return mixed the config value |
|
| 146 | + */ |
|
| 147 | + function get_config($key, $default = null){ |
|
| 148 | + static $cfg; |
|
| 149 | + if (empty($cfg)){ |
|
| 150 | + $cfg[0] = & load_configurations(); |
|
| 151 | + } |
|
| 152 | + return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * This function is a helper to logging message |
|
| 157 | - * @param string $level the log level "ERROR", "DEBUG", "INFO", etc. |
|
| 158 | - * @param string $message the log message to be saved |
|
| 159 | - * @param string $logger the logger to use if is set |
|
| 160 | - * |
|
| 161 | - * @codeCoverageIgnore |
|
| 162 | - */ |
|
| 163 | - function save_to_log($level, $message, $logger = null){ |
|
| 164 | - $log =& class_loader('Log', 'classes'); |
|
| 165 | - if ($logger){ |
|
| 166 | - $log->setLogger($logger); |
|
| 167 | - } |
|
| 168 | - $log->writeLog($message, $level); |
|
| 169 | - } |
|
| 155 | + /** |
|
| 156 | + * This function is a helper to logging message |
|
| 157 | + * @param string $level the log level "ERROR", "DEBUG", "INFO", etc. |
|
| 158 | + * @param string $message the log message to be saved |
|
| 159 | + * @param string $logger the logger to use if is set |
|
| 160 | + * |
|
| 161 | + * @codeCoverageIgnore |
|
| 162 | + */ |
|
| 163 | + function save_to_log($level, $message, $logger = null){ |
|
| 164 | + $log =& class_loader('Log', 'classes'); |
|
| 165 | + if ($logger){ |
|
| 166 | + $log->setLogger($logger); |
|
| 167 | + } |
|
| 168 | + $log->writeLog($message, $level); |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Set the HTTP status header |
|
| 173 | - * @param integer $code the HTTP status code |
|
| 174 | - * @param string $text the HTTP status text |
|
| 175 | - * |
|
| 176 | - * @codeCoverageIgnore |
|
| 177 | - */ |
|
| 178 | - function set_http_status_header($code = 200, $text = null){ |
|
| 179 | - if (empty($text)){ |
|
| 180 | - $http_status = array( |
|
| 181 | - 100 => 'Continue', |
|
| 182 | - 101 => 'Switching Protocols', |
|
| 171 | + /** |
|
| 172 | + * Set the HTTP status header |
|
| 173 | + * @param integer $code the HTTP status code |
|
| 174 | + * @param string $text the HTTP status text |
|
| 175 | + * |
|
| 176 | + * @codeCoverageIgnore |
|
| 177 | + */ |
|
| 178 | + function set_http_status_header($code = 200, $text = null){ |
|
| 179 | + if (empty($text)){ |
|
| 180 | + $http_status = array( |
|
| 181 | + 100 => 'Continue', |
|
| 182 | + 101 => 'Switching Protocols', |
|
| 183 | 183 | |
| 184 | - 200 => 'OK', |
|
| 185 | - 201 => 'Created', |
|
| 186 | - 202 => 'Accepted', |
|
| 187 | - 203 => 'Non-Authoritative Information', |
|
| 188 | - 204 => 'No Content', |
|
| 189 | - 205 => 'Reset Content', |
|
| 190 | - 206 => 'Partial Content', |
|
| 184 | + 200 => 'OK', |
|
| 185 | + 201 => 'Created', |
|
| 186 | + 202 => 'Accepted', |
|
| 187 | + 203 => 'Non-Authoritative Information', |
|
| 188 | + 204 => 'No Content', |
|
| 189 | + 205 => 'Reset Content', |
|
| 190 | + 206 => 'Partial Content', |
|
| 191 | 191 | |
| 192 | - 300 => 'Multiple Choices', |
|
| 193 | - 301 => 'Moved Permanently', |
|
| 194 | - 302 => 'Found', |
|
| 195 | - 303 => 'See Other', |
|
| 196 | - 304 => 'Not Modified', |
|
| 197 | - 305 => 'Use Proxy', |
|
| 198 | - 307 => 'Temporary Redirect', |
|
| 192 | + 300 => 'Multiple Choices', |
|
| 193 | + 301 => 'Moved Permanently', |
|
| 194 | + 302 => 'Found', |
|
| 195 | + 303 => 'See Other', |
|
| 196 | + 304 => 'Not Modified', |
|
| 197 | + 305 => 'Use Proxy', |
|
| 198 | + 307 => 'Temporary Redirect', |
|
| 199 | 199 | |
| 200 | - 400 => 'Bad Request', |
|
| 201 | - 401 => 'Unauthorized', |
|
| 202 | - 402 => 'Payment Required', |
|
| 203 | - 403 => 'Forbidden', |
|
| 204 | - 404 => 'Not Found', |
|
| 205 | - 405 => 'Method Not Allowed', |
|
| 206 | - 406 => 'Not Acceptable', |
|
| 207 | - 407 => 'Proxy Authentication Required', |
|
| 208 | - 408 => 'Request Timeout', |
|
| 209 | - 409 => 'Conflict', |
|
| 210 | - 410 => 'Gone', |
|
| 211 | - 411 => 'Length Required', |
|
| 212 | - 412 => 'Precondition Failed', |
|
| 213 | - 413 => 'Request Entity Too Large', |
|
| 214 | - 414 => 'Request-URI Too Long', |
|
| 215 | - 415 => 'Unsupported Media Type', |
|
| 216 | - 416 => 'Requested Range Not Satisfiable', |
|
| 217 | - 417 => 'Expectation Failed', |
|
| 218 | - 418 => 'I\'m a teapot', |
|
| 200 | + 400 => 'Bad Request', |
|
| 201 | + 401 => 'Unauthorized', |
|
| 202 | + 402 => 'Payment Required', |
|
| 203 | + 403 => 'Forbidden', |
|
| 204 | + 404 => 'Not Found', |
|
| 205 | + 405 => 'Method Not Allowed', |
|
| 206 | + 406 => 'Not Acceptable', |
|
| 207 | + 407 => 'Proxy Authentication Required', |
|
| 208 | + 408 => 'Request Timeout', |
|
| 209 | + 409 => 'Conflict', |
|
| 210 | + 410 => 'Gone', |
|
| 211 | + 411 => 'Length Required', |
|
| 212 | + 412 => 'Precondition Failed', |
|
| 213 | + 413 => 'Request Entity Too Large', |
|
| 214 | + 414 => 'Request-URI Too Long', |
|
| 215 | + 415 => 'Unsupported Media Type', |
|
| 216 | + 416 => 'Requested Range Not Satisfiable', |
|
| 217 | + 417 => 'Expectation Failed', |
|
| 218 | + 418 => 'I\'m a teapot', |
|
| 219 | 219 | |
| 220 | - 500 => 'Internal Server Error', |
|
| 221 | - 501 => 'Not Implemented', |
|
| 222 | - 502 => 'Bad Gateway', |
|
| 223 | - 503 => 'Service Unavailable', |
|
| 224 | - 504 => 'Gateway Timeout', |
|
| 225 | - 505 => 'HTTP Version Not Supported', |
|
| 226 | - ); |
|
| 227 | - if (isset($http_status[$code])){ |
|
| 228 | - $text = $http_status[$code]; |
|
| 229 | - } |
|
| 230 | - else{ |
|
| 231 | - show_error('No HTTP status text found for your code please check it.'); |
|
| 232 | - } |
|
| 233 | - } |
|
| 220 | + 500 => 'Internal Server Error', |
|
| 221 | + 501 => 'Not Implemented', |
|
| 222 | + 502 => 'Bad Gateway', |
|
| 223 | + 503 => 'Service Unavailable', |
|
| 224 | + 504 => 'Gateway Timeout', |
|
| 225 | + 505 => 'HTTP Version Not Supported', |
|
| 226 | + ); |
|
| 227 | + if (isset($http_status[$code])){ |
|
| 228 | + $text = $http_status[$code]; |
|
| 229 | + } |
|
| 230 | + else{ |
|
| 231 | + show_error('No HTTP status text found for your code please check it.'); |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - if (strpos(php_sapi_name(), 'cgi') === 0){ |
|
| 236 | - header('Status: ' . $code . ' ' . $text, TRUE); |
|
| 237 | - } |
|
| 238 | - else{ |
|
| 239 | - $proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; |
|
| 240 | - header($proto . ' ' . $code . ' ' . $text, TRUE, $code); |
|
| 241 | - } |
|
| 242 | - } |
|
| 235 | + if (strpos(php_sapi_name(), 'cgi') === 0){ |
|
| 236 | + header('Status: ' . $code . ' ' . $text, TRUE); |
|
| 237 | + } |
|
| 238 | + else{ |
|
| 239 | + $proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; |
|
| 240 | + header($proto . ' ' . $code . ' ' . $text, TRUE, $code); |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - /** |
|
| 245 | - * This function displays an error message to the user and ends the execution of the script. |
|
| 246 | - * |
|
| 247 | - * @param string $msg the message to display |
|
| 248 | - * @param string $title the message title: "error", "info", "warning", etc. |
|
| 249 | - * @param boolean $logging either to save error in log |
|
| 250 | - * |
|
| 251 | - * @codeCoverageIgnore |
|
| 252 | - */ |
|
| 253 | - function show_error($msg, $title = 'error', $logging = true){ |
|
| 254 | - $title = strtoupper($title); |
|
| 255 | - $data = array(); |
|
| 256 | - $data['error'] = $msg; |
|
| 257 | - $data['title'] = $title; |
|
| 258 | - if ($logging){ |
|
| 259 | - save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR'); |
|
| 260 | - } |
|
| 261 | - $response = & class_loader('Response', 'classes'); |
|
| 262 | - $response->sendError($data); |
|
| 263 | - die(); |
|
| 264 | - } |
|
| 244 | + /** |
|
| 245 | + * This function displays an error message to the user and ends the execution of the script. |
|
| 246 | + * |
|
| 247 | + * @param string $msg the message to display |
|
| 248 | + * @param string $title the message title: "error", "info", "warning", etc. |
|
| 249 | + * @param boolean $logging either to save error in log |
|
| 250 | + * |
|
| 251 | + * @codeCoverageIgnore |
|
| 252 | + */ |
|
| 253 | + function show_error($msg, $title = 'error', $logging = true){ |
|
| 254 | + $title = strtoupper($title); |
|
| 255 | + $data = array(); |
|
| 256 | + $data['error'] = $msg; |
|
| 257 | + $data['title'] = $title; |
|
| 258 | + if ($logging){ |
|
| 259 | + save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR'); |
|
| 260 | + } |
|
| 261 | + $response = & class_loader('Response', 'classes'); |
|
| 262 | + $response->sendError($data); |
|
| 263 | + die(); |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - /** |
|
| 267 | - * Check whether the protocol used is "https" or not |
|
| 268 | - * That is, the web server is configured to use a secure connection. |
|
| 269 | - * @codeCoverageIgnore |
|
| 270 | - * |
|
| 271 | - * @return boolean true if the web server uses the https protocol, false if not. |
|
| 272 | - */ |
|
| 273 | - function is_https(){ |
|
| 274 | - /* |
|
| 266 | + /** |
|
| 267 | + * Check whether the protocol used is "https" or not |
|
| 268 | + * That is, the web server is configured to use a secure connection. |
|
| 269 | + * @codeCoverageIgnore |
|
| 270 | + * |
|
| 271 | + * @return boolean true if the web server uses the https protocol, false if not. |
|
| 272 | + */ |
|
| 273 | + function is_https(){ |
|
| 274 | + /* |
|
| 275 | 275 | * some servers pass the "HTTPS" parameter in the server variable, |
| 276 | 276 | * if is the case, check if the value is "on", "true", "1". |
| 277 | 277 | */ |
| 278 | - if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){ |
|
| 279 | - return true; |
|
| 280 | - } |
|
| 281 | - else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
| 282 | - return true; |
|
| 283 | - } |
|
| 284 | - else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
| 285 | - return true; |
|
| 286 | - } |
|
| 287 | - return false; |
|
| 288 | - } |
|
| 278 | + if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){ |
|
| 279 | + return true; |
|
| 280 | + } |
|
| 281 | + else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
| 282 | + return true; |
|
| 283 | + } |
|
| 284 | + else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
| 285 | + return true; |
|
| 286 | + } |
|
| 287 | + return false; |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - /** |
|
| 291 | - * This function is used to check the URL format of the given string argument. |
|
| 292 | - * The address is valid if the protocol is http, https, ftp, etc. |
|
| 293 | - * |
|
| 294 | - * @param string $url the URL address to check |
|
| 295 | - * @test |
|
| 296 | - * |
|
| 297 | - * @return boolean true if is a valid URL address or false. |
|
| 298 | - */ |
|
| 299 | - function is_url($url){ |
|
| 300 | - return preg_match('/^(http|https|ftp):\/\/(.*)/', $url) == 1; |
|
| 301 | - } |
|
| 290 | + /** |
|
| 291 | + * This function is used to check the URL format of the given string argument. |
|
| 292 | + * The address is valid if the protocol is http, https, ftp, etc. |
|
| 293 | + * |
|
| 294 | + * @param string $url the URL address to check |
|
| 295 | + * @test |
|
| 296 | + * |
|
| 297 | + * @return boolean true if is a valid URL address or false. |
|
| 298 | + */ |
|
| 299 | + function is_url($url){ |
|
| 300 | + return preg_match('/^(http|https|ftp):\/\/(.*)/', $url) == 1; |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | - /** |
|
| 304 | - * Function defined to load controller |
|
| 305 | - * |
|
| 306 | - * @param string $controllerClass the controller class name to be loaded |
|
| 307 | - * @codeCoverageIgnore |
|
| 308 | - */ |
|
| 309 | - function autoload_controller($controllerClass){ |
|
| 310 | - if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){ |
|
| 311 | - require_once $path; |
|
| 312 | - } |
|
| 313 | - } |
|
| 303 | + /** |
|
| 304 | + * Function defined to load controller |
|
| 305 | + * |
|
| 306 | + * @param string $controllerClass the controller class name to be loaded |
|
| 307 | + * @codeCoverageIgnore |
|
| 308 | + */ |
|
| 309 | + function autoload_controller($controllerClass){ |
|
| 310 | + if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){ |
|
| 311 | + require_once $path; |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - /** |
|
| 316 | - * Function defined for handling PHP exception error message, |
|
| 317 | - * it displays an error message using the function "show_error" |
|
| 318 | - * |
|
| 319 | - * @param object $ex instance of the "Exception" class or a derived class |
|
| 320 | - * @codeCoverageIgnore |
|
| 321 | - * |
|
| 322 | - * @return boolean |
|
| 323 | - */ |
|
| 324 | - function php_exception_handler($ex){ |
|
| 325 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
| 326 | - show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
| 327 | - } |
|
| 328 | - else{ |
|
| 329 | - save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception'); |
|
| 330 | - } |
|
| 331 | - return true; |
|
| 332 | - } |
|
| 315 | + /** |
|
| 316 | + * Function defined for handling PHP exception error message, |
|
| 317 | + * it displays an error message using the function "show_error" |
|
| 318 | + * |
|
| 319 | + * @param object $ex instance of the "Exception" class or a derived class |
|
| 320 | + * @codeCoverageIgnore |
|
| 321 | + * |
|
| 322 | + * @return boolean |
|
| 323 | + */ |
|
| 324 | + function php_exception_handler($ex){ |
|
| 325 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
| 326 | + show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
| 327 | + } |
|
| 328 | + else{ |
|
| 329 | + save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception'); |
|
| 330 | + } |
|
| 331 | + return true; |
|
| 332 | + } |
|
| 333 | 333 | |
| 334 | - /** |
|
| 335 | - * Function defined for PHP error message handling |
|
| 336 | - * |
|
| 337 | - * @param int $errno the type of error for example: E_USER_ERROR, E_USER_WARNING, etc. |
|
| 338 | - * @param string $errstr the error message |
|
| 339 | - * @param string $errfile the file where the error occurred |
|
| 340 | - * @param int $errline the line number where the error occurred |
|
| 341 | - * @codeCoverageIgnore |
|
| 342 | - * |
|
| 343 | - * @return boolean |
|
| 344 | - */ |
|
| 345 | - function php_error_handler($errno , $errstr, $errfile , $errline){ |
|
| 346 | - $isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno); |
|
| 347 | - if ($isError){ |
|
| 348 | - set_http_status_header(500); |
|
| 349 | - } |
|
| 350 | - if (! (error_reporting() & $errno)) { |
|
| 351 | - save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ERROR'); |
|
| 352 | - return; |
|
| 353 | - } |
|
| 354 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
| 355 | - $errorType = 'error'; |
|
| 356 | - switch ($errno) { |
|
| 357 | - case E_USER_ERROR: |
|
| 358 | - $errorType = 'error'; |
|
| 359 | - break; |
|
| 360 | - case E_USER_WARNING: |
|
| 361 | - $errorType = 'warning'; |
|
| 362 | - break; |
|
| 363 | - case E_USER_NOTICE: |
|
| 364 | - $errorType = 'notice'; |
|
| 365 | - break; |
|
| 366 | - default: |
|
| 367 | - $errorType = 'error'; |
|
| 368 | - break; |
|
| 369 | - } |
|
| 370 | - show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
| 371 | - } |
|
| 372 | - if ($isError){ |
|
| 373 | - die(); |
|
| 374 | - } |
|
| 375 | - return true; |
|
| 376 | - } |
|
| 334 | + /** |
|
| 335 | + * Function defined for PHP error message handling |
|
| 336 | + * |
|
| 337 | + * @param int $errno the type of error for example: E_USER_ERROR, E_USER_WARNING, etc. |
|
| 338 | + * @param string $errstr the error message |
|
| 339 | + * @param string $errfile the file where the error occurred |
|
| 340 | + * @param int $errline the line number where the error occurred |
|
| 341 | + * @codeCoverageIgnore |
|
| 342 | + * |
|
| 343 | + * @return boolean |
|
| 344 | + */ |
|
| 345 | + function php_error_handler($errno , $errstr, $errfile , $errline){ |
|
| 346 | + $isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno); |
|
| 347 | + if ($isError){ |
|
| 348 | + set_http_status_header(500); |
|
| 349 | + } |
|
| 350 | + if (! (error_reporting() & $errno)) { |
|
| 351 | + save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ERROR'); |
|
| 352 | + return; |
|
| 353 | + } |
|
| 354 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
| 355 | + $errorType = 'error'; |
|
| 356 | + switch ($errno) { |
|
| 357 | + case E_USER_ERROR: |
|
| 358 | + $errorType = 'error'; |
|
| 359 | + break; |
|
| 360 | + case E_USER_WARNING: |
|
| 361 | + $errorType = 'warning'; |
|
| 362 | + break; |
|
| 363 | + case E_USER_NOTICE: |
|
| 364 | + $errorType = 'notice'; |
|
| 365 | + break; |
|
| 366 | + default: |
|
| 367 | + $errorType = 'error'; |
|
| 368 | + break; |
|
| 369 | + } |
|
| 370 | + show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
| 371 | + } |
|
| 372 | + if ($isError){ |
|
| 373 | + die(); |
|
| 374 | + } |
|
| 375 | + return true; |
|
| 376 | + } |
|
| 377 | 377 | |
| 378 | - /** |
|
| 379 | - * This function is used to run in shutdown situation of the script |
|
| 380 | - * @codeCoverageIgnore |
|
| 381 | - */ |
|
| 382 | - function php_shudown_handler(){ |
|
| 383 | - $lastError = error_get_last(); |
|
| 384 | - if (isset($lastError) && |
|
| 385 | - ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){ |
|
| 386 | - php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']); |
|
| 387 | - } |
|
| 388 | - } |
|
| 378 | + /** |
|
| 379 | + * This function is used to run in shutdown situation of the script |
|
| 380 | + * @codeCoverageIgnore |
|
| 381 | + */ |
|
| 382 | + function php_shudown_handler(){ |
|
| 383 | + $lastError = error_get_last(); |
|
| 384 | + if (isset($lastError) && |
|
| 385 | + ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){ |
|
| 386 | + php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']); |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | 389 | |
| 390 | 390 | |
| 391 | - /** |
|
| 392 | - * Convert array attributes to string |
|
| 393 | - * |
|
| 394 | - * This function converts an associative array into HTML attributes. |
|
| 395 | - * For example : |
|
| 396 | - * $a = array('name' => 'Foo', 'type' => 'text'); => produces the following string: |
|
| 397 | - * name = "Foo" type = "text" |
|
| 398 | - * |
|
| 399 | - * @param array $attributes associative array to convert to a string attribute. |
|
| 400 | - * |
|
| 401 | - * @return string string of the HTML attribute. |
|
| 402 | - */ |
|
| 403 | - function attributes_to_string(array $attributes){ |
|
| 404 | - $str = ' '; |
|
| 405 | - //we check that the array passed as an argument is not empty. |
|
| 406 | - if (! empty($attributes)){ |
|
| 407 | - foreach($attributes as $key => $value){ |
|
| 408 | - $key = trim(htmlspecialchars($key)); |
|
| 409 | - $value = trim(htmlspecialchars($value)); |
|
| 410 | - /* |
|
| 391 | + /** |
|
| 392 | + * Convert array attributes to string |
|
| 393 | + * |
|
| 394 | + * This function converts an associative array into HTML attributes. |
|
| 395 | + * For example : |
|
| 396 | + * $a = array('name' => 'Foo', 'type' => 'text'); => produces the following string: |
|
| 397 | + * name = "Foo" type = "text" |
|
| 398 | + * |
|
| 399 | + * @param array $attributes associative array to convert to a string attribute. |
|
| 400 | + * |
|
| 401 | + * @return string string of the HTML attribute. |
|
| 402 | + */ |
|
| 403 | + function attributes_to_string(array $attributes){ |
|
| 404 | + $str = ' '; |
|
| 405 | + //we check that the array passed as an argument is not empty. |
|
| 406 | + if (! empty($attributes)){ |
|
| 407 | + foreach($attributes as $key => $value){ |
|
| 408 | + $key = trim(htmlspecialchars($key)); |
|
| 409 | + $value = trim(htmlspecialchars($value)); |
|
| 410 | + /* |
|
| 411 | 411 | * To predict the case where the string to convert contains the character " |
| 412 | 412 | * we check if this is the case we add a slash to solve this problem. |
| 413 | 413 | * For example: |
| 414 | 414 | * $attr = array('placeholder' => 'I am a "puple"') |
| 415 | 415 | * $str = attributes_to_string($attr); => placeholder = "I am a \"puple\"" |
| 416 | 416 | */ |
| 417 | - if ($value && strpos('"', $value) !== false){ |
|
| 418 | - $value = addslashes($value); |
|
| 419 | - } |
|
| 420 | - $str .= $key.' = "'.$value.'" '; |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - //remove the space after using rtrim() |
|
| 424 | - return rtrim($str); |
|
| 425 | - } |
|
| 417 | + if ($value && strpos('"', $value) !== false){ |
|
| 418 | + $value = addslashes($value); |
|
| 419 | + } |
|
| 420 | + $str .= $key.' = "'.$value.'" '; |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + //remove the space after using rtrim() |
|
| 424 | + return rtrim($str); |
|
| 425 | + } |
|
| 426 | 426 | |
| 427 | 427 | |
| 428 | - /** |
|
| 429 | - * Function to stringfy PHP variable, useful in debug situation |
|
| 430 | - * |
|
| 431 | - * @param mixed $var the variable to stringfy |
|
| 432 | - * @codeCoverageIgnore |
|
| 433 | - * |
|
| 434 | - * @return string the stringfy value |
|
| 435 | - */ |
|
| 436 | - function stringfy_vars($var){ |
|
| 437 | - return print_r($var, true); |
|
| 438 | - } |
|
| 428 | + /** |
|
| 429 | + * Function to stringfy PHP variable, useful in debug situation |
|
| 430 | + * |
|
| 431 | + * @param mixed $var the variable to stringfy |
|
| 432 | + * @codeCoverageIgnore |
|
| 433 | + * |
|
| 434 | + * @return string the stringfy value |
|
| 435 | + */ |
|
| 436 | + function stringfy_vars($var){ |
|
| 437 | + return print_r($var, true); |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | - /** |
|
| 441 | - * Clean the user input |
|
| 442 | - * @param mixed $str the value to clean |
|
| 443 | - * @test |
|
| 444 | - * |
|
| 445 | - * @return mixed the sanitize value |
|
| 446 | - */ |
|
| 447 | - function clean_input($str){ |
|
| 448 | - if (is_array($str)){ |
|
| 449 | - $str = array_map('clean_input', $str); |
|
| 450 | - } |
|
| 451 | - else if (is_object($str)){ |
|
| 452 | - $obj = $str; |
|
| 453 | - foreach ($str as $var => $value) { |
|
| 454 | - $obj->$var = clean_input($value); |
|
| 455 | - } |
|
| 456 | - $str = $obj; |
|
| 457 | - } |
|
| 458 | - else{ |
|
| 459 | - $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
|
| 460 | - } |
|
| 461 | - return $str; |
|
| 462 | - } |
|
| 440 | + /** |
|
| 441 | + * Clean the user input |
|
| 442 | + * @param mixed $str the value to clean |
|
| 443 | + * @test |
|
| 444 | + * |
|
| 445 | + * @return mixed the sanitize value |
|
| 446 | + */ |
|
| 447 | + function clean_input($str){ |
|
| 448 | + if (is_array($str)){ |
|
| 449 | + $str = array_map('clean_input', $str); |
|
| 450 | + } |
|
| 451 | + else if (is_object($str)){ |
|
| 452 | + $obj = $str; |
|
| 453 | + foreach ($str as $var => $value) { |
|
| 454 | + $obj->$var = clean_input($value); |
|
| 455 | + } |
|
| 456 | + $str = $obj; |
|
| 457 | + } |
|
| 458 | + else{ |
|
| 459 | + $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
|
| 460 | + } |
|
| 461 | + return $str; |
|
| 462 | + } |
|
| 463 | 463 | |
| 464 | - /** |
|
| 465 | - * This function is used to hidden some part of the given string. Helpful if you need hide some confidential |
|
| 466 | - * Information like credit card number, password, etc. |
|
| 467 | - * |
|
| 468 | - * @param string $str the string you want to hide some part |
|
| 469 | - * @param int $startCount the length of non hidden for the beginning char |
|
| 470 | - * @param int $endCount the length of non hidden for the ending char |
|
| 471 | - * @param string $hiddenChar the char used to hide the given string |
|
| 472 | - * @test |
|
| 473 | - * |
|
| 474 | - * @return string the string with the hidden part. |
|
| 475 | - */ |
|
| 476 | - function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
|
| 477 | - //get the string length |
|
| 478 | - $len = strlen($str); |
|
| 479 | - //if str is empty |
|
| 480 | - if ($len <= 0){ |
|
| 481 | - return str_repeat($hiddenChar, 6); |
|
| 482 | - } |
|
| 483 | - //if the length is less than startCount and endCount |
|
| 484 | - //or the startCount and endCount length is 0 |
|
| 485 | - //or startCount is negative or endCount is negative |
|
| 486 | - //return the full string hidden |
|
| 464 | + /** |
|
| 465 | + * This function is used to hidden some part of the given string. Helpful if you need hide some confidential |
|
| 466 | + * Information like credit card number, password, etc. |
|
| 467 | + * |
|
| 468 | + * @param string $str the string you want to hide some part |
|
| 469 | + * @param int $startCount the length of non hidden for the beginning char |
|
| 470 | + * @param int $endCount the length of non hidden for the ending char |
|
| 471 | + * @param string $hiddenChar the char used to hide the given string |
|
| 472 | + * @test |
|
| 473 | + * |
|
| 474 | + * @return string the string with the hidden part. |
|
| 475 | + */ |
|
| 476 | + function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
|
| 477 | + //get the string length |
|
| 478 | + $len = strlen($str); |
|
| 479 | + //if str is empty |
|
| 480 | + if ($len <= 0){ |
|
| 481 | + return str_repeat($hiddenChar, 6); |
|
| 482 | + } |
|
| 483 | + //if the length is less than startCount and endCount |
|
| 484 | + //or the startCount and endCount length is 0 |
|
| 485 | + //or startCount is negative or endCount is negative |
|
| 486 | + //return the full string hidden |
|
| 487 | 487 | |
| 488 | - if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){ |
|
| 489 | - return str_repeat($hiddenChar, $len); |
|
| 490 | - } |
|
| 491 | - //the start non hidden string |
|
| 492 | - $startNonHiddenStr = substr($str, 0, $startCount); |
|
| 493 | - //the end non hidden string |
|
| 494 | - $endNonHiddenStr = null; |
|
| 495 | - if ($endCount > 0){ |
|
| 496 | - $endNonHiddenStr = substr($str, - $endCount); |
|
| 497 | - } |
|
| 498 | - //the hidden string |
|
| 499 | - $hiddenStr = str_repeat($hiddenChar, $len - ($startCount + $endCount)); |
|
| 488 | + if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){ |
|
| 489 | + return str_repeat($hiddenChar, $len); |
|
| 490 | + } |
|
| 491 | + //the start non hidden string |
|
| 492 | + $startNonHiddenStr = substr($str, 0, $startCount); |
|
| 493 | + //the end non hidden string |
|
| 494 | + $endNonHiddenStr = null; |
|
| 495 | + if ($endCount > 0){ |
|
| 496 | + $endNonHiddenStr = substr($str, - $endCount); |
|
| 497 | + } |
|
| 498 | + //the hidden string |
|
| 499 | + $hiddenStr = str_repeat($hiddenChar, $len - ($startCount + $endCount)); |
|
| 500 | 500 | |
| 501 | - return $startNonHiddenStr . $hiddenStr . $endNonHiddenStr; |
|
| 502 | - } |
|
| 501 | + return $startNonHiddenStr . $hiddenStr . $endNonHiddenStr; |
|
| 502 | + } |
|
| 503 | 503 | |
| 504 | - /** |
|
| 505 | - * This function is used to set the initial session config regarding the configuration |
|
| 506 | - * @codeCoverageIgnore |
|
| 507 | - */ |
|
| 508 | - function set_session_config(){ |
|
| 509 | - //$_SESSION is not available on cli mode |
|
| 510 | - if (! IS_CLI){ |
|
| 511 | - $logger =& class_loader('Log', 'classes'); |
|
| 512 | - $logger->setLogger('PHPSession'); |
|
| 513 | - //set session params |
|
| 514 | - $sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files |
|
| 515 | - $sessionName = get_config('session_name'); |
|
| 516 | - if ($sessionName){ |
|
| 517 | - session_name($sessionName); |
|
| 518 | - } |
|
| 519 | - $logger->info('Session handler: ' . $sessionHandler); |
|
| 520 | - $logger->info('Session name: ' . $sessionName); |
|
| 504 | + /** |
|
| 505 | + * This function is used to set the initial session config regarding the configuration |
|
| 506 | + * @codeCoverageIgnore |
|
| 507 | + */ |
|
| 508 | + function set_session_config(){ |
|
| 509 | + //$_SESSION is not available on cli mode |
|
| 510 | + if (! IS_CLI){ |
|
| 511 | + $logger =& class_loader('Log', 'classes'); |
|
| 512 | + $logger->setLogger('PHPSession'); |
|
| 513 | + //set session params |
|
| 514 | + $sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files |
|
| 515 | + $sessionName = get_config('session_name'); |
|
| 516 | + if ($sessionName){ |
|
| 517 | + session_name($sessionName); |
|
| 518 | + } |
|
| 519 | + $logger->info('Session handler: ' . $sessionHandler); |
|
| 520 | + $logger->info('Session name: ' . $sessionName); |
|
| 521 | 521 | |
| 522 | - if ($sessionHandler == 'files'){ |
|
| 523 | - $sessionSavePath = get_config('session_save_path'); |
|
| 524 | - if ($sessionSavePath){ |
|
| 525 | - if (! is_dir($sessionSavePath)){ |
|
| 526 | - mkdir($sessionSavePath, 1773); |
|
| 527 | - } |
|
| 528 | - session_save_path($sessionSavePath); |
|
| 529 | - $logger->info('Session save path: ' . $sessionSavePath); |
|
| 530 | - } |
|
| 531 | - } |
|
| 532 | - else if ($sessionHandler == 'database'){ |
|
| 533 | - //load database session handle library |
|
| 534 | - //Database Session handler Model |
|
| 535 | - require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php'; |
|
| 522 | + if ($sessionHandler == 'files'){ |
|
| 523 | + $sessionSavePath = get_config('session_save_path'); |
|
| 524 | + if ($sessionSavePath){ |
|
| 525 | + if (! is_dir($sessionSavePath)){ |
|
| 526 | + mkdir($sessionSavePath, 1773); |
|
| 527 | + } |
|
| 528 | + session_save_path($sessionSavePath); |
|
| 529 | + $logger->info('Session save path: ' . $sessionSavePath); |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | + else if ($sessionHandler == 'database'){ |
|
| 533 | + //load database session handle library |
|
| 534 | + //Database Session handler Model |
|
| 535 | + require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php'; |
|
| 536 | 536 | |
| 537 | - $DBS =& class_loader('DBSessionHandler', 'classes'); |
|
| 538 | - session_set_save_handler($DBS, true); |
|
| 539 | - $logger->info('session save path: ' . get_config('session_save_path')); |
|
| 540 | - } |
|
| 541 | - else{ |
|
| 542 | - show_error('Invalid session handler configuration'); |
|
| 543 | - } |
|
| 544 | - $lifetime = get_config('session_cookie_lifetime', 0); |
|
| 545 | - $path = get_config('session_cookie_path', '/'); |
|
| 546 | - $domain = get_config('session_cookie_domain', ''); |
|
| 547 | - $secure = get_config('session_cookie_secure', false); |
|
| 548 | - session_set_cookie_params( |
|
| 549 | - $lifetime, |
|
| 550 | - $path, |
|
| 551 | - $domain, |
|
| 552 | - $secure, |
|
| 553 | - $httponly = true /*for security for access to cookie via javascript or XSS attack*/ |
|
| 554 | - ); |
|
| 555 | - //to prevent attack of Session Fixation |
|
| 556 | - //thank to https://www.phparch.com/2018/01/php-sessions-in-depth/ |
|
| 557 | - ini_set('session.use_strict_mode ', 1); |
|
| 558 | - ini_set('session.use_only_cookies', 1); |
|
| 559 | - ini_set('session.use_trans_sid ', 0); |
|
| 537 | + $DBS =& class_loader('DBSessionHandler', 'classes'); |
|
| 538 | + session_set_save_handler($DBS, true); |
|
| 539 | + $logger->info('session save path: ' . get_config('session_save_path')); |
|
| 540 | + } |
|
| 541 | + else{ |
|
| 542 | + show_error('Invalid session handler configuration'); |
|
| 543 | + } |
|
| 544 | + $lifetime = get_config('session_cookie_lifetime', 0); |
|
| 545 | + $path = get_config('session_cookie_path', '/'); |
|
| 546 | + $domain = get_config('session_cookie_domain', ''); |
|
| 547 | + $secure = get_config('session_cookie_secure', false); |
|
| 548 | + session_set_cookie_params( |
|
| 549 | + $lifetime, |
|
| 550 | + $path, |
|
| 551 | + $domain, |
|
| 552 | + $secure, |
|
| 553 | + $httponly = true /*for security for access to cookie via javascript or XSS attack*/ |
|
| 554 | + ); |
|
| 555 | + //to prevent attack of Session Fixation |
|
| 556 | + //thank to https://www.phparch.com/2018/01/php-sessions-in-depth/ |
|
| 557 | + ini_set('session.use_strict_mode ', 1); |
|
| 558 | + ini_set('session.use_only_cookies', 1); |
|
| 559 | + ini_set('session.use_trans_sid ', 0); |
|
| 560 | 560 | |
| 561 | - $logger->info('Session lifetime: ' . $lifetime); |
|
| 562 | - $logger->info('Session cookie path: ' . $path); |
|
| 563 | - $logger->info('Session domain: ' . $domain); |
|
| 564 | - $logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE')); |
|
| 561 | + $logger->info('Session lifetime: ' . $lifetime); |
|
| 562 | + $logger->info('Session cookie path: ' . $path); |
|
| 563 | + $logger->info('Session domain: ' . $domain); |
|
| 564 | + $logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE')); |
|
| 565 | 565 | |
| 566 | - if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){ |
|
| 567 | - $logger->info('Session not yet start, start it now'); |
|
| 568 | - session_start(); |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - } |
|
| 566 | + if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){ |
|
| 567 | + $logger->info('Session not yet start, start it now'); |
|
| 568 | + session_start(); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + } |
|
| 572 | 572 | |
| 573 | - /** |
|
| 574 | - * This function is very useful, it allows to recover the instance of the global controller. |
|
| 575 | - * Note this function always returns the address of the super instance. |
|
| 576 | - * For example : |
|
| 577 | - * $obj = & get_instance(); |
|
| 578 | - * |
|
| 579 | - * @codeCoverageIgnore |
|
| 580 | - * |
|
| 581 | - * @return object the instance of the "Controller" class |
|
| 582 | - */ |
|
| 583 | - function & get_instance(){ |
|
| 584 | - return Controller::get_instance(); |
|
| 585 | - } |
|
| 573 | + /** |
|
| 574 | + * This function is very useful, it allows to recover the instance of the global controller. |
|
| 575 | + * Note this function always returns the address of the super instance. |
|
| 576 | + * For example : |
|
| 577 | + * $obj = & get_instance(); |
|
| 578 | + * |
|
| 579 | + * @codeCoverageIgnore |
|
| 580 | + * |
|
| 581 | + * @return object the instance of the "Controller" class |
|
| 582 | + */ |
|
| 583 | + function & get_instance(){ |
|
| 584 | + return Controller::get_instance(); |
|
| 585 | + } |
|
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @package FileUpload |
| 38 | 38 | * @version 1.5 |
| 39 | 39 | */ |
| 40 | - class Upload{ |
|
| 40 | + class Upload { |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Version |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @version 1.0 |
| 70 | 70 | * @var array |
| 71 | 71 | */ |
| 72 | - private $file_array = array(); |
|
| 72 | + private $file_array = array(); |
|
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * If the file you are trying to upload already exists it will |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @version 1.0 |
| 120 | 120 | * @var float |
| 121 | 121 | */ |
| 122 | - private $max_file_size= 0.0; |
|
| 122 | + private $max_file_size = 0.0; |
|
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * List of allowed mime types |
@@ -217,12 +217,12 @@ discard block |
||
| 217 | 217 | * @return object |
| 218 | 218 | * @method object __construct |
| 219 | 219 | */ |
| 220 | - public function __construct(){ |
|
| 221 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 220 | + public function __construct() { |
|
| 221 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 222 | 222 | $this->logger->setLogger('Library::Upload'); |
| 223 | 223 | |
| 224 | 224 | Loader::lang('file_upload'); |
| 225 | - $obj =& get_instance(); |
|
| 225 | + $obj = & get_instance(); |
|
| 226 | 226 | |
| 227 | 227 | $this->error_messages = array( |
| 228 | 228 | 'upload_err_ini_size' => $obj->lang->get('fu_upload_err_ini_size'), |
@@ -239,15 +239,15 @@ discard block |
||
| 239 | 239 | ); |
| 240 | 240 | |
| 241 | 241 | $this->file = array( |
| 242 | - 'status' => false, // True: success upload |
|
| 243 | - 'mime' => '', // Empty string |
|
| 244 | - 'filename' => '', // Empty string |
|
| 245 | - 'original' => '', // Empty string |
|
| 246 | - 'size' => 0, // 0 Bytes |
|
| 247 | - 'sizeFormated' => '0B', // 0 Bytes |
|
| 248 | - 'destination' => './', // Default: ./ |
|
| 249 | - 'allowed_mime_types' => array(), // Allowed mime types |
|
| 250 | - 'error' => null, // File error |
|
| 242 | + 'status' => false, // True: success upload |
|
| 243 | + 'mime' => '', // Empty string |
|
| 244 | + 'filename' => '', // Empty string |
|
| 245 | + 'original' => '', // Empty string |
|
| 246 | + 'size' => 0, // 0 Bytes |
|
| 247 | + 'sizeFormated' => '0B', // 0 Bytes |
|
| 248 | + 'destination' => './', // Default: ./ |
|
| 249 | + 'allowed_mime_types' => array(), // Allowed mime types |
|
| 250 | + 'error' => null, // File error |
|
| 251 | 251 | ); |
| 252 | 252 | |
| 253 | 253 | // Change dir to current dir |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | if (isset($_FILES) && is_array($_FILES)) { |
| 258 | 258 | $this->file_array = $_FILES; |
| 259 | 259 | } |
| 260 | - $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array)); |
|
| 260 | + $this->logger->info('The upload file information are : ' . stringfy_vars($this->file_array)); |
|
| 261 | 261 | } |
| 262 | 262 | /** |
| 263 | 263 | * Set input. |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | */ |
| 274 | 274 | public function setInput($input) |
| 275 | 275 | { |
| 276 | - if (!empty($input) && (is_string($input) || is_numeric($input) )) { |
|
| 276 | + if (!empty($input) && (is_string($input) || is_numeric($input))) { |
|
| 277 | 277 | $this->input = $input; |
| 278 | 278 | } |
| 279 | 279 | return $this; |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | */ |
| 310 | 310 | public function setAutoFilename() |
| 311 | 311 | { |
| 312 | - $this->filename = sha1(mt_rand(1, 9999).uniqid()); |
|
| 312 | + $this->filename = sha1(mt_rand(1, 9999) . uniqid()); |
|
| 313 | 313 | $this->filename .= time(); |
| 314 | 314 | return $this; |
| 315 | 315 | } |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | $php_size = $this->sizeInBytes((int) ini_get('upload_max_filesize')); |
| 331 | 331 | // Calculate difference |
| 332 | 332 | if ($php_size < $file_size) { |
| 333 | - $this->logger->warning('The upload max file size you set [' .$file_size. '] is greather than the PHP configuration for upload max file size [' .$php_size. ']'); |
|
| 333 | + $this->logger->warning('The upload max file size you set [' . $file_size . '] is greather than the PHP configuration for upload max file size [' . $php_size . ']'); |
|
| 334 | 334 | } |
| 335 | 335 | $this->max_file_size = $file_size; |
| 336 | 336 | } |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | public function setAllowedMimeTypes(array $mimes) |
| 349 | 349 | { |
| 350 | 350 | if (count($mimes) > 0) { |
| 351 | - array_map(array($this , 'setAllowMimeType'), $mimes); |
|
| 351 | + array_map(array($this, 'setAllowMimeType'), $mimes); |
|
| 352 | 352 | } |
| 353 | 353 | return $this; |
| 354 | 354 | } |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | { |
| 414 | 414 | if (!empty($name) && is_string($name)) { |
| 415 | 415 | if (array_key_exists($name, $this->mime_helping)) { |
| 416 | - return $this->setAllowedMimeTypes($this->mime_helping[ $name ]); |
|
| 416 | + return $this->setAllowedMimeTypes($this->mime_helping[$name]); |
|
| 417 | 417 | } |
| 418 | 418 | } |
| 419 | 419 | return $this; |
@@ -432,8 +432,8 @@ discard block |
||
| 432 | 432 | */ |
| 433 | 433 | public function setUploadFunction($function) |
| 434 | 434 | { |
| 435 | - if (!empty($function) && (is_array($function) || is_string($function) )) { |
|
| 436 | - if (is_callable( $function)) { |
|
| 435 | + if (!empty($function) && (is_array($function) || is_string($function))) { |
|
| 436 | + if (is_callable($function)) { |
|
| 437 | 437 | $this->upload_function = $function; |
| 438 | 438 | } |
| 439 | 439 | } |
@@ -478,8 +478,8 @@ discard block |
||
| 478 | 478 | $this->destination_directory = $destination_directory; |
| 479 | 479 | chdir($destination_directory); |
| 480 | 480 | } |
| 481 | - else{ |
|
| 482 | - $this->logger->warning('Can not create the upload directory [' .$destination_directory. ']'); |
|
| 481 | + else { |
|
| 482 | + $this->logger->warning('Can not create the upload directory [' . $destination_directory . ']'); |
|
| 483 | 483 | } |
| 484 | 484 | } |
| 485 | 485 | } |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | public function isFilename($filename) |
| 530 | 530 | { |
| 531 | 531 | $filename = basename($filename); |
| 532 | - return (!empty($filename) && (is_string( $filename) || is_numeric($filename))); |
|
| 532 | + return (!empty($filename) && (is_string($filename) || is_numeric($filename))); |
|
| 533 | 533 | } |
| 534 | 534 | /** |
| 535 | 535 | * Validate mime type with allowed mime types, |
@@ -571,11 +571,11 @@ discard block |
||
| 571 | 571 | */ |
| 572 | 572 | public function isDirpath($path) |
| 573 | 573 | { |
| 574 | - if (!empty( $path) && (is_string( $path) || is_numeric($path) )) { |
|
| 574 | + if (!empty($path) && (is_string($path) || is_numeric($path))) { |
|
| 575 | 575 | if (DIRECTORY_SEPARATOR == '/') { |
| 576 | - return (preg_match( '/^[^*?"<>|:]*$/' , $path) == 1 ); |
|
| 576 | + return (preg_match('/^[^*?"<>|:]*$/', $path) == 1); |
|
| 577 | 577 | } else { |
| 578 | - return (preg_match( "/^[^*?\"<>|:]*$/" , substr($path,2) ) == 1); |
|
| 578 | + return (preg_match("/^[^*?\"<>|:]*$/", substr($path, 2)) == 1); |
|
| 579 | 579 | } |
| 580 | 580 | } |
| 581 | 581 | return false; |
@@ -603,7 +603,7 @@ discard block |
||
| 603 | 603 | */ |
| 604 | 604 | public function getInfo() |
| 605 | 605 | { |
| 606 | - return (object)$this->file; |
|
| 606 | + return (object) $this->file; |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | * Check if the file is uploaded |
| 612 | 612 | * @return boolean |
| 613 | 613 | */ |
| 614 | - public function isUploaded(){ |
|
| 614 | + public function isUploaded() { |
|
| 615 | 615 | return isset($this->file_array[$this->input]) |
| 616 | 616 | && is_uploaded_file($this->file_array[$this->input]['tmp_name']); |
| 617 | 617 | } |
@@ -625,13 +625,13 @@ discard block |
||
| 625 | 625 | * @return boolean |
| 626 | 626 | * @method boolean save |
| 627 | 627 | */ |
| 628 | - public function save(){ |
|
| 628 | + public function save() { |
|
| 629 | 629 | if (count($this->file_array) > 0 && array_key_exists($this->input, $this->file_array)) { |
| 630 | 630 | // set original filename if not have a new name |
| 631 | 631 | if (empty($this->filename)) { |
| 632 | 632 | $this->filename = $this->file_array[$this->input]['name']; |
| 633 | 633 | } |
| 634 | - else{ |
|
| 634 | + else { |
|
| 635 | 635 | // Replace %s for extension in filename |
| 636 | 636 | // Before: /[\w\d]*(.[\d\w]+)$/i |
| 637 | 637 | // After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu |
@@ -655,10 +655,10 @@ discard block |
||
| 655 | 655 | $this->file['filename'] = $this->filename; |
| 656 | 656 | $this->file['error'] = $this->file_array[$this->input]['error']; |
| 657 | 657 | |
| 658 | - $this->logger->info('The upload file information to process is : ' .stringfy_vars($this->file)); |
|
| 658 | + $this->logger->info('The upload file information to process is : ' . stringfy_vars($this->file)); |
|
| 659 | 659 | |
| 660 | 660 | $error = $this->uploadHasError(); |
| 661 | - if($error){ |
|
| 661 | + if ($error) { |
|
| 662 | 662 | return false; |
| 663 | 663 | } |
| 664 | 664 | // Execute input callback |
@@ -692,10 +692,10 @@ discard block |
||
| 692 | 692 | */ |
| 693 | 693 | public function sizeFormat($size, $precision = 2) |
| 694 | 694 | { |
| 695 | - if($size > 0){ |
|
| 695 | + if ($size > 0) { |
|
| 696 | 696 | $base = log($size) / log(1024); |
| 697 | 697 | $suffixes = array('B', 'K', 'M', 'G', 'T'); |
| 698 | - return round(pow(1024, $base - floor($base)), $precision) . ( isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : ''); |
|
| 698 | + return round(pow(1024, $base - floor($base)), $precision) . (isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : ''); |
|
| 699 | 699 | } |
| 700 | 700 | return null; |
| 701 | 701 | } |
@@ -719,14 +719,14 @@ discard block |
||
| 719 | 719 | if (array_key_exists('unit', $matches)) { |
| 720 | 720 | $unit = strtoupper($matches['unit']); |
| 721 | 721 | } |
| 722 | - return (floatval($matches['size']) * pow(1024, $units[$unit]) ) ; |
|
| 722 | + return (floatval($matches['size']) * pow(1024, $units[$unit])); |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | /** |
| 726 | 726 | * Get the upload error message |
| 727 | 727 | * @return string |
| 728 | 728 | */ |
| 729 | - public function getError(){ |
|
| 729 | + public function getError() { |
|
| 730 | 730 | return $this->error; |
| 731 | 731 | } |
| 732 | 732 | |
@@ -734,7 +734,7 @@ discard block |
||
| 734 | 734 | * Set the upload error message |
| 735 | 735 | * @param string $message the upload error message to set |
| 736 | 736 | */ |
| 737 | - public function setError($message){ |
|
| 737 | + public function setError($message) { |
|
| 738 | 738 | $this->logger->info('The file upload got error : ' . $message); |
| 739 | 739 | $this->error = $message; |
| 740 | 740 | } |
@@ -744,9 +744,9 @@ discard block |
||
| 744 | 744 | * @param string $type the type of callback "input" or "output" |
| 745 | 745 | * @return void |
| 746 | 746 | */ |
| 747 | - protected function runCallback($type){ |
|
| 748 | - if (!empty( $this->callbacks[$type])) { |
|
| 749 | - call_user_func($this->callbacks[$type], (object)$this->file); |
|
| 747 | + protected function runCallback($type) { |
|
| 748 | + if (!empty($this->callbacks[$type])) { |
|
| 749 | + call_user_func($this->callbacks[$type], (object) $this->file); |
|
| 750 | 750 | } |
| 751 | 751 | } |
| 752 | 752 | |
@@ -754,21 +754,21 @@ discard block |
||
| 754 | 754 | * Check if file upload has error |
| 755 | 755 | * @return boolean |
| 756 | 756 | */ |
| 757 | - protected function uploadHasError(){ |
|
| 757 | + protected function uploadHasError() { |
|
| 758 | 758 | //check if file upload is allowed in the configuration |
| 759 | - if(! ini_get('file_uploads')){ |
|
| 759 | + if (!ini_get('file_uploads')) { |
|
| 760 | 760 | $this->setError($this->error_messages['file_uploads']); |
| 761 | 761 | return true; |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | //check for php upload error |
| 765 | - if(is_numeric($this->file['error']) && $this->file['error'] > 0){ |
|
| 765 | + if (is_numeric($this->file['error']) && $this->file['error'] > 0) { |
|
| 766 | 766 | $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error'])); |
| 767 | 767 | return true; |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | //check for mime type |
| 771 | - if (! $this->checkMimeType($this->file['mime'])) { |
|
| 771 | + if (!$this->checkMimeType($this->file['mime'])) { |
|
| 772 | 772 | $this->setError($this->error_messages['accept_file_types']); |
| 773 | 773 | return true; |
| 774 | 774 | } |
@@ -792,7 +792,7 @@ discard block |
||
| 792 | 792 | * @param int $code the error code |
| 793 | 793 | * @return string the error message |
| 794 | 794 | */ |
| 795 | - private function getPhpUploadErrorMessageByCode($code){ |
|
| 795 | + private function getPhpUploadErrorMessageByCode($code) { |
|
| 796 | 796 | $codeMessageMaps = array( |
| 797 | 797 | 1 => $this->error_messages['upload_err_ini_size'], |
| 798 | 798 | 2 => $this->error_messages['upload_err_form_size'], |
@@ -477,8 +477,7 @@ discard block |
||
| 477 | 477 | if (mkdir($destination_directory, 0775, true)) { |
| 478 | 478 | $this->destination_directory = $destination_directory; |
| 479 | 479 | chdir($destination_directory); |
| 480 | - } |
|
| 481 | - else{ |
|
| 480 | + } else{ |
|
| 482 | 481 | $this->logger->warning('Can not create the upload directory [' .$destination_directory. ']'); |
| 483 | 482 | } |
| 484 | 483 | } |
@@ -630,8 +629,7 @@ discard block |
||
| 630 | 629 | // set original filename if not have a new name |
| 631 | 630 | if (empty($this->filename)) { |
| 632 | 631 | $this->filename = $this->file_array[$this->input]['name']; |
| 633 | - } |
|
| 634 | - else{ |
|
| 632 | + } else{ |
|
| 635 | 633 | // Replace %s for extension in filename |
| 636 | 634 | // Before: /[\w\d]*(.[\d\w]+)$/i |
| 637 | 635 | // After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu |
@@ -22,139 +22,139 @@ discard block |
||
| 22 | 22 | * You should have received a copy of the GNU General Public License |
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | - */ |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Upload |
|
| 31 | - * |
|
| 32 | - * A complete class to upload files with php 5 or higher, but the best: very simple to use. |
|
| 33 | - * |
|
| 34 | - * @author Olaf Erlandsen <[email protected]> |
|
| 35 | - * @author http://www.webdevfreelance.com/ |
|
| 36 | - * |
|
| 37 | - * @package FileUpload |
|
| 38 | - * @version 1.5 |
|
| 39 | - */ |
|
| 30 | + * Upload |
|
| 31 | + * |
|
| 32 | + * A complete class to upload files with php 5 or higher, but the best: very simple to use. |
|
| 33 | + * |
|
| 34 | + * @author Olaf Erlandsen <[email protected]> |
|
| 35 | + * @author http://www.webdevfreelance.com/ |
|
| 36 | + * |
|
| 37 | + * @package FileUpload |
|
| 38 | + * @version 1.5 |
|
| 39 | + */ |
|
| 40 | 40 | class Upload{ |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | - * Version |
|
| 44 | - * |
|
| 45 | - * @since 1.5 |
|
| 46 | - * @version 1.0 |
|
| 47 | - */ |
|
| 43 | + * Version |
|
| 44 | + * |
|
| 45 | + * @since 1.5 |
|
| 46 | + * @version 1.0 |
|
| 47 | + */ |
|
| 48 | 48 | const VERSION = '1.5'; |
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | - * Upload function name |
|
| 52 | - * Remember: |
|
| 53 | - * Default function: move_uploaded_file |
|
| 54 | - * Native options: |
|
| 55 | - * - move_uploaded_file (Default and best option) |
|
| 56 | - * - copy |
|
| 57 | - * |
|
| 58 | - * @since 1.0 |
|
| 59 | - * @version 1.0 |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 51 | + * Upload function name |
|
| 52 | + * Remember: |
|
| 53 | + * Default function: move_uploaded_file |
|
| 54 | + * Native options: |
|
| 55 | + * - move_uploaded_file (Default and best option) |
|
| 56 | + * - copy |
|
| 57 | + * |
|
| 58 | + * @since 1.0 |
|
| 59 | + * @version 1.0 |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | 62 | private $upload_function = 'move_uploaded_file'; |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * Array with the information obtained from the |
|
| 66 | - * variable $_FILES or $HTTP_POST_FILES. |
|
| 67 | - * |
|
| 68 | - * @since 1.0 |
|
| 69 | - * @version 1.0 |
|
| 70 | - * @var array |
|
| 71 | - */ |
|
| 65 | + * Array with the information obtained from the |
|
| 66 | + * variable $_FILES or $HTTP_POST_FILES. |
|
| 67 | + * |
|
| 68 | + * @since 1.0 |
|
| 69 | + * @version 1.0 |
|
| 70 | + * @var array |
|
| 71 | + */ |
|
| 72 | 72 | private $file_array = array(); |
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | - * If the file you are trying to upload already exists it will |
|
| 76 | - * be overwritten if you set the variable to true. |
|
| 77 | - * |
|
| 78 | - * @since 1.0 |
|
| 79 | - * @version 1.0 |
|
| 80 | - * @var boolean |
|
| 81 | - */ |
|
| 75 | + * If the file you are trying to upload already exists it will |
|
| 76 | + * be overwritten if you set the variable to true. |
|
| 77 | + * |
|
| 78 | + * @since 1.0 |
|
| 79 | + * @version 1.0 |
|
| 80 | + * @var boolean |
|
| 81 | + */ |
|
| 82 | 82 | private $overwrite_file = false; |
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | - * Input element |
|
| 86 | - * Example: |
|
| 87 | - * <input type="file" name="file" /> |
|
| 88 | - * Result: |
|
| 89 | - * FileUpload::$input = file |
|
| 90 | - * |
|
| 91 | - * @since 1.0 |
|
| 92 | - * @version 1.0 |
|
| 93 | - * @var string |
|
| 94 | - */ |
|
| 85 | + * Input element |
|
| 86 | + * Example: |
|
| 87 | + * <input type="file" name="file" /> |
|
| 88 | + * Result: |
|
| 89 | + * FileUpload::$input = file |
|
| 90 | + * |
|
| 91 | + * @since 1.0 |
|
| 92 | + * @version 1.0 |
|
| 93 | + * @var string |
|
| 94 | + */ |
|
| 95 | 95 | private $input; |
| 96 | 96 | |
| 97 | 97 | /** |
| 98 | - * Path output |
|
| 99 | - * |
|
| 100 | - * @since 1.0 |
|
| 101 | - * @version 1.0 |
|
| 102 | - * @var string |
|
| 103 | - */ |
|
| 98 | + * Path output |
|
| 99 | + * |
|
| 100 | + * @since 1.0 |
|
| 101 | + * @version 1.0 |
|
| 102 | + * @var string |
|
| 103 | + */ |
|
| 104 | 104 | private $destination_directory; |
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | - * Output filename |
|
| 108 | - * |
|
| 109 | - * @since 1.0 |
|
| 110 | - * @version 1.0 |
|
| 111 | - * @var string |
|
| 112 | - */ |
|
| 107 | + * Output filename |
|
| 108 | + * |
|
| 109 | + * @since 1.0 |
|
| 110 | + * @version 1.0 |
|
| 111 | + * @var string |
|
| 112 | + */ |
|
| 113 | 113 | private $filename; |
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | - * Max file size |
|
| 117 | - * |
|
| 118 | - * @since 1.0 |
|
| 119 | - * @version 1.0 |
|
| 120 | - * @var float |
|
| 121 | - */ |
|
| 116 | + * Max file size |
|
| 117 | + * |
|
| 118 | + * @since 1.0 |
|
| 119 | + * @version 1.0 |
|
| 120 | + * @var float |
|
| 121 | + */ |
|
| 122 | 122 | private $max_file_size= 0.0; |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | - * List of allowed mime types |
|
| 126 | - * |
|
| 127 | - * @since 1.0 |
|
| 128 | - * @version 1.0 |
|
| 129 | - * @var array |
|
| 130 | - */ |
|
| 125 | + * List of allowed mime types |
|
| 126 | + * |
|
| 127 | + * @since 1.0 |
|
| 128 | + * @version 1.0 |
|
| 129 | + * @var array |
|
| 130 | + */ |
|
| 131 | 131 | private $allowed_mime_types = array(); |
| 132 | 132 | |
| 133 | 133 | /** |
| 134 | - * Callbacks |
|
| 135 | - * |
|
| 136 | - * @since 1.0 |
|
| 137 | - * @version 1.0 |
|
| 138 | - * @var array |
|
| 139 | - */ |
|
| 134 | + * Callbacks |
|
| 135 | + * |
|
| 136 | + * @since 1.0 |
|
| 137 | + * @version 1.0 |
|
| 138 | + * @var array |
|
| 139 | + */ |
|
| 140 | 140 | private $callbacks = array('before' => null, 'after' => null); |
| 141 | 141 | |
| 142 | 142 | /** |
| 143 | - * File object |
|
| 144 | - * |
|
| 145 | - * @since 1.0 |
|
| 146 | - * @version 1.0 |
|
| 147 | - * @var object |
|
| 148 | - */ |
|
| 143 | + * File object |
|
| 144 | + * |
|
| 145 | + * @since 1.0 |
|
| 146 | + * @version 1.0 |
|
| 147 | + * @var object |
|
| 148 | + */ |
|
| 149 | 149 | private $file; |
| 150 | 150 | |
| 151 | 151 | /** |
| 152 | - * Helping mime types |
|
| 153 | - * |
|
| 154 | - * @since 1.0 |
|
| 155 | - * @version 1.0 |
|
| 156 | - * @var array |
|
| 157 | - */ |
|
| 152 | + * Helping mime types |
|
| 153 | + * |
|
| 154 | + * @since 1.0 |
|
| 155 | + * @version 1.0 |
|
| 156 | + * @var array |
|
| 157 | + */ |
|
| 158 | 158 | private $mime_helping = array( |
| 159 | 159 | 'text' => array('text/plain',), |
| 160 | 160 | 'image' => array( |
@@ -210,13 +210,13 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | |
| 212 | 212 | /** |
| 213 | - * Construct |
|
| 214 | - * |
|
| 215 | - * @since 0.1 |
|
| 216 | - * @version 1.0.1 |
|
| 217 | - * @return object |
|
| 218 | - * @method object __construct |
|
| 219 | - */ |
|
| 213 | + * Construct |
|
| 214 | + * |
|
| 215 | + * @since 0.1 |
|
| 216 | + * @version 1.0.1 |
|
| 217 | + * @return object |
|
| 218 | + * @method object __construct |
|
| 219 | + */ |
|
| 220 | 220 | public function __construct(){ |
| 221 | 221 | $this->logger =& class_loader('Log', 'classes'); |
| 222 | 222 | $this->logger->setLogger('Library::Upload'); |
@@ -260,17 +260,17 @@ discard block |
||
| 260 | 260 | $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array)); |
| 261 | 261 | } |
| 262 | 262 | /** |
| 263 | - * Set input. |
|
| 264 | - * If you have $_FILES["file"], you must use the key "file" |
|
| 265 | - * Example: |
|
| 266 | - * $object->setInput("file"); |
|
| 267 | - * |
|
| 268 | - * @since 1.0 |
|
| 269 | - * @version 1.0 |
|
| 270 | - * @param string $input |
|
| 271 | - * @return object |
|
| 272 | - * @method boolean setInput |
|
| 273 | - */ |
|
| 263 | + * Set input. |
|
| 264 | + * If you have $_FILES["file"], you must use the key "file" |
|
| 265 | + * Example: |
|
| 266 | + * $object->setInput("file"); |
|
| 267 | + * |
|
| 268 | + * @since 1.0 |
|
| 269 | + * @version 1.0 |
|
| 270 | + * @param string $input |
|
| 271 | + * @return object |
|
| 272 | + * @method boolean setInput |
|
| 273 | + */ |
|
| 274 | 274 | public function setInput($input) |
| 275 | 275 | { |
| 276 | 276 | if (!empty($input) && (is_string($input) || is_numeric($input) )) { |
@@ -279,18 +279,18 @@ discard block |
||
| 279 | 279 | return $this; |
| 280 | 280 | } |
| 281 | 281 | /** |
| 282 | - * Set new filename |
|
| 283 | - * Example: |
|
| 284 | - * FileUpload::setFilename("new file.txt") |
|
| 285 | - * Remember: |
|
| 286 | - * Use %s to retrive file extension |
|
| 287 | - * |
|
| 288 | - * @since 1.0 |
|
| 289 | - * @version 1.0 |
|
| 290 | - * @param string $filename |
|
| 291 | - * @return object |
|
| 292 | - * @method boolean setFilename |
|
| 293 | - */ |
|
| 282 | + * Set new filename |
|
| 283 | + * Example: |
|
| 284 | + * FileUpload::setFilename("new file.txt") |
|
| 285 | + * Remember: |
|
| 286 | + * Use %s to retrive file extension |
|
| 287 | + * |
|
| 288 | + * @since 1.0 |
|
| 289 | + * @version 1.0 |
|
| 290 | + * @param string $filename |
|
| 291 | + * @return object |
|
| 292 | + * @method boolean setFilename |
|
| 293 | + */ |
|
| 294 | 294 | public function setFilename($filename) |
| 295 | 295 | { |
| 296 | 296 | if ($this->isFilename($filename)) { |
@@ -299,14 +299,14 @@ discard block |
||
| 299 | 299 | return $this; |
| 300 | 300 | } |
| 301 | 301 | /** |
| 302 | - * Set automatic filename |
|
| 303 | - * |
|
| 304 | - * @since 1.0 |
|
| 305 | - * @version 1.5 |
|
| 306 | - * @param string $extension |
|
| 307 | - * @return object |
|
| 308 | - * @method boolean setAutoFilename |
|
| 309 | - */ |
|
| 302 | + * Set automatic filename |
|
| 303 | + * |
|
| 304 | + * @since 1.0 |
|
| 305 | + * @version 1.5 |
|
| 306 | + * @param string $extension |
|
| 307 | + * @return object |
|
| 308 | + * @method boolean setAutoFilename |
|
| 309 | + */ |
|
| 310 | 310 | public function setAutoFilename() |
| 311 | 311 | { |
| 312 | 312 | $this->filename = sha1(mt_rand(1, 9999).uniqid()); |
@@ -314,14 +314,14 @@ discard block |
||
| 314 | 314 | return $this; |
| 315 | 315 | } |
| 316 | 316 | /** |
| 317 | - * Set file size limit |
|
| 318 | - * |
|
| 319 | - * @since 1.0 |
|
| 320 | - * @version 1.0 |
|
| 321 | - * @param double $file_size |
|
| 322 | - * @return object |
|
| 323 | - * @method boolean setMaxFileSize |
|
| 324 | - */ |
|
| 317 | + * Set file size limit |
|
| 318 | + * |
|
| 319 | + * @since 1.0 |
|
| 320 | + * @version 1.0 |
|
| 321 | + * @param double $file_size |
|
| 322 | + * @return object |
|
| 323 | + * @method boolean setMaxFileSize |
|
| 324 | + */ |
|
| 325 | 325 | public function setMaxFileSize($file_size) |
| 326 | 326 | { |
| 327 | 327 | $file_size = $this->sizeInBytes($file_size); |
@@ -337,14 +337,14 @@ discard block |
||
| 337 | 337 | return $this; |
| 338 | 338 | } |
| 339 | 339 | /** |
| 340 | - * Set array mime types |
|
| 341 | - * |
|
| 342 | - * @since 1.0 |
|
| 343 | - * @version 1.0 |
|
| 344 | - * @param array $mimes |
|
| 345 | - * @return object |
|
| 346 | - * @method boolean setAllowedMimeTypes |
|
| 347 | - */ |
|
| 340 | + * Set array mime types |
|
| 341 | + * |
|
| 342 | + * @since 1.0 |
|
| 343 | + * @version 1.0 |
|
| 344 | + * @param array $mimes |
|
| 345 | + * @return object |
|
| 346 | + * @method boolean setAllowedMimeTypes |
|
| 347 | + */ |
|
| 348 | 348 | public function setAllowedMimeTypes(array $mimes) |
| 349 | 349 | { |
| 350 | 350 | if (count($mimes) > 0) { |
@@ -353,14 +353,14 @@ discard block |
||
| 353 | 353 | return $this; |
| 354 | 354 | } |
| 355 | 355 | /** |
| 356 | - * Set input callback |
|
| 357 | - * |
|
| 358 | - * @since 1.0 |
|
| 359 | - * @version 1.0 |
|
| 360 | - * @param mixed $callback |
|
| 361 | - * @return object |
|
| 362 | - * @method boolean setCallbackInput |
|
| 363 | - */ |
|
| 356 | + * Set input callback |
|
| 357 | + * |
|
| 358 | + * @since 1.0 |
|
| 359 | + * @version 1.0 |
|
| 360 | + * @param mixed $callback |
|
| 361 | + * @return object |
|
| 362 | + * @method boolean setCallbackInput |
|
| 363 | + */ |
|
| 364 | 364 | public function setCallbackInput($callback) |
| 365 | 365 | { |
| 366 | 366 | if (is_callable($callback, false)) { |
@@ -369,14 +369,14 @@ discard block |
||
| 369 | 369 | return $this; |
| 370 | 370 | } |
| 371 | 371 | /** |
| 372 | - * Set output callback |
|
| 373 | - * |
|
| 374 | - * @since 1.0 |
|
| 375 | - * @version 1.0 |
|
| 376 | - * @param mixed $callback |
|
| 377 | - * @return object |
|
| 378 | - * @method boolean setCallbackOutput |
|
| 379 | - */ |
|
| 372 | + * Set output callback |
|
| 373 | + * |
|
| 374 | + * @since 1.0 |
|
| 375 | + * @version 1.0 |
|
| 376 | + * @param mixed $callback |
|
| 377 | + * @return object |
|
| 378 | + * @method boolean setCallbackOutput |
|
| 379 | + */ |
|
| 380 | 380 | public function setCallbackOutput($callback) |
| 381 | 381 | { |
| 382 | 382 | if (is_callable($callback, false)) { |
@@ -385,14 +385,14 @@ discard block |
||
| 385 | 385 | return $this; |
| 386 | 386 | } |
| 387 | 387 | /** |
| 388 | - * Append a mime type to allowed mime types |
|
| 389 | - * |
|
| 390 | - * @since 1.0 |
|
| 391 | - * @version 1.0.1 |
|
| 392 | - * @param string $mime |
|
| 393 | - * @return object |
|
| 394 | - * @method boolean setAllowMimeType |
|
| 395 | - */ |
|
| 388 | + * Append a mime type to allowed mime types |
|
| 389 | + * |
|
| 390 | + * @since 1.0 |
|
| 391 | + * @version 1.0.1 |
|
| 392 | + * @param string $mime |
|
| 393 | + * @return object |
|
| 394 | + * @method boolean setAllowMimeType |
|
| 395 | + */ |
|
| 396 | 396 | public function setAllowMimeType($mime) |
| 397 | 397 | { |
| 398 | 398 | if (!empty($mime) && is_string($mime)) { |
@@ -402,13 +402,13 @@ discard block |
||
| 402 | 402 | return $this; |
| 403 | 403 | } |
| 404 | 404 | /** |
| 405 | - * Set allowed mime types from mime helping |
|
| 406 | - * |
|
| 407 | - * @since 1.0.1 |
|
| 408 | - * @version 1.0.1 |
|
| 409 | - * @return object |
|
| 410 | - * @method boolean setMimeHelping |
|
| 411 | - */ |
|
| 405 | + * Set allowed mime types from mime helping |
|
| 406 | + * |
|
| 407 | + * @since 1.0.1 |
|
| 408 | + * @version 1.0.1 |
|
| 409 | + * @return object |
|
| 410 | + * @method boolean setMimeHelping |
|
| 411 | + */ |
|
| 412 | 412 | public function setMimeHelping($name) |
| 413 | 413 | { |
| 414 | 414 | if (!empty($name) && is_string($name)) { |
@@ -419,17 +419,17 @@ discard block |
||
| 419 | 419 | return $this; |
| 420 | 420 | } |
| 421 | 421 | /** |
| 422 | - * Set function to upload file |
|
| 423 | - * Examples: |
|
| 424 | - * 1.- FileUpload::setUploadFunction("move_uploaded_file"); |
|
| 425 | - * 2.- FileUpload::setUploadFunction("copy"); |
|
| 426 | - * |
|
| 427 | - * @since 1.0 |
|
| 428 | - * @version 1.0 |
|
| 429 | - * @param string $function |
|
| 430 | - * @return object |
|
| 431 | - * @method boolean setUploadFunction |
|
| 432 | - */ |
|
| 422 | + * Set function to upload file |
|
| 423 | + * Examples: |
|
| 424 | + * 1.- FileUpload::setUploadFunction("move_uploaded_file"); |
|
| 425 | + * 2.- FileUpload::setUploadFunction("copy"); |
|
| 426 | + * |
|
| 427 | + * @since 1.0 |
|
| 428 | + * @version 1.0 |
|
| 429 | + * @param string $function |
|
| 430 | + * @return object |
|
| 431 | + * @method boolean setUploadFunction |
|
| 432 | + */ |
|
| 433 | 433 | public function setUploadFunction($function) |
| 434 | 434 | { |
| 435 | 435 | if (!empty($function) && (is_array($function) || is_string($function) )) { |
@@ -440,13 +440,13 @@ discard block |
||
| 440 | 440 | return $this; |
| 441 | 441 | } |
| 442 | 442 | /** |
| 443 | - * Clear allowed mime types cache |
|
| 444 | - * |
|
| 445 | - * @since 1.0 |
|
| 446 | - * @version 1.0 |
|
| 447 | - * @return object |
|
| 448 | - * @method boolean clearAllowedMimeTypes |
|
| 449 | - */ |
|
| 443 | + * Clear allowed mime types cache |
|
| 444 | + * |
|
| 445 | + * @since 1.0 |
|
| 446 | + * @version 1.0 |
|
| 447 | + * @return object |
|
| 448 | + * @method boolean clearAllowedMimeTypes |
|
| 449 | + */ |
|
| 450 | 450 | public function clearAllowedMimeTypes() |
| 451 | 451 | { |
| 452 | 452 | $this->allowed_mime_types = array(); |
@@ -454,15 +454,15 @@ discard block |
||
| 454 | 454 | return $this; |
| 455 | 455 | } |
| 456 | 456 | /** |
| 457 | - * Set destination output |
|
| 458 | - * |
|
| 459 | - * @since 1.0 |
|
| 460 | - * @version 1.0 |
|
| 461 | - * @param string $destination_directory Destination path |
|
| 462 | - * @param boolean $create_if_not_exist |
|
| 463 | - * @return object |
|
| 464 | - * @method boolean setDestinationDirectory |
|
| 465 | - */ |
|
| 457 | + * Set destination output |
|
| 458 | + * |
|
| 459 | + * @since 1.0 |
|
| 460 | + * @version 1.0 |
|
| 461 | + * @param string $destination_directory Destination path |
|
| 462 | + * @param boolean $create_if_not_exist |
|
| 463 | + * @return object |
|
| 464 | + * @method boolean setDestinationDirectory |
|
| 465 | + */ |
|
| 466 | 466 | public function setDestinationDirectory($destination_directory, $create_if_not_exist = false) { |
| 467 | 467 | $destination_directory = realpath($destination_directory); |
| 468 | 468 | if (substr($destination_directory, -1) != DIRECTORY_SEPARATOR) { |
@@ -486,14 +486,14 @@ discard block |
||
| 486 | 486 | return $this; |
| 487 | 487 | } |
| 488 | 488 | /** |
| 489 | - * Check file exists |
|
| 490 | - * |
|
| 491 | - * @since 1.0 |
|
| 492 | - * @version 1.0.1 |
|
| 493 | - * @param string $file_destination |
|
| 494 | - * @return boolean |
|
| 495 | - * @method boolean fileExists |
|
| 496 | - */ |
|
| 489 | + * Check file exists |
|
| 490 | + * |
|
| 491 | + * @since 1.0 |
|
| 492 | + * @version 1.0.1 |
|
| 493 | + * @param string $file_destination |
|
| 494 | + * @return boolean |
|
| 495 | + * @method boolean fileExists |
|
| 496 | + */ |
|
| 497 | 497 | public function fileExists($file_destination) |
| 498 | 498 | { |
| 499 | 499 | if ($this->isFilename($file_destination)) { |
@@ -502,14 +502,14 @@ discard block |
||
| 502 | 502 | return false; |
| 503 | 503 | } |
| 504 | 504 | /** |
| 505 | - * Check dir exists |
|
| 506 | - * |
|
| 507 | - * @since 1.0 |
|
| 508 | - * @version 1.0.1 |
|
| 509 | - * @param string $path |
|
| 510 | - * @return boolean |
|
| 511 | - * @method boolean dirExists |
|
| 512 | - */ |
|
| 505 | + * Check dir exists |
|
| 506 | + * |
|
| 507 | + * @since 1.0 |
|
| 508 | + * @version 1.0.1 |
|
| 509 | + * @param string $path |
|
| 510 | + * @return boolean |
|
| 511 | + * @method boolean dirExists |
|
| 512 | + */ |
|
| 513 | 513 | public function dirExists($path) |
| 514 | 514 | { |
| 515 | 515 | if ($this->isDirpath($path)) { |
@@ -518,29 +518,29 @@ discard block |
||
| 518 | 518 | return false; |
| 519 | 519 | } |
| 520 | 520 | /** |
| 521 | - * Check valid filename |
|
| 522 | - * |
|
| 523 | - * @since 1.0 |
|
| 524 | - * @version 1.0.1 |
|
| 525 | - * @param string $filename |
|
| 526 | - * @return boolean |
|
| 527 | - * @method boolean isFilename |
|
| 528 | - */ |
|
| 521 | + * Check valid filename |
|
| 522 | + * |
|
| 523 | + * @since 1.0 |
|
| 524 | + * @version 1.0.1 |
|
| 525 | + * @param string $filename |
|
| 526 | + * @return boolean |
|
| 527 | + * @method boolean isFilename |
|
| 528 | + */ |
|
| 529 | 529 | public function isFilename($filename) |
| 530 | 530 | { |
| 531 | 531 | $filename = basename($filename); |
| 532 | 532 | return (!empty($filename) && (is_string( $filename) || is_numeric($filename))); |
| 533 | 533 | } |
| 534 | 534 | /** |
| 535 | - * Validate mime type with allowed mime types, |
|
| 536 | - * but if allowed mime types is empty, this method return true |
|
| 537 | - * |
|
| 538 | - * @since 1.0 |
|
| 539 | - * @version 1.0 |
|
| 540 | - * @param string $mime |
|
| 541 | - * @return boolean |
|
| 542 | - * @method boolean checkMimeType |
|
| 543 | - */ |
|
| 535 | + * Validate mime type with allowed mime types, |
|
| 536 | + * but if allowed mime types is empty, this method return true |
|
| 537 | + * |
|
| 538 | + * @since 1.0 |
|
| 539 | + * @version 1.0 |
|
| 540 | + * @param string $mime |
|
| 541 | + * @return boolean |
|
| 542 | + * @method boolean checkMimeType |
|
| 543 | + */ |
|
| 544 | 544 | public function checkMimeType($mime) |
| 545 | 545 | { |
| 546 | 546 | if (count($this->allowed_mime_types) == 0) { |
@@ -549,26 +549,26 @@ discard block |
||
| 549 | 549 | return in_array(strtolower($mime), $this->allowed_mime_types); |
| 550 | 550 | } |
| 551 | 551 | /** |
| 552 | - * Retrive status of upload |
|
| 553 | - * |
|
| 554 | - * @since 1.0 |
|
| 555 | - * @version 1.0 |
|
| 556 | - * @return boolean |
|
| 557 | - * @method boolean getStatus |
|
| 558 | - */ |
|
| 552 | + * Retrive status of upload |
|
| 553 | + * |
|
| 554 | + * @since 1.0 |
|
| 555 | + * @version 1.0 |
|
| 556 | + * @return boolean |
|
| 557 | + * @method boolean getStatus |
|
| 558 | + */ |
|
| 559 | 559 | public function getStatus() |
| 560 | 560 | { |
| 561 | 561 | return $this->file['status']; |
| 562 | 562 | } |
| 563 | 563 | /** |
| 564 | - * Check valid path |
|
| 565 | - * |
|
| 566 | - * @since 1.0 |
|
| 567 | - * @version 1.0.1 |
|
| 568 | - * @param string $filename |
|
| 569 | - * @return boolean |
|
| 570 | - * @method boolean isDirpath |
|
| 571 | - */ |
|
| 564 | + * Check valid path |
|
| 565 | + * |
|
| 566 | + * @since 1.0 |
|
| 567 | + * @version 1.0.1 |
|
| 568 | + * @param string $filename |
|
| 569 | + * @return boolean |
|
| 570 | + * @method boolean isDirpath |
|
| 571 | + */ |
|
| 572 | 572 | public function isDirpath($path) |
| 573 | 573 | { |
| 574 | 574 | if (!empty( $path) && (is_string( $path) || is_numeric($path) )) { |
@@ -581,26 +581,26 @@ discard block |
||
| 581 | 581 | return false; |
| 582 | 582 | } |
| 583 | 583 | /** |
| 584 | - * Allow overwriting files |
|
| 585 | - * |
|
| 586 | - * @since 1.0 |
|
| 587 | - * @version 1.0 |
|
| 588 | - * @return object |
|
| 589 | - * @method boolean allowOverwriting |
|
| 590 | - */ |
|
| 584 | + * Allow overwriting files |
|
| 585 | + * |
|
| 586 | + * @since 1.0 |
|
| 587 | + * @version 1.0 |
|
| 588 | + * @return object |
|
| 589 | + * @method boolean allowOverwriting |
|
| 590 | + */ |
|
| 591 | 591 | public function allowOverwriting() |
| 592 | 592 | { |
| 593 | 593 | $this->overwrite_file = true; |
| 594 | 594 | return $this; |
| 595 | 595 | } |
| 596 | 596 | /** |
| 597 | - * File info |
|
| 598 | - * |
|
| 599 | - * @since 1.0 |
|
| 600 | - * @version 1.0 |
|
| 601 | - * @return object |
|
| 602 | - * @method object getInfo |
|
| 603 | - */ |
|
| 597 | + * File info |
|
| 598 | + * |
|
| 599 | + * @since 1.0 |
|
| 600 | + * @version 1.0 |
|
| 601 | + * @return object |
|
| 602 | + * @method object getInfo |
|
| 603 | + */ |
|
| 604 | 604 | public function getInfo() |
| 605 | 605 | { |
| 606 | 606 | return (object)$this->file; |
@@ -618,13 +618,13 @@ discard block |
||
| 618 | 618 | |
| 619 | 619 | |
| 620 | 620 | /** |
| 621 | - * Upload file |
|
| 622 | - * |
|
| 623 | - * @since 1.0 |
|
| 624 | - * @version 1.0.1 |
|
| 625 | - * @return boolean |
|
| 626 | - * @method boolean save |
|
| 627 | - */ |
|
| 621 | + * Upload file |
|
| 622 | + * |
|
| 623 | + * @since 1.0 |
|
| 624 | + * @version 1.0.1 |
|
| 625 | + * @return boolean |
|
| 626 | + * @method boolean save |
|
| 627 | + */ |
|
| 628 | 628 | public function save(){ |
| 629 | 629 | if (count($this->file_array) > 0 && array_key_exists($this->input, $this->file_array)) { |
| 630 | 630 | // set original filename if not have a new name |
@@ -681,15 +681,15 @@ discard block |
||
| 681 | 681 | |
| 682 | 682 | |
| 683 | 683 | /** |
| 684 | - * File size for humans. |
|
| 685 | - * |
|
| 686 | - * @since 1.0 |
|
| 687 | - * @version 1.0 |
|
| 688 | - * @param integer $bytes |
|
| 689 | - * @param integer $precision |
|
| 690 | - * @return string |
|
| 691 | - * @method string sizeFormat |
|
| 692 | - */ |
|
| 684 | + * File size for humans. |
|
| 685 | + * |
|
| 686 | + * @since 1.0 |
|
| 687 | + * @version 1.0 |
|
| 688 | + * @param integer $bytes |
|
| 689 | + * @param integer $precision |
|
| 690 | + * @return string |
|
| 691 | + * @method string sizeFormat |
|
| 692 | + */ |
|
| 693 | 693 | public function sizeFormat($size, $precision = 2) |
| 694 | 694 | { |
| 695 | 695 | if($size > 0){ |
@@ -702,14 +702,14 @@ discard block |
||
| 702 | 702 | |
| 703 | 703 | |
| 704 | 704 | /** |
| 705 | - * Convert human file size to bytes |
|
| 706 | - * |
|
| 707 | - * @since 1.0 |
|
| 708 | - * @version 1.0.1 |
|
| 709 | - * @param integer|double $size |
|
| 710 | - * @return integer|double |
|
| 711 | - * @method string sizeInBytes |
|
| 712 | - */ |
|
| 705 | + * Convert human file size to bytes |
|
| 706 | + * |
|
| 707 | + * @since 1.0 |
|
| 708 | + * @version 1.0.1 |
|
| 709 | + * @param integer|double $size |
|
| 710 | + * @return integer|double |
|
| 711 | + * @method string sizeInBytes |
|
| 712 | + */ |
|
| 713 | 713 | public function sizeInBytes($size) |
| 714 | 714 | { |
| 715 | 715 | $unit = 'B'; |
@@ -761,7 +761,7 @@ discard block |
||
| 761 | 761 | return true; |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | - //check for php upload error |
|
| 764 | + //check for php upload error |
|
| 765 | 765 | if(is_numeric($this->file['error']) && $this->file['error'] > 0){ |
| 766 | 766 | $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error'])); |
| 767 | 767 | return true; |
@@ -773,7 +773,7 @@ discard block |
||
| 773 | 773 | return true; |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | - // Check file size |
|
| 776 | + // Check file size |
|
| 777 | 777 | if ($this->max_file_size > 0 && $this->max_file_size < $this->file['size']) { |
| 778 | 778 | $this->setError(sprintf($this->error_messages['max_file_size'], $this->sizeFormat($this->max_file_size))); |
| 779 | 779 | return true; |
@@ -1,25 +1,25 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | 3 | |
| 4 | - /** |
|
| 5 | - * |
|
| 6 | - */ |
|
| 7 | - class Home extends Controller { |
|
| 4 | + /** |
|
| 5 | + * |
|
| 6 | + */ |
|
| 7 | + class Home extends Controller { |
|
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * the class constructor |
|
| 11 | - */ |
|
| 12 | - public function __construct() { |
|
| 13 | - parent::__construct(); |
|
| 14 | - } |
|
| 9 | + /** |
|
| 10 | + * the class constructor |
|
| 11 | + */ |
|
| 12 | + public function __construct() { |
|
| 13 | + parent::__construct(); |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * The default method |
|
| 18 | - * @return null |
|
| 19 | - */ |
|
| 20 | - public function index() { |
|
| 21 | - Loader::library('Assets'); |
|
| 22 | - Loader::library('Html'); |
|
| 23 | - $this->response->render('home'); |
|
| 24 | - } |
|
| 25 | - } |
|
| 16 | + /** |
|
| 17 | + * The default method |
|
| 18 | + * @return null |
|
| 19 | + */ |
|
| 20 | + public function index() { |
|
| 21 | + Loader::library('Assets'); |
|
| 22 | + Loader::library('Html'); |
|
| 23 | + $this->response->render('home'); |
|
| 24 | + } |
|
| 25 | + } |
|
@@ -1,94 +1,94 @@ |
||
| 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 resources that you want to load automatically: |
|
| 29 | - * personal or system libraries, configuration files, models, |
|
| 30 | - * personal functions or systems that are used most often in your application |
|
| 31 | - * instead of loading them every time you want to use it. |
|
| 32 | - * Note: loading a lot of resources can decrease the performance of your application. |
|
| 33 | - */ |
|
| 27 | + /** |
|
| 28 | + * This file contains the configuration of resources that you want to load automatically: |
|
| 29 | + * personal or system libraries, configuration files, models, |
|
| 30 | + * personal functions or systems that are used most often in your application |
|
| 31 | + * instead of loading them every time you want to use it. |
|
| 32 | + * Note: loading a lot of resources can decrease the performance of your application. |
|
| 33 | + */ |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * If you have personal libraries or systems to load automatically, then list them in the following array. |
|
| 38 | - * For example : |
|
| 39 | - * |
|
| 40 | - * $autoload['libraries'] = array('library1', 'library1'); |
|
| 41 | - * |
|
| 42 | - * Note: Personal libraries have priority over system libraries, |
|
| 43 | - * ie the loading order is as follows: it looks in the folder of the personal libraries, |
|
| 44 | - * if it is found, it is loaded, if not , we search in the system libraries folder, |
|
| 45 | - * before returning an error in case it does not find it. |
|
| 46 | - */ |
|
| 47 | - $autoload['libraries'] = array(); |
|
| 36 | + /** |
|
| 37 | + * If you have personal libraries or systems to load automatically, then list them in the following array. |
|
| 38 | + * For example : |
|
| 39 | + * |
|
| 40 | + * $autoload['libraries'] = array('library1', 'library1'); |
|
| 41 | + * |
|
| 42 | + * Note: Personal libraries have priority over system libraries, |
|
| 43 | + * ie the loading order is as follows: it looks in the folder of the personal libraries, |
|
| 44 | + * if it is found, it is loaded, if not , we search in the system libraries folder, |
|
| 45 | + * before returning an error in case it does not find it. |
|
| 46 | + */ |
|
| 47 | + $autoload['libraries'] = array(); |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * If you have configuration files to load automatically, then list them in the following array. |
|
| 51 | - * For example : |
|
| 52 | - * |
|
| 53 | - * $autoload['config'] = array('config1', 'config2'); |
|
| 54 | - * |
|
| 55 | - * Note 1: the file name must have as prefix "config_" |
|
| 56 | - * for example "config_name_of_the_file_config.php" and contains as configuration variable the array $config, |
|
| 57 | - * otherwise the system can not find this configuration file. |
|
| 58 | - * For example : |
|
| 59 | - * |
|
| 60 | - * $config['key1'] = value1; |
|
| 61 | - * $config['key2'] = value2; |
|
| 62 | - * |
|
| 63 | - * Note 2: the files to be loaded must be in the folder defined by the constant "CONFIG_PATH" in "index.php". |
|
| 64 | - */ |
|
| 65 | - $autoload['config'] = array(); |
|
| 49 | + /** |
|
| 50 | + * If you have configuration files to load automatically, then list them in the following array. |
|
| 51 | + * For example : |
|
| 52 | + * |
|
| 53 | + * $autoload['config'] = array('config1', 'config2'); |
|
| 54 | + * |
|
| 55 | + * Note 1: the file name must have as prefix "config_" |
|
| 56 | + * for example "config_name_of_the_file_config.php" and contains as configuration variable the array $config, |
|
| 57 | + * otherwise the system can not find this configuration file. |
|
| 58 | + * For example : |
|
| 59 | + * |
|
| 60 | + * $config['key1'] = value1; |
|
| 61 | + * $config['key2'] = value2; |
|
| 62 | + * |
|
| 63 | + * Note 2: the files to be loaded must be in the folder defined by the constant "CONFIG_PATH" in "index.php". |
|
| 64 | + */ |
|
| 65 | + $autoload['config'] = array(); |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * If you have models to load automatically, then list them in the following table. |
|
| 69 | - * For example : |
|
| 70 | - * |
|
| 71 | - * $autoload['models'] = array('model1', 'model2'); |
|
| 72 | - */ |
|
| 73 | - $autoload['models'] = array(); |
|
| 67 | + /** |
|
| 68 | + * If you have models to load automatically, then list them in the following table. |
|
| 69 | + * For example : |
|
| 70 | + * |
|
| 71 | + * $autoload['models'] = array('model1', 'model2'); |
|
| 72 | + */ |
|
| 73 | + $autoload['models'] = array(); |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * If you have system or personal functions to load automatically, specify them in the following array. |
|
| 77 | - * For example : |
|
| 78 | - * |
|
| 79 | - * $autoload['functions'] = array('function1', 'function2'); |
|
| 80 | - * |
|
| 81 | - * Note: Personal functions have priority over system functions, |
|
| 82 | - * that is to say that the order of loading is the following : it looks in the directory of the personal functions, |
|
| 83 | - * if it is found, it is loaded, otherwise, it looks in the directory of the system functions, |
|
| 84 | - * before returning an error in case he does not find it. |
|
| 85 | - */ |
|
| 86 | - $autoload['functions'] = array(); |
|
| 75 | + /** |
|
| 76 | + * If you have system or personal functions to load automatically, specify them in the following array. |
|
| 77 | + * For example : |
|
| 78 | + * |
|
| 79 | + * $autoload['functions'] = array('function1', 'function2'); |
|
| 80 | + * |
|
| 81 | + * Note: Personal functions have priority over system functions, |
|
| 82 | + * that is to say that the order of loading is the following : it looks in the directory of the personal functions, |
|
| 83 | + * if it is found, it is loaded, otherwise, it looks in the directory of the system functions, |
|
| 84 | + * before returning an error in case he does not find it. |
|
| 85 | + */ |
|
| 86 | + $autoload['functions'] = array(); |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * If you have system or personal language to load automatically, specify them in the following array. |
|
| 90 | - * For example : |
|
| 91 | - * |
|
| 92 | - * $autoload['languages'] = array('lang1', 'lang2'); |
|
| 93 | - */ |
|
| 94 | - $autoload['languages'] = array(); |
|
| 88 | + /** |
|
| 89 | + * If you have system or personal language to load automatically, specify them in the following array. |
|
| 90 | + * For example : |
|
| 91 | + * |
|
| 92 | + * $autoload['languages'] = array('lang1', 'lang2'); |
|
| 93 | + */ |
|
| 94 | + $autoload['languages'] = array(); |
|
@@ -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 |