]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/resolver/action/class_BaseActionResolver.php
Continued:
[core.git] / framework / main / classes / resolver / action / class_BaseActionResolver.php
index 238267b2e98d9c3e4921d0e0f4f59dc2ce9625e6..2832256d67a66582088834eeeb9797a6bfbb6f5e 100644 (file)
@@ -1,18 +1,21 @@
 <?php
 // Own namespace
-namespace CoreFramework\Resolver\Action;
+namespace Org\Mxchange\CoreFramework\Resolver\Action;
 
 // Import framework stuff
-use CoreFramework\Factory\ObjectFactory;
-use CoreFramework\Generic\EmptyVariableException;
-use CoreFramework\Resolver\BaseResolver;
+use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Resolver\BaseResolver;
+use Org\Mxchange\CoreFramework\Utils\Strings\StringUtils;
+
+// Import SPL stuff
+use \InvalidArgumentException;
 
 /**
  * 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
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2022 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -29,7 +32,7 @@ use CoreFramework\Resolver\BaseResolver;
  * 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 {
+abstract class BaseActionResolver extends BaseResolver {
        /**
         * Validated action name
         */
@@ -41,7 +44,7 @@ class BaseActionResolver extends BaseResolver {
         * @param       $className      Name of the class
         * @return      void
         */
-       protected function __construct ($className) {
+       protected function __construct (string $className) {
                // Call parent constructor
                parent::__construct($className);
        }
@@ -52,8 +55,8 @@ class BaseActionResolver extends BaseResolver {
         * @param       $actionName     Last validated action name
         * @return      void
         */
-       protected final function setActionName ($actionName) {
-               $this->actionName = (string) $actionName;
+       protected final function setActionName (string $actionName) {
+               $this->actionName = $actionName;
        }
 
        /**
@@ -71,40 +74,37 @@ class BaseActionResolver extends BaseResolver {
         * @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
+        * @throws      InvalidArgumentException        Thrown if given action is not set
         */
-       public function isActionValid ($namespace, $actionName) {
-               // By default nothing shall be valid
-               $isValid = FALSE;
-
+       public function isActionValid (string $namespace, string $actionName) {
                // Is a action set?
                if (empty($namespace)) {
                        // Then thrown an exception here
-                       throw new EmptyVariableException(array($this, 'namespace'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+                       throw new InvalidArgumentException('Parameter "namespace" is empty');
                } elseif (empty($actionName)) {
                        // Then thrown an exception here
-                       throw new EmptyVariableException(array($this, 'actionName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
-               } // END - if
+                       throw new InvalidArgumentException('Parameter "actionName" is empty');
+               }
 
                // Create class name
                $className = sprintf(
                        '%s\%s%sAction',
                        $namespace,
                        $this->getCapitalizedClassPrefix(),
-                       self::convertToClassName($actionName)
+                       StringUtils::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
+               $isValid = class_exists($this->getClassName());
 
-               // Set action name
-               $this->setActionName($actionName);
+               // Is it valid?
+               if ($isValid) {
+                       // Set action name
+                       $this->setActionName($actionName);
+               }
 
                // Return the result
                return $isValid;
@@ -124,14 +124,14 @@ class BaseActionResolver extends BaseResolver {
                        '%s\%s%sAction',
                        $this->getNamespace(),
                        $this->getCapitalizedClassPrefix(),
-                       self::convertToClassName($actionName)
+                       StringUtils::convertToClassName($actionName)
                );
 
                // ... and set it
                $this->setClassName($className);
 
                // Initiate the action
-               $actionInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this));
+               $actionInstance = ObjectFactory::createObjectByName($this->getClassName(), [$this]);
 
                // Return the result
                return $actionInstance;