3 * A resolver for resolving states locally
5 * @author Roland Haeder <webmaster@ship-simu.org>
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
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.
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.
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/>.
24 class NetworkStateResolver extends BaseStateResolver implements StateResolver {
26 * Last successfull resolved state (name)
28 private $lastStateName = '';
31 * Last successfull resolved state (instance)
33 private $lastStateInstance = null;
36 * Protected constructor
40 protected function __construct () {
41 // Call parent constructor
42 parent::__construct(__CLASS__);
44 // Set prefix to 'Network'
45 $this->setStatePrefix('Network');
49 * Creates an instance of a resolver class with a given state
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
55 public final static function createNetworkStateResolver () {
56 // Create the new instance
57 $resolverInstance = new NetworkStateResolver();
59 // Return the prepared instance
60 return $resolverInstance;
64 * Returns an state instance for a given package class
66 * @param $packageInstance An instance of a package class
67 * @param $rawData The raw data
68 * @return $stateInstance An instance of the resolved state
71 public function resolveStateByPackage (Networkable $packageInstance, $rawData) {
73 $errorCode = $packageInstance->getErrorCode();
75 // Is the code a number, then we have to change it
76 if (($errorCode == 134) || ($errorCode == 107)) {
77 // Transport endpoint not connected, should be handled else!
78 // @TODO On some systems it is 134, on some 107?
79 $errorCode = BaseNetworkPackageHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT;
80 } elseif (is_int($errorCode)) {
81 // Debug output (because we might want to handle it like the above(s)
82 $this->debugOutput(__METHOD__ . ': UNKNOWN ERROR CODE = ' . $errorCode);
84 // Change it only in this class
85 $errorCode = BaseNetworkPackageHandler::SOCKET_ERROR_UNKNOWN;
88 $this->partialStub('errorCode='.$errorCode.',rawData[] = '.gettype($rawData).'('.strlen($rawData).')');