<?php
// Own namespace
-namespace CoreFramework\Resolver\Controller;
+namespace CoreFramework\Resolver\Command;
+
+// Import framework stuff
+use CoreFramework\Command\Commandable;
+use CoreFramework\Command\InvalidCommandException;
+use CoreFramework\Factory\ObjectFactory;
+use CoreFramework\Generic\EmptyVariableException;
+use CoreFramework\Request\Requestable;
+use CoreFramework\Resolver\BaseResolver;
/**
* A generic command resolver class
$commandInstance = NULL;
// Create class name
- $className = $this->getCapitalizedClassPrefix() . self::convertToClassName($commandName) . 'Command';
+ $className = sprintf(
+ '%s\%s%sCommand',
+ $this->getNamespace(),
+ $this->getCapitalizedClassPrefix(),
+ self::convertToClassName($commandName)
+ );
// Create command class name
$this->setClassName($className);
* Returns an command instance for a given request class or null if
* it was not found
*
- * @param $requestInstance An instance of a request class
+ * @param $requestInstance An instance of a Requestable class
* @return $commandInstance An instance of the resolved command
* @throws InvalidCommandException Thrown if $commandName is
* invalid
} // END - if
// Check if command is valid
- if ($this->isCommandValid($commandName) === FALSE) {
+ if ($this->isCommandValid($this->getNamespace(), $commandName) === FALSE) {
// This command is invalid!
throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
} // END - if
/**
* Checks whether the given command is valid
*
+ * @param $namespace Namespace to look in
* @param $commandName The default command we shall execute
* @return $isValid Whether the given command is valid
* @throws EmptyVariableException Thrown if given command is not set
*/
- public function isCommandValid ($commandName) {
+ protected function isCommandValid ($namespace, $commandName) {
// By default nothing shall be valid
$isValid = FALSE;
- // Is a command set?
- if (empty($commandName)) {
+ // Is namespace and command name set?
+ if (empty($namespace)) {
+ // Then thrown an exception here
+ throw new EmptyVariableException(array($this, 'namespace'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ } elseif (empty($commandName)) {
// Then thrown an exception here
throw new EmptyVariableException(array($this, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
} // END - if
// Create the full class name
- $className = $this->getCapitalizedClassPrefix() . self::convertToClassName($commandName) . 'Command';
+ $className = sprintf(
+ '%s\%s%sCommand',
+ $namespace,
+ $this->getCapitalizedClassPrefix(),
+ self::convertToClassName($commandName)
+ );
// Now, let us create the full name of the command class
$this->setClassName($className);