/**
* A generic state resolver class
*
- * @author Roland Haeder <webmaster@ship-simu.org>
+ * @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
+ * @link http://www.shipsimu.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/**
* "Loads" a given state and instances it if not yet cached. If the
- * state was not found an InvalidStateException is thrown
+ * state was not found an UnresolveableStateException is thrown
*
* @param $stateName A state name we shall look for
* @return $stateInstance A loaded state instance
- * @throws InvalidStateException Thrown if even the requested
- * state class is missing (bad!)
+ * @throws UnresolveableStateException Thrown if even the requested
+ * state class is missing (bad!)
*/
protected function loadState ($stateName) {
// Init state instance
- $stateInstance = null;
+ $stateInstance = NULL;
// Create state class name
- $className = $this->getStatePrefix() . '' . $this->convertToClassName($stateName) . 'State';
+ $className = $this->getStatePrefix() . '' . self::convertToClassName($stateName) . 'State';
// ... and set it
$this->setClassName($className);
// Is this class loaded?
if (!class_exists($this->getClassName())) {
// Throw an exception here
- throw new InvalidStateException(array($this, $stateName), self::EXCEPTION_INVALID_STATE);
+ throw new UnresolveableStateException(array($this, $stateName), self::EXCEPTION_INVALID_STATE);
} // END - if
// Initialize the state
}
/**
- * Checks wether the given state is valid
+ * Checks whether the given state is valid
*
* @param $stateName The default state we shall execute
- * @return $isValid Wether the given state is valid
+ * @return $isValid Whether the given state is valid
* @throws EmptyVariableException Thrown if given state is not set
* @throws DefaultStateException Thrown if default state was not found
*/
public function isStateValid ($stateName) {
// By default nothing shall be valid
- $isValid = false;
+ $isValid = FALSE;
// Is a state set?
if (empty($stateName)) {
} // END - if
// Create class name
- $className = $this->statePrefix . $this->convertToClassName($stateName) . 'State';
+ $className = $this->statePrefix . self::convertToClassName($stateName) . 'State';
// Now, let us create the full name of the state class
$this->setClassName($className);
// Try it hard to get an state
- while ($isValid === false) {
+ while ($isValid === FALSE) {
// Is this class already loaded?
if (class_exists($this->getClassName())) {
// This class does exist. :-)
- $isValid = true;
- } elseif ($this->getClassName() != $this->statePrefix.'DefaultNewsState') {
+ $isValid = TRUE;
+ } elseif ($this->getClassName() != $this->statePrefix . 'DefaultState') {
// Set default state
- $this->setClassName($this->statePrefix . 'DefaultNewsState');
+ $this->setClassName($this->statePrefix . 'DefaultState');
} else {
// All is tried, give it up here
throw new DefaultStateException($this, self::EXCEPTION_DEFAULT_STATE_GONE);