]> git.mxchange.org Git - hub.git/blob - application/hub/main/resolver/state/network/class_NetworkStateResolver.php
Task handler added, a lot rewrites
[hub.git] / application / hub / main / resolver / state / network / class_NetworkStateResolver.php
1 <?php
2 /**
3  * A resolver for resolving states locally
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 class NetworkStateResolver extends BaseStateResolver implements StateResolver {
25         /**
26          * Last successfull resolved state (name)
27          */
28         private $lastStateName = '';
29
30         /**
31          * Last successfull resolved state (instance)
32          */
33         private $lastStateInstance = null;
34
35         /**
36          * Protected constructor
37          *
38          * @return      void
39          */
40         protected function __construct () {
41                 // Call parent constructor
42                 parent::__construct(__CLASS__);
43
44                 // Set prefix to 'Network'
45                 $this->setStatePrefix('Network');
46         }
47
48         /**
49          * Creates an instance of a resolver class with a given state
50          *
51          * @return      $resolverInstance                       The prepared state resolver instance
52          * @throws      EmptyVariableException          Thrown if default state is not set
53          * @throws      InvalidStateException   Thrown if default state is invalid
54          */
55         public final static function createNetworkStateResolver () {
56                 // Create the new instance
57                 $resolverInstance = new NetworkStateResolver();
58
59                 // Return the prepared instance
60                 return $resolverInstance;
61         }
62
63         /**
64          * Returns an state instance for a given package class
65          *
66          * @param       $packageInstance        An instance of a package class
67          * @param       $rawData                        The raw data
68          * @return      $stateInstance          An instance of the resolved state
69          * @todo        0%
70          */
71         public function resolveStateByPackage (Networkable $packageInstance, $rawData) {
72                 // Get error code
73                 $errorCode = $packageInstance->getErrorCode();
74
75                 // Is the code a number, then we have to change it
76                 if ($errorCode == 134) {
77                         // Transport endpoint not connected, should be handled else!
78                         $errorCode = BaseNetworkPackageHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT;
79                 } elseif (is_int($errorCode)) {
80                         // Debug output (because we might want to handle it like the above(s)
81                         $this->debugOutput(__METHOD__ . ': errorCode=' . $errorCode);
82
83                         // Change it only in this class
84                         $errorCode = BaseNetworkPackageHandler::SOCKET_ERROR_GENERAL;
85                 } // END - if
86
87                 $this->partialStub('errorCode='.$errorCode.',rawData[] = '.gettype($rawData).'('.strlen($rawData).')');
88         }
89 }
90
91 // [EOF]
92 ?>