]> git.mxchange.org Git - core.git/blob - framework/main/classes/visitor/tasks/class_ActiveTaskVisitor.php
be9b83bc04193ae89773346a19ae74207ed9ea95
[core.git] / framework / main / classes / visitor / tasks / class_ActiveTaskVisitor.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Visitor\Task\Active;
4
5 // Import framework stuff
6 use CoreFramework\Generic\BaseDecorator;
7 use CoreFramework\Listener\Listenable;
8 use CoreFramework\Pool\Poolable;
9 use CoreFramework\Task\Taskable;
10 use CoreFramework\Visitor\BaseVisitor;
11 use CoreFramework\Visitor\Decorator\DecoratorVisitor;
12 use CoreFramework\Visitor\Listener\ListenerVisitor;
13 use CoreFramework\Visitor\Pool\PoolVisitor;
14 use CoreFramework\Visitor\Task\TaskVisitor;
15
16 /**
17  * An ActiveTask visitor
18  *
19  * @author              Roland Haeder <webmaster@shipsimu.org>
20  * @version             0.0.0
21  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
22  * @license             GNU GPL 3.0 or any newer version
23  * @link                http://www.shipsimu.org
24  *
25  * This program is free software: you can redistribute it and/or modify
26  * it under the terms of the GNU General Public License as published by
27  * the Free Software Foundation, either version 3 of the License, or
28  * (at your option) any later version.
29  *
30  * This program is distributed in the hope that it will be useful,
31  * but WITHOUT ANY WARRANTY; without even the implied warranty of
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33  * GNU General Public License for more details.
34  *
35  * You should have received a copy of the GNU General Public License
36  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
37  */
38 class ActiveTaskVisitor extends BaseVisitor implements TaskVisitor, PoolVisitor, ListenerVisitor, DecoratorVisitor {
39         /**
40          * Protected constructor
41          *
42          * @return      void
43          */
44         protected function __construct () {
45                 // Call parent constructor
46                 parent::__construct(__CLASS__);
47
48                 // Set visitor mode
49                 $this->setVisitorMode('task');
50         }
51
52         /**
53          * Creates an instance of this class
54          *
55          * @return      $visitorInstance        An instance a Visitorable class
56          */
57         public static final function createActiveTaskVisitor () {
58                 // Get new instance
59                 $visitorInstance = new ActiveTaskVisitor();
60
61                 // Return the prepared instance
62                 return $visitorInstance;
63         }
64
65         /**
66          * Visits the given task instance
67          *
68          * @param       $taskInstance   A Taskable instance
69          * @return      void
70          */
71         public function visitTask (Taskable $taskInstance) {
72                 // Execute the task from this visitor
73                 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting task ' . $taskInstance->__toString() . ' - CALLED!');
74                 $taskInstance->executeTask();
75                 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting task ' . $taskInstance->__toString() . ' - EXIT!');
76         }
77
78         /**
79          * Pool visitor method for active tasks
80          *
81          * @param       $poolInstance   A Poolable instance
82          * @return      void
83          */
84         public function visitPool (Poolable $poolInstance) {
85                 /**
86                  * We don't need to visit a pool as an active task because a pool can
87                  * never become a task. Instead e.g. by a listener pool we should visit
88                  * all listeners one by one
89                  */
90         }
91
92         /**
93          * Visits the given listener instance
94          *
95          * @param       $listenerInstance       A Listenable instance
96          * @return      void
97          */
98         public function visitListener (Listenable $listenerInstance) {
99                 // Do "listen" here
100                 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting ' . $listenerInstance->__toString() . ' - CALLED!');
101                 $listenerInstance->doListen();
102                 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting ' . $listenerInstance->__toString() . ' - FINISH');
103         }
104
105         /**
106          * Visits the given decorator instance
107          *
108          * @param       $decoratorInstance      A decorator instance
109          * @return      void
110          */
111         public function visitDecorator (BaseDecorator $decoratorInstance) {
112                 // A decorator itself can never become an active task so this method
113                 // remains empty.
114         }
115
116 }