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