Continued with renaming-season:
[core.git] / framework / main / classes / visitor / tasks / class_ActiveTaskVisitor.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Visitor\Task\Active;
4
5 /**
6  * An ActiveTask visitor
7  *
8  * @author              Roland Haeder <webmaster@shipsimu.org>
9  * @version             0.0.0
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
13  *
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.
18  *
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.
23  *
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/>.
26  */
27 class ActiveTaskVisitor extends BaseVisitor implements TaskVisitor, PoolVisitor, ListenerVisitor, DecoratorVisitor {
28         /**
29          * Protected constructor
30          *
31          * @return      void
32          */
33         protected function __construct () {
34                 // Call parent constructor
35                 parent::__construct(__CLASS__);
36
37                 // Set visitor mode
38                 $this->setVisitorMode('task');
39         }
40
41         /**
42          * Creates an instance of this class
43          *
44          * @return      $visitorInstance        An instance a Visitorable class
45          */
46         public static final function createActiveTaskVisitor () {
47                 // Get new instance
48                 $visitorInstance = new ActiveTaskVisitor();
49
50                 // Return the prepared instance
51                 return $visitorInstance;
52         }
53
54         /**
55          * Visits the given task instance
56          *
57          * @param       $taskInstance   A Taskable instance
58          * @return      void
59          */
60         public function visitTask (Taskable $taskInstance) {
61                 // Execute the task from this visitor
62                 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting task ' . $taskInstance->__toString() . ' - CALLED!');
63                 $taskInstance->executeTask();
64                 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting task ' . $taskInstance->__toString() . ' - EXIT!');
65         }
66
67         /**
68          * Pool visitor method for active tasks
69          *
70          * @param       $poolInstance   A Poolable instance
71          * @return      void
72          */
73         public function visitPool (Poolable $poolInstance) {
74                 /**
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
78                  */
79         }
80
81         /**
82          * Visits the given listener instance
83          *
84          * @param       $listenerInstance       A Listenable instance
85          * @return      void
86          */
87         public function visitListener (Listenable $listenerInstance) {
88                 // Do "listen" here
89                 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting ' . $listenerInstance->__toString() . ' - CALLED!');
90                 $listenerInstance->doListen();
91                 //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting ' . $listenerInstance->__toString() . ' - FINISH');
92         }
93
94         /**
95          * Visits the given decorator instance
96          *
97          * @param       $decoratorInstance      A decorator instance
98          * @return      void
99          */
100         public function visitDecorator (BaseDecorator $decoratorInstance) {
101                 // A decorator itself can never become an active task so this method
102                 // remains empty.
103         }
104
105 }