3 namespace CoreFramework\Visitor\Task\Active;
6 * An ActiveTask visitor
8 * @author Roland Haeder <webmaster@shipsimu.org>
10 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
11 * @license GNU GPL 3.0 or any newer version
12 * @link http://www.shipsimu.org
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 class ActiveTaskVisitor extends BaseVisitor implements TaskVisitor, PoolVisitor, ListenerVisitor, DecoratorVisitor {
29 * Protected constructor
33 protected function __construct () {
34 // Call parent constructor
35 parent::__construct(__CLASS__);
38 $this->setVisitorMode('task');
42 * Creates an instance of this class
44 * @return $visitorInstance An instance a Visitorable class
46 public static final function createActiveTaskVisitor () {
48 $visitorInstance = new ActiveTaskVisitor();
50 // Return the prepared instance
51 return $visitorInstance;
55 * Visits the given task instance
57 * @param $taskInstance A Taskable instance
60 public function visitTask (Taskable $taskInstance) {
61 // Execute the task from this visitor
62 //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting task ' . $taskInstance->__toString() . ' - CALLED!');
63 $taskInstance->executeTask();
64 //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting task ' . $taskInstance->__toString() . ' - EXIT!');
68 * Pool visitor method for active tasks
70 * @param $poolInstance A Poolable instance
73 public function visitPool (Poolable $poolInstance) {
75 * We don't need to visit a pool as an active task because a pool can
76 * never become a task. Instead e.g. by a listener pool we should visit
77 * all listeners one by one
82 * Visits the given listener instance
84 * @param $listenerInstance A Listenable instance
87 public function visitListener (Listenable $listenerInstance) {
89 //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting ' . $listenerInstance->__toString() . ' - CALLED!');
90 $listenerInstance->doListen();
91 //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting ' . $listenerInstance->__toString() . ' - FINISH');
95 * Visits the given decorator instance
97 * @param $decoratorInstance A decorator instance
100 public function visitDecorator (BaseDecorator $decoratorInstance) {
101 // A decorator itself can never become an active task so this method