renamed lib-local.php -> lib-lfdb.php because it really loads the "legendary"
[core.git] / inc / main / classes / listener / socket / decorator / class_SocketFileListenerDecorator.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Listener\Socket;
4
5 /**
6  * A decorator for the SocketFileListener to communicate to hubs
7  *
8  * @author              Roland Haeder <webmaster@shipsimu.org>
9  * @version             0.0.0
10  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 SocketFileListenerDecorator extends BaseListenerDecorator implements Listenable {
28         /**
29          * Protected constructor
30          *
31          * @return      void
32          */
33         protected function __construct () {
34                 // Call parent constructor
35                 parent::__construct(__CLASS__);
36
37                 // Set listener type and protocol name
38                 $this->setListenerType('hub');
39                 $this->setProtocolName('tcp');
40         }
41
42         /**
43          * Creates an instance of this class
44          *
45          * @param       $listenerInstance       A Listener instance
46          * @return      $decoratorInstance      An instance a prepared listener decorator class
47          */
48         public static final function createSocketFileListenerDecorator (Listenable $listenerInstance) {
49                 // Get new instance
50                 $decoratorInstance = new SocketFileListenerDecorator();
51
52                 // Set the application instance
53                 $decoratorInstance->setListenerInstance($listenerInstance);
54
55                 // Return the prepared instance
56                 return $decoratorInstance;
57         }
58
59         /**
60          * Initializes the listener by setting up the required socket server
61          *
62          * @return      void
63          */
64         public function initListener () {
65                 $this->partialStub('WARNING: This method should not be called.');
66         }
67
68         /**
69          * "Listens" for incoming network packages
70          *
71          * @return      void
72          */
73         public function doListen () {
74                 // Handle generic TCP package
75                 $this->getListenerInstance()->doListen();
76
77                 // Handle hub TCP package
78                 $this->partialStub('Need to handle hub TCP package.');
79         }
80
81         /**
82          * Checks whether the listener would accept the given package data array
83          *
84          * @param       $packageData    Raw package data
85          * @return      $accepts                Whether this listener does accept
86          */
87         public function ifListenerAcceptsPackageData (array $packageData) {
88                 // Get a tags instance
89                 $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
90
91                 // So is the package accepted with this listener?
92                 $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
93
94                 // Return the result
95                 return $accepts;
96         }
97
98 }