3 namespace CoreFramework\Listener\Socket;
6 * A decorator for the SocketFileListener to communicate to hubs
8 * @author Roland Haeder <webmaster@shipsimu.org>
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
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.
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.
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/>.
27 class SocketFileListenerDecorator extends BaseListenerDecorator implements Listenable {
29 * Protected constructor
33 protected function __construct () {
34 // Call parent constructor
35 parent::__construct(__CLASS__);
37 // Set listener type and protocol name
38 $this->setListenerType('hub');
39 $this->setProtocolName('tcp');
43 * Creates an instance of this class
45 * @param $listenerInstance A Listener instance
46 * @return $decoratorInstance An instance a prepared listener decorator class
48 public static final function createSocketFileListenerDecorator (Listenable $listenerInstance) {
50 $decoratorInstance = new SocketFileListenerDecorator();
52 // Set the application instance
53 $decoratorInstance->setListenerInstance($listenerInstance);
55 // Return the prepared instance
56 return $decoratorInstance;
60 * Initializes the listener by setting up the required socket server
64 public function initListener () {
65 $this->partialStub('WARNING: This method should not be called.');
69 * "Listens" for incoming network packages
73 public function doListen () {
74 // Handle generic TCP package
75 $this->getListenerInstance()->doListen();
77 // Handle hub TCP package
78 $this->partialStub('Need to handle hub TCP package.');
82 * Checks whether the listener would accept the given package data array
84 * @param $packageData Raw package data
85 * @return $accepts Whether this listener does accept
87 public function ifListenerAcceptsPackageData (array $packageData) {
88 // Get a tags instance
89 $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
91 // So is the package accepted with this listener?
92 $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);