* @version 0.0.0 * @copyright Copyright (c) 2007 - 2009 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.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 * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ class BaseActionResolver extends BaseResolver { /** * Prefix for local, remote or other resolver */ private $actionPrefix = ''; /** * Validated action name */ private $actionName = ''; /** * Protected constructor * * @param $className Name of the class * @return void */ protected function __construct ($className) { // Call parent constructor parent::__construct($className); } /** * Setter for action prefix * * @param $actionPrefix Last validated actionPrefix * @return void */ protected final function setActionPrefix ($actionPrefix) { $this->actionPrefix = $actionPrefix; } /** * Setter for action name * * @param $actionName Last validated action name * @return void */ protected final function setActionName ($actionName) { $this->actionName = (string) $actionName; } /** * Getter for action name * * @return $actionName Last validated action name */ public final function getActionName () { return $this->actionName; } /** * Checks wether the given action is valid * * @param $actionName The default action we shall execute * @return $isValid Wether the given action is valid * @throws EmptyVariableException Thrown if given action is not set */ public function isActionValid ($actionName) { // By default nothing shall be valid $isValid = false; // Is a action set? if (empty($actionName)) { // Then thrown an exception here throw new EmptyVariableException(array($this, 'actionName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); } // END - if // Now, let us create the full name of the action class $this->setClassName(sprintf("%s%sAction", $this->actionPrefix, $this->convertToClassName($actionName) )); // Is this class already loaded? if (class_exists($this->getClassName())) { // This class does exist. :-) $isValid = true; } // END - if // Set action name $this->setActionName($actionName); // Return the result return $isValid; } /** * "Loads" current action and instances it if not yet cached * * @return $actionInstance A loaded action instance */ protected function loadAction () { // Init action instance $actionInstance = null; // Create action class name $this->setClassName(sprintf("Web%sAction", $this->convertToClassName($this->getActionName()) )); // Initiate the action $actionInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this)); // Return the result return $actionInstance; } } // [EOF] ?>