also the factory has been imported
[core.git] / framework / main / classes / listener / socket / decorator / class_SocketFileListenerDecorator.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Listener\Socket;
4
5 // Import framework stuff
6 use CoreFramework\Listener\Listenable;
7
8 /**
9  * A decorator for the SocketFileListener to communicate to hubs
10  *
11  * @author              Roland Haeder <webmaster@shipsimu.org>
12  * @version             0.0.0
13  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
14  * @license             GNU GPL 3.0 or any newer version
15  * @link                http://www.shipsimu.org
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program. If not, see <http://www.gnu.org/licenses/>.
29  */
30 class SocketFileListenerDecorator extends BaseListenerDecorator implements Listenable {
31         /**
32          * Protected constructor
33          *
34          * @return      void
35          */
36         protected function __construct () {
37                 // Call parent constructor
38                 parent::__construct(__CLASS__);
39
40                 // Set listener type and protocol name
41                 $this->setListenerType('hub');
42                 $this->setProtocolName('tcp');
43         }
44
45         /**
46          * Creates an instance of this class
47          *
48          * @param       $listenerInstance       A Listener instance
49          * @return      $decoratorInstance      An instance a prepared listener decorator class
50          */
51         public static final function createSocketFileListenerDecorator (Listenable $listenerInstance) {
52                 // Get new instance
53                 $decoratorInstance = new SocketFileListenerDecorator();
54
55                 // Set the application instance
56                 $decoratorInstance->setListenerInstance($listenerInstance);
57
58                 // Return the prepared instance
59                 return $decoratorInstance;
60         }
61
62         /**
63          * Initializes the listener by setting up the required socket server
64          *
65          * @return      void
66          */
67         public function initListener () {
68                 $this->partialStub('WARNING: This method should not be called.');
69         }
70
71         /**
72          * "Listens" for incoming network packages
73          *
74          * @return      void
75          */
76         public function doListen () {
77                 // Handle generic TCP package
78                 $this->getListenerInstance()->doListen();
79
80                 // Handle hub TCP package
81                 $this->partialStub('Need to handle hub TCP package.');
82         }
83
84         /**
85          * Checks whether the listener would accept the given package data array
86          *
87          * @param       $packageData    Raw package data
88          * @return      $accepts                Whether this listener does accept
89          */
90         public function ifListenerAcceptsPackageData (array $packageData) {
91                 // Get a tags instance
92                 $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
93
94                 // So is the package accepted with this listener?
95                 $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
96
97                 // Return the result
98                 return $accepts;
99         }
100
101 }