+++ /dev/null
-<?php
-// Own namespace
-namespace CoreFramework\Resolver\Action;
-
-// Import framework stuff
-use CoreFramework\Factory\ObjectFactory;
-use CoreFramework\Generic\EmptyVariableException;
-use CoreFramework\Resolver\BaseResolver;
-
-/**
- * A generic action resolver class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @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
- * 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 <http://www.gnu.org/licenses/>.
- */
-class BaseActionResolver extends BaseResolver {
- /**
- * 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 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 whether the given action is valid
- *
- * @param $namespace Namespace to look in
- * @param $actionName The default action we shall execute
- * @return $isValid Whether the given action is valid
- * @throws EmptyVariableException Thrown if given action is not set
- */
- public function isActionValid ($namespace, $actionName) {
- // By default nothing shall be valid
- $isValid = FALSE;
-
- // Is a action set?
- if (empty($namespace)) {
- // Then thrown an exception here
- throw new EmptyVariableException(array($this, 'namespace'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
- } elseif (empty($actionName)) {
- // Then thrown an exception here
- throw new EmptyVariableException(array($this, 'actionName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
- } // END - if
-
- // Create class name
- $className = sprintf(
- '%s\%s%sAction',
- $namespace,
- $this->getCapitalizedClassPrefix(),
- self::convertToClassName($actionName)
- );
-
- // Now, let us create the full name of the action class
- $this->setClassName($className);
-
- // 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 class name
- $className = sprintf(
- '%s\%s%sAction',
- $this->getNamespace(),
- $this->getCapitalizedClassPrefix(),
- self::convertToClassName($actionName)
- );
-
- // ... and set it
- $this->setClassName($className);
-
- // Initiate the action
- $actionInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this));
-
- // Return the result
- return $actionInstance;
- }
-
-}