$helperInstance = new ConsoleTools();
// First get a socket
+ // @TODO Add some DNS caching here
$socket = fsockopen('188.138.90.169', 80, $errorNo, $errorStr, 5);
// Check if there was an error else
// Prepare the GET request
$request = 'GET /ip.php HTTP/1.0' . self::HTTP_EOL;
- $request .= 'Host: www.ship-simu.org' . self::HTTP_EOL;
+ $request .= 'Host: ship-simu.org' . self::HTTP_EOL;
$request .= 'User-Agent: ' . self::HTTP_USER_AGENT . self::HTTP_EOL;
$request .= 'Connection: close' . self::HTTP_EOL;
$request .= self::HTTP_EOL;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class BaseActionResolver extends BaseResolver {
- /**
- * Prefix for local, remote or other resolver
- */
- private $actionPrefix = '';
-
/**
* Validated action name
*/
parent::__construct($className);
}
- /**
- * Setter for action prefix
- *
- * @param $actionPrefix Last validated actionPrefix
- * @return void
- */
- protected final function setActionPrefix ($actionPrefix) {
- $this->actionPrefix = $actionPrefix;
- }
-
/**
* Setter for action name
*
} // END - if
// Create class name
- $className = $this->actionPrefix . $this->convertToClassName($actionName) . 'Action';
+ $className = $this->getClassPrefix() . $this->convertToClassName($actionName) . 'Action';
// Now, let us create the full name of the action class
$this->setClassName($className);
$actionInstance = null;
// Create action class name
- $className = $this->actionPrefix . $this->convertToClassName($this->getActionName()) . 'Action';
+ $className = $this->getClassPrefix() . $this->convertToClassName($this->getActionName()) . 'Action';
// ... and set it
$this->setClassName($className);
/**
* Last successfull resolved action
*/
- private $lastActionInstance = '';
+ private $lastActionInstance = null;
/**
* Protected constructor
parent::__construct(__CLASS__);
// Set prefix to "Web"
- $this->setActionPrefix("Web");
+ $this->setClassPrefix('Web');
}
/**
$actionName = $requestInstance->getRequestElement('action');
// Is the action empty? Then fall back to default action
- if (empty($actionName)) $actionName = $this->getConfigInstance()->getConfigEntry('default_action');
+ if (empty($actionName)) {
+ $actionName = $this->getConfigInstance()->getConfigEntry('default_action');
+ } // END - if
// Check if action is valid
if ($this->isActionValid($actionName) === false) {
} // END - if
// Set last action
- $this->lastActionInstance = $actionInstance;
+ $this->setResolvedInstance($actionInstance);
// Return the resolved action instance
return $actionInstance;
$actionName = $this->getActionName();
// Is the action empty? Then fall back to default action
- if (empty($actionName)) $actionName = $this->getConfigInstance()->getConfigEntry('default_action');
+ if (empty($actionName)) {
+ $actionName = $this->getConfigInstance()->getConfigEntry('default_action');
+ } // END - if
// Check if action is valid
if ($this->isActionValid($actionName) === false) {
// This action is invalid!
throw new InvalidActionException(array($this, $actionName), self::EXCEPTION_INVALID_ACTION);
- }
+ } // END - if
// Get the action
$actionInstance = $this->loadAction();
*/
private $className = '';
+ /**
+ * Prefix for class
+ */
+ private $classPrefix = '';
+
+ /**
+ * (Last) resolved instance
+ */
+ private $resolvedInstance = null;
+
// Exception constants
const EXCEPTION_INVALID_COMMAND = 0x1d0;
const EXCEPTION_INVALID_CONTROLLER = 0x1d1;
parent::__construct($className);
}
+ /**
+ * Getter for class name
+ *
+ * @return $className Name of the class
+ */
+ public final function getClassName () {
+ return $this->className;
+ }
+
/**
* Setter for class name
*
* @return void
*/
protected final function setClassName ($className) {
- $this->className = $className;
+ $this->className = (string) $className;
}
/**
- * Getter for class name
+ * Getter for class prefix
*
- * @return $className Name of the class
+ * @return $classPrefix Last validated classPrefix
*/
- public final function getClassName () {
- return $this->className;
+ protected final function getClassPrefix () {
+ return $this->classPrefix;
+ }
+
+ /**
+ * Setter for class prefix
+ *
+ * @param $classPrefix Last validated classPrefix
+ * @return void
+ */
+ protected final function setClassPrefix ($classPrefix) {
+ $this->classPrefix = (string) $classPrefix;
+ }
+
+ /**
+ * Getter for (last) resolved instance
+ *
+ * @return $resolvedInstance Last validated resolvedInstance
+ */
+ protected final function getResolvedInstance () {
+ return $this->resolvedInstance;
+ }
+
+ /**
+ * Setter for (last) resolved instance
+ *
+ * @param $resolvedInstance (Last) validated resolved instance
+ * @return void
+ */
+ protected final function setResolvedInstance (FrameworkInterface $resolvedInstance) {
+ $this->resolvedInstance = $resolvedInstance;
}
}
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class BaseCommandResolver extends BaseResolver {
- /**
- * Prefix for local, remote or other resolver
- */
- private $commandPrefix = '';
-
/**
* Validated command name
*/
parent::__construct($className);
}
- /**
- * Getter for command prefix
- *
- * @return $commandPrefix Last validated commandPrefix
- */
- protected final function getCommandPrefix () {
- return $this->commandPrefix;
- }
-
- /**
- * Setter for command prefix
- *
- * @param $commandPrefix Last validated commandPrefix
- * @return void
- */
- protected final function setCommandPrefix ($commandPrefix) {
- $this->commandPrefix = $commandPrefix;
- }
-
/**
* Setter for command name
*
} // END - if
// Create the full class name
- $className = $this->getCommandPrefix() . $this->convertToClassName($commandName) . 'Command';
+ $className = $this->getClassPrefix() . $this->convertToClassName($commandName) . 'Command';
// Now, let us create the full name of the command class
$this->setClassName($className);
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class ConsoleCommandResolver extends BaseCommandResolver implements CommandResolver {
- /**
- * Last successfull resolved command
- */
- private $lastCommandInstance = null;
-
/**
* Protected constructor
*
parent::__construct(__CLASS__);
// Set prefix to "Console"
- $this->setCommandPrefix('Console');
+ $this->setClassPrefix('Console');
}
/**
$commandName = $requestInstance->getRequestElement('command');
// Is the command empty? Then fall back to default command
- if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_console_command');
+ if (empty($commandName)) {
+ $commandName = $this->getConfigInstance()->getConfigEntry('default_console_command');
+ } // END - if
// Check if command is valid
if ($this->isCommandValid($commandName) === false) {
} // END - if
// Set last command
- $this->lastCommandInstance = $commandInstance;
+ $this->setResolvedInstance($commandInstance);
// Return the resolved command instance
return $commandInstance;
$commandInstance = null;
// Is the command empty? Then fall back to default command
- if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_console_command');
+ if (empty($commandName)) {
+ $commandName = $this->getConfigInstance()->getConfigEntry('default_console_command');
+ } // END - if
// Check if command is valid
if ($this->isCommandValid($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);
$commandInstance = null;
// Create class name
- $className = $this->getCommandPrefix() . $this->convertToClassName($commandName) . 'Command';
+ $className = $this->getClassPrefix() . $this->convertToClassName($commandName) . 'Command';
// Create command class name
$this->setClassName($className);
parent::__construct(__CLASS__);
// Set prefix to "Image"
- $this->setCommandPrefix('Image');
+ $this->setClassPrefix('Image');
}
/**
$commandName = $requestInstance->getRequestElement('page');
// Is the command empty? Then fall back to default command
- if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_image_command');
+ if (empty($commandName)) {
+ $commandName = $this->getConfigInstance()->getConfigEntry('default_image_command');
+ } // END - if
// Check if command is valid
if ($this->isCommandValid($commandName) === false) {
} // END - if
// Set last command
- $this->lastCommandInstance = $commandInstance;
+ $this->setResolvedInstance($commandInstance);
// Return the resolved command instance
return $commandInstance;
$commandInstance = null;
// Is the command empty? Then fall back to default command
- if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_image_command');
+ if (empty($commandName)) {
+ $commandName = $this->getConfigInstance()->getConfigEntry('default_image_command');
+ } // END - if
// Check if command is valid
if ($this->isCommandValid($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);
$commandInstance = null;
// Create class name
- $className = $this->getCommandPrefix() . $this->convertToClassName($commandName) . 'Command';
+ $className = $this->getClassPrefix() . $this->convertToClassName($commandName) . 'Command';
// Is this class loaded?
if (!class_exists($this->getClassName())) {
parent::__construct(__CLASS__);
// Set prefix to "Web"
- $this->setCommandPrefix('Web');
+ $this->setClassPrefix('Web');
}
/**
$commandName = $requestInstance->getRequestElement('page');
// Is the command empty? Then fall back to default command
- if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_web_command');
+ if (empty($commandName)) {
+ $commandName = $this->getConfigInstance()->getConfigEntry('default_web_command');
+ } // END - if
// Check if command is valid
if ($this->isCommandValid($commandName) === false) {
} // END - if
// Set last command
- $this->lastCommandInstance = $commandInstance;
+ $this->setResolvedInstance($commandInstance);
// Return the resolved command instance
return $commandInstance;
$commandInstance = null;
// Is the command empty? Then fall back to default command
- if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_web_command');
+ if (empty($commandName)) {
+ $commandName = $this->getConfigInstance()->getConfigEntry('default_web_command');
+ } // END - if
// Check if command is valid
if ($this->isCommandValid($commandName) === false) {
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class BaseControllerResolver extends BaseResolver {
- /**
- * Prefix for local, remote or other resolver
- */
- private $controllerPrefix = '';
-
/**
* Validated controller name
*/
parent::__construct($className);
}
- /**
- * Setter for controller prefix
- *
- * @param $controllerPrefix Last validated controllerPrefix
- * @return void
- */
- protected final function setControllerPrefix ($controllerPrefix) {
- $this->controllerPrefix = $controllerPrefix;
- }
-
- /**
- * Getter for controller prefix
- *
- * @param $controllerPrefix Last validated controllerPrefix
- * @return void
- */
- protected final function getControllerPrefix () {
- return $this->controllerPrefix;
- }
-
/**
* Setter for controller name
*
*/
protected function loadController ($controllerName) {
// Cache default command
- $defaultController = $this->getConfigInstance()->getConfigEntry('default_' . strtolower($this->getControllerPrefix()) . '_command');
+ $defaultController = $this->getConfigInstance()->getConfigEntry('default_' . strtolower($this->getClassPrefix()) . '_command');
// Init controller instance
$controllerInstance = null;
// Default controller
- $this->setClassName($this->getControllerPrefix() . 'DefaultNewsController');
+ $this->setClassName($this->getClassPrefix() . 'DefaultNewsController');
// Generate the class name
//* DEBUG: */ echo __METHOD__.": Controller=".$controllerName;
if ($controllerName != $defaultController) {
// Create controller class name
- $className = $this->getControllerPrefix() . '' . $this->convertToClassName($controllerName) . 'Controller';
+ $className = $this->getClassPrefix() . $this->convertToClassName($controllerName) . 'Controller';
// ... and set it
$this->setClassName($className);
} else {
// No news at main command or non-news command
- $this->setClassName($this->getControllerPrefix() . 'DefaultNewsController');
+ $this->setClassName($this->getClassPrefix() . 'DefaultNewsController');
}
//* DEBUG: */ echo ", controller=".$this->getClassName()."<br />\n";
$resolverConfigEntry = '';
// Try to read a config entry for our resolver including controller name... ;-)
- $resolverConfigEntry = sprintf("%s_cmd_%s_resolver_class", strtolower($this->getControllerPrefix()), strtolower($controllerName));
+ $resolverConfigEntry = sprintf("%s_cmd_%s_resolver_class", strtolower($this->getClassPrefix()), strtolower($controllerName));
// Get the config, this will throw an exception if there is no special command resolver
$resolverClass = $this->getConfigInstance()->getConfigEntry($resolverConfigEntry);
} // END - if
// Create class name
- $className = $this->controllerPrefix . $this->convertToClassName($controllerName) . 'Controller';
+ $className = $this->getClassPrefix() . $this->convertToClassName($controllerName) . 'Controller';
// Now, let us create the full name of the controller class
$this->setClassName($className);
if (class_exists($this->getClassName())) {
// This class does exist. :-)
$isValid = true;
- } elseif ($this->getClassName() != $this->controllerPrefix.'DefaultNewsController') {
+ } elseif ($this->getClassName() != $this->getClassPrefix() . 'DefaultNewsController') {
// Set default controller
- $this->setClassName($this->controllerPrefix . 'DefaultNewsController');
+ $this->setClassName($this->getClassPrefix() . 'DefaultNewsController');
} else {
// All is tried, give it up here
throw new DefaultControllerException($this, self::EXCEPTION_DEFAULT_CONTROLLER_GONE);
parent::__construct(__CLASS__);
// Set prefix to "Console"
- $this->setControllerPrefix('Console');
+ $this->setClassPrefix('Console');
}
/**
} // END - if
// Set last controller
- $this->lastControllerInstance = $controllerInstance;
+ $this->setResolvedInstance($controllerInstance);
// Return the maybe resolved instance
return $controllerInstance;
parent::__construct(__CLASS__);
// Set prefix to 'Image'
- $this->setControllerPrefix('Image');
+ $this->setClassPrefix('Image');
}
/**
} // END - if
// Set last controller
- $this->lastControllerInstance = $controllerInstance;
+ $this->setResolvedInstance($controllerInstance);
// Return the maybe resolved instance
return $controllerInstance;
parent::__construct(__CLASS__);
// Set prefix to 'Web'
- $this->setControllerPrefix('Web');
+ $this->setClassPrefix('Web');
}
/**
} // END - if
// Set last controller
- $this->lastControllerInstance = $controllerInstance;
+ $this->setResolvedInstance($controllerInstance);
// Return the maybe resolved instance
return $controllerInstance;