3 namespace Org\Mxchange\CoreFramework\Resolver\Action;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
7 use Org\Mxchange\CoreFramework\Resolver\BaseResolver;
10 use \InvalidArgumentException;
13 * A generic action resolver class
15 * @author Roland Haeder <webmaster@shipsimu.org>
17 <<<<<<< HEAD:framework/main/classes/resolver/action/class_BaseActionResolver.php
18 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
20 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
21 >>>>>>> Some updates::inc/main/classes/resolver/action/class_BaseActionResolver.php
22 * @license GNU GPL 3.0 or any newer version
23 * @link http://www.shipsimu.org
25 * This program is free software: you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation, either version 3 of the License, or
28 * (at your option) any later version.
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program. If not, see <http://www.gnu.org/licenses/>.
38 abstract class BaseActionResolver extends BaseResolver {
40 * Validated action name
42 private $actionName = '';
45 * Protected constructor
47 * @param $className Name of the class
50 protected function __construct ($className) {
51 // Call parent constructor
52 parent::__construct($className);
56 * Setter for action name
58 * @param $actionName Last validated action name
61 protected final function setActionName ($actionName) {
62 $this->actionName = (string) $actionName;
66 * Getter for action name
68 * @return $actionName Last validated action name
70 public final function getActionName () {
71 return $this->actionName;
75 * Checks whether the given action is valid
77 * @param $namespace Namespace to look in
78 * @param $actionName The default action we shall execute
79 * @return $isValid Whether the given action is valid
80 * @throws InvalidArgumentException Thrown if given action is not set
82 public function isActionValid ($namespace, $actionName) {
83 // By default nothing shall be valid
87 if (empty($namespace)) {
88 // Then thrown an exception here
89 throw new InvalidArgumentException('Parameter "namespace" is empty');
90 } elseif (empty($actionName)) {
91 // Then thrown an exception here
92 throw new InvalidArgumentException('Parameter "actionName" is empty');
99 $this->getCapitalizedClassPrefix(),
100 self::convertToClassName($actionName)
103 // Now, let us create the full name of the action class
104 $this->setClassName($className);
106 // Is this class already loaded?
107 if (class_exists($this->getClassName())) {
108 // This class does exist. :-)
113 $this->setActionName($actionName);
120 * "Loads" current action and instances it if not yet cached
122 * @return $actionInstance A loaded action instance
124 protected function loadAction () {
125 // Init action instance
126 $actionInstance = NULL;
129 $className = sprintf(
131 $this->getNamespace(),
132 $this->getCapitalizedClassPrefix(),
133 self::convertToClassName($actionName)
137 $this->setClassName($className);
139 // Initiate the action
140 $actionInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this));
143 return $actionInstance;