3 namespace CoreFramework\Resolver\Action;
5 // Import framework stuff
6 use CoreFramework\Factory\ObjectFactory;
7 use CoreFramework\Resolver\BaseResolver;
10 * A generic action resolver class
12 * @author Roland Haeder <webmaster@shipsimu.org>
14 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
15 * @license GNU GPL 3.0 or any newer version
16 * @link http://www.shipsimu.org
18 * This program is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 class BaseActionResolver extends BaseResolver {
33 * Validated action name
35 private $actionName = '';
38 * Protected constructor
40 * @param $className Name of the class
43 protected function __construct ($className) {
44 // Call parent constructor
45 parent::__construct($className);
49 * Setter for action name
51 * @param $actionName Last validated action name
54 protected final function setActionName ($actionName) {
55 $this->actionName = (string) $actionName;
59 * Getter for action name
61 * @return $actionName Last validated action name
63 public final function getActionName () {
64 return $this->actionName;
68 * Checks whether the given action is valid
70 * @param $namespace Namespace to look in
71 * @param $actionName The default action we shall execute
72 * @return $isValid Whether the given action is valid
73 * @throws EmptyVariableException Thrown if given action is not set
75 public function isActionValid ($namespace, $actionName) {
76 // By default nothing shall be valid
80 if (empty($namespace)) {
81 // Then thrown an exception here
82 throw new EmptyVariableException(array($this, 'namespace'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
83 } elseif (empty($actionName)) {
84 // Then thrown an exception here
85 throw new EmptyVariableException(array($this, 'actionName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
92 $this->getCapitalizedClassPrefix(),
93 self::convertToClassName($actionName)
96 // Now, let us create the full name of the action class
97 $this->setClassName($className);
99 // Is this class already loaded?
100 if (class_exists($this->getClassName())) {
101 // This class does exist. :-)
106 $this->setActionName($actionName);
113 * "Loads" current action and instances it if not yet cached
115 * @return $actionInstance A loaded action instance
117 protected function loadAction () {
118 // Init action instance
119 $actionInstance = NULL;
122 $className = sprintf(
124 $this->getNamespace(),
125 $this->getCapitalizedClassPrefix(),
126 self::convertToClassName($actionName)
130 $this->setClassName($className);
132 // Initiate the action
133 $actionInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this));
136 return $actionInstance;