parent::__construct(__CLASS__);
// Set part description
- $this->setObjectDescription("Lokaler Kommandoauflöser");
+ $this->setObjectDescription("Resolver for local web commands");
// Create unique ID number
$this->createUniqueID();
- // Clean up a little
- $this->removeNumberFormaters();
- $this->removeSystemArray();
-
// Set prefix to "Web"
$this->setCommandPrefix("Web");
}
/**
* Creates an instance of a Web command resolver with a given default command
*
- * @param $defaultCommand The default command we shall execute
+ * @param $commandName The default command we shall execute
* @param $appInstance An instance of a manageable application helper class
* @return $resolverInstance The prepared command resolver instance
* @throws EmptyVariableException Thrown if the default command is not set
* @throws InvalidCommandException Thrown if the default command is invalid
*/
- public final static function createWebCommandResolver ($defaultCommand, ManageableApplication $appInstance) {
+ public final static function createWebCommandResolver ($commandName, ManageableApplication $appInstance) {
// Create the new instance
$resolverInstance = new WebCommandResolver();
- // Is the variable $defaultCommand set and the command is valid?
- if (empty($defaultCommand)) {
+ // Is the variable $commandName set and the command is valid?
+ if (empty($commandName)) {
// Then thrown an exception here
throw new EmptyVariableException(array($resolverInstance, 'defaultCommand'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
- } elseif (!$resolverInstance->isCommandValid($defaultCommand)) {
+ } elseif (!$resolverInstance->isCommandValid($commandName)) {
// Invalid command found
- throw new InvalidCommandException(array($resolverInstance, $defaultCommand), self::EXCEPTION_INVALID_COMMAND);
+ throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND);
}
// Set the application instance
// Test if the required parameter is set
try {
// This goes fine so let's resolv the command
- $commandName = $requestInstance->getRequestElement($this->getConfigInstance()->readConfig("command_parameter"));
+ $commandName = $requestInstance->getRequestElement($this->getConfigInstance()->readConfig('command_parameter'));
// Is the command empty? Then fall back to default command
- if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig("default_command");
+ if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_command');
// Check if the command is valid
if (!$this->isCommandValid($commandName)) {
return $commandInstance;
}
+ /**
+ * Resolves the command by its direct name and returns an instance of its class
+ *
+ * @param $commandName The direct command name we shall resolve
+ * @return $commandInstance An instance of the command class
+ * @throws InvalidCommandException Thrown if $commandName is invalid
+ */
+ public function resolveCommand ($commandName) {
+ // Initiate the instance variable
+ $commandInstance = null;
+
+ // Is the command empty? Then fall back to default command
+ if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_command');
+
+ // Check if the command is valid
+ if (!$this->isCommandValid($commandName)) {
+ // This command is invalid!
+ throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
+ }
+
+ // Get the command
+ $commandInstance = $this->loadCommand($commandName);
+
+ // Return the instance
+ return $commandInstance;
+ }
+
/**
* "Loads" a given command and instances it if not yet cached
*
*/
private function loadCommand ($commandName) {
// Cache default command
- $defaultCommand = $this->getConfigInstance()->readConfig("default_command");
+ $defaultCommand = $this->getConfigInstance()->readConfig('default_command');
// Init command instance
$commandInstance = null;
// Create command class name
- $class = sprintf("Web%sCommand",
- ucfirst(strtolower($commandName))
+ $className = sprintf("Web%sCommand",
+ $this->convertToClassName($commandName)
);
// Is this class loaded?
- if (!class_exists($class)) {
+ if (!class_exists($className)) {
// Class not found, so try the default one or throw exception
if ($commandName != $defaultCommand) {
// Try the default command
// Initiate the command
$eval = sprintf("\$commandInstance = %s::create%s(\$this);",
- $class,
- $class
+ $className,
+ $className
);
// Run the command