3 namespace CoreFramework\Resolver\Action;
6 * A generic action resolver class
8 * @author Roland Haeder <webmaster@shipsimu.org>
10 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
11 * @license GNU GPL 3.0 or any newer version
12 * @link http://www.shipsimu.org
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 class BaseActionResolver extends BaseResolver {
29 * Validated action name
31 private $actionName = '';
34 * Protected constructor
36 * @param $className Name of the class
39 protected function __construct ($className) {
40 // Call parent constructor
41 parent::__construct($className);
45 * Setter for action name
47 * @param $actionName Last validated action name
50 protected final function setActionName ($actionName) {
51 $this->actionName = (string) $actionName;
55 * Getter for action name
57 * @return $actionName Last validated action name
59 public final function getActionName () {
60 return $this->actionName;
64 * Checks whether the given action is valid
66 * @param $actionName The default action we shall execute
67 * @return $isValid Whether the given action is valid
68 * @throws EmptyVariableException Thrown if given action is not set
70 public function isActionValid ($actionName) {
71 // By default nothing shall be valid
75 if (empty($actionName)) {
76 // Then thrown an exception here
77 throw new EmptyVariableException(array($this, 'actionName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
81 $className = $this->getCapitalizedClassPrefix() . self::convertToClassName($actionName) . 'Action';
83 // Now, let us create the full name of the action class
84 $this->setClassName($className);
86 // Is this class already loaded?
87 if (class_exists($this->getClassName())) {
88 // This class does exist. :-)
93 $this->setActionName($actionName);
100 * "Loads" current action and instances it if not yet cached
102 * @return $actionInstance A loaded action instance
104 protected function loadAction () {
105 // Init action instance
106 $actionInstance = NULL;
108 // Create action class name
109 $className = $this->getCapitalizedClassPrefix() . self::convertToClassName($this->getActionName()) . 'Action';
112 $this->setClassName($className);
114 // Initiate the action
115 $actionInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this));
118 return $actionInstance;