]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/resolver/command/class_BaseCommandResolver.php
Refacuring:
[core.git] / framework / main / classes / resolver / command / class_BaseCommandResolver.php
index bb1b096516ca6c35a327de6d369e1e9b55d37fae..9d5177aa4575fe5eb5c4b5e3bc1c55c52d86f84b 100644 (file)
@@ -100,7 +100,7 @@ abstract class BaseCommandResolver extends BaseResolver {
                if (!class_exists($this->getClassName())) {
                        // Class not found, so throw an exception
                        throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
-               } // END - if
+               }
 
                // Initiate the command
                $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this));
@@ -120,22 +120,21 @@ abstract class BaseCommandResolver extends BaseResolver {
         */
        public function resolveCommandByRequest (Requestable $requestInstance) {
                // Init variables
-               $commandName = '';
-               $commandInstance = NULL;
-
-               // This goes fine so let's resolve the command
                $commandName = $requestInstance->getRequestElement('command');
+               $commandType = FrameworkBootstrap::getRequestTypeFromSystem();
+               $commandInstance = NULL;
 
                // Is the command empty? Then fall back to default command
                if (empty($commandName)) {
-                       $commandName = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('default_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_command');
-               } // END - if
+                       // Fall back to default command
+                       $commandName = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry(sprintf('default_%s_command', $commandType));
+               }
 
                // Check if command is valid
                if ($this->isCommandValid($this->getNamespace(), $commandName) === false) {
                        // This command is invalid!
                        throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
-               } // END - if
+               }
 
                // Get the command
                $commandInstance = $this->loadCommand($commandName);
@@ -144,11 +143,14 @@ abstract class BaseCommandResolver extends BaseResolver {
                if ((!is_object($commandInstance)) || (!$commandInstance instanceof Commandable)) {
                        // This command has an invalid instance!
                        throw new UnexpectedValueException(sprintf('commandInstance for commandName=%s is not object (%s) or does not implement Commandable.', $commandName, gettype($commandInstance)), self::EXCEPTION_INVALID_COMMAND);
-               } // END - if
+               }
 
                // Set last command
                $this->setResolvedInstance($commandInstance);
 
+               // Init template engine
+               $commandInstance->initTemplateEngine($commandType);
+
                // Return the resolved command instance
                return $commandInstance;
        }
@@ -161,7 +163,7 @@ abstract class BaseCommandResolver extends BaseResolver {
         * @return      $commandInstance        An instance of the command class
         * @throws      InvalidCommandException         Thrown if $commandName is invalid
         */
-       public function resolveCommand ($namespace, $commandName) {
+       public function resolveCommand (string $namespace, string $commandName) {
                // Is a action set?
                if (empty($namespace)) {
                        // Then thrown an exception here
@@ -173,22 +175,26 @@ abstract class BaseCommandResolver extends BaseResolver {
 
                // Initiate the instance variable
                $commandInstance = NULL;
+               $commandType = FrameworkBootstrap::getRequestTypeFromSystem();
 
                // Is the command empty? Then fall back to default command
                if (empty($commandName)) {
                        // Init default command
-                       $commandName = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('default_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_command');
-               } // END - if
+                       $commandName = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry(sprintf('default_%s_command', $commandType));
+               }
 
                // Check if command is valid
                if ($this->isCommandValid($namespace, $commandName) === false) {
                        // This command is invalid!
                        throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
-               } // END - if
+               }
 
                // Get the command
                $commandInstance = $this->loadCommand($commandName);
 
+               // Init template engine
+               $commandInstance->initTemplateEngine($commandType);
+
                // Return the instance
                return $commandInstance;
        }
@@ -201,7 +207,7 @@ abstract class BaseCommandResolver extends BaseResolver {
         * @return      $isValid                Whether the given command is valid
         * @throws      InvalidArgumentException        Thrown if given command is not set
         */
-       protected function isCommandValid ($namespace, $commandName) {
+       protected function isCommandValid (string $namespace, string $commandName) {
                // Is namespace and command name set?
                if (empty($namespace)) {
                        // Then thrown an exception here
@@ -229,7 +235,7 @@ abstract class BaseCommandResolver extends BaseResolver {
                if (class_exists($this->getClassName())) {
                        // This class does exist. :-)
                        $isValid = true;
-               } // END - if
+               }
 
                // Set command name
                $this->setCommandName($commandName);