@@ -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 | } |
@@ -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 | |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | /** |
| 85 | 85 | * This method is used to set the module name |
| 86 | 86 | */ |
| 87 | - protected function setModuleNameFromRouter(){ |
|
| 87 | + protected function setModuleNameFromRouter() { |
|
| 88 | 88 | //determine the current module |
| 89 | - if(isset($this->router) && $this->router->getModule()){ |
|
| 89 | + if (isset($this->router) && $this->router->getModule()) { |
|
| 90 | 90 | $this->moduleName = $this->router->getModule(); |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -95,13 +95,13 @@ discard block |
||
| 95 | 95 | * Set the cache using the argument otherwise will use the configuration |
| 96 | 96 | * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured |
| 97 | 97 | */ |
| 98 | - protected function setCacheFromParamOrConfig(CacheInterface $cache = null){ |
|
| 98 | + protected function setCacheFromParamOrConfig(CacheInterface $cache = null) { |
|
| 99 | 99 | $this->logger->debug('Setting the cache handler instance'); |
| 100 | 100 | //set cache handler instance |
| 101 | - if(get_config('cache_enable', false)){ |
|
| 102 | - if ($cache !== null){ |
|
| 101 | + if (get_config('cache_enable', false)) { |
|
| 102 | + if ($cache !== null) { |
|
| 103 | 103 | $this->cache = $cache; |
| 104 | - } else if (isset($this->{strtolower(get_config('cache_handler'))})){ |
|
| 104 | + } else if (isset($this->{strtolower(get_config('cache_handler'))})) { |
|
| 105 | 105 | $this->cache = $this->{strtolower(get_config('cache_handler'))}; |
| 106 | 106 | unset($this->{strtolower(get_config('cache_handler'))}); |
| 107 | 107 | } |
@@ -112,12 +112,12 @@ discard block |
||
| 112 | 112 | * Set the Log instance using argument or create new instance |
| 113 | 113 | * @param object $logger the Log instance if not null |
| 114 | 114 | */ |
| 115 | - protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
|
| 116 | - if($logger !== null){ |
|
| 115 | + protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) { |
|
| 116 | + if ($logger !== null) { |
|
| 117 | 117 | $this->logger = $logger; |
| 118 | 118 | } |
| 119 | - else{ |
|
| 120 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 119 | + else { |
|
| 120 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 121 | 121 | $this->logger->setLogger('MainController'); |
| 122 | 122 | } |
| 123 | 123 | } |
@@ -126,20 +126,20 @@ discard block |
||
| 126 | 126 | * This method is used to load the required resources for framework to work |
| 127 | 127 | * @return void |
| 128 | 128 | */ |
| 129 | - private function loadRequiredResources(){ |
|
| 129 | + private function loadRequiredResources() { |
|
| 130 | 130 | $this->logger->debug('Adding the loaded classes to the super instance'); |
| 131 | - foreach (class_loaded() as $var => $class){ |
|
| 132 | - $this->$var =& class_loader($class); |
|
| 131 | + foreach (class_loaded() as $var => $class) { |
|
| 132 | + $this->$var = & class_loader($class); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | $this->logger->debug('Loading the required classes into super instance'); |
| 136 | - $this->eventdispatcher =& class_loader('EventDispatcher', 'classes'); |
|
| 137 | - $this->loader =& class_loader('Loader', 'classes'); |
|
| 138 | - $this->lang =& class_loader('Lang', 'classes'); |
|
| 139 | - $this->request =& class_loader('Request', 'classes'); |
|
| 136 | + $this->eventdispatcher = & class_loader('EventDispatcher', 'classes'); |
|
| 137 | + $this->loader = & class_loader('Loader', 'classes'); |
|
| 138 | + $this->lang = & class_loader('Lang', 'classes'); |
|
| 139 | + $this->request = & class_loader('Request', 'classes'); |
|
| 140 | 140 | //dispatch the request instance created event |
| 141 | 141 | $this->eventdispatcher->dispatch('REQUEST_CREATED'); |
| 142 | - $this->response =& class_loader('Response', 'classes', 'classes'); |
|
| 142 | + $this->response = & class_loader('Response', 'classes', 'classes'); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | } |
@@ -1,145 +1,145 @@ |
||
| 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 required resources |
|
| 59 | - $this->loadRequiredResources(); |
|
| 58 | + //load the required resources |
|
| 59 | + $this->loadRequiredResources(); |
|
| 60 | 60 | |
| 61 | - //set the cache using the configuration |
|
| 62 | - $this->setCacheFromParamOrConfig(null); |
|
| 61 | + //set the cache using the configuration |
|
| 62 | + $this->setCacheFromParamOrConfig(null); |
|
| 63 | 63 | |
| 64 | - //set application session configuration |
|
| 65 | - $this->logger->debug('Setting PHP application session handler'); |
|
| 66 | - set_session_config(); |
|
| 64 | + //set application session configuration |
|
| 65 | + $this->logger->debug('Setting PHP application session handler'); |
|
| 66 | + set_session_config(); |
|
| 67 | 67 | |
| 68 | - //set module using the router |
|
| 69 | - $this->setModuleNameFromRouter(); |
|
| 68 | + //set module using the router |
|
| 69 | + $this->setModuleNameFromRouter(); |
|
| 70 | 70 | |
| 71 | - //dispatch the loaded instance of super controller event |
|
| 72 | - $this->eventdispatcher->dispatch('SUPER_CONTROLLER_CREATED'); |
|
| 73 | - } |
|
| 71 | + //dispatch the loaded instance of super controller event |
|
| 72 | + $this->eventdispatcher->dispatch('SUPER_CONTROLLER_CREATED'); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * This is a very useful method it's used to get the super object instance |
|
| 78 | - * @return Controller the super object instance |
|
| 79 | - */ |
|
| 80 | - public static function &get_instance(){ |
|
| 81 | - return self::$instance; |
|
| 82 | - } |
|
| 76 | + /** |
|
| 77 | + * This is a very useful method it's used to get the super object instance |
|
| 78 | + * @return Controller the super object instance |
|
| 79 | + */ |
|
| 80 | + public static function &get_instance(){ |
|
| 81 | + return self::$instance; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * This method is used to set the module name |
|
| 86 | - */ |
|
| 87 | - protected function setModuleNameFromRouter(){ |
|
| 88 | - //determine the current module |
|
| 89 | - if(isset($this->router) && $this->router->getModule()){ |
|
| 90 | - $this->moduleName = $this->router->getModule(); |
|
| 91 | - } |
|
| 92 | - } |
|
| 84 | + /** |
|
| 85 | + * This method is used to set the module name |
|
| 86 | + */ |
|
| 87 | + protected function setModuleNameFromRouter(){ |
|
| 88 | + //determine the current module |
|
| 89 | + if(isset($this->router) && $this->router->getModule()){ |
|
| 90 | + $this->moduleName = $this->router->getModule(); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Set the cache using the argument otherwise will use the configuration |
|
| 96 | - * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured |
|
| 97 | - */ |
|
| 98 | - protected function setCacheFromParamOrConfig(CacheInterface $cache = null){ |
|
| 99 | - $this->logger->debug('Setting the cache handler instance'); |
|
| 100 | - //set cache handler instance |
|
| 101 | - if(get_config('cache_enable', false)){ |
|
| 102 | - if ($cache !== null){ |
|
| 103 | - $this->cache = $cache; |
|
| 104 | - } else if (isset($this->{strtolower(get_config('cache_handler'))})){ |
|
| 105 | - $this->cache = $this->{strtolower(get_config('cache_handler'))}; |
|
| 106 | - unset($this->{strtolower(get_config('cache_handler'))}); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - } |
|
| 94 | + /** |
|
| 95 | + * Set the cache using the argument otherwise will use the configuration |
|
| 96 | + * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured |
|
| 97 | + */ |
|
| 98 | + protected function setCacheFromParamOrConfig(CacheInterface $cache = null){ |
|
| 99 | + $this->logger->debug('Setting the cache handler instance'); |
|
| 100 | + //set cache handler instance |
|
| 101 | + if(get_config('cache_enable', false)){ |
|
| 102 | + if ($cache !== null){ |
|
| 103 | + $this->cache = $cache; |
|
| 104 | + } else if (isset($this->{strtolower(get_config('cache_handler'))})){ |
|
| 105 | + $this->cache = $this->{strtolower(get_config('cache_handler'))}; |
|
| 106 | + unset($this->{strtolower(get_config('cache_handler'))}); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Set the Log instance using argument or create new instance |
|
| 113 | - * @param object $logger the Log instance if not null |
|
| 114 | - */ |
|
| 115 | - protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
|
| 116 | - if($logger !== null){ |
|
| 117 | - $this->logger = $logger; |
|
| 118 | - } |
|
| 119 | - else{ |
|
| 120 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 121 | - $this->logger->setLogger('MainController'); |
|
| 122 | - } |
|
| 123 | - } |
|
| 111 | + /** |
|
| 112 | + * Set the Log instance using argument or create new instance |
|
| 113 | + * @param object $logger the Log instance if not null |
|
| 114 | + */ |
|
| 115 | + protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
|
| 116 | + if($logger !== null){ |
|
| 117 | + $this->logger = $logger; |
|
| 118 | + } |
|
| 119 | + else{ |
|
| 120 | + $this->logger =& class_loader('Log', 'classes'); |
|
| 121 | + $this->logger->setLogger('MainController'); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * This method is used to load the required resources for framework to work |
|
| 127 | - * @return void |
|
| 128 | - */ |
|
| 129 | - private function loadRequiredResources(){ |
|
| 130 | - $this->logger->debug('Adding the loaded classes to the super instance'); |
|
| 131 | - foreach (class_loaded() as $var => $class){ |
|
| 132 | - $this->$var =& class_loader($class); |
|
| 133 | - } |
|
| 125 | + /** |
|
| 126 | + * This method is used to load the required resources for framework to work |
|
| 127 | + * @return void |
|
| 128 | + */ |
|
| 129 | + private function loadRequiredResources(){ |
|
| 130 | + $this->logger->debug('Adding the loaded classes to the super instance'); |
|
| 131 | + foreach (class_loaded() as $var => $class){ |
|
| 132 | + $this->$var =& class_loader($class); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - $this->logger->debug('Loading the required classes into super instance'); |
|
| 136 | - $this->eventdispatcher =& class_loader('EventDispatcher', 'classes'); |
|
| 137 | - $this->loader =& class_loader('Loader', 'classes'); |
|
| 138 | - $this->lang =& class_loader('Lang', 'classes'); |
|
| 139 | - $this->request =& class_loader('Request', 'classes'); |
|
| 140 | - //dispatch the request instance created event |
|
| 141 | - $this->eventdispatcher->dispatch('REQUEST_CREATED'); |
|
| 142 | - $this->response =& class_loader('Response', 'classes', 'classes'); |
|
| 143 | - } |
|
| 135 | + $this->logger->debug('Loading the required classes into super instance'); |
|
| 136 | + $this->eventdispatcher =& class_loader('EventDispatcher', 'classes'); |
|
| 137 | + $this->loader =& class_loader('Loader', 'classes'); |
|
| 138 | + $this->lang =& class_loader('Lang', 'classes'); |
|
| 139 | + $this->request =& class_loader('Request', 'classes'); |
|
| 140 | + //dispatch the request instance created event |
|
| 141 | + $this->eventdispatcher->dispatch('REQUEST_CREATED'); |
|
| 142 | + $this->response =& class_loader('Response', 'classes', 'classes'); |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - } |
|
| 145 | + } |
|
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - public function testDefaultValue(){ |
|
| 28 | + public function testDefaultValue() { |
|
| 29 | 29 | $e = new EventInfo('foo'); |
| 30 | 30 | $this->assertSame($e->name, 'foo'); |
| 31 | 31 | $this->assertSame($e->payload, array()); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $this->assertFalse($e->stop); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - public function testPayloadValueIsSet(){ |
|
| 36 | + public function testPayloadValueIsSet() { |
|
| 37 | 37 | $e = new EventInfo('foo', array('bar')); |
| 38 | 38 | $this->assertSame($e->name, 'foo'); |
| 39 | 39 | $this->assertSame($e->payload, array('bar')); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $this->assertFalse($e->stop); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - public function testReturnBackValueIsSetToTrue(){ |
|
| 44 | + public function testReturnBackValueIsSetToTrue() { |
|
| 45 | 45 | $e = new EventInfo('foo', array('bar'), true); |
| 46 | 46 | $this->assertSame($e->name, 'foo'); |
| 47 | 47 | $this->assertSame($e->payload, array('bar')); |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $this->assertFalse($e->stop); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - public function testStopValueIsSetToTue(){ |
|
| 52 | + public function testStopValueIsSetToTue() { |
|
| 53 | 53 | $e = new EventInfo('foo', array('bar'), true, true); |
| 54 | 54 | $this->assertSame($e->name, 'foo'); |
| 55 | 55 | $this->assertSame($e->payload, array('bar')); |
@@ -1,59 +1,59 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use PHPUnit\Framework\TestCase; |
|
| 3 | + use PHPUnit\Framework\TestCase; |
|
| 4 | 4 | |
| 5 | - class EventInfoTest extends TestCase |
|
| 6 | - { |
|
| 5 | + class EventInfoTest extends TestCase |
|
| 6 | + { |
|
| 7 | 7 | |
| 8 | - public static function setUpBeforeClass() |
|
| 9 | - { |
|
| 8 | + public static function setUpBeforeClass() |
|
| 9 | + { |
|
| 10 | 10 | |
| 11 | - } |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public static function tearDownAfterClass() |
|
| 14 | - { |
|
| 13 | + public static function tearDownAfterClass() |
|
| 14 | + { |
|
| 15 | 15 | |
| 16 | - } |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - protected function setUp() |
|
| 19 | - { |
|
| 20 | - } |
|
| 18 | + protected function setUp() |
|
| 19 | + { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - protected function tearDown() |
|
| 23 | - { |
|
| 24 | - } |
|
| 22 | + protected function tearDown() |
|
| 23 | + { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - public function testDefaultValue(){ |
|
| 29 | - $e = new EventInfo('foo'); |
|
| 30 | - $this->assertSame($e->name, 'foo'); |
|
| 31 | - $this->assertSame($e->payload, array()); |
|
| 32 | - $this->assertFalse($e->returnBack); |
|
| 33 | - $this->assertFalse($e->stop); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - public function testPayloadValueIsSet(){ |
|
| 37 | - $e = new EventInfo('foo', array('bar')); |
|
| 38 | - $this->assertSame($e->name, 'foo'); |
|
| 39 | - $this->assertSame($e->payload, array('bar')); |
|
| 40 | - $this->assertFalse($e->returnBack); |
|
| 41 | - $this->assertFalse($e->stop); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - public function testReturnBackValueIsSetToTrue(){ |
|
| 45 | - $e = new EventInfo('foo', array('bar'), true); |
|
| 46 | - $this->assertSame($e->name, 'foo'); |
|
| 47 | - $this->assertSame($e->payload, array('bar')); |
|
| 48 | - $this->assertTrue($e->returnBack); |
|
| 49 | - $this->assertFalse($e->stop); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public function testStopValueIsSetToTue(){ |
|
| 53 | - $e = new EventInfo('foo', array('bar'), true, true); |
|
| 54 | - $this->assertSame($e->name, 'foo'); |
|
| 55 | - $this->assertSame($e->payload, array('bar')); |
|
| 56 | - $this->assertTrue($e->returnBack); |
|
| 57 | - $this->assertTrue($e->stop); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | 28 | \ No newline at end of file |
| 29 | + public function testDefaultValue(){ |
|
| 30 | + $e = new EventInfo('foo'); |
|
| 31 | + $this->assertSame($e->name, 'foo'); |
|
| 32 | + $this->assertSame($e->payload, array()); |
|
| 33 | + $this->assertFalse($e->returnBack); |
|
| 34 | + $this->assertFalse($e->stop); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function testPayloadValueIsSet(){ |
|
| 38 | + $e = new EventInfo('foo', array('bar')); |
|
| 39 | + $this->assertSame($e->name, 'foo'); |
|
| 40 | + $this->assertSame($e->payload, array('bar')); |
|
| 41 | + $this->assertFalse($e->returnBack); |
|
| 42 | + $this->assertFalse($e->stop); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function testReturnBackValueIsSetToTrue(){ |
|
| 46 | + $e = new EventInfo('foo', array('bar'), true); |
|
| 47 | + $this->assertSame($e->name, 'foo'); |
|
| 48 | + $this->assertSame($e->payload, array('bar')); |
|
| 49 | + $this->assertTrue($e->returnBack); |
|
| 50 | + $this->assertFalse($e->stop); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + public function testStopValueIsSetToTue(){ |
|
| 54 | + $e = new EventInfo('foo', array('bar'), true, true); |
|
| 55 | + $this->assertSame($e->name, 'foo'); |
|
| 56 | + $this->assertSame($e->payload, array('bar')); |
|
| 57 | + $this->assertTrue($e->returnBack); |
|
| 58 | + $this->assertTrue($e->stop); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | 61 | \ No newline at end of file |
@@ -220,8 +220,7 @@ discard block |
||
| 220 | 220 | //first check for CSRF |
| 221 | 221 | if ((get_config('csrf_enable', false) || $this->enableCsrfCheck) && ! Security::validateCSRF()){ |
| 222 | 222 | show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.'); |
| 223 | - } |
|
| 224 | - else{ |
|
| 223 | + } else{ |
|
| 225 | 224 | $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it'); |
| 226 | 225 | } |
| 227 | 226 | } |
@@ -231,8 +230,7 @@ discard block |
||
| 231 | 230 | foreach ($this->getData() as $inputName => $inputVal) { |
| 232 | 231 | if(is_array($this->data[$inputName])){ |
| 233 | 232 | $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
| 234 | - } |
|
| 235 | - else{ |
|
| 233 | + } else{ |
|
| 236 | 234 | $this->data[$inputName] = trim($this->data[$inputName]); |
| 237 | 235 | } |
| 238 | 236 | |
@@ -600,8 +598,7 @@ discard block |
||
| 600 | 598 | if ($inputVal == '' && $callbackReturn == true) { |
| 601 | 599 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 602 | 600 | } |
| 603 | - } |
|
| 604 | - else if($inputVal == '') { |
|
| 601 | + } else if($inputVal == '') { |
|
| 605 | 602 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 606 | 603 | } |
| 607 | 604 | } |
@@ -660,8 +657,7 @@ discard block |
||
| 660 | 657 | $this->_setError($inputName, $ruleName . ',post:key', array($this->_getLabel($inputName), $this->_getLabel(str_replace('post:', '', $doNotEqual)))); |
| 661 | 658 | continue; |
| 662 | 659 | } |
| 663 | - } |
|
| 664 | - else{ |
|
| 660 | + } else{ |
|
| 665 | 661 | if ($inputVal == $doNotEqual) { |
| 666 | 662 | $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual)); |
| 667 | 663 | continue; |
@@ -25,13 +25,13 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class FormValidation{ |
|
| 28 | + class FormValidation { |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * The form validation status |
| 32 | 32 | * @var boolean |
| 33 | 33 | */ |
| 34 | - protected $_success = false; |
|
| 34 | + protected $_success = false; |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * The list of errors messages |
@@ -40,31 +40,31 @@ discard block |
||
| 40 | 40 | protected $_errorsMessages = array(); |
| 41 | 41 | |
| 42 | 42 | // Array of rule sets, fieldName => PIPE seperated ruleString |
| 43 | - protected $_rules = array(); |
|
| 43 | + protected $_rules = array(); |
|
| 44 | 44 | |
| 45 | 45 | // Array of errors, niceName => Error Message |
| 46 | - protected $_errors = array(); |
|
| 46 | + protected $_errors = array(); |
|
| 47 | 47 | |
| 48 | 48 | // Array of post Key => Nice name labels |
| 49 | - protected $_labels = array(); |
|
| 49 | + protected $_labels = array(); |
|
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * The errors delimiters |
| 53 | 53 | * @var array |
| 54 | 54 | */ |
| 55 | - protected $_allErrorsDelimiter = array('<div class="error">', '</div>'); |
|
| 55 | + protected $_allErrorsDelimiter = array('<div class="error">', '</div>'); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * The each error delimiter |
| 59 | 59 | * @var array |
| 60 | 60 | */ |
| 61 | - protected $_eachErrorDelimiter = array('<p class="error">', '</p>'); |
|
| 61 | + protected $_eachErrorDelimiter = array('<p class="error">', '</p>'); |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * Indicated if need force the validation to be failed |
| 65 | 65 | * @var boolean |
| 66 | 66 | */ |
| 67 | - protected $_forceFail = false; |
|
| 67 | + protected $_forceFail = false; |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * The list of the error messages overrides by the original |
@@ -98,13 +98,13 @@ discard block |
||
| 98 | 98 | * @return void |
| 99 | 99 | */ |
| 100 | 100 | public function __construct() { |
| 101 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 101 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 102 | 102 | $this->logger->setLogger('Library::FormValidation'); |
| 103 | 103 | |
| 104 | 104 | //Load form validation language message |
| 105 | 105 | Loader::lang('form_validation'); |
| 106 | 106 | $obj = & get_instance(); |
| 107 | - $this->_errorsMessages = array( |
|
| 107 | + $this->_errorsMessages = array( |
|
| 108 | 108 | 'required' => $obj->lang->get('fv_required'), |
| 109 | 109 | 'min_length' => $obj->lang->get('fv_min_length'), |
| 110 | 110 | 'max_length' => $obj->lang->get('fv_max_length'), |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $this->_success = false; |
| 142 | 142 | $this->_forceFail = false; |
| 143 | 143 | $this->data = array(); |
| 144 | - $this->enableCsrfCheck = false; |
|
| 144 | + $this->enableCsrfCheck = false; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * |
| 151 | 151 | * @return FormValidation Current instance of object. |
| 152 | 152 | */ |
| 153 | - public function setData(array $data){ |
|
| 153 | + public function setData(array $data) { |
|
| 154 | 154 | $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data)); |
| 155 | 155 | $this->data = $data; |
| 156 | 156 | return $this; |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * Get the form validation data |
| 161 | 161 | * @return array the form validation data to be validated |
| 162 | 162 | */ |
| 163 | - public function getData(){ |
|
| 163 | + public function getData() { |
|
| 164 | 164 | return $this->data; |
| 165 | 165 | } |
| 166 | 166 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * |
| 170 | 170 | * @return string the function name |
| 171 | 171 | */ |
| 172 | - protected function _toCallCase($funcName, $prefix='_validate') { |
|
| 172 | + protected function _toCallCase($funcName, $prefix = '_validate') { |
|
| 173 | 173 | $funcName = strtolower($funcName); |
| 174 | 174 | $finalFuncName = $prefix; |
| 175 | 175 | foreach (explode('_', $funcName) as $funcNamePart) { |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | * @return boolean Whether or not the form has been submitted or the data is available for validation. |
| 194 | 194 | */ |
| 195 | 195 | public function canDoValidation() { |
| 196 | - return get_instance()->request->method() === 'POST' || ! empty($this->data); |
|
| 196 | + return get_instance()->request->method() === 'POST' || !empty($this->data); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -213,14 +213,14 @@ discard block |
||
| 213 | 213 | * Validate the CSRF |
| 214 | 214 | * @return void |
| 215 | 215 | */ |
| 216 | - protected function validateCSRF(){ |
|
| 217 | - if(get_instance()->request->method() == 'POST' || $this->enableCsrfCheck){ |
|
| 216 | + protected function validateCSRF() { |
|
| 217 | + if (get_instance()->request->method() == 'POST' || $this->enableCsrfCheck) { |
|
| 218 | 218 | $this->logger->debug('Check if CSRF is enabled in configuration'); |
| 219 | 219 | //first check for CSRF |
| 220 | - if ((get_config('csrf_enable', false) || $this->enableCsrfCheck) && ! Security::validateCSRF()){ |
|
| 220 | + if ((get_config('csrf_enable', false) || $this->enableCsrfCheck) && !Security::validateCSRF()) { |
|
| 221 | 221 | show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.'); |
| 222 | 222 | } |
| 223 | - else{ |
|
| 223 | + else { |
|
| 224 | 224 | $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it'); |
| 225 | 225 | } |
| 226 | 226 | } |
@@ -237,10 +237,10 @@ discard block |
||
| 237 | 237 | $this->_forceFail = false; |
| 238 | 238 | |
| 239 | 239 | foreach ($this->getData() as $inputName => $inputVal) { |
| 240 | - if(is_array($this->data[$inputName])){ |
|
| 240 | + if (is_array($this->data[$inputName])) { |
|
| 241 | 241 | $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
| 242 | 242 | } |
| 243 | - else{ |
|
| 243 | + else { |
|
| 244 | 244 | $this->data[$inputName] = trim($this->data[$inputName]); |
| 245 | 245 | } |
| 246 | 246 | |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | public function setRule($inputField, $inputLabel, $ruleSets) { |
| 268 | 268 | $this->_rules[$inputField] = $ruleSets; |
| 269 | 269 | $this->_labels[$inputField] = $inputLabel; |
| 270 | - $this->logger->info('Set the field rule: name [' .$inputField. '], label [' .$inputLabel. '], rules [' .$ruleSets. ']'); |
|
| 270 | + $this->logger->info('Set the field rule: name [' . $inputField . '], label [' . $inputLabel . '], rules [' . $ruleSets . ']'); |
|
| 271 | 271 | return $this; |
| 272 | 272 | } |
| 273 | 273 | |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | } |
| 432 | 432 | $errorOutput .= $errorsEnd; |
| 433 | 433 | echo ($echo) ? $errorOutput : ''; |
| 434 | - return (! $echo) ? $errorOutput : null; |
|
| 434 | + return (!$echo) ? $errorOutput : null; |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | /** |
@@ -456,25 +456,25 @@ discard block |
||
| 456 | 456 | /* |
| 457 | 457 | //////////////// hack for regex rule that can contain "|" |
| 458 | 458 | */ |
| 459 | - if(strpos($ruleString, 'regex') !== false){ |
|
| 459 | + if (strpos($ruleString, 'regex') !== false) { |
|
| 460 | 460 | $regexRule = array(); |
| 461 | 461 | $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#'; |
| 462 | 462 | preg_match($rule, $ruleString, $regexRule); |
| 463 | 463 | $ruleStringTemp = preg_replace($rule, '', $ruleString); |
| 464 | - if(!empty($regexRule[0])){ |
|
| 464 | + if (!empty($regexRule[0])) { |
|
| 465 | 465 | $ruleSets[] = $regexRule[0]; |
| 466 | 466 | } |
| 467 | 467 | $ruleStringRegex = explode('|', $ruleStringTemp); |
| 468 | 468 | foreach ($ruleStringRegex as $rule) { |
| 469 | 469 | $rule = trim($rule); |
| 470 | - if($rule){ |
|
| 470 | + if ($rule) { |
|
| 471 | 471 | $ruleSets[] = $rule; |
| 472 | 472 | } |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | } |
| 476 | 476 | /***********************************/ |
| 477 | - else{ |
|
| 477 | + else { |
|
| 478 | 478 | if (strpos($ruleString, '|') !== FALSE) { |
| 479 | 479 | $ruleSets = explode('|', $ruleString); |
| 480 | 480 | } else { |
@@ -506,7 +506,7 @@ discard block |
||
| 506 | 506 | * @return void |
| 507 | 507 | */ |
| 508 | 508 | protected function _validateRule($inputName, $inputVal, $ruleName) { |
| 509 | - $this->logger->debug('Rule validation of field [' .$inputName. '], value [' .$inputVal. '], rule [' .$ruleName. ']'); |
|
| 509 | + $this->logger->debug('Rule validation of field [' . $inputName . '], value [' . $inputVal . '], rule [' . $ruleName . ']'); |
|
| 510 | 510 | // Array to store args |
| 511 | 511 | $ruleArgs = array(); |
| 512 | 512 | |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | $key = $i - 1; |
| 552 | 552 | $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase); |
| 553 | 553 | } |
| 554 | - if (! array_key_exists($inputName, $this->_errors)) { |
|
| 554 | + if (!array_key_exists($inputName, $this->_errors)) { |
|
| 555 | 555 | $this->_errors[$inputName] = $rulePhrase; |
| 556 | 556 | } |
| 557 | 557 | } |
@@ -603,13 +603,13 @@ discard block |
||
| 603 | 603 | */ |
| 604 | 604 | protected function _validateRequired($inputName, $ruleName, array $ruleArgs) { |
| 605 | 605 | $inputVal = $this->post($inputName); |
| 606 | - if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) { |
|
| 606 | + if (array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) { |
|
| 607 | 607 | $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]); |
| 608 | 608 | if ($inputVal == '' && $callbackReturn == true) { |
| 609 | 609 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 610 | 610 | } |
| 611 | 611 | } |
| 612 | - else if($inputVal == '') { |
|
| 612 | + else if ($inputVal == '') { |
|
| 613 | 613 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 614 | 614 | } |
| 615 | 615 | } |
@@ -635,7 +635,7 @@ discard block |
||
| 635 | 635 | protected function _validateCallback($inputName, $ruleName, array $ruleArgs) { |
| 636 | 636 | if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) { |
| 637 | 637 | $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]); |
| 638 | - if(! $result){ |
|
| 638 | + if (!$result) { |
|
| 639 | 639 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
| 640 | 640 | } |
| 641 | 641 | } |
@@ -669,7 +669,7 @@ discard block |
||
| 669 | 669 | continue; |
| 670 | 670 | } |
| 671 | 671 | } |
| 672 | - else{ |
|
| 672 | + else { |
|
| 673 | 673 | if ($inputVal == $doNotEqual) { |
| 674 | 674 | $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual)); |
| 675 | 675 | continue; |
@@ -699,8 +699,8 @@ discard block |
||
| 699 | 699 | */ |
| 700 | 700 | protected function _validateValidEmail($inputName, $ruleName, array $ruleArgs) { |
| 701 | 701 | $inputVal = $this->post($inputName); |
| 702 | - if (! preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) { |
|
| 703 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 702 | + if (!preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) { |
|
| 703 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 704 | 704 | return; |
| 705 | 705 | } |
| 706 | 706 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
@@ -716,7 +716,7 @@ discard block |
||
| 716 | 716 | protected function _validateExactLength($inputName, $ruleName, array $ruleArgs) { |
| 717 | 717 | $inputVal = $this->post($inputName); |
| 718 | 718 | if (strlen($inputVal) != $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
| 719 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 719 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 720 | 720 | return; |
| 721 | 721 | } |
| 722 | 722 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -732,7 +732,7 @@ discard block |
||
| 732 | 732 | protected function _validateMaxLength($inputName, $ruleName, array $ruleArgs) { |
| 733 | 733 | $inputVal = $this->post($inputName); |
| 734 | 734 | if (strlen($inputVal) > $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
| 735 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 735 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 736 | 736 | return; |
| 737 | 737 | } |
| 738 | 738 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -748,7 +748,7 @@ discard block |
||
| 748 | 748 | protected function _validateMinLength($inputName, $ruleName, array $ruleArgs) { |
| 749 | 749 | $inputVal = $this->post($inputName); |
| 750 | 750 | if (strlen($inputVal) < $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length |
| 751 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 751 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 752 | 752 | return; |
| 753 | 753 | } |
| 754 | 754 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -764,7 +764,7 @@ discard block |
||
| 764 | 764 | protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) { |
| 765 | 765 | $inputVal = $this->post($inputName); |
| 766 | 766 | if ($inputVal >= $ruleArgs[1]) { |
| 767 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 767 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 768 | 768 | return; |
| 769 | 769 | } |
| 770 | 770 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) { |
| 781 | 781 | $inputVal = $this->post($inputName); |
| 782 | 782 | if ($inputVal <= $ruleArgs[1]) { |
| 783 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 783 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 784 | 784 | return; |
| 785 | 785 | } |
| 786 | 786 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -795,8 +795,8 @@ discard block |
||
| 795 | 795 | */ |
| 796 | 796 | protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) { |
| 797 | 797 | $inputVal = $this->post($inputName); |
| 798 | - if (! is_numeric($inputVal)) { |
|
| 799 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 798 | + if (!is_numeric($inputVal)) { |
|
| 799 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 800 | 800 | return; |
| 801 | 801 | } |
| 802 | 802 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | protected function _validateExists($inputName, $ruleName, array $ruleArgs) { |
| 813 | 813 | $inputVal = $this->post($inputName); |
| 814 | 814 | $obj = & get_instance(); |
| 815 | - if(! isset($obj->database)){ |
|
| 815 | + if (!isset($obj->database)) { |
|
| 816 | 816 | return; |
| 817 | 817 | } |
| 818 | 818 | list($table, $column) = explode('.', $ruleArgs[1]); |
@@ -821,7 +821,7 @@ discard block |
||
| 821 | 821 | ->get(); |
| 822 | 822 | $nb = $obj->database->numRows(); |
| 823 | 823 | if ($nb == 0) { |
| 824 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 824 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 825 | 825 | return; |
| 826 | 826 | } |
| 827 | 827 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -837,7 +837,7 @@ discard block |
||
| 837 | 837 | protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) { |
| 838 | 838 | $inputVal = $this->post($inputName); |
| 839 | 839 | $obj = & get_instance(); |
| 840 | - if(! isset($obj->database)){ |
|
| 840 | + if (!isset($obj->database)) { |
|
| 841 | 841 | return; |
| 842 | 842 | } |
| 843 | 843 | list($table, $column) = explode('.', $ruleArgs[1]); |
@@ -846,7 +846,7 @@ discard block |
||
| 846 | 846 | ->get(); |
| 847 | 847 | $nb = $obj->database->numRows(); |
| 848 | 848 | if ($nb != 0) { |
| 849 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 849 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 850 | 850 | return; |
| 851 | 851 | } |
| 852 | 852 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -862,11 +862,11 @@ discard block |
||
| 862 | 862 | protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) { |
| 863 | 863 | $inputVal = $this->post($inputName); |
| 864 | 864 | $obj = & get_instance(); |
| 865 | - if(! isset($obj->database)){ |
|
| 865 | + if (!isset($obj->database)) { |
|
| 866 | 866 | return; |
| 867 | 867 | } |
| 868 | 868 | $data = explode(',', $ruleArgs[1]); |
| 869 | - if(count($data) < 2){ |
|
| 869 | + if (count($data) < 2) { |
|
| 870 | 870 | return; |
| 871 | 871 | } |
| 872 | 872 | list($table, $column) = explode('.', $data[0]); |
@@ -877,7 +877,7 @@ discard block |
||
| 877 | 877 | ->get(); |
| 878 | 878 | $nb = $obj->database->numRows(); |
| 879 | 879 | if ($nb != 0) { |
| 880 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 880 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 881 | 881 | return; |
| 882 | 882 | } |
| 883 | 883 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -894,8 +894,8 @@ discard block |
||
| 894 | 894 | $inputVal = $this->post($inputName); |
| 895 | 895 | $list = explode(',', $ruleArgs[1]); |
| 896 | 896 | $list = array_map('trim', $list); |
| 897 | - if (! in_array($inputVal, $list)) { |
|
| 898 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 897 | + if (!in_array($inputVal, $list)) { |
|
| 898 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 899 | 899 | return; |
| 900 | 900 | } |
| 901 | 901 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1]))); |
@@ -911,8 +911,8 @@ discard block |
||
| 911 | 911 | protected function _validateRegex($inputName, $ruleName, array $ruleArgs) { |
| 912 | 912 | $inputVal = $this->post($inputName); |
| 913 | 913 | $regex = $ruleArgs[1]; |
| 914 | - if (! preg_match($regex, $inputVal)) { |
|
| 915 | - if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 914 | + if (!preg_match($regex, $inputVal)) { |
|
| 915 | + if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
|
| 916 | 916 | return; |
| 917 | 917 | } |
| 918 | 918 | $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
@@ -22,10 +22,10 @@ discard block |
||
| 22 | 22 | * You should have received a copy of the GNU General Public License |
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | - */ |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class FormValidation{ |
|
| 28 | + class FormValidation{ |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * The form validation status |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | protected $_eachErrorDelimiter = array('<p class="error">', '</p>'); |
| 62 | 62 | |
| 63 | - /** |
|
| 63 | + /** |
|
| 64 | 64 | * Indicated if need force the validation to be failed |
| 65 | 65 | * @var boolean |
| 66 | 66 | */ |
@@ -86,8 +86,8 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * Whether to check the CSRF. This attribute is just a way to allow custom change of the |
| 89 | - * CSRF global configuration |
|
| 90 | - * |
|
| 89 | + * CSRF global configuration |
|
| 90 | + * |
|
| 91 | 91 | * @var boolean |
| 92 | 92 | */ |
| 93 | 93 | public $enableCsrfCheck = false; |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | $this->logger =& class_loader('Log', 'classes'); |
| 102 | 102 | $this->logger->setLogger('Library::FormValidation'); |
| 103 | 103 | |
| 104 | - //Load form validation language message |
|
| 104 | + //Load form validation language message |
|
| 105 | 105 | Loader::lang('form_validation'); |
| 106 | 106 | $obj = & get_instance(); |
| 107 | 107 | $this->_errorsMessages = array( |
@@ -141,19 +141,19 @@ discard block |
||
| 141 | 141 | $this->_success = false; |
| 142 | 142 | $this->_forceFail = false; |
| 143 | 143 | $this->data = array(); |
| 144 | - $this->enableCsrfCheck = false; |
|
| 144 | + $this->enableCsrfCheck = false; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
| 148 | 148 | * Set the form validation data |
| 149 | 149 | * @param array $data the values to be validated |
| 150 | - * |
|
| 150 | + * |
|
| 151 | 151 | * @return FormValidation Current instance of object. |
| 152 | 152 | */ |
| 153 | 153 | public function setData(array $data){ |
| 154 | 154 | $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data)); |
| 155 | 155 | $this->data = $data; |
| 156 | - return $this; |
|
| 156 | + return $this; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -164,11 +164,11 @@ discard block |
||
| 164 | 164 | return $this->data; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Get the validation function name to validate a rule |
|
| 169 | - * |
|
| 170 | - * @return string the function name |
|
| 171 | - */ |
|
| 167 | + /** |
|
| 168 | + * Get the validation function name to validate a rule |
|
| 169 | + * |
|
| 170 | + * @return string the function name |
|
| 171 | + */ |
|
| 172 | 172 | protected function _toCallCase($funcName, $prefix='_validate') { |
| 173 | 173 | $funcName = strtolower($funcName); |
| 174 | 174 | $finalFuncName = $prefix; |
@@ -238,12 +238,12 @@ discard block |
||
| 238 | 238 | $this->_forceFail = false; |
| 239 | 239 | |
| 240 | 240 | foreach ($this->getData() as $inputName => $inputVal) { |
| 241 | - if(is_array($this->data[$inputName])){ |
|
| 242 | - $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
|
| 243 | - } |
|
| 244 | - else{ |
|
| 245 | - $this->data[$inputName] = trim($this->data[$inputName]); |
|
| 246 | - } |
|
| 241 | + if(is_array($this->data[$inputName])){ |
|
| 242 | + $this->data[$inputName] = array_map('trim', $this->data[$inputName]); |
|
| 243 | + } |
|
| 244 | + else{ |
|
| 245 | + $this->data[$inputName] = trim($this->data[$inputName]); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | 248 | if (array_key_exists($inputName, $this->_rules)) { |
| 249 | 249 | foreach ($this->_parseRuleString($this->_rules[$inputName]) as $eachRule) { |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * |
| 263 | 263 | * @param string $inputField Name of the field or the data key to add a rule to |
| 264 | 264 | * @param string $ruleSets PIPE seperated string of rules |
| 265 | - * |
|
| 265 | + * |
|
| 266 | 266 | * @return FormValidation Current instance of object. |
| 267 | 267 | */ |
| 268 | 268 | public function setRule($inputField, $inputLabel, $ruleSets) { |
@@ -276,8 +276,8 @@ discard block |
||
| 276 | 276 | * Takes an array of rules and uses setRule() to set them, accepts an array |
| 277 | 277 | * of rule names rather than a pipe-delimited string as well. |
| 278 | 278 | * @param array $ruleSets |
| 279 | - * |
|
| 280 | - * @return FormValidation Current instance of object. |
|
| 279 | + * |
|
| 280 | + * @return FormValidation Current instance of object. |
|
| 281 | 281 | */ |
| 282 | 282 | public function setRules(array $ruleSets) { |
| 283 | 283 | foreach ($ruleSets as $ruleSet) { |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @param string $start Before block of errors gets displayed, HTML allowed. |
| 300 | 300 | * @param string $end After the block of errors gets displayed, HTML allowed. |
| 301 | 301 | * |
| 302 | - * @return FormValidation Current instance of object. |
|
| 302 | + * @return FormValidation Current instance of object. |
|
| 303 | 303 | */ |
| 304 | 304 | public function setErrorsDelimiter($start, $end) { |
| 305 | 305 | $this->_allErrorsDelimiter[0] = $start; |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | * @param string $start Displayed before each error. |
| 315 | 315 | * @param string $end Displayed after each error. |
| 316 | 316 | * |
| 317 | - * @return FormValidation Current instance of object. |
|
| 317 | + * @return FormValidation Current instance of object. |
|
| 318 | 318 | */ |
| 319 | 319 | public function setErrorDelimiter($start, $end) { |
| 320 | 320 | $this->_eachErrorDelimiter[0] = $start; |
@@ -322,21 +322,21 @@ discard block |
||
| 322 | 322 | return $this; |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - /** |
|
| 326 | - * Get the each errors delimiters |
|
| 327 | - * |
|
| 328 | - * @return array |
|
| 329 | - */ |
|
| 330 | - public function getErrorDelimiter() { |
|
| 325 | + /** |
|
| 326 | + * Get the each errors delimiters |
|
| 327 | + * |
|
| 328 | + * @return array |
|
| 329 | + */ |
|
| 330 | + public function getErrorDelimiter() { |
|
| 331 | 331 | return $this->_eachErrorDelimiter; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - /** |
|
| 335 | - * Get the all errors delimiters |
|
| 336 | - * |
|
| 337 | - * @return array |
|
| 338 | - */ |
|
| 339 | - public function getErrorsDelimiter() { |
|
| 334 | + /** |
|
| 335 | + * Get the all errors delimiters |
|
| 336 | + * |
|
| 337 | + * @return array |
|
| 338 | + */ |
|
| 339 | + public function getErrorsDelimiter() { |
|
| 340 | 340 | return $this->_allErrorsDelimiter; |
| 341 | 341 | } |
| 342 | 342 | |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | * |
| 375 | 375 | * @param string $inputName The form input name or data key |
| 376 | 376 | * @param string $errorMessage Error to display |
| 377 | - * |
|
| 377 | + * |
|
| 378 | 378 | * @return formValidation Current instance of the object |
| 379 | 379 | */ |
| 380 | 380 | public function setCustomError($inputName, $errorMessage) { |
@@ -411,17 +411,17 @@ discard block |
||
| 411 | 411 | * |
| 412 | 412 | * @param boolean $limit number of error to display or return |
| 413 | 413 | * @param boolean $echo Whether or not the values are to be returned or displayed |
| 414 | - * |
|
| 414 | + * |
|
| 415 | 415 | * @return string Errors formatted for output |
| 416 | 416 | */ |
| 417 | 417 | public function displayErrors($limit = null, $echo = true) { |
| 418 | 418 | list($errorsStart, $errorsEnd) = $this->_allErrorsDelimiter; |
| 419 | 419 | list($errorStart, $errorEnd) = $this->_eachErrorDelimiter; |
| 420 | 420 | $errorOutput = $errorsStart; |
| 421 | - $i = 0; |
|
| 421 | + $i = 0; |
|
| 422 | 422 | if (!empty($this->_errors)) { |
| 423 | 423 | foreach ($this->_errors as $fieldName => $error) { |
| 424 | - if ($i === $limit) { |
|
| 424 | + if ($i === $limit) { |
|
| 425 | 425 | break; |
| 426 | 426 | } |
| 427 | 427 | $errorOutput .= $errorStart; |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | * Breaks up a PIPE seperated string of rules, and puts them into an array. |
| 450 | 450 | * |
| 451 | 451 | * @param string $ruleString String to be parsed. |
| 452 | - * |
|
| 452 | + * |
|
| 453 | 453 | * @return array Array of each value in original string. |
| 454 | 454 | */ |
| 455 | 455 | protected function _parseRuleString($ruleString) { |
@@ -462,10 +462,10 @@ discard block |
||
| 462 | 462 | $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#'; |
| 463 | 463 | preg_match($rule, $ruleString, $regexRule); |
| 464 | 464 | $ruleStringTemp = preg_replace($rule, '', $ruleString); |
| 465 | - if(!empty($regexRule[0])){ |
|
| 466 | - $ruleSets[] = $regexRule[0]; |
|
| 467 | - } |
|
| 468 | - $ruleStringRegex = explode('|', $ruleStringTemp); |
|
| 465 | + if(!empty($regexRule[0])){ |
|
| 466 | + $ruleSets[] = $regexRule[0]; |
|
| 467 | + } |
|
| 468 | + $ruleStringRegex = explode('|', $ruleStringTemp); |
|
| 469 | 469 | foreach ($ruleStringRegex as $rule) { |
| 470 | 470 | $rule = trim($rule); |
| 471 | 471 | if($rule){ |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | } else { |
| 482 | 482 | $ruleSets[] = $ruleString; |
| 483 | 483 | } |
| 484 | - } |
|
| 484 | + } |
|
| 485 | 485 | return $ruleSets; |
| 486 | 486 | } |
| 487 | 487 | |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | * Returns whether or not a field obtains the rule "required". |
| 490 | 490 | * |
| 491 | 491 | * @param string $fieldName Field to check if required. |
| 492 | - * |
|
| 492 | + * |
|
| 493 | 493 | * @return boolean Whether or not the field is required. |
| 494 | 494 | */ |
| 495 | 495 | protected function _fieldIsRequired($fieldName) { |
@@ -524,13 +524,13 @@ discard block |
||
| 524 | 524 | return; |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | - /** |
|
| 528 | - * Set error for the given field or key |
|
| 529 | - * |
|
| 530 | - * @param string $inputName the input or key name |
|
| 531 | - * @param string $ruleName the rule name |
|
| 532 | - * @param array|string $replacements |
|
| 533 | - */ |
|
| 527 | + /** |
|
| 528 | + * Set error for the given field or key |
|
| 529 | + * |
|
| 530 | + * @param string $inputName the input or key name |
|
| 531 | + * @param string $ruleName the rule name |
|
| 532 | + * @param array|string $replacements |
|
| 533 | + */ |
|
| 534 | 534 | protected function _setError($inputName, $ruleName, $replacements = array()) { |
| 535 | 535 | $rulePhraseKeyParts = explode(',', $ruleName); |
| 536 | 536 | $rulePhrase = null; |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | } |
| 548 | 548 | // Type cast to array in case it's a string |
| 549 | 549 | $replacements = (array) $replacements; |
| 550 | - $replacementCount = count($replacements); |
|
| 550 | + $replacementCount = count($replacements); |
|
| 551 | 551 | for ($i = 1; $i <= $replacementCount; $i++) { |
| 552 | 552 | $key = $i - 1; |
| 553 | 553 | $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase); |
@@ -565,11 +565,11 @@ discard block |
||
| 565 | 565 | * |
| 566 | 566 | * @param type $inputArg |
| 567 | 567 | * @param string $callbackFunc |
| 568 | - * |
|
| 568 | + * |
|
| 569 | 569 | * @return mixed |
| 570 | 570 | */ |
| 571 | 571 | protected function _runCallback($inputArg, $callbackFunc) { |
| 572 | - return eval('return ' . $callbackFunc . '("' . $inputArg . '");'); |
|
| 572 | + return eval('return ' . $callbackFunc . '("' . $inputArg . '");'); |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
@@ -578,7 +578,7 @@ discard block |
||
| 578 | 578 | * arguments. |
| 579 | 579 | * |
| 580 | 580 | * @param string $callbackFunc |
| 581 | - * |
|
| 581 | + * |
|
| 582 | 582 | * @return mixed |
| 583 | 583 | */ |
| 584 | 584 | protected function _runEmptyCallback($callbackFunc) { |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | * Gets a specific label of a specific field input name. |
| 590 | 590 | * |
| 591 | 591 | * @param string $inputName |
| 592 | - * |
|
| 592 | + * |
|
| 593 | 593 | * @return string |
| 594 | 594 | */ |
| 595 | 595 | protected function _getLabel($inputName) { |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | * @param string $ruleName the rule name for this validation ("required") |
| 603 | 603 | * @param array $ruleArgs the rules argument |
| 604 | 604 | */ |
| 605 | - protected function _validateRequired($inputName, $ruleName, array $ruleArgs) { |
|
| 605 | + protected function _validateRequired($inputName, $ruleName, array $ruleArgs) { |
|
| 606 | 606 | $inputVal = $this->post($inputName); |
| 607 | 607 | if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) { |
| 608 | 608 | $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]); |
@@ -610,8 +610,8 @@ discard block |
||
| 610 | 610 | $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
| 611 | 611 | } |
| 612 | 612 | } |
| 613 | - else if($inputVal == '') { |
|
| 614 | - $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
|
| 613 | + else if($inputVal == '') { |
|
| 614 | + $this->_setError($inputName, $ruleName, $this->_getLabel($inputName)); |
|
| 615 | 615 | } |
| 616 | 616 | } |
| 617 | 617 | |
@@ -635,10 +635,10 @@ discard block |
||
| 635 | 635 | */ |
| 636 | 636 | protected function _validateCallback($inputName, $ruleName, array $ruleArgs) { |
| 637 | 637 | if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) { |
| 638 | - $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]); |
|
| 639 | - if(! $result){ |
|
| 640 | - $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
|
| 641 | - } |
|
| 638 | + $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]); |
|
| 639 | + if(! $result){ |
|
| 640 | + $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName))); |
|
| 641 | + } |
|
| 642 | 642 | } |
| 643 | 643 | } |
| 644 | 644 | |
@@ -670,7 +670,7 @@ discard block |
||
| 670 | 670 | continue; |
| 671 | 671 | } |
| 672 | 672 | } |
| 673 | - else{ |
|
| 673 | + else{ |
|
| 674 | 674 | if ($inputVal == $doNotEqual) { |
| 675 | 675 | $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual)); |
| 676 | 676 | continue; |
@@ -762,7 +762,7 @@ discard block |
||
| 762 | 762 | * @param string $ruleName the rule name for this validation ("less_than") |
| 763 | 763 | * @param array $ruleArgs the rules argument |
| 764 | 764 | */ |
| 765 | - protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) { |
|
| 765 | + protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) { |
|
| 766 | 766 | $inputVal = $this->post($inputName); |
| 767 | 767 | if ($inputVal >= $ruleArgs[1]) { |
| 768 | 768 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
@@ -778,7 +778,7 @@ discard block |
||
| 778 | 778 | * @param string $ruleName the rule name for this validation ("greater_than") |
| 779 | 779 | * @param array $ruleArgs the rules argument |
| 780 | 780 | */ |
| 781 | - protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) { |
|
| 781 | + protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) { |
|
| 782 | 782 | $inputVal = $this->post($inputName); |
| 783 | 783 | if ($inputVal <= $ruleArgs[1]) { |
| 784 | 784 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
@@ -794,7 +794,7 @@ discard block |
||
| 794 | 794 | * @param string $ruleName the rule name for this validation ("numeric") |
| 795 | 795 | * @param array $ruleArgs the rules argument |
| 796 | 796 | */ |
| 797 | - protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) { |
|
| 797 | + protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) { |
|
| 798 | 798 | $inputVal = $this->post($inputName); |
| 799 | 799 | if (! is_numeric($inputVal)) { |
| 800 | 800 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
@@ -810,17 +810,17 @@ discard block |
||
| 810 | 810 | * @param string $ruleName the rule name for this validation ("exists") |
| 811 | 811 | * @param array $ruleArgs the rules argument |
| 812 | 812 | */ |
| 813 | - protected function _validateExists($inputName, $ruleName, array $ruleArgs) { |
|
| 813 | + protected function _validateExists($inputName, $ruleName, array $ruleArgs) { |
|
| 814 | 814 | $inputVal = $this->post($inputName); |
| 815 | - $obj = & get_instance(); |
|
| 816 | - if(! isset($obj->database)){ |
|
| 817 | - return; |
|
| 818 | - } |
|
| 819 | - list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 820 | - $obj->database->from($table) |
|
| 821 | - ->where($column, $inputVal) |
|
| 822 | - ->get(); |
|
| 823 | - $nb = $obj->database->numRows(); |
|
| 815 | + $obj = & get_instance(); |
|
| 816 | + if(! isset($obj->database)){ |
|
| 817 | + return; |
|
| 818 | + } |
|
| 819 | + list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 820 | + $obj->database->from($table) |
|
| 821 | + ->where($column, $inputVal) |
|
| 822 | + ->get(); |
|
| 823 | + $nb = $obj->database->numRows(); |
|
| 824 | 824 | if ($nb == 0) { |
| 825 | 825 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
| 826 | 826 | return; |
@@ -835,17 +835,17 @@ discard block |
||
| 835 | 835 | * @param string $ruleName the rule name for this validation ("is_unique") |
| 836 | 836 | * @param array $ruleArgs the rules argument |
| 837 | 837 | */ |
| 838 | - protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) { |
|
| 838 | + protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) { |
|
| 839 | 839 | $inputVal = $this->post($inputName); |
| 840 | - $obj = & get_instance(); |
|
| 841 | - if(! isset($obj->database)){ |
|
| 842 | - return; |
|
| 843 | - } |
|
| 844 | - list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 845 | - $obj->database->from($table) |
|
| 846 | - ->where($column, $inputVal) |
|
| 847 | - ->get(); |
|
| 848 | - $nb = $obj->database->numRows(); |
|
| 840 | + $obj = & get_instance(); |
|
| 841 | + if(! isset($obj->database)){ |
|
| 842 | + return; |
|
| 843 | + } |
|
| 844 | + list($table, $column) = explode('.', $ruleArgs[1]); |
|
| 845 | + $obj->database->from($table) |
|
| 846 | + ->where($column, $inputVal) |
|
| 847 | + ->get(); |
|
| 848 | + $nb = $obj->database->numRows(); |
|
| 849 | 849 | if ($nb != 0) { |
| 850 | 850 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
| 851 | 851 | return; |
@@ -860,23 +860,23 @@ discard block |
||
| 860 | 860 | * @param string $ruleName the rule name for this validation ("is_unique_update") |
| 861 | 861 | * @param array $ruleArgs the rules argument |
| 862 | 862 | */ |
| 863 | - protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) { |
|
| 863 | + protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) { |
|
| 864 | 864 | $inputVal = $this->post($inputName); |
| 865 | - $obj = & get_instance(); |
|
| 866 | - if(! isset($obj->database)){ |
|
| 867 | - return; |
|
| 868 | - } |
|
| 869 | - $data = explode(',', $ruleArgs[1]); |
|
| 870 | - if(count($data) < 2){ |
|
| 871 | - return; |
|
| 872 | - } |
|
| 873 | - list($table, $column) = explode('.', $data[0]); |
|
| 874 | - list($field, $val) = explode('=', $data[1]); |
|
| 875 | - $obj->database->from($table) |
|
| 876 | - ->where($column, $inputVal) |
|
| 877 | - ->where($field, '!=', trim($val)) |
|
| 878 | - ->get(); |
|
| 879 | - $nb = $obj->database->numRows(); |
|
| 865 | + $obj = & get_instance(); |
|
| 866 | + if(! isset($obj->database)){ |
|
| 867 | + return; |
|
| 868 | + } |
|
| 869 | + $data = explode(',', $ruleArgs[1]); |
|
| 870 | + if(count($data) < 2){ |
|
| 871 | + return; |
|
| 872 | + } |
|
| 873 | + list($table, $column) = explode('.', $data[0]); |
|
| 874 | + list($field, $val) = explode('=', $data[1]); |
|
| 875 | + $obj->database->from($table) |
|
| 876 | + ->where($column, $inputVal) |
|
| 877 | + ->where($field, '!=', trim($val)) |
|
| 878 | + ->get(); |
|
| 879 | + $nb = $obj->database->numRows(); |
|
| 880 | 880 | if ($nb != 0) { |
| 881 | 881 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
| 882 | 882 | return; |
@@ -893,7 +893,7 @@ discard block |
||
| 893 | 893 | */ |
| 894 | 894 | protected function _validateInList($inputName, $ruleName, array $ruleArgs) { |
| 895 | 895 | $inputVal = $this->post($inputName); |
| 896 | - $list = explode(',', $ruleArgs[1]); |
|
| 896 | + $list = explode(',', $ruleArgs[1]); |
|
| 897 | 897 | $list = array_map('trim', $list); |
| 898 | 898 | if (! in_array($inputVal, $list)) { |
| 899 | 899 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
@@ -911,7 +911,7 @@ discard block |
||
| 911 | 911 | */ |
| 912 | 912 | protected function _validateRegex($inputName, $ruleName, array $ruleArgs) { |
| 913 | 913 | $inputVal = $this->post($inputName); |
| 914 | - $regex = $ruleArgs[1]; |
|
| 914 | + $regex = $ruleArgs[1]; |
|
| 915 | 915 | if (! preg_match($regex, $inputVal)) { |
| 916 | 916 | if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) { |
| 917 | 917 | return; |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | private static $config = null; |
| 15 | 15 | |
| 16 | - public function __construct(){ |
|
| 16 | + public function __construct() { |
|
| 17 | 17 | $this->db = new Database(array( |
| 18 | 18 | 'driver' => 'sqlite', |
| 19 | 19 | 'database' => TESTS_PATH . 'assets/db_tests.db', |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | |
| 51 | 51 | |
| 52 | - public function testUsingSessionConfiguration(){ |
|
| 52 | + public function testUsingSessionConfiguration() { |
|
| 53 | 53 | //using value in the configuration |
| 54 | 54 | self::$config->set('session_save_path', 'DBSessionModel'); |
| 55 | 55 | self::$config->set('session_secret', $this->secret); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | $this->assertEquals($dbsh->decode($encoded), 'foo'); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - public function testWhenDataIsExpired(){ |
|
| 78 | + public function testWhenDataIsExpired() { |
|
| 79 | 79 | $dbsh = new DBSessionHandler($this->model); |
| 80 | 80 | $dbsh->setSessionSecret($this->secret); |
| 81 | 81 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | $this->assertNull($dbsh->read('foo')); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - public function testWhenDataAlreadyExistDoUpdate(){ |
|
| 91 | + public function testWhenDataAlreadyExistDoUpdate() { |
|
| 92 | 92 | $dbsh = new DBSessionHandler($this->model); |
| 93 | 93 | $dbsh->setSessionSecret($this->secret); |
| 94 | 94 | |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | $this->assertEquals($dbsh->read('foo'), '445'); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - public function testUsingCustomModelInstance(){ |
|
| 104 | + public function testUsingCustomModelInstance() { |
|
| 105 | 105 | $dbsh = new DBSessionHandler($this->model); |
| 106 | 106 | $dbsh->setSessionSecret($this->secret); |
| 107 | 107 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | |
| 132 | - public function testUsingCustomLogInstance(){ |
|
| 132 | + public function testUsingCustomLogInstance() { |
|
| 133 | 133 | $dbsh = new DBSessionHandler($this->model, new Log()); |
| 134 | 134 | $dbsh->setSessionSecret($this->secret); |
| 135 | 135 | |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | $this->assertEquals($dbsh->decode($encoded), 'foo'); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - public function testUsingCustomLoaderInstance(){ |
|
| 159 | + public function testUsingCustomLoaderInstance() { |
|
| 160 | 160 | $dbsh = new DBSessionHandler($this->model, null, new Loader()); |
| 161 | 161 | $dbsh->setSessionSecret($this->secret); |
| 162 | 162 | |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | |
| 187 | - public function testWhenModelInsanceIsNotSet(){ |
|
| 187 | + public function testWhenModelInsanceIsNotSet() { |
|
| 188 | 188 | $dbsh = new DBSessionHandler(null, null, new Loader()); |
| 189 | 189 | $dbsh->setSessionSecret($this->secret); |
| 190 | 190 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | $this->assertEquals($dbsh->decode($encoded), 'foo'); |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - public function testWhenModelTableColumnsIsNotSet(){ |
|
| 215 | + public function testWhenModelTableColumnsIsNotSet() { |
|
| 216 | 216 | //session table is empty |
| 217 | 217 | $this->model->setSessionTableColumns(array()); |
| 218 | 218 | $dbsh = new DBSessionHandler($this->model); |
@@ -1,226 +1,226 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use PHPUnit\Framework\TestCase; |
|
| 3 | + use PHPUnit\Framework\TestCase; |
|
| 4 | 4 | |
| 5 | - class DBSessionHandlerTest extends TestCase |
|
| 6 | - { |
|
| 5 | + class DBSessionHandlerTest extends TestCase |
|
| 6 | + { |
|
| 7 | 7 | |
| 8 | - private $db = null; |
|
| 8 | + private $db = null; |
|
| 9 | 9 | |
| 10 | - private $model = null; |
|
| 10 | + private $model = null; |
|
| 11 | 11 | |
| 12 | - private $secret = 'bXlzZWNyZXQ'; |
|
| 12 | + private $secret = 'bXlzZWNyZXQ'; |
|
| 13 | 13 | |
| 14 | - private static $config = null; |
|
| 14 | + private static $config = null; |
|
| 15 | 15 | |
| 16 | - public function __construct(){ |
|
| 17 | - $this->db = new Database(array( |
|
| 18 | - 'driver' => 'sqlite', |
|
| 19 | - 'database' => TESTS_PATH . 'assets/db_tests.db', |
|
| 20 | - 'charset' => 'utf8', |
|
| 21 | - 'collation' => 'utf8_general_ci', |
|
| 22 | - )); |
|
| 16 | + public function __construct(){ |
|
| 17 | + $this->db = new Database(array( |
|
| 18 | + 'driver' => 'sqlite', |
|
| 19 | + 'database' => TESTS_PATH . 'assets/db_tests.db', |
|
| 20 | + 'charset' => 'utf8', |
|
| 21 | + 'collation' => 'utf8_general_ci', |
|
| 22 | + )); |
|
| 23 | 23 | $qr = new DatabaseQueryRunner($this->db->getPdo()); |
| 24 | 24 | $qr->setBenchmark(new Benchmark()); |
| 25 | 25 | $qr->setDriver('sqlite'); |
| 26 | 26 | $this->db->setQueryRunner($qr); |
| 27 | - } |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public static function setUpBeforeClass() |
|
| 30 | - { |
|
| 31 | - require APPS_MODEL_PATH . 'DBSessionModel.php'; |
|
| 32 | - self::$config = new Config(); |
|
| 33 | - self::$config->init(); |
|
| 34 | - } |
|
| 29 | + public static function setUpBeforeClass() |
|
| 30 | + { |
|
| 31 | + require APPS_MODEL_PATH . 'DBSessionModel.php'; |
|
| 32 | + self::$config = new Config(); |
|
| 33 | + self::$config->init(); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | |
| 37 | - public static function tearDownAfterClass() |
|
| 38 | - { |
|
| 37 | + public static function tearDownAfterClass() |
|
| 38 | + { |
|
| 39 | 39 | |
| 40 | - } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - protected function setUp() |
|
| 43 | - { |
|
| 44 | - $this->model = new DBSessionModel($this->db); |
|
| 42 | + protected function setUp() |
|
| 43 | + { |
|
| 44 | + $this->model = new DBSessionModel($this->db); |
|
| 45 | 45 | //to prevent old data conflict |
| 46 | - $this->model->truncate(); |
|
| 47 | - } |
|
| 46 | + $this->model->truncate(); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - protected function tearDown() |
|
| 50 | - { |
|
| 51 | - } |
|
| 49 | + protected function tearDown() |
|
| 50 | + { |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | 54 | |
| 55 | - public function testUsingSessionConfiguration(){ |
|
| 56 | - //using value in the configuration |
|
| 57 | - self::$config->set('session_save_path', 'DBSessionModel'); |
|
| 58 | - self::$config->set('session_secret', $this->secret); |
|
| 59 | - $dbsh = new DBSessionHandler(); |
|
| 60 | - //assign Database instance manually |
|
| 61 | - $o = &get_instance(); |
|
| 62 | - $o->database = $this->db; |
|
| 63 | - |
|
| 64 | - $this->assertTrue($dbsh->open(null, null)); |
|
| 65 | - $this->assertTrue($dbsh->close()); |
|
| 66 | - $this->assertNull($dbsh->read('foo')); |
|
| 67 | - $this->assertTrue($dbsh->write('foo', '444')); |
|
| 68 | - $this->assertNotEmpty($dbsh->read('foo')); |
|
| 69 | - $this->assertEquals($dbsh->read('foo'), '444'); |
|
| 70 | - //do update of existing data |
|
| 71 | - $this->assertTrue($dbsh->write('foo', '445')); |
|
| 72 | - $this->assertEquals($dbsh->read('foo'), '445'); |
|
| 73 | - $this->assertTrue($dbsh->destroy('foo')); |
|
| 74 | - $this->assertNull($dbsh->read('foo')); |
|
| 75 | - $this->assertTrue($dbsh->gc(13)); |
|
| 76 | - $encoded = $dbsh->encode('foo'); |
|
| 77 | - $this->assertNotEmpty($encoded); |
|
| 78 | - $this->assertEquals($dbsh->decode($encoded), 'foo'); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - public function testWhenDataIsExpired(){ |
|
| 82 | - $dbsh = new DBSessionHandler($this->model); |
|
| 83 | - $dbsh->setSessionSecret($this->secret); |
|
| 84 | - |
|
| 85 | - $this->assertTrue($dbsh->open(null, null)); |
|
| 86 | - $this->assertTrue($dbsh->write('foo', '444')); |
|
| 87 | - $this->assertNotEmpty($dbsh->read('foo')); |
|
| 88 | - $this->assertEquals($dbsh->read('foo'), '444'); |
|
| 89 | - //put it in expired |
|
| 90 | - $this->model->update('foo', array('s_time' => 1234567)); |
|
| 91 | - $this->assertNull($dbsh->read('foo')); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - public function testWhenDataAlreadyExistDoUpdate(){ |
|
| 95 | - $dbsh = new DBSessionHandler($this->model); |
|
| 96 | - $dbsh->setSessionSecret($this->secret); |
|
| 97 | - |
|
| 98 | - $this->assertTrue($dbsh->open(null, null)); |
|
| 99 | - $this->assertTrue($dbsh->write('foo', '444')); |
|
| 100 | - $this->assertNotEmpty($dbsh->read('foo')); |
|
| 101 | - $this->assertEquals($dbsh->read('foo'), '444'); |
|
| 102 | - //do update of existing data |
|
| 103 | - $this->assertTrue($dbsh->write('foo', '445')); |
|
| 104 | - $this->assertEquals($dbsh->read('foo'), '445'); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - public function testUsingCustomModelInstance(){ |
|
| 108 | - $dbsh = new DBSessionHandler($this->model); |
|
| 109 | - $dbsh->setSessionSecret($this->secret); |
|
| 110 | - |
|
| 111 | - $this->assertTrue($dbsh->open(null, null)); |
|
| 112 | - $this->assertTrue($dbsh->close()); |
|
| 113 | - $this->assertNull($dbsh->read('foo')); |
|
| 114 | - $this->assertTrue($dbsh->write('foo', '444')); |
|
| 115 | - $this->assertNotEmpty($dbsh->read('foo')); |
|
| 116 | - $this->assertEquals($dbsh->read('foo'), '444'); |
|
| 117 | - //put it in expired |
|
| 118 | - $this->model->update('foo', array('s_time' => 1234567)); |
|
| 119 | - |
|
| 120 | - $this->assertNull($dbsh->read('foo')); |
|
| 121 | - $this->assertTrue($dbsh->write('foo', '444')); |
|
| 122 | - |
|
| 123 | - //do update of existing data |
|
| 124 | - $this->assertTrue($dbsh->write('foo', '445')); |
|
| 125 | - $this->assertEquals($dbsh->read('foo'), '445'); |
|
| 126 | - $this->assertTrue($dbsh->destroy('foo')); |
|
| 127 | - $this->assertNull($dbsh->read('foo')); |
|
| 128 | - $this->assertTrue($dbsh->gc(13)); |
|
| 129 | - $encoded = $dbsh->encode('foo'); |
|
| 130 | - $this->assertNotEmpty($encoded); |
|
| 131 | - $this->assertEquals($dbsh->decode($encoded), 'foo'); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - public function testUsingCustomLogInstance(){ |
|
| 136 | - $dbsh = new DBSessionHandler($this->model, new Log()); |
|
| 137 | - $dbsh->setSessionSecret($this->secret); |
|
| 138 | - |
|
| 139 | - $this->assertTrue($dbsh->open(null, null)); |
|
| 140 | - $this->assertTrue($dbsh->close()); |
|
| 141 | - $this->assertNull($dbsh->read('foo')); |
|
| 142 | - $this->assertTrue($dbsh->write('foo', '444')); |
|
| 143 | - $this->assertNotEmpty($dbsh->read('foo')); |
|
| 144 | - $this->assertEquals($dbsh->read('foo'), '444'); |
|
| 145 | - //put it in expired |
|
| 146 | - $this->model->update('foo', array('s_time' => 1234567)); |
|
| 147 | - |
|
| 148 | - $this->assertNull($dbsh->read('foo')); |
|
| 149 | - $this->assertTrue($dbsh->write('foo', '444')); |
|
| 150 | - |
|
| 151 | - //do update of existing data |
|
| 152 | - $this->assertTrue($dbsh->write('foo', '445')); |
|
| 153 | - $this->assertEquals($dbsh->read('foo'), '445'); |
|
| 154 | - $this->assertTrue($dbsh->destroy('foo')); |
|
| 155 | - $this->assertNull($dbsh->read('foo')); |
|
| 156 | - $this->assertTrue($dbsh->gc(13)); |
|
| 157 | - $encoded = $dbsh->encode('foo'); |
|
| 158 | - $this->assertNotEmpty($encoded); |
|
| 159 | - $this->assertEquals($dbsh->decode($encoded), 'foo'); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - public function testUsingCustomLoaderInstance(){ |
|
| 163 | - $dbsh = new DBSessionHandler($this->model, null, new Loader()); |
|
| 164 | - $dbsh->setSessionSecret($this->secret); |
|
| 165 | - |
|
| 166 | - $this->assertTrue($dbsh->open(null, null)); |
|
| 167 | - $this->assertTrue($dbsh->close()); |
|
| 168 | - $this->assertNull($dbsh->read('foo')); |
|
| 169 | - $this->assertTrue($dbsh->write('foo', '444')); |
|
| 170 | - $this->assertNotEmpty($dbsh->read('foo')); |
|
| 171 | - $this->assertEquals($dbsh->read('foo'), '444'); |
|
| 172 | - //put it in expired |
|
| 173 | - $this->model->update('foo', array('s_time' => 1234567)); |
|
| 174 | - |
|
| 175 | - $this->assertNull($dbsh->read('foo')); |
|
| 176 | - $this->assertTrue($dbsh->write('foo', '444')); |
|
| 177 | - |
|
| 178 | - //do update of existing data |
|
| 179 | - $this->assertTrue($dbsh->write('foo', '445')); |
|
| 180 | - $this->assertEquals($dbsh->read('foo'), '445'); |
|
| 181 | - $this->assertTrue($dbsh->destroy('foo')); |
|
| 182 | - $this->assertNull($dbsh->read('foo')); |
|
| 183 | - $this->assertTrue($dbsh->gc(13)); |
|
| 184 | - $encoded = $dbsh->encode('foo'); |
|
| 185 | - $this->assertNotEmpty($encoded); |
|
| 186 | - $this->assertEquals($dbsh->decode($encoded), 'foo'); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - public function testWhenModelInsanceIsNotSet(){ |
|
| 191 | - $dbsh = new DBSessionHandler(null, null, new Loader()); |
|
| 192 | - $dbsh->setSessionSecret($this->secret); |
|
| 193 | - |
|
| 194 | - $this->assertTrue($dbsh->open(null, null)); |
|
| 195 | - $this->assertTrue($dbsh->close()); |
|
| 196 | - $this->assertNull($dbsh->read('foo')); |
|
| 197 | - $this->assertTrue($dbsh->write('foo', '444')); |
|
| 198 | - $this->assertNotEmpty($dbsh->read('foo')); |
|
| 199 | - $this->assertEquals($dbsh->read('foo'), '444'); |
|
| 200 | - //put it in expired |
|
| 201 | - $this->model->update('foo', array('s_time' => 1234567)); |
|
| 202 | - |
|
| 203 | - $this->assertNull($dbsh->read('foo')); |
|
| 204 | - $this->assertTrue($dbsh->write('foo', '444')); |
|
| 205 | - |
|
| 206 | - //do update of existing data |
|
| 207 | - $this->assertTrue($dbsh->write('tnh', '445')); |
|
| 208 | - $this->assertTrue($dbsh->write('foo', '445')); |
|
| 209 | - $this->assertEquals($dbsh->read('foo'), '445'); |
|
| 210 | - $this->assertTrue($dbsh->destroy('foo')); |
|
| 211 | - $this->assertNull($dbsh->read('foo')); |
|
| 212 | - $this->assertTrue($dbsh->gc(13)); |
|
| 213 | - $encoded = $dbsh->encode('foo'); |
|
| 214 | - $this->assertNotEmpty($encoded); |
|
| 215 | - $this->assertEquals($dbsh->decode($encoded), 'foo'); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - public function testWhenModelTableColumnsIsNotSet(){ |
|
| 219 | - //session table is empty |
|
| 220 | - $this->model->setSessionTableColumns(array()); |
|
| 221 | - $dbsh = new DBSessionHandler($this->model); |
|
| 222 | - $this->assertTrue($dbsh->open(null, null)); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - } |
|
| 227 | 55 | \ No newline at end of file |
| 56 | + public function testUsingSessionConfiguration(){ |
|
| 57 | + //using value in the configuration |
|
| 58 | + self::$config->set('session_save_path', 'DBSessionModel'); |
|
| 59 | + self::$config->set('session_secret', $this->secret); |
|
| 60 | + $dbsh = new DBSessionHandler(); |
|
| 61 | + //assign Database instance manually |
|
| 62 | + $o = &get_instance(); |
|
| 63 | + $o->database = $this->db; |
|
| 64 | + |
|
| 65 | + $this->assertTrue($dbsh->open(null, null)); |
|
| 66 | + $this->assertTrue($dbsh->close()); |
|
| 67 | + $this->assertNull($dbsh->read('foo')); |
|
| 68 | + $this->assertTrue($dbsh->write('foo', '444')); |
|
| 69 | + $this->assertNotEmpty($dbsh->read('foo')); |
|
| 70 | + $this->assertEquals($dbsh->read('foo'), '444'); |
|
| 71 | + //do update of existing data |
|
| 72 | + $this->assertTrue($dbsh->write('foo', '445')); |
|
| 73 | + $this->assertEquals($dbsh->read('foo'), '445'); |
|
| 74 | + $this->assertTrue($dbsh->destroy('foo')); |
|
| 75 | + $this->assertNull($dbsh->read('foo')); |
|
| 76 | + $this->assertTrue($dbsh->gc(13)); |
|
| 77 | + $encoded = $dbsh->encode('foo'); |
|
| 78 | + $this->assertNotEmpty($encoded); |
|
| 79 | + $this->assertEquals($dbsh->decode($encoded), 'foo'); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + public function testWhenDataIsExpired(){ |
|
| 83 | + $dbsh = new DBSessionHandler($this->model); |
|
| 84 | + $dbsh->setSessionSecret($this->secret); |
|
| 85 | + |
|
| 86 | + $this->assertTrue($dbsh->open(null, null)); |
|
| 87 | + $this->assertTrue($dbsh->write('foo', '444')); |
|
| 88 | + $this->assertNotEmpty($dbsh->read('foo')); |
|
| 89 | + $this->assertEquals($dbsh->read('foo'), '444'); |
|
| 90 | + //put it in expired |
|
| 91 | + $this->model->update('foo', array('s_time' => 1234567)); |
|
| 92 | + $this->assertNull($dbsh->read('foo')); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + public function testWhenDataAlreadyExistDoUpdate(){ |
|
| 96 | + $dbsh = new DBSessionHandler($this->model); |
|
| 97 | + $dbsh->setSessionSecret($this->secret); |
|
| 98 | + |
|
| 99 | + $this->assertTrue($dbsh->open(null, null)); |
|
| 100 | + $this->assertTrue($dbsh->write('foo', '444')); |
|
| 101 | + $this->assertNotEmpty($dbsh->read('foo')); |
|
| 102 | + $this->assertEquals($dbsh->read('foo'), '444'); |
|
| 103 | + //do update of existing data |
|
| 104 | + $this->assertTrue($dbsh->write('foo', '445')); |
|
| 105 | + $this->assertEquals($dbsh->read('foo'), '445'); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + public function testUsingCustomModelInstance(){ |
|
| 109 | + $dbsh = new DBSessionHandler($this->model); |
|
| 110 | + $dbsh->setSessionSecret($this->secret); |
|
| 111 | + |
|
| 112 | + $this->assertTrue($dbsh->open(null, null)); |
|
| 113 | + $this->assertTrue($dbsh->close()); |
|
| 114 | + $this->assertNull($dbsh->read('foo')); |
|
| 115 | + $this->assertTrue($dbsh->write('foo', '444')); |
|
| 116 | + $this->assertNotEmpty($dbsh->read('foo')); |
|
| 117 | + $this->assertEquals($dbsh->read('foo'), '444'); |
|
| 118 | + //put it in expired |
|
| 119 | + $this->model->update('foo', array('s_time' => 1234567)); |
|
| 120 | + |
|
| 121 | + $this->assertNull($dbsh->read('foo')); |
|
| 122 | + $this->assertTrue($dbsh->write('foo', '444')); |
|
| 123 | + |
|
| 124 | + //do update of existing data |
|
| 125 | + $this->assertTrue($dbsh->write('foo', '445')); |
|
| 126 | + $this->assertEquals($dbsh->read('foo'), '445'); |
|
| 127 | + $this->assertTrue($dbsh->destroy('foo')); |
|
| 128 | + $this->assertNull($dbsh->read('foo')); |
|
| 129 | + $this->assertTrue($dbsh->gc(13)); |
|
| 130 | + $encoded = $dbsh->encode('foo'); |
|
| 131 | + $this->assertNotEmpty($encoded); |
|
| 132 | + $this->assertEquals($dbsh->decode($encoded), 'foo'); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + public function testUsingCustomLogInstance(){ |
|
| 137 | + $dbsh = new DBSessionHandler($this->model, new Log()); |
|
| 138 | + $dbsh->setSessionSecret($this->secret); |
|
| 139 | + |
|
| 140 | + $this->assertTrue($dbsh->open(null, null)); |
|
| 141 | + $this->assertTrue($dbsh->close()); |
|
| 142 | + $this->assertNull($dbsh->read('foo')); |
|
| 143 | + $this->assertTrue($dbsh->write('foo', '444')); |
|
| 144 | + $this->assertNotEmpty($dbsh->read('foo')); |
|
| 145 | + $this->assertEquals($dbsh->read('foo'), '444'); |
|
| 146 | + //put it in expired |
|
| 147 | + $this->model->update('foo', array('s_time' => 1234567)); |
|
| 148 | + |
|
| 149 | + $this->assertNull($dbsh->read('foo')); |
|
| 150 | + $this->assertTrue($dbsh->write('foo', '444')); |
|
| 151 | + |
|
| 152 | + //do update of existing data |
|
| 153 | + $this->assertTrue($dbsh->write('foo', '445')); |
|
| 154 | + $this->assertEquals($dbsh->read('foo'), '445'); |
|
| 155 | + $this->assertTrue($dbsh->destroy('foo')); |
|
| 156 | + $this->assertNull($dbsh->read('foo')); |
|
| 157 | + $this->assertTrue($dbsh->gc(13)); |
|
| 158 | + $encoded = $dbsh->encode('foo'); |
|
| 159 | + $this->assertNotEmpty($encoded); |
|
| 160 | + $this->assertEquals($dbsh->decode($encoded), 'foo'); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + public function testUsingCustomLoaderInstance(){ |
|
| 164 | + $dbsh = new DBSessionHandler($this->model, null, new Loader()); |
|
| 165 | + $dbsh->setSessionSecret($this->secret); |
|
| 166 | + |
|
| 167 | + $this->assertTrue($dbsh->open(null, null)); |
|
| 168 | + $this->assertTrue($dbsh->close()); |
|
| 169 | + $this->assertNull($dbsh->read('foo')); |
|
| 170 | + $this->assertTrue($dbsh->write('foo', '444')); |
|
| 171 | + $this->assertNotEmpty($dbsh->read('foo')); |
|
| 172 | + $this->assertEquals($dbsh->read('foo'), '444'); |
|
| 173 | + //put it in expired |
|
| 174 | + $this->model->update('foo', array('s_time' => 1234567)); |
|
| 175 | + |
|
| 176 | + $this->assertNull($dbsh->read('foo')); |
|
| 177 | + $this->assertTrue($dbsh->write('foo', '444')); |
|
| 178 | + |
|
| 179 | + //do update of existing data |
|
| 180 | + $this->assertTrue($dbsh->write('foo', '445')); |
|
| 181 | + $this->assertEquals($dbsh->read('foo'), '445'); |
|
| 182 | + $this->assertTrue($dbsh->destroy('foo')); |
|
| 183 | + $this->assertNull($dbsh->read('foo')); |
|
| 184 | + $this->assertTrue($dbsh->gc(13)); |
|
| 185 | + $encoded = $dbsh->encode('foo'); |
|
| 186 | + $this->assertNotEmpty($encoded); |
|
| 187 | + $this->assertEquals($dbsh->decode($encoded), 'foo'); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + public function testWhenModelInsanceIsNotSet(){ |
|
| 192 | + $dbsh = new DBSessionHandler(null, null, new Loader()); |
|
| 193 | + $dbsh->setSessionSecret($this->secret); |
|
| 194 | + |
|
| 195 | + $this->assertTrue($dbsh->open(null, null)); |
|
| 196 | + $this->assertTrue($dbsh->close()); |
|
| 197 | + $this->assertNull($dbsh->read('foo')); |
|
| 198 | + $this->assertTrue($dbsh->write('foo', '444')); |
|
| 199 | + $this->assertNotEmpty($dbsh->read('foo')); |
|
| 200 | + $this->assertEquals($dbsh->read('foo'), '444'); |
|
| 201 | + //put it in expired |
|
| 202 | + $this->model->update('foo', array('s_time' => 1234567)); |
|
| 203 | + |
|
| 204 | + $this->assertNull($dbsh->read('foo')); |
|
| 205 | + $this->assertTrue($dbsh->write('foo', '444')); |
|
| 206 | + |
|
| 207 | + //do update of existing data |
|
| 208 | + $this->assertTrue($dbsh->write('tnh', '445')); |
|
| 209 | + $this->assertTrue($dbsh->write('foo', '445')); |
|
| 210 | + $this->assertEquals($dbsh->read('foo'), '445'); |
|
| 211 | + $this->assertTrue($dbsh->destroy('foo')); |
|
| 212 | + $this->assertNull($dbsh->read('foo')); |
|
| 213 | + $this->assertTrue($dbsh->gc(13)); |
|
| 214 | + $encoded = $dbsh->encode('foo'); |
|
| 215 | + $this->assertNotEmpty($encoded); |
|
| 216 | + $this->assertEquals($dbsh->decode($encoded), 'foo'); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + public function testWhenModelTableColumnsIsNotSet(){ |
|
| 220 | + //session table is empty |
|
| 221 | + $this->model->setSessionTableColumns(array()); |
|
| 222 | + $dbsh = new DBSessionHandler($this->model); |
|
| 223 | + $this->assertTrue($dbsh->open(null, null)); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + } |
|
| 228 | 228 | \ No newline at end of file |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | /** |
| 61 | 61 | * Custom application path for tests |
| 62 | 62 | */ |
| 63 | - define('APPS_PATH', TESTS_PATH .'hmvc' . DS); |
|
| 63 | + define('APPS_PATH', TESTS_PATH . 'hmvc' . DS); |
|
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * The path to the controller directory of your application. |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
| 197 | 197 | * in HMVC architecture (hierichical, controllers, models, views). |
| 198 | 198 | */ |
| 199 | - define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS); |
|
| 199 | + define('MODULE_PATH', dirname(realpath(__FILE__)) . DS . 'hmvc' . DS . 'modules' . DS); |
|
| 200 | 200 | |
| 201 | 201 | /** |
| 202 | 202 | * The path to the directory of sources external to your application. |
@@ -235,12 +235,12 @@ discard block |
||
| 235 | 235 | //Fix to allow test as if application is running in CLI mode $_SESSION global variable is not available |
| 236 | 236 | $_SESSION = array(); |
| 237 | 237 | |
| 238 | - if(! isset($_SERVER['REMOTE_ADDR'])){ |
|
| 238 | + if (!isset($_SERVER['REMOTE_ADDR'])) { |
|
| 239 | 239 | $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | //check for composer autoload file if exists include it |
| 243 | - if (file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 243 | + if (file_exists(VENDOR_PATH . 'autoload.php')) { |
|
| 244 | 244 | require_once VENDOR_PATH . 'autoload.php'; |
| 245 | 245 | |
| 246 | 246 | //define the class alias for vstream |
@@ -1,292 +1,292 @@ |
||
| 1 | 1 | <?php |
| 2 | - /** |
|
| 3 | - * TNH Framework |
|
| 4 | - * |
|
| 5 | - * A simple PHP framework using HMVC architecture |
|
| 6 | - * |
|
| 7 | - * This content is released under the GNU GPL License (GPL) |
|
| 8 | - * |
|
| 9 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 10 | - * |
|
| 11 | - * This program is free software; you can redistribute it and/or |
|
| 12 | - * modify it under the terms of the GNU General Public License |
|
| 13 | - * as published by the Free Software Foundation; either version 3 |
|
| 14 | - * of the License, or (at your option) any later version. |
|
| 15 | - * |
|
| 16 | - * This program is distributed in the hope that it will be useful, |
|
| 17 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 18 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 19 | - * GNU General Public License for more details. |
|
| 20 | - * |
|
| 21 | - * You should have received a copy of the GNU General Public License |
|
| 22 | - * along with this program; if not, write to the Free Software |
|
| 23 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 24 | - */ |
|
| 2 | + /** |
|
| 3 | + * TNH Framework |
|
| 4 | + * |
|
| 5 | + * A simple PHP framework using HMVC architecture |
|
| 6 | + * |
|
| 7 | + * This content is released under the GNU GPL License (GPL) |
|
| 8 | + * |
|
| 9 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 10 | + * |
|
| 11 | + * This program is free software; you can redistribute it and/or |
|
| 12 | + * modify it under the terms of the GNU General Public License |
|
| 13 | + * as published by the Free Software Foundation; either version 3 |
|
| 14 | + * of the License, or (at your option) any later version. |
|
| 15 | + * |
|
| 16 | + * This program is distributed in the hope that it will be useful, |
|
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 19 | + * GNU General Public License for more details. |
|
| 20 | + * |
|
| 21 | + * You should have received a copy of the GNU General Public License |
|
| 22 | + * along with this program; if not, write to the Free Software |
|
| 23 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 24 | + */ |
|
| 25 | 25 | |
| 26 | - error_reporting(E_ALL | E_STRICT); |
|
| 27 | - ini_set('display_errors', 1); |
|
| 26 | + error_reporting(E_ALL | E_STRICT); |
|
| 27 | + ini_set('display_errors', 1); |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * the directory separator, under windows it is \ and unix, linux / |
|
| 31 | - */ |
|
| 32 | - define('DS', DIRECTORY_SEPARATOR); |
|
| 29 | + /** |
|
| 30 | + * the directory separator, under windows it is \ and unix, linux / |
|
| 31 | + */ |
|
| 32 | + define('DS', DIRECTORY_SEPARATOR); |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * The root directory of the application. |
|
| 36 | - * |
|
| 37 | - * you can place this directory outside of your web directory, for example "/home/your_app", etc. |
|
| 38 | - */ |
|
| 39 | - define('ROOT_PATH', dirname(realpath(__FILE__)) . DS . '..' . DS); |
|
| 34 | + /** |
|
| 35 | + * The root directory of the application. |
|
| 36 | + * |
|
| 37 | + * you can place this directory outside of your web directory, for example "/home/your_app", etc. |
|
| 38 | + */ |
|
| 39 | + define('ROOT_PATH', dirname(realpath(__FILE__)) . DS . '..' . DS); |
|
| 40 | 40 | |
| 41 | - //tests dir path |
|
| 42 | - define('TESTS_PATH', dirname(realpath(__FILE__)) . DS); |
|
| 41 | + //tests dir path |
|
| 42 | + define('TESTS_PATH', dirname(realpath(__FILE__)) . DS); |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * The path to the directory. |
|
| 47 | - * |
|
| 48 | - * That contains your static files (javascript, css, images, etc.) |
|
| 49 | - * Note: the path must be relative to the file index.php (the front-end controller). |
|
| 50 | - */ |
|
| 51 | - define('ASSETS_PATH', 'assets/'); |
|
| 45 | + /** |
|
| 46 | + * The path to the directory. |
|
| 47 | + * |
|
| 48 | + * That contains your static files (javascript, css, images, etc.) |
|
| 49 | + * Note: the path must be relative to the file index.php (the front-end controller). |
|
| 50 | + */ |
|
| 51 | + define('ASSETS_PATH', 'assets/'); |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * The path to the directory of your cache files. |
|
| 55 | - * |
|
| 56 | - * This feature is available currently for database and views. |
|
| 57 | - */ |
|
| 58 | - define('CACHE_PATH', ROOT_PATH . 'cache' . DS); |
|
| 53 | + /** |
|
| 54 | + * The path to the directory of your cache files. |
|
| 55 | + * |
|
| 56 | + * This feature is available currently for database and views. |
|
| 57 | + */ |
|
| 58 | + define('CACHE_PATH', ROOT_PATH . 'cache' . DS); |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Custom application path for tests |
|
| 62 | - */ |
|
| 63 | - define('APPS_PATH', TESTS_PATH .'hmvc' . DS); |
|
| 60 | + /** |
|
| 61 | + * Custom application path for tests |
|
| 62 | + */ |
|
| 63 | + define('APPS_PATH', TESTS_PATH .'hmvc' . DS); |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * The path to the controller directory of your application. |
|
| 67 | - * |
|
| 68 | - * If you already know the MVC architecture you know what a controller means; |
|
| 69 | - * it is he who makes the business logic of your application in general. |
|
| 70 | - */ |
|
| 71 | - define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS); |
|
| 65 | + /** |
|
| 66 | + * The path to the controller directory of your application. |
|
| 67 | + * |
|
| 68 | + * If you already know the MVC architecture you know what a controller means; |
|
| 69 | + * it is he who makes the business logic of your application in general. |
|
| 70 | + */ |
|
| 71 | + define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS); |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * The path to the directory of your model classes of your application. |
|
| 75 | - * |
|
| 76 | - * If you already know the MVC architecture you know what a model means; |
|
| 77 | - * it's the one who interacts with the database, in one word persistent data from your application. |
|
| 78 | - */ |
|
| 79 | - define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS); |
|
| 73 | + /** |
|
| 74 | + * The path to the directory of your model classes of your application. |
|
| 75 | + * |
|
| 76 | + * If you already know the MVC architecture you know what a model means; |
|
| 77 | + * it's the one who interacts with the database, in one word persistent data from your application. |
|
| 78 | + */ |
|
| 79 | + define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS); |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * The path to the directory of your views. |
|
| 83 | - * |
|
| 84 | - * If you already know the MVC architecture you know what a view means, |
|
| 85 | - * a view is just a user interface (html page, form, etc.) that is to say |
|
| 86 | - * everything displayed in the browser interface, etc. |
|
| 87 | - */ |
|
| 88 | - define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS); |
|
| 81 | + /** |
|
| 82 | + * The path to the directory of your views. |
|
| 83 | + * |
|
| 84 | + * If you already know the MVC architecture you know what a view means, |
|
| 85 | + * a view is just a user interface (html page, form, etc.) that is to say |
|
| 86 | + * everything displayed in the browser interface, etc. |
|
| 87 | + */ |
|
| 88 | + define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS); |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * The path to the configuration directory. |
|
| 92 | - * |
|
| 93 | - * That contains most of the configuration files for your |
|
| 94 | - * application (database, class loading file, functions, etc.) |
|
| 95 | - */ |
|
| 96 | - define('CONFIG_PATH', ROOT_PATH . 'config' . DS); |
|
| 90 | + /** |
|
| 91 | + * The path to the configuration directory. |
|
| 92 | + * |
|
| 93 | + * That contains most of the configuration files for your |
|
| 94 | + * application (database, class loading file, functions, etc.) |
|
| 95 | + */ |
|
| 96 | + define('CONFIG_PATH', ROOT_PATH . 'config' . DS); |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * The core directory |
|
| 100 | - * |
|
| 101 | - * It is recommended to put this folder out of the web directory of your server and |
|
| 102 | - * you should not change its content because in case of update you could lose the modified files. |
|
| 103 | - */ |
|
| 104 | - define('CORE_PATH', ROOT_PATH . 'core' . DS); |
|
| 98 | + /** |
|
| 99 | + * The core directory |
|
| 100 | + * |
|
| 101 | + * It is recommended to put this folder out of the web directory of your server and |
|
| 102 | + * you should not change its content because in case of update you could lose the modified files. |
|
| 103 | + */ |
|
| 104 | + define('CORE_PATH', ROOT_PATH . 'core' . DS); |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * The path to the directory of core classes that used by the system. |
|
| 108 | - * |
|
| 109 | - * It contains PHP classes that are used by the framework internally. |
|
| 110 | - */ |
|
| 111 | - define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS); |
|
| 106 | + /** |
|
| 107 | + * The path to the directory of core classes that used by the system. |
|
| 108 | + * |
|
| 109 | + * It contains PHP classes that are used by the framework internally. |
|
| 110 | + */ |
|
| 111 | + define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS); |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * The path to the directory of core classes for the cache used by the system. |
|
| 115 | - * |
|
| 116 | - * It contains PHP classes for the cache drivers. |
|
| 117 | - */ |
|
| 118 | - define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS); |
|
| 113 | + /** |
|
| 114 | + * The path to the directory of core classes for the cache used by the system. |
|
| 115 | + * |
|
| 116 | + * It contains PHP classes for the cache drivers. |
|
| 117 | + */ |
|
| 118 | + define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS); |
|
| 119 | 119 | |
| 120 | 120 | /** |
| 121 | - * The path to the directory of core classes for the database used by the system. |
|
| 122 | - * |
|
| 123 | - * It contains PHP classes for the database library, drivers, etc. |
|
| 124 | - */ |
|
| 125 | - define('CORE_CLASSES_DATABASE_PATH', CORE_CLASSES_PATH . 'database' . DS); |
|
| 121 | + * The path to the directory of core classes for the database used by the system. |
|
| 122 | + * |
|
| 123 | + * It contains PHP classes for the database library, drivers, etc. |
|
| 124 | + */ |
|
| 125 | + define('CORE_CLASSES_DATABASE_PATH', CORE_CLASSES_PATH . 'database' . DS); |
|
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * The path to the directory of core classes for the model used by the system. |
|
| 129 | - * |
|
| 130 | - * It contains PHP classes for the models. |
|
| 131 | - */ |
|
| 132 | - define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS); |
|
| 127 | + /** |
|
| 128 | + * The path to the directory of core classes for the model used by the system. |
|
| 129 | + * |
|
| 130 | + * It contains PHP classes for the models. |
|
| 131 | + */ |
|
| 132 | + define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS); |
|
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * The path to the directory of functions or helper systems. |
|
| 136 | - * |
|
| 137 | - * It contains PHP functions that perform a particular task: character string processing, URL, etc. |
|
| 138 | - */ |
|
| 139 | - define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS); |
|
| 134 | + /** |
|
| 135 | + * The path to the directory of functions or helper systems. |
|
| 136 | + * |
|
| 137 | + * It contains PHP functions that perform a particular task: character string processing, URL, etc. |
|
| 138 | + */ |
|
| 139 | + define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS); |
|
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * The path to the core directory of languages files. |
|
| 143 | - * |
|
| 144 | - */ |
|
| 145 | - define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS); |
|
| 141 | + /** |
|
| 142 | + * The path to the core directory of languages files. |
|
| 143 | + * |
|
| 144 | + */ |
|
| 145 | + define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS); |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * The path to the system library directory. |
|
| 149 | - * |
|
| 150 | - * Which contains the libraries most often used in your web application, as for the |
|
| 151 | - * core directory it is advisable to put it out of the root directory of your application. |
|
| 152 | - */ |
|
| 153 | - define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS); |
|
| 147 | + /** |
|
| 148 | + * The path to the system library directory. |
|
| 149 | + * |
|
| 150 | + * Which contains the libraries most often used in your web application, as for the |
|
| 151 | + * core directory it is advisable to put it out of the root directory of your application. |
|
| 152 | + */ |
|
| 153 | + define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS); |
|
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * The path to the system view directory. |
|
| 157 | - * |
|
| 158 | - * That contains the views used for the system, such as error messages, and so on. |
|
| 159 | - */ |
|
| 160 | - define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS); |
|
| 155 | + /** |
|
| 156 | + * The path to the system view directory. |
|
| 157 | + * |
|
| 158 | + * That contains the views used for the system, such as error messages, and so on. |
|
| 159 | + */ |
|
| 160 | + define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS); |
|
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * The path to the directory of your PHP personal functions or helper. |
|
| 164 | - * |
|
| 165 | - * It contains your PHP functions that perform a particular task: utilities, etc. |
|
| 166 | - * Note: Do not put your personal functions or helpers in the system functions directory, |
|
| 167 | - * because if you update the system you may lose them. |
|
| 168 | - */ |
|
| 169 | - define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS); |
|
| 162 | + /** |
|
| 163 | + * The path to the directory of your PHP personal functions or helper. |
|
| 164 | + * |
|
| 165 | + * It contains your PHP functions that perform a particular task: utilities, etc. |
|
| 166 | + * Note: Do not put your personal functions or helpers in the system functions directory, |
|
| 167 | + * because if you update the system you may lose them. |
|
| 168 | + */ |
|
| 169 | + define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS); |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * The path to the app directory of personal language. |
|
| 173 | - * |
|
| 174 | - * This feature is not yet available. |
|
| 175 | - * You can help us do this if you are nice or wish to see the developed framework. |
|
| 176 | - */ |
|
| 177 | - define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS); |
|
| 171 | + /** |
|
| 172 | + * The path to the app directory of personal language. |
|
| 173 | + * |
|
| 174 | + * This feature is not yet available. |
|
| 175 | + * You can help us do this if you are nice or wish to see the developed framework. |
|
| 176 | + */ |
|
| 177 | + define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS); |
|
| 178 | 178 | |
| 179 | - /** |
|
| 180 | - * The path to the directory of your personal libraries |
|
| 181 | - * |
|
| 182 | - * It contains your PHP classes, package, etc. |
|
| 183 | - * Note: you should not put your personal libraries in the system library directory, |
|
| 184 | - * because it is recalled in case of updating the system you might have surprises. |
|
| 185 | - */ |
|
| 186 | - define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS); |
|
| 179 | + /** |
|
| 180 | + * The path to the directory of your personal libraries |
|
| 181 | + * |
|
| 182 | + * It contains your PHP classes, package, etc. |
|
| 183 | + * Note: you should not put your personal libraries in the system library directory, |
|
| 184 | + * because it is recalled in case of updating the system you might have surprises. |
|
| 185 | + */ |
|
| 186 | + define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS); |
|
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * The path to the directory that contains the log files. |
|
| 190 | - * |
|
| 191 | - * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, |
|
| 192 | - * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more |
|
| 193 | - * details see the documentation of your web server. |
|
| 194 | - * Example for Unix or linux with apache web server: |
|
| 195 | - * # chmod -R 700 /path/to/your/logs/directory/ |
|
| 196 | - * # chown -R www-data:www-data /path/to/your/logs/directory/ |
|
| 197 | - */ |
|
| 198 | - define('LOGS_PATH', ROOT_PATH . 'logs' . DS); |
|
| 188 | + /** |
|
| 189 | + * The path to the directory that contains the log files. |
|
| 190 | + * |
|
| 191 | + * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, |
|
| 192 | + * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more |
|
| 193 | + * details see the documentation of your web server. |
|
| 194 | + * Example for Unix or linux with apache web server: |
|
| 195 | + * # chmod -R 700 /path/to/your/logs/directory/ |
|
| 196 | + * # chown -R www-data:www-data /path/to/your/logs/directory/ |
|
| 197 | + */ |
|
| 198 | + define('LOGS_PATH', ROOT_PATH . 'logs' . DS); |
|
| 199 | 199 | |
| 200 | - /** |
|
| 201 | - * The path to the modules directory. |
|
| 202 | - * |
|
| 203 | - * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
|
| 204 | - * in HMVC architecture (hierichical, controllers, models, views). |
|
| 205 | - */ |
|
| 206 | - define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS); |
|
| 200 | + /** |
|
| 201 | + * The path to the modules directory. |
|
| 202 | + * |
|
| 203 | + * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
|
| 204 | + * in HMVC architecture (hierichical, controllers, models, views). |
|
| 205 | + */ |
|
| 206 | + define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS); |
|
| 207 | 207 | |
| 208 | - /** |
|
| 209 | - * The path to the directory of sources external to your application. |
|
| 210 | - * |
|
| 211 | - * If you have already used "composer" you know what that means. |
|
| 212 | - */ |
|
| 213 | - define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS); |
|
| 208 | + /** |
|
| 209 | + * The path to the directory of sources external to your application. |
|
| 210 | + * |
|
| 211 | + * If you have already used "composer" you know what that means. |
|
| 212 | + */ |
|
| 213 | + define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS); |
|
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * The front controller of your application. |
|
| 217 | - * |
|
| 218 | - * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of |
|
| 219 | - * your application by using the rewrite module URL of your web server . |
|
| 220 | - * For example, under apache web server, there is a configuration example file that is located at the root |
|
| 221 | - * of your framework folder : "htaccess.txt" rename it to ".htaccess". |
|
| 222 | - */ |
|
| 223 | - define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); |
|
| 215 | + /** |
|
| 216 | + * The front controller of your application. |
|
| 217 | + * |
|
| 218 | + * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of |
|
| 219 | + * your application by using the rewrite module URL of your web server . |
|
| 220 | + * For example, under apache web server, there is a configuration example file that is located at the root |
|
| 221 | + * of your framework folder : "htaccess.txt" rename it to ".htaccess". |
|
| 222 | + */ |
|
| 223 | + define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); |
|
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * Check if user run the application under CLI |
|
| 227 | - */ |
|
| 228 | - define('IS_CLI', stripos('cli', php_sapi_name()) !== false); |
|
| 225 | + /** |
|
| 226 | + * Check if user run the application under CLI |
|
| 227 | + */ |
|
| 228 | + define('IS_CLI', stripos('cli', php_sapi_name()) !== false); |
|
| 229 | 229 | |
| 230 | - /** |
|
| 231 | - * The environment of your application (production, test, development). |
|
| 232 | - * |
|
| 233 | - * if your application is still in development you use the value "development" |
|
| 234 | - * so you will have the display of the error messages, etc. |
|
| 235 | - * Once you finish the development of your application that is to put it online |
|
| 236 | - * you change this value to "production" or "testing", in this case there will be deactivation of error messages, |
|
| 237 | - * the loading of the system, will be fast. |
|
| 238 | - */ |
|
| 239 | - define('ENVIRONMENT', 'testing'); |
|
| 230 | + /** |
|
| 231 | + * The environment of your application (production, test, development). |
|
| 232 | + * |
|
| 233 | + * if your application is still in development you use the value "development" |
|
| 234 | + * so you will have the display of the error messages, etc. |
|
| 235 | + * Once you finish the development of your application that is to put it online |
|
| 236 | + * you change this value to "production" or "testing", in this case there will be deactivation of error messages, |
|
| 237 | + * the loading of the system, will be fast. |
|
| 238 | + */ |
|
| 239 | + define('ENVIRONMENT', 'testing'); |
|
| 240 | 240 | |
| 241 | 241 | |
| 242 | - //Fix to allow test as if application is running in CLI mode $_SESSION global variable is not available |
|
| 243 | - $_SESSION = array(); |
|
| 242 | + //Fix to allow test as if application is running in CLI mode $_SESSION global variable is not available |
|
| 243 | + $_SESSION = array(); |
|
| 244 | 244 | |
| 245 | - if(! isset($_SERVER['REMOTE_ADDR'])){ |
|
| 246 | - $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; |
|
| 247 | - } |
|
| 245 | + if(! isset($_SERVER['REMOTE_ADDR'])){ |
|
| 246 | + $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - //check for composer autoload file if exists include it |
|
| 250 | - if (file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 251 | - require_once VENDOR_PATH . 'autoload.php'; |
|
| 249 | + //check for composer autoload file if exists include it |
|
| 250 | + if (file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 251 | + require_once VENDOR_PATH . 'autoload.php'; |
|
| 252 | 252 | |
| 253 | - //define the class alias for vstream |
|
| 254 | - class_alias('org\bovigo\vfs\vfsStream', 'vfsStream'); |
|
| 255 | - class_alias('org\bovigo\vfs\vfsStreamDirectory', 'vfsStreamDirectory'); |
|
| 256 | - class_alias('org\bovigo\vfs\vfsStreamWrapper', 'vfsStreamWrapper'); |
|
| 253 | + //define the class alias for vstream |
|
| 254 | + class_alias('org\bovigo\vfs\vfsStream', 'vfsStream'); |
|
| 255 | + class_alias('org\bovigo\vfs\vfsStreamDirectory', 'vfsStreamDirectory'); |
|
| 256 | + class_alias('org\bovigo\vfs\vfsStreamWrapper', 'vfsStreamWrapper'); |
|
| 257 | 257 | |
| 258 | - } |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - //require autoloader for test |
|
| 261 | - require_once 'include/autoloader.php'; |
|
| 260 | + //require autoloader for test |
|
| 261 | + require_once 'include/autoloader.php'; |
|
| 262 | 262 | |
| 263 | 263 | |
| 264 | 264 | |
| 265 | - //grap from core/common.php functions and mock some functions for tests |
|
| 266 | - require_once 'include/common.php'; |
|
| 265 | + //grap from core/common.php functions and mock some functions for tests |
|
| 266 | + require_once 'include/common.php'; |
|
| 267 | 267 | |
| 268 | - //Some utilities functions, classes, etc. |
|
| 269 | - require_once 'include/testsUtil.php'; |
|
| 268 | + //Some utilities functions, classes, etc. |
|
| 269 | + require_once 'include/testsUtil.php'; |
|
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * Setting of the PHP error message handling function |
|
| 273 | - */ |
|
| 274 | - set_error_handler('php_error_handler'); |
|
| 271 | + /** |
|
| 272 | + * Setting of the PHP error message handling function |
|
| 273 | + */ |
|
| 274 | + set_error_handler('php_error_handler'); |
|
| 275 | 275 | |
| 276 | - /** |
|
| 277 | - * Setting of the PHP error exception handling function |
|
| 278 | - */ |
|
| 279 | - set_exception_handler('php_exception_handler'); |
|
| 276 | + /** |
|
| 277 | + * Setting of the PHP error exception handling function |
|
| 278 | + */ |
|
| 279 | + set_exception_handler('php_exception_handler'); |
|
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * Setting of the PHP shutdown handling function |
|
| 283 | - */ |
|
| 284 | - register_shutdown_function('php_shudown_handler'); |
|
| 281 | + /** |
|
| 282 | + * Setting of the PHP shutdown handling function |
|
| 283 | + */ |
|
| 284 | + register_shutdown_function('php_shudown_handler'); |
|
| 285 | 285 | |
| 286 | - /** |
|
| 287 | - * Register the tests autoload |
|
| 288 | - */ |
|
| 289 | - spl_autoload_register('tests_autoload'); |
|
| 286 | + /** |
|
| 287 | + * Register the tests autoload |
|
| 288 | + */ |
|
| 289 | + spl_autoload_register('tests_autoload'); |
|
| 290 | 290 | |
| 291 | 291 | |
| 292 | - |
|
| 293 | 292 | \ No newline at end of file |
| 293 | + |
|
| 294 | 294 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | - class DBSessionModel extends DBSessionHandlerModel{ |
|
| 2 | + class DBSessionModel extends DBSessionHandlerModel { |
|
| 3 | 3 | |
| 4 | 4 | protected $_table = 'ses'; |
| 5 | 5 | protected $primary_key = 's_id'; |
@@ -14,14 +14,14 @@ discard block |
||
| 14 | 14 | 'skey' => 'test_id' //VARCHAR(255) |
| 15 | 15 | ); |
| 16 | 16 | |
| 17 | - public function deleteByTime($time){ |
|
| 17 | + public function deleteByTime($time) { |
|
| 18 | 18 | $this->getQueryBuilder()->from($this->_table) |
| 19 | 19 | ->where('s_time', '<', $time); |
| 20 | 20 | $this->_database->delete(); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
| 24 | - public function getKeyValue(){ |
|
| 24 | + public function getKeyValue() { |
|
| 25 | 25 | $user_id = 0; |
| 26 | 26 | return $user_id; |
| 27 | 27 | } |
@@ -1,28 +1,28 @@ |
||
| 1 | 1 | <?php |
| 2 | - class DBSessionModel extends DBSessionHandlerModel{ |
|
| 2 | + class DBSessionModel extends DBSessionHandlerModel{ |
|
| 3 | 3 | |
| 4 | - protected $_table = 'ses'; |
|
| 5 | - protected $primary_key = 's_id'; |
|
| 4 | + protected $_table = 'ses'; |
|
| 5 | + protected $primary_key = 's_id'; |
|
| 6 | 6 | |
| 7 | - protected $sessionTableColumns = array( |
|
| 8 | - 'sid' => 's_id', //VARCHAR(255) |
|
| 9 | - 'sdata' => 's_data', //TEXT |
|
| 10 | - 'stime' => 's_time', //unix timestamp (INT|BIGINT) |
|
| 11 | - 'shost' => 's_host', //VARCHAR(255) |
|
| 12 | - 'sip' => 's_ip', //VARCHAR(255) |
|
| 13 | - 'sbrowser' => 's_browser', //VARCHAR(255) |
|
| 14 | - 'skey' => 'test_id' //VARCHAR(255) |
|
| 15 | - ); |
|
| 7 | + protected $sessionTableColumns = array( |
|
| 8 | + 'sid' => 's_id', //VARCHAR(255) |
|
| 9 | + 'sdata' => 's_data', //TEXT |
|
| 10 | + 'stime' => 's_time', //unix timestamp (INT|BIGINT) |
|
| 11 | + 'shost' => 's_host', //VARCHAR(255) |
|
| 12 | + 'sip' => 's_ip', //VARCHAR(255) |
|
| 13 | + 'sbrowser' => 's_browser', //VARCHAR(255) |
|
| 14 | + 'skey' => 'test_id' //VARCHAR(255) |
|
| 15 | + ); |
|
| 16 | 16 | |
| 17 | - public function deleteByTime($time){ |
|
| 18 | - $this->getQueryBuilder()->from($this->_table) |
|
| 19 | - ->where('s_time', '<', $time); |
|
| 20 | - $this->_database->delete(); |
|
| 21 | - } |
|
| 17 | + public function deleteByTime($time){ |
|
| 18 | + $this->getQueryBuilder()->from($this->_table) |
|
| 19 | + ->where('s_time', '<', $time); |
|
| 20 | + $this->_database->delete(); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | - public function getKeyValue(){ |
|
| 25 | - $user_id = 0; |
|
| 26 | - return $user_id; |
|
| 27 | - } |
|
| 28 | - } |
|
| 29 | 24 | \ No newline at end of file |
| 25 | + public function getKeyValue(){ |
|
| 26 | + $user_id = 0; |
|
| 27 | + return $user_id; |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | 30 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | //Autoload function |
| 3 | - function tests_autoload($class){ |
|
| 3 | + function tests_autoload($class) { |
|
| 4 | 4 | $classesMap = array( |
| 5 | 5 | //Caches |
| 6 | 6 | 'ApcCache' => CORE_CLASSES_CACHE_PATH . 'ApcCache.php', |
@@ -40,11 +40,11 @@ discard block |
||
| 40 | 40 | 'StringHash' => CORE_LIBRARY_PATH . 'StringHash.php', |
| 41 | 41 | 'Upload' => CORE_LIBRARY_PATH . 'Upload.php', |
| 42 | 42 | ); |
| 43 | - if(isset($classesMap[$class])){ |
|
| 44 | - if(file_exists($classesMap[$class])){ |
|
| 43 | + if (isset($classesMap[$class])) { |
|
| 44 | + if (file_exists($classesMap[$class])) { |
|
| 45 | 45 | require_once $classesMap[$class]; |
| 46 | 46 | } |
| 47 | - else{ |
|
| 47 | + else { |
|
| 48 | 48 | echo 'File for class ' . $class . ' not found'; |
| 49 | 49 | } |
| 50 | 50 | } |
@@ -43,8 +43,7 @@ |
||
| 43 | 43 | if(isset($classesMap[$class])){ |
| 44 | 44 | if(file_exists($classesMap[$class])){ |
| 45 | 45 | require_once $classesMap[$class]; |
| 46 | - } |
|
| 47 | - else{ |
|
| 46 | + } else{ |
|
| 48 | 47 | echo 'File for class ' . $class . ' not found'; |
| 49 | 48 | } |
| 50 | 49 | } |
@@ -1,54 +1,54 @@ |
||
| 1 | 1 | <?php |
| 2 | - //Autoload function |
|
| 3 | - function tests_autoload($class){ |
|
| 4 | - $classesMap = array( |
|
| 5 | - //Caches |
|
| 6 | - 'ApcCache' => CORE_CLASSES_CACHE_PATH . 'ApcCache.php', |
|
| 7 | - 'CacheInterface' => CORE_CLASSES_CACHE_PATH . 'CacheInterface.php', |
|
| 8 | - 'FileCache' => CORE_CLASSES_CACHE_PATH . 'FileCache.php', |
|
| 9 | - //models |
|
| 10 | - 'DBSessionHandlerModel' => CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php', |
|
| 11 | - 'Model' => CORE_CLASSES_MODEL_PATH . 'Model.php', |
|
| 12 | - //Core classes |
|
| 13 | - 'Config' => CORE_CLASSES_PATH . 'Config.php', |
|
| 14 | - 'Controller' => CORE_CLASSES_PATH . 'Controller.php', |
|
| 15 | - 'Database' => CORE_CLASSES_DATABASE_PATH . 'Database.php', |
|
| 16 | - 'DatabaseQueryBuilder' => CORE_CLASSES_DATABASE_PATH . 'DatabaseQueryBuilder.php', |
|
| 17 | - 'DatabaseQueryResult' => CORE_CLASSES_DATABASE_PATH . 'DatabaseQueryResult.php', |
|
| 18 | - 'DatabaseQueryRunner' => CORE_CLASSES_DATABASE_PATH . 'DatabaseQueryRunner.php', |
|
| 19 | - 'DBSessionHandler' => CORE_CLASSES_PATH . 'DBSessionHandler.php', |
|
| 20 | - 'EventInfo' => CORE_CLASSES_PATH . 'EventInfo.php', |
|
| 21 | - 'EventDispatcher' => CORE_CLASSES_PATH . 'EventDispatcher.php', |
|
| 22 | - 'Lang' => CORE_CLASSES_PATH . 'Lang.php', |
|
| 23 | - 'Loader' => CORE_CLASSES_PATH . 'Loader.php', |
|
| 24 | - 'Log' => CORE_CLASSES_PATH . 'Log.php', |
|
| 25 | - 'Module' => CORE_CLASSES_PATH . 'Module.php', |
|
| 26 | - 'Request' => CORE_CLASSES_PATH . 'Request.php', |
|
| 27 | - 'Response' => CORE_CLASSES_PATH . 'Response.php', |
|
| 28 | - 'Router' => CORE_CLASSES_PATH . 'Router.php', |
|
| 29 | - 'Security' => CORE_CLASSES_PATH . 'Security.php', |
|
| 30 | - 'Session' => CORE_CLASSES_PATH . 'Session.php', |
|
| 31 | - 'Url' => CORE_CLASSES_PATH . 'Url.php', |
|
| 32 | - //Core libraries |
|
| 33 | - 'Assets' => CORE_LIBRARY_PATH . 'Assets.php', |
|
| 34 | - 'Benchmark' => CORE_LIBRARY_PATH . 'Benchmark.php', |
|
| 35 | - 'Browser' => CORE_LIBRARY_PATH . 'Browser.php', |
|
| 36 | - 'Cookie' => CORE_LIBRARY_PATH . 'Cookie.php', |
|
| 37 | - 'Email' => CORE_LIBRARY_PATH . 'Email.php', |
|
| 38 | - 'Form' => CORE_LIBRARY_PATH . 'Form.php', |
|
| 39 | - 'FormValidation' => CORE_LIBRARY_PATH . 'FormValidation.php', |
|
| 40 | - 'Html' => CORE_LIBRARY_PATH . 'Html.php', |
|
| 41 | - 'Pagination' => CORE_LIBRARY_PATH . 'Pagination.php', |
|
| 42 | - 'PDF' => CORE_LIBRARY_PATH . 'PDF.php', |
|
| 43 | - 'StringHash' => CORE_LIBRARY_PATH . 'StringHash.php', |
|
| 44 | - 'Upload' => CORE_LIBRARY_PATH . 'Upload.php', |
|
| 45 | - ); |
|
| 46 | - if(isset($classesMap[$class])){ |
|
| 47 | - if(file_exists($classesMap[$class])){ |
|
| 48 | - require_once $classesMap[$class]; |
|
| 49 | - } |
|
| 50 | - else{ |
|
| 51 | - echo 'File for class ' . $class . ' not found'; |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | 2 | \ No newline at end of file |
| 3 | + //Autoload function |
|
| 4 | + function tests_autoload($class){ |
|
| 5 | + $classesMap = array( |
|
| 6 | + //Caches |
|
| 7 | + 'ApcCache' => CORE_CLASSES_CACHE_PATH . 'ApcCache.php', |
|
| 8 | + 'CacheInterface' => CORE_CLASSES_CACHE_PATH . 'CacheInterface.php', |
|
| 9 | + 'FileCache' => CORE_CLASSES_CACHE_PATH . 'FileCache.php', |
|
| 10 | + //models |
|
| 11 | + 'DBSessionHandlerModel' => CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php', |
|
| 12 | + 'Model' => CORE_CLASSES_MODEL_PATH . 'Model.php', |
|
| 13 | + //Core classes |
|
| 14 | + 'Config' => CORE_CLASSES_PATH . 'Config.php', |
|
| 15 | + 'Controller' => CORE_CLASSES_PATH . 'Controller.php', |
|
| 16 | + 'Database' => CORE_CLASSES_DATABASE_PATH . 'Database.php', |
|
| 17 | + 'DatabaseQueryBuilder' => CORE_CLASSES_DATABASE_PATH . 'DatabaseQueryBuilder.php', |
|
| 18 | + 'DatabaseQueryResult' => CORE_CLASSES_DATABASE_PATH . 'DatabaseQueryResult.php', |
|
| 19 | + 'DatabaseQueryRunner' => CORE_CLASSES_DATABASE_PATH . 'DatabaseQueryRunner.php', |
|
| 20 | + 'DBSessionHandler' => CORE_CLASSES_PATH . 'DBSessionHandler.php', |
|
| 21 | + 'EventInfo' => CORE_CLASSES_PATH . 'EventInfo.php', |
|
| 22 | + 'EventDispatcher' => CORE_CLASSES_PATH . 'EventDispatcher.php', |
|
| 23 | + 'Lang' => CORE_CLASSES_PATH . 'Lang.php', |
|
| 24 | + 'Loader' => CORE_CLASSES_PATH . 'Loader.php', |
|
| 25 | + 'Log' => CORE_CLASSES_PATH . 'Log.php', |
|
| 26 | + 'Module' => CORE_CLASSES_PATH . 'Module.php', |
|
| 27 | + 'Request' => CORE_CLASSES_PATH . 'Request.php', |
|
| 28 | + 'Response' => CORE_CLASSES_PATH . 'Response.php', |
|
| 29 | + 'Router' => CORE_CLASSES_PATH . 'Router.php', |
|
| 30 | + 'Security' => CORE_CLASSES_PATH . 'Security.php', |
|
| 31 | + 'Session' => CORE_CLASSES_PATH . 'Session.php', |
|
| 32 | + 'Url' => CORE_CLASSES_PATH . 'Url.php', |
|
| 33 | + //Core libraries |
|
| 34 | + 'Assets' => CORE_LIBRARY_PATH . 'Assets.php', |
|
| 35 | + 'Benchmark' => CORE_LIBRARY_PATH . 'Benchmark.php', |
|
| 36 | + 'Browser' => CORE_LIBRARY_PATH . 'Browser.php', |
|
| 37 | + 'Cookie' => CORE_LIBRARY_PATH . 'Cookie.php', |
|
| 38 | + 'Email' => CORE_LIBRARY_PATH . 'Email.php', |
|
| 39 | + 'Form' => CORE_LIBRARY_PATH . 'Form.php', |
|
| 40 | + 'FormValidation' => CORE_LIBRARY_PATH . 'FormValidation.php', |
|
| 41 | + 'Html' => CORE_LIBRARY_PATH . 'Html.php', |
|
| 42 | + 'Pagination' => CORE_LIBRARY_PATH . 'Pagination.php', |
|
| 43 | + 'PDF' => CORE_LIBRARY_PATH . 'PDF.php', |
|
| 44 | + 'StringHash' => CORE_LIBRARY_PATH . 'StringHash.php', |
|
| 45 | + 'Upload' => CORE_LIBRARY_PATH . 'Upload.php', |
|
| 46 | + ); |
|
| 47 | + if(isset($classesMap[$class])){ |
|
| 48 | + if(file_exists($classesMap[$class])){ |
|
| 49 | + require_once $classesMap[$class]; |
|
| 50 | + } |
|
| 51 | + else{ |
|
| 52 | + echo 'File for class ' . $class . ' not found'; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | 56 | \ No newline at end of file |