<?php
/**
- * A command resolver for local (non-hubbed) commands
+ * A command resolver for local (non-hubbed) web commands
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
/**
* Last successfull resolved command
*/
- private $lastCommandInstance = "";
+ private $lastCommandInstance = null;
/**
* Protected constructor
// Call parent constructor
parent::__construct(__CLASS__);
- // Set part description
- $this->setObjectDescription("Resolver for local web commands");
-
- // Create unique ID number
- $this->generateUniqueId();
-
// Set prefix to "Web"
$this->setCommandPrefix("Web");
}
// 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($commandName)) {
+ throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ } elseif ($resolverInstance->isCommandValid($commandName) === false) {
// Invalid command found
throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND);
}
$commandName = $requestInstance->getRequestElement('page');
// 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_web_command');
// Check if the command is valid
- if (!$this->isCommandValid($commandName)) {
+ if ($this->isCommandValid($commandName) === false) {
// This command is invalid!
throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
} // END - if
$commandInstance = null;
// 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_web_command');
// Check if the command is valid
- if (!$this->isCommandValid($commandName)) {
+ if ($this->isCommandValid($commandName) === false) {
// This command is invalid!
throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
}
*/
private function loadCommand ($commandName) {
// Cache default command
- $defaultCommand = $this->getConfigInstance()->readConfig('default_command');
+ $defaultCommand = $this->getConfigInstance()->readConfig('default_web_command');
// Init command instance
$commandInstance = null;
// Create command class name
- $className = sprintf("Web%sCommand",
+ $this->setClassName(sprintf("Web%sCommand",
$this->convertToClassName($commandName)
- );
+ ));
// Is this class loaded?
- if (!class_exists($className)) {
- // Class not found, so try the default one or throw exception
- if ($commandName != $defaultCommand) {
- // Try the default command
- return $this->loadCommand($defaultCommand);
- } else {
- // Still not found?
- throw new InvalidCommandException(array($this, $defaultCommand), self::EXCEPTION_INVALID_COMMAND);
- }
+ if (!class_exists($this->getClassName())) {
+ // Class not found, so throw an exception
+ throw new InvalidCommandException(array($this, $defaultCommand), self::EXCEPTION_INVALID_COMMAND);
} // END - if
// Initiate the command
- $commandInstance = ObjectFactory::createObjectByName($className, array($this));
+ $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this));
// Return the result
return $commandInstance;