X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Fresolver%2Faction%2Fclass_BaseActionResolver.php;h=6123b9719344fc7ea42c3481c65534378b9fb1ec;hp=58996de9a07894b275ec4ffa668b4e4d7ae2693f;hb=HEAD;hpb=a60894f1d6ef33613d2d0351075aa07aa257f304 diff --git a/framework/main/classes/resolver/action/class_BaseActionResolver.php b/framework/main/classes/resolver/action/class_BaseActionResolver.php index 58996de9..a266d2e1 100644 --- a/framework/main/classes/resolver/action/class_BaseActionResolver.php +++ b/framework/main/classes/resolver/action/class_BaseActionResolver.php @@ -3,8 +3,10 @@ namespace Org\Mxchange\CoreFramework\Resolver\Action; // Import framework stuff -use Org\Mxchange\CoreFramework\Factory\ObjectFactory; +use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory; +use Org\Mxchange\CoreFramework\Generic\FrameworkInterface; use Org\Mxchange\CoreFramework\Resolver\BaseResolver; +use Org\Mxchange\CoreFramework\Utils\Strings\StringUtils; // Import SPL stuff use \InvalidArgumentException; @@ -14,7 +16,7 @@ use \InvalidArgumentException; * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.shipsimu.org * @@ -43,7 +45,7 @@ abstract 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); } @@ -54,8 +56,8 @@ abstract 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; } /** @@ -75,17 +77,14 @@ abstract class BaseActionResolver extends BaseResolver { * @return $isValid Whether the given action is valid * @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 InvalidArgumentException('Parameter "namespace" is empty'); + throw new InvalidArgumentException('Parameter "namespace" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } elseif (empty($actionName)) { // Then thrown an exception here - throw new InvalidArgumentException('Parameter "actionName" is empty'); + throw new InvalidArgumentException('Parameter "actionName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } // Create class name @@ -93,20 +92,20 @@ abstract class BaseActionResolver extends BaseResolver { '%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; @@ -126,14 +125,14 @@ abstract 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;