d4f6d9f58a9c626a1f977a78b6e7ab6324bc3560
[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\Task\Taskable;
7 use CoreFramework\Visitor\BaseVisitor;
8 use CoreFramework\Visitor\Pool\PoolVisitor;
9 use CoreFramework\Visitor\Task\TaskVisitor;
10
11 /**
12  * An ActiveTask visitor
13  *
14  * @author              Roland Haeder <webmaster@shipsimu.org>
15  * @version             0.0.0
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
19  *
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.
24  *
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.
29  *
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/>.
32  */
33 class ActiveTaskVisitor extends BaseVisitor implements TaskVisitor, PoolVisitor, ListenerVisitor, DecoratorVisitor {
34         /**
35          * Protected constructor
36          *
37          * @return      void
38          */
39         protected function __construct () {
40                 // Call parent constructor
41                 parent::__construct(__CLASS__);
42
43                 // Set visitor mode
44                 $this->setVisitorMode('task');
45         }
46
47         /**
48          * Creates an instance of this class
49          *
50          * @return      $visitorInstance        An instance a Visitorable class
51          */
52         public static final function createActiveTaskVisitor () {
53                 // Get new instance
54                 $visitorInstance = new ActiveTaskVisitor();
55
56                 // Return the prepared instance
57                 return $visitorInstance;
58         }
59
60         /**
61          * Visits the given task instance
62          *
63          * @param       $taskInstance   A Taskable instance
64          * @return      void
65          */
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!');
71         }
72
73         /**
74          * Pool visitor method for active tasks
75          *
76          * @param       $poolInstance   A Poolable instance
77          * @return      void
78          */
79         public function visitPool (Poolable $poolInstance) {
80                 /**
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
84                  */
85         }
86
87         /**
88          * Visits the given listener instance
89          *
90          * @param       $listenerInstance       A Listenable instance
91          * @return      void
92          */
93         public function visitListener (Listenable $listenerInstance) {
94                 // Do "listen" here
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');
98         }
99
100         /**
101          * Visits the given decorator instance
102          *
103          * @param       $decoratorInstance      A decorator instance
104          * @return      void
105          */
106         public function visitDecorator (BaseDecorator $decoratorInstance) {
107                 // A decorator itself can never become an active task so this method
108                 // remains empty.
109         }
110
111 }