application/ship-simu/main/actions/web/.htaccess -text
application/ship-simu/main/actions/web/class_WebShipSimuLogin -text
application/ship-simu/main/actions/web/class_WebShipSimuLoginCompanyAction.php -text
+application/ship-simu/main/actions/web/class_WebShipSimuLoginGovermentStartupHelpAction.php -text
application/ship-simu/main/actions/web/class_WebShipSimuLoginGovermentTrainingAction.php -text
application/ship-simu/main/actions/web/class_WebShipSimuLoginLogoutAction.php -text
application/ship-simu/main/actions/web/class_WebShipSimuLoginProfileAction.php -text
application/ship-simu/main/constructions/terminals/class_Terminal.php -text
application/ship-simu/main/constructions/yards/.htaccess -text
application/ship-simu/main/constructions/yards/class_Shipyard.php -text
+application/ship-simu/main/controller/.htaccess -text
+application/ship-simu/main/controller/web/.htaccess -text
+application/ship-simu/main/controller/web/class_WebGovermentFailedController.php -text
application/ship-simu/main/drives/.htaccess -text
application/ship-simu/main/drives/class_BaseDrive.php -text
application/ship-simu/main/drives/motor/.htaccess -text
application/ship-simu/main/factories/class_ShipSimuWebNewsFactory.php -text
application/ship-simu/main/filter/.htaccess -text
application/ship-simu/main/filter/goverment/.htaccess -text
+application/ship-simu/main/filter/goverment/class_ShipSimuGovermentPaysStartupHelpFilter.php -text
application/ship-simu/main/filter/goverment/class_ShipSimuGovermentPaysTrainingFilter.php -text
application/ship-simu/main/filter/page/.htaccess -text
application/ship-simu/main/filter/page/class_RefillPageFilter.php -text
application/ship-simu/main/personell/company/class_CompanyEmployee.php -text
application/ship-simu/main/registration/.htaccess -text
application/ship-simu/main/registration/class_ShipSimuRegistration.php -text
+application/ship-simu/main/resolver/.htaccess -text
+application/ship-simu/main/resolver/web/.htaccess -text
+application/ship-simu/main/resolver/web/class_WebGovermentFailedCommandResolver.php -text
application/ship-simu/main/ships/.htaccess -text
application/ship-simu/main/ships/class_BaseShip.php -text
application/ship-simu/main/ships/passenger/.htaccess -text
inc/classes/main/commands/image/.htaccess -text
inc/classes/main/commands/image/class_ImageCodeCaptchaCommand.php -text
inc/classes/main/commands/web/.htaccess -text
+inc/classes/main/commands/web/class_ -text
inc/classes/main/commands/web/class_WebConfirmCommand.php -text
inc/classes/main/commands/web/class_WebDoFormCommand.php -text
inc/classes/main/commands/web/class_WebHomeCommand.php -text
inc/classes/main/controller/login/.htaccess -text
inc/classes/main/controller/login/class_WebLoginAreaController.php -text
inc/classes/main/controller/web/.htaccess -text
+inc/classes/main/controller/web/class_ -text
inc/classes/main/controller/web/class_WebConfirmController.php -text
inc/classes/main/controller/web/class_WebDefaultController.php -text
inc/classes/main/controller/web/class_WebDefaultNewsController.php -text
inc/classes/main/resolver/command/image/.htaccess -text
inc/classes/main/resolver/command/image/class_ImageCommandResolver.php -text
inc/classes/main/resolver/command/web/.htaccess -text
+inc/classes/main/resolver/command/web/class_ -text
inc/classes/main/resolver/command/web/class_WebCommandResolver.php -text
inc/classes/main/resolver/controller/.htaccess -text
inc/classes/main/resolver/controller/class_BaseControllerResolver.php -text
}
/**
- * Determines wether the login was fine. This is done by checking if the 'login' instance is in registry
+ * Determines wether the login was fine. This is done by checking if 'login' instance is in registry
*
* @return $loginDone Wether the login was fine or not
*/
}
/**
- * Encrypt the given request key or throw an exception if the key was not
- * found in the request
+ * Encrypt given request key or throw an exception if key was not found in
+ * request
*
* @param $requestKey Key in request class
* @return void
*/
public function encryptPassword ($requestKey) {
- // Check if the password is found in the request
+ // Check if password is found in request
if ($this->getRequestInstance()->isRequestElementSet($requestKey)) {
// So encrypt the password and store it for later usage in
// the request:
// Get a crypto helper and hash the password
$this->hashedPassword = ObjectFactory::createObjectByConfiguredName('crypto_class')->hashString($plainPassword, $userInstance->getPasswordHash());
- // Store the hash back in the request
+ // Store the hash back in request
$this->getRequestInstance()->setRequestElement('pass_hash', $this->hashedPassword);
} // END - if
}
// CFG: USER-NOT-FOUND-URL
$cfg->setConfigEntry('user_not_found_url', "index.php?app={?app_short_name?}&page=status&status=user_not_found");
+// CFG: LOGIN-GOVERMENT-STARTUP-FAILED-URL
+$cfg->setConfigEntry('login_goverment_startup_failed_url', "index.php?app={?app_short_name?}&page=goverment_failed&failed=startup");
+
+// CFG: LOGIN-GOVERMENT-TRAINING-FAILED-URL
+$cfg->setConfigEntry('login_goverment_training_failed_url', "index.php?app={?app_short_name?}&page=goverment_failed&failed=training");
+
// CFG: LOGIN-DEFAULT-ACTION
$cfg->setConfigEntry('login_default_action', "welcome");
// CFG: GOVERMENT-PAYS-TRAINING-FILTER
$cfg->setConfigEntry('goverment_pays_training_filter', "ShipSimuGovermentPaysTrainingFilter");
+// CFG: GOVERMENT-PAYS-STARTUP-HELP-FILTER
+$cfg->setConfigEntry('goverment_pays_startup_help_filter', "ShipSimuGovermentPaysStartupHelpFilter");
+
// CFG: NEWS-HOME-LIMIT
$cfg->setConfigEntry('news_home_limit', 10);
// CFG: WEB-LINK-HELPER
$cfg->setConfigEntry('web_link_helper', "WebLinkHelper");
+// CFG: WEB-CMD-GOVERMENT-FAILED-RESOLVER-CLASS
+$cfg->setConfigEntry('web_cmd_goverment_failed_resolver_class', "WebGovermentFailedCommandResolver");
+
// [EOF]
?>
<?php
/**
- * An exception thrown when the requested item is not in the pricing list
+ * An exception thrown when the requested item is not in pricing list
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
--- /dev/null
+<?php
+/**
+ * An action for goverment startup help form
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @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
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class WebShipSimuLoginGovermentStartupHelpAction extends BaseAction implements Commandable, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this action
+ *
+ * @param $resolverInstance An instance of an action resolver
+ * @return $actionInstance An instance of this action class
+ */
+ public final static function createWebShipSimuLoginGovermentStartupHelpAction (ActionResolver $resolverInstance) {
+ // Get a new instance
+ $actionInstance = new WebShipSimuLoginGovermentStartupHelpAction();
+
+ // Set the resolver instance
+ $actionInstance->setResolverInstance($resolverInstance);
+
+ // Return the instance
+ return $actionInstance;
+ }
+
+ /**
+ * Executes the command with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Unfinished method
+ }
+
+ /**
+ * Adds extra filters to the given controller instance
+ *
+ * @param $controllerInstance A controller instance
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @return void
+ * @todo Add some filters here
+ */
+ public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
+ // Check for user status by default
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_status_filter'));
+
+ // Check if goverment can pay startup help
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('goverment_pays_startup_help_filter'));
+ }
+}
+
+// [EOF]
+?>
// Get it's real class name
$shipType = $shipInstance->__toString();
- // Now check if the ship type is in any list and return the result
+ // Now check if ship type is in any list and return the result
return ($this->isShipTypeConstructable($shipType));
}
throw new ClassMismatchException(array($shipyard->__toString(), "Shipyard"), self::EXCEPTION_CLASSES_NOT_MATCHING);
}
- // Validate if the first found shipyard can construct the requested type
+ // Validate if first found shipyard can construct the requested type
$result = $shipyard->isShipTypeConstructable($shipType);
// Does this shipyard construct the requested ship type?
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * Controller for failed goverment requests
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @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
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class WebGovermentFailedController extends BaseController implements Controller {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $resolverInstance An instance of a command resolver class
+ * @return $controllerInstance A prepared instance of this class
+ * @todo Add some filters to this controller
+ */
+ public final static function createWebGovermentFailedController (CommandResolver $resolverInstance) {
+ // Create the instance
+ $controllerInstance = new WebGovermentFailedController();
+
+ // Set the command resolver
+ $controllerInstance->setResolverInstance($resolverInstance);
+
+ // User auth filter
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_auth_filter'));
+
+ // User update filter
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_update_filter'));
+
+ // News fetcher filter
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_download_filter'));
+
+ // News proccess/display-preparation
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_process_filter'));
+
+ // Return the prepared instance
+ return $controllerInstance;
+ }
+
+ /**
+ * Handles the given request and response
+ *
+ * @param $requestInstance An instance of a request class
+ * @param $responseInstance An instance of a response class
+ * @return void
+ */
+ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get the command instance from the resolver by sending a request instance to the resolver
+ $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
+
+ // Add more filters by the command
+ $commandInstance->addExtraFilters($this, $requestInstance);
+
+ // Try to run the pre filters, if auth exceptions come through redirect here
+ try {
+ // Run the pre filters
+ $this->executePreFilters($requestInstance, $responseInstance);
+ } catch (UserAuthorizationException $e) {
+ // Redirect to main page
+ $responseInstance->redirectToConfiguredUrl('login_failed_url');
+ }
+
+ // This request was valid! :-D
+ $requestInstance->requestIsValid();
+
+ // Execute the command
+ $commandInstance->execute($requestInstance, $responseInstance);
+
+ // Run the pre filters
+ $this->executePostFilters($requestInstance, $responseInstance);
+
+ // Flush the response out
+ $responseInstance->flushBuffer();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A filter for checking if goverment can pay startup helps
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @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
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class ShipSimuGovermentPaysStartupHelpFilter extends BaseFrameworkSystem implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Clean up a little
+ $this->removeNumberFormaters();
+ $this->removeSystemArray();
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createShipSimuGovermentPaysStartupHelpFilter () {
+ // Get a new instance
+ $filterInstance = new ShipSimuGovermentPaysStartupHelpFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get the user instance from registry
+ $userInstance = Registry::getRegistry()->getInstance('user');
+
+ // Now simply check for it
+ if (($userInstance instanceof ManageableMember) || ($userInstance->ifGovermentPaysStartupHelp() === false)) {
+ // Request is invalid
+ $requestInstance->requestIsValid(false);
+
+ // Redirect to configured URL
+ $responseInstance->redirectToConfiguredUrl('login_goverment_startup_failed_url');
+
+ // Stop processing here
+ exit();
+ } // END - if
+ }
+}
+
+// [EOF]
+?>
// Request is invalid
$requestInstance->requestIsValid(false);
- // Add a message to the response
- $responseInstance->addFatalMessage('goverment_pays_no_training');
+ // Redirect to configured URL
+ $responseInstance->redirectToConfiguredUrl('login_goverment_training_failed_url');
- // Abort here
- return false;
+ // Stop processing here
+ exit();
} // END - if
}
}
}
/**
- * Determines wether the login was fine. This is done by checking if the 'login' instance is in registry
+ * Determines wether the login was fine. This is done by checking if 'login' instance is in registry
*
* @return $loginDone Wether the login was fine or not
*/
}
/**
- * Encrypt the given request key or throw an exception if the key was not
- * found in the request
+ * Encrypt given request key or throw an exception if key was not found in
+ * request
*
* @param $requestKey Key in request class
* @return void
*/
public function encryptPassword ($requestKey) {
- // Check if the password is found in the request
+ // Check if password is found in request
if ($this->getRequestInstance()->isRequestElementSet($requestKey)) {
// So encrypt the password and store it for later usage in
// the request:
// Get a crypto helper and hash the password
$this->hashedPassword = ObjectFactory::createObjectByConfiguredName('crypto_class')->hashString($plainPassword, $userInstance->getPasswordHash());
- // Store the hash back in the request
+ // Store the hash back in request
$this->getRequestInstance()->setRequestElement('pass_hash', $this->hashedPassword);
} // END - if
}
}
/**
- * Determines wether the login was fine. This is done by checking if the 'login' instance is in registry
+ * Determines wether the login was fine. This is done by checking if 'login' instance is in registry
*
* @return $loginDone Wether the login was fine or not
*/
}
/**
- * Encrypt the given request key or throw an exception if the key was not
- * found in the request
+ * Encrypt given request key or throw an exception if key was not found in
+ * request
*
* @param $requestKey Key in request class
* @return void
*/
public function encryptPassword ($requestKey) {
- // Check if the password is found in the request
+ // Check if password is found in request
if ($this->getRequestInstance()->isRequestElementSet($requestKey)) {
// So encrypt the password and store it for later usage in
// the request:
// Get a crypto helper and hash the password
$this->hashedPassword = ObjectFactory::createObjectByConfiguredName('crypto_class')->hashString($plainPassword, $userInstance->getPasswordHash());
- // Store the hash back in the request
+ // Store the hash back in request
$this->getRequestInstance()->setRequestElement('pass_hash', $this->hashedPassword);
} // END - if
}
<?php
/**
- * A user registration specially for Ship-Simu
+ * A user registration class specially for Ship-Simu
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class ShipSimuRegistration extends BaseRegistration {
+class ShipSimuRegistration extends BaseRegistration implements UserRegister {
/**
* Hashed password
*/
}
/**
- * Encrypt the given request key or throw an exception if the key was not
- * found in the request
+ * Encrypt given request key or throw an exception if key was not found in
+ * request
*
* @param $requestKey Key in request class
* @return void
*/
public function encryptPassword ($requestKey) {
- // Check if the password is found in the request
+ // Check if password is found in request
if ($this->getRequestInstance()->isRequestElementSet($requestKey)) {
// So encrypt the password and store it for later usage in
// the request:
// 2. Get a crypto helper and hash the password
$this->hashedPassword = ObjectFactory::createObjectByConfiguredName('crypto_class')->hashString($plainPassword);
- // 3. Store the hash back in the request
+ // 3. Store the hash back in request
$this->getRequestInstance()->setRequestElement('pass_hash', $this->hashedPassword);
}
}
* before registration
*
* @return void
+ * @todo Maybe add more things to perform
*/
public function doPreRegistration () {
// First run all pre filters
* database and paying some start credits or throw exceptions if this fails
*
* @return void
+ * @todo Maybe add more things to perform
*/
public function registerNewUser () {
// Get a user database wrapper
* Perform things like notifying partner websites after registration is done
*
* @return void
+ * @todo Maybe add more things to perform
*/
public function doPostRegistration () {
// First run all post filters
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A command resolver for local (non-hubbed) web commands including the failed goverment request
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @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
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class WebGovermentFailedCommandResolver extends BaseCommandResolver implements CommandResolver {
+ /**
+ * Last successfull resolved command
+ */
+ private $lastCommandInstance = null;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set prefix to "Web"
+ $this->setCommandPrefix("Web");
+ }
+
+ /**
+ * Creates an instance of a Web command resolver with a given default command
+ *
+ * @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 default command is not set
+ * @throws InvalidInterfaceException Thrown if command does not implement interface Commandable
+ */
+ public final static function createWebGovermentFailedCommandResolver ($commandName, ManageableApplication $appInstance) {
+ // Create the new instance
+ $resolverInstance = new WebGovermentFailedCommandResolver();
+
+ // Get request instance
+ $requestInstance = $appInstance->getRequestInstance();
+
+ // Is the variable $commandName set and the command is valid?
+ if (empty($commandName)) {
+ // Then thrown an exception here
+ throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ } elseif (!$resolverInstance->resolveCommandByRequest($requestInstance) instanceof Commandable) {
+ // Invalid command found (missing interface?)
+ throw new InvalidInterfaceException(array($userInstance, 'ManageableMember'), self::EXCEPTION_REQUIRED_INTERFACE_MISSING);
+ }
+
+ // Set the application instance
+ $resolverInstance->setApplicationInstance($appInstance);
+
+ // Return the prepared instance
+ return $resolverInstance;
+ }
+
+ /**
+ * Returns an command instance for a given request class or null if
+ * it was not found
+ *
+ * @param $requestInstance An instance of a request class
+ * @return $commandInstance An instance of the resolved command
+ * @throws InvalidCommandException Thrown if $commandName is
+ * invalid
+ * @throws InvalidCommandInstanceException Thrown if $commandInstance
+ * is an invalid instance
+ */
+ public function resolveCommandByRequest (Requestable $requestInstance) {
+ // Init instance
+ $commandInstance = null;
+
+ // This goes fine so let's resolv the command
+ $commandName = $requestInstance->getRequestElement('page');
+
+ // Is there a "failed" request?
+ if ($requestInstance->isRequestElementSet('failed')) {
+ // Then include with within the command name
+ $commandName = sprintf("%s_%s", $commandName, $requestInstance->getRequestElement('failed'));
+ } // END - if
+
+ // Is the command empty? Then fall back to default command
+ if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_web_command');
+
+ // 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);
+
+ // And validate it
+ if ((!is_object($commandInstance)) || (!$commandInstance instanceof Commandable)) {
+ // This command has an invalid instance!
+ throw new InvalidCommandInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
+ } // END - if
+
+ // Set last command
+ $this->lastCommandInstance = $commandInstance;
+
+ // Return the resolved command instance
+ 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_web_command');
+
+ // Check if command is valid
+ if ($this->isCommandValid($commandName) === false) {
+ // 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
+ *
+ * @param $commandName A command name we shall look for
+ * @return $commandInstance A loaded command instance
+ * @throws InvalidCommandException Thrown if even the default
+ * command class is missing (bad!)
+ */
+ private function loadCommand ($commandName) {
+ // Cache default command
+ $defaultCommand = $this->getConfigInstance()->readConfig('default_web_command');
+
+ // Init command instance
+ $commandInstance = null;
+
+ // Create command class name
+ $this->setClassName(sprintf("Web%sCommand",
+ $this->convertToClassName($commandName)
+ ));
+
+ // Is this class loaded?
+ 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($this->getClassName(), array($this));
+
+ // Return the result
+ return $commandInstance;
+ }
+}
+
+// [EOF]
+?>
}
/**
- * Determines if the goverment can still pay a "virtual training course" in general
+ * Determines if goverment can still pay a "virtual training course" in general
*
- * @return $ifGovHelps Wether if the goverment helps the user with a virtual training course
+ * @return $ifGovHelps Wether if goverment helps the user with a virtual training course
*/
public function ifGovermentPaysTraining () {
// By default they want to help.
}
/**
- * Determines if the goverment can still pay a "startup help" to the user
+ * Determines if goverment can still pay a "startup help" to the user
*
- * @return $ifGovHelps Wether if the goverment helps the user with some startup money
+ * @return $ifGovHelps Wether if goverment helps the user with some startup money
*/
public function ifGovermentPaysStartupHelp () {
// By default they want to help.
/**
* Creates an instance of this user class by a provided username. This
- * factory method will check if the username is already taken and if not
+ * factory method will check if username is already taken and if not
* so it will throw an exception.
*
* @param $userName Username we need a class instance for
// Set the username
$userInstance->setUserName($userName);
- // Check if the username exists
+ // Check if username exists
if ($userInstance->ifUsernameExists() === false) {
// Throw an exception here
throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND);
/**
* Creates an instance of this user class by a provided email address. This
- * factory method will not check if the email address is there.
+ * factory method will not check if email address is there.
*
* @param $email Email address of the user
* @return $userInstance An instance of this user class
/**
* Creates an instance of this user class by a provided username. This
- * factory method will check if the username is already taken and if not
+ * factory method will check if username is already taken and if not
* so it will throw an exception.
*
* @param $userName Username we need a class instance for
// Set the username
$userInstance->setUserName($userName);
- // Check if the username exists
+ // Check if username exists
if ($userInstance->ifUsernameExists() === false) {
// Throw an exception here
throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND);
/**
* Creates an instance of this user class by a provided email address. This
- * factory method will not check if the email address is there.
+ * factory method will not check if email address is there.
*
* @param $email Email address of the user
* @return $userInstance An instance of this user class
TODO:
=====
+- Rename all FooNotFoundException to NoBarException
+
- Hub and MXChange 0.3.0 must be ported to new framework changes:
+ ClassLoader::includeAllClasses() removed
+ FrameworkArrayObject::__construct($className) requires class name
*/
public function __construct (array $classArray, $code) {
// Add a message around the missing class
- $message = sprintf("[%s:%d] Object does not implement expected interface <span class=\"exception_reason\">.",
+ $message = sprintf("[%s:%d] Object does not implement expected interface <span class=\"exception_reason\">%s</span>.",
$classArray[0]->__toString(),
$this->getLine(),
$classArray[1]
<?php
/**
- * An exception thrown if the result was not updated
+ * An exception thrown if result was not updated.
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
/**
* Hashes a string with salt and returns the hash. If an old previous hash
* is supplied the method will use the first X chars of that hash for hashing
- * the password. This is useful if you want to check if the password is
- * identical for authorization purposes.
+ * the password. This is useful if you want to check if password is identical
+ * for authorization purposes.
*
* @param $str Unhashed string
* @param $oldHash A hash from previous hashed string
*/
interface UserRegister extends FrameworkInterface {
/**
- * Encrypt the given request key or throws an exception if the key was not
- * found in the request
+ * Encrypt given request key or throws an exception if key was not found in
+ * request.
*
* @param $requestKey Key in request class
* @return void
/**
* Checks wether an instance key was found
*
- * @param $instanceKey The key holding an instance in the registry
- * @return $exists Wether the key exists in the registry
+ * @param $instanceKey The key holding an instance in registry
+ * @return $exists Wether the key exists in registry
*/
function instanceExists ($instanceKey);
function isRequestElementSet ($element);
/**
- * Getter for request element or 'null' if the element was not found
+ * Getter for request element or 'null' if element was not found
*
* @param $element Name of the request element we want to check
* @return $value Value of the found request element or 'null' if the
function getParameterNames ();
/**
- * Getter for a header element or 'null' if the header was not found
+ * Getter for a header element or 'null' if header was not found
*
* @param $headerName Name of the header
* @return $headerValue Value of the header or 'null' if not found
*
* @param $actionName The default action we shall execute
* @return $isValid Wether the given action is valid
- * @throws EmptyVariableException Thrown if the given action is not set
+ * @throws EmptyVariableException Thrown if given action is not set
*/
function isActionValid ($actionName);
}
*
* @param $commandName The default command we shall execute
* @return $isValid Wether the given command is valid
- * @throws EmptyVariableException Thrown if the given command is not set
+ * @throws EmptyVariableException Thrown if given command is not set
*/
function isCommandValid ($commandName);
}
function ifEmailAddressExists ();
/**
- * Checks if the supplied password hash in request matches with the stored
- * in database.
+ * Checks if supplied password hash in request matches with stored in
+ * database.
*
* @param $requestInstance A requestable class instance
* @return $matches Wether the supplied password hash matches
<?php
/**
- * A general action class
+ * A general action class. You shall extend this class if you are going to write
+ * your own action classes even when this class has no real content in it. We
+ * just handle the removal of some attributed here which you really don't need.
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
* Setter for cache offset
*
* @param $offset The offset we shall set
- * @param $data Data to store in the cache
+ * @param $data Data to store in cache
* @return void
*/
public final function offsetSet ($offset, $data) {
* Getter for cache offset or "null" if not found
*
* @param $offset The offset we shall set
- * @return $data Data to store in the cache
+ * @return $data Data to store in cache
*/
public final function offsetGet ($offset) {
// Default is offset not found
// Set real class
$this->setRealClass($className);
- // Initialize the class if the class Registry is there
+ // Initialize the class if class Registry is there
if ((class_exists('Registry')) && (Registry::isInitialized() === false)) {
// Initialize the registry automatically
$this->initInstance();
<?php
/**
* Class for saving arrays as an object. We need this little extension for
- * some common methods used in the whole application. Please see below if you
+ * some common methods used in whole application. Please see below if you
* need more details.
*
* @author Roland Haeder <webmaster@ship-simu.org>
--- /dev/null
+<?php
+/**
+ * A command for
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @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
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class Web???Command extends BaseCommand implements Commandable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $resolverInstance An instance of a command resolver class
+ * @return $commandInstance An instance a prepared command class
+ */
+ public final static function createWeb???Command (CommandResolver $resolverInstance) {
+ // Get new instance
+ $commandInstance = new Web???Command();
+
+ // Set the application instance
+ $commandInstance->setResolverInstance($resolverInstance);
+
+ // Return the prepared instance
+ return $commandInstance;
+ }
+
+ /**
+ * Executes the given command with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ $this->partialStub("Unfinished method.");
+ }
+
+ /**
+ * Adds extra filters to the given controller instance
+ *
+ * @param $controllerInstance A controller instance
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @return void
+ */
+ public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
+ // Empty for now
+ }
+}
+
+// [EOF]
+?>
// these two calls to cache compiled templates.
$templateInstance->compileVariables();
- // Get the content back from the template engine and put it in the response class
+ // Get the content back from the template engine and put it in response class
$templateInstance->transferToResponse($responseInstance);
}
// these two calls to cache compiled templates.
$templateInstance->compileVariables();
- // Get the content back from the template engine and put it in the response class
+ // Get the content back from the template engine and put it in response class
$templateInstance->transferToResponse($responseInstance);
}
// these two calls to cache compiled templates.
$templateInstance->compileVariables();
- // Get the content back from the template engine and put it in the response class
+ // Get the content back from the template engine and put it in response class
$templateInstance->transferToResponse($responseInstance);
}
// these two calls to cache compiled templates.
$templateInstance->compileVariables();
- // Get the content back from the template engine and put it in the response class
+ // Get the content back from the template engine and put it in response class
$templateInstance->transferToResponse($responseInstance);
}
// these two calls to cache compiled templates.
$templateInstance->compileVariables();
- // Get the content back from the template engine and put it in the response class
+ // Get the content back from the template engine and put it in response class
$templateInstance->transferToResponse($responseInstance);
}
// these two calls to cache compiled templates.
$templateInstance->compileVariables();
- // Get the content back from the template engine and put it in the response class
+ // Get the content back from the template engine and put it in response class
$templateInstance->transferToResponse($responseInstance);
}
// these two calls to cache compiled templates.
$templateInstance->compileVariables();
- // Get the content back from the template engine and put it in the response class
+ // Get the content back from the template engine and put it in response class
$templateInstance->transferToResponse($responseInstance);
}
// Set resolver instance
$controllerInstance->setResolverInstance($resolverInstance);
- // We need the controller instance in the resolver class so set it here
+ // We need the controller instance in resolver class so set it here
$resolverInstance->setControllerInstance($controllerInstance);
// Return the prepared instance
--- /dev/null
+<?php
+/**
+ * Controller for
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @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
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class Web???Controller extends BaseController implements Controller {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $resolverInstance An instance of a command resolver class
+ * @return $controllerInstance A prepared instance of this class
+ * @todo Add some filters to this controller
+ */
+ public final static function createWeb???Controller (CommandResolver $resolverInstance) {
+ // Create the instance
+ $controllerInstance = new Web???Controller();
+
+ // Set the command resolver
+ $controllerInstance->setResolverInstance($resolverInstance);
+
+ // Add filters
+ //$controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_status_confirmed_filter'));
+
+ // Return the prepared instance
+ return $controllerInstance;
+ }
+
+ /**
+ * Handles the given request and response
+ *
+ * @param $requestInstance An instance of a request class
+ * @param $responseInstance An instance of a response class
+ * @return void
+ */
+ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get the command instance from the resolver by sending a request instance to the resolver
+ $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
+
+ // Run the pre filters
+ $this->executePreFilters($requestInstance, $responseInstance);
+
+ // This request was valid! :-D
+ $requestInstance->requestIsValid();
+
+ // Execute the command
+ $commandInstance->execute($requestInstance, $responseInstance);
+
+ // Run the pre filters
+ $this->executePostFilters($requestInstance, $responseInstance);
+
+ // Flush the response out
+ $responseInstance->flushBuffer();
+ }
+}
+
+// [EOF]
+?>
} // END - foreach
} // END - foreach
- // Now check if the criteria matches
+ // Now check if expected criteria counts match
$matches = ($counted == count($this->searchCriteria));
// Return the result
/**
* Hashes a string with salt and returns the hash. If an old previous hash
* is supplied the method will use the first X chars of that hash for hashing
- * the password. This is useful if you want to check if the password is
- * identical for authorization purposes.
+ * the password. This is useful if you want to check if password is identical
+ * for authorization purposes.
*
* @param $str Unhashed string
* @param $oldHash A hash from previous hashed string
}
/**
- * Getter for table information file contents or an empty if the info file was not created
+ * Getter for table information file contents or an empty if info file was not created
*
* @param $dataSetInstance An instance of a database set class
* @return $infoArray An array with all table informations
<?php
/**
- * A filter for checking if the "encrypt" value is set and fine
+ * A filter for checking if value "encrypt" is set and fine
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
<?php
/**
- * A filter for checking if the username "guest" has been choosen as configured.
- * If so the password will be set to the configured password.
+ * A filter for checking if username "guest" has been choosen as configured. If
+ * so the password will be set to the configured password.
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
<?php
/**
* A concrete filter for validating the email address. This filter may intercept
- * the filter chain if no email address is given or if the supplied email has an
- * invalid form. It could also intercept the filter chain if the email address
- * is already used by some one if configuration requires this.
+ * the filter chain if no email address is given or if supplied email has an
+ * invalid form. It could also intercept our filter chain if email address is
+ * already used by some one if configuration requires this.
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
<?php
/**
* A concrete filter for validating the username. This filter may intercept the
- * filter chain if no username is given or if the supplied username has an
- * invalid form. It could also intercept the filter chain if the username is
- * already taken.
+ * filter chain if no username is given or if supplied username has an invalid
+ * form. It could also intercept our filter chain if username is already taken.
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
<?php
/**
- * A filter for checking if the the supplied confirmation code is valid
+ * A filter for checking if supplied confirmation code is valid.
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
<?php
/**
* A concrete filter for verfying the guest username. This filter may intercept the
- * filter chain if no username is given or if the supplied username has an
- * invalid form. It could also intercept the filter chain if the username was
- * not found.
+ * filter chain if no username is given or if supplied username has an invalid
+ * form. It could also intercept our filter chain if username was not found.
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
<?php
/**
* A concrete filter for verfying the username. This filter may intercept the
- * filter chain if no username is given or if the supplied username has an
- * invalid form. It could also intercept the filter chain if the username was
- * not found.
+ * filter chain if no username is given or if supplied username has an invalid
+ * form. It could also intercept our filter chain if username was not found.
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
<?php
/**
- * A filter for checking if the user status is GUEST or CONFIRMED
+ * A filter for checking if user status is GUEST or CONFIRMED.
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
<?php
/**
- * A filter for checking if the user status is UNCONFIRMED
+ * A filter for checking if user status is UNCONFIRMED.
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
/**
* Setter for image message string
*
- * @param $imageString A message to display in the image
+ * @param $imageString A message to display in image
* @return void
*/
public final function setImageString ($imageString) {
/**
* Getter for image message string
*
- * @return $imageString A message to display in the image
+ * @return $imageString A message to display in image
*/
public final function getImageString () {
return $this->imageStrings[$this->currString]['string'];
// Switch the state
$this->closePreviousGroupByContent($content);
- // All call it again if the group name is not empty
+ // All call it again if group name is not empty
if ((!empty($groupId)) && ($groupId != $prevGroupId)) {
//* DEBUG: */ echo $groupId."/".$prevGroupId."<br />\n";
$this->addFormGroup($groupId, $groupText);
/**
* Add a form sub group or close an already opened and open a new one or
- * throws an exception if no group has been opened before or if the sub
- * group name is empty.
+ * throws an exception if no group has been opened before or if sub group
+ * name is empty.
*
* @param $subGroupId Name of the group or last opened if empty
* @param $subGroupText Text including HTML to show above this group
* @return void
*/
public final function setPointer ($dirPointer) {
- // Sanity-check if the pointer is a valid directory resource
+ // Sanity-check if pointer is a valid directory resource
if (is_resource($dirPointer) || is_null($dirPointer)) {
// Is a valid resource
$this->dirPointer = $dirPointer;
* @return void
*/
public final function setPointer ($filePointer) {
- // Sanity-check if the pointer is a valid file resource
+ // Sanity-check if pointer is a valid file resource
if (is_resource($filePointer) || is_null($filePointer)) {
// Is a valid resource
$this->filePointer = $filePointer;
* @return void
*/
public final function setPointer ($filePointer) {
- // Sanity-check if the pointer is a valid file resource
+ // Sanity-check if pointer is a valid file resource
if (is_resource($filePointer) || is_null($filePointer)) {
// Is a valid resource
$this->filePointer = $filePointer;
// Get the field from the value instance
$fieldValue = $recipientList['values'][$variable]->getField($variable);
- // Set it in the template engine
+ // Set it in template engine
$templateInstance->assignVariable($variable, $fieldValue);
}
<?php
/**
- * A general registration class
+ * A general registration class.
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-abstract class BaseRegistration extends BaseFrameworkSystem implements UserRegister {
+class BaseRegistration extends BaseFrameworkSystem {
/**
* Pre-registration filter chain
*/
/**
* Checks wether an instance key was found
*
- * @param $instanceKey The key holding an instance in the registry
- * @return $exists Wether the key exists in the registry
+ * @param $instanceKey The key holding an instance in registry
+ * @return $exists Wether the key exists in registry
*/
public function instanceExists ($instanceKey) {
// Does this key exists?
* @return $objectInstance An instance we shall store
*/
public function getInstance ($instanceKey) {
- // By default the instance is not in the registry
+ // By default the instance is not in registry
$objectInstance = null;
// Is the instance there?
*/
public function isRequestElementSet ($element) {
// Is this element found?
- if (!isset($this->requestData[$element])) {
- // Then return false
- return false;
- } // END - if
+ $isSet = isset($this->requestData[$element]);
- // All clear
- return true;
+ // Return result
+ return $isSet;
}
/**
- * Getter for request element or 'null' if the element was not found
+ * Getter for request element or 'null' if element was not found
*
* @param $element Name of the request element we want to check
* @return $value Value of the found request element or 'null' if the
}
/**
- * Getter for a header element or 'null' if the header was not found
+ * Getter for a header element or 'null' if header was not found
*
* @param $headerName Name of the header
* @return $headerValue Value of the header or 'null' if not found
*
* @param $actionName The default action we shall execute
* @return $isValid Wether the given action is valid
- * @throws EmptyVariableException Thrown if the given action is not set
+ * @throws EmptyVariableException Thrown if given action is not set
*/
public function isActionValid ($actionName) {
// By default nothing shall be valid
* @param $actionName The default action we shall execute
* @param $appInstance An instance of a manageable application helper class
* @return $resolverInstance The prepared action resolver instance
- * @throws EmptyVariableException Thrown if the default action is not set
- * @throws InvalidActionException Thrown if the default action is invalid
+ * @throws EmptyVariableException Thrown if default action is not set
+ * @throws InvalidActionException Thrown if default action is invalid
*/
public final static function createWebActionResolver ($actionName, ManageableApplication $appInstance) {
// Create the new instance
// Is the action empty? Then fall back to default action
if (empty($actionName)) $actionName = $this->getConfigInstance()->readConfig('default_action');
- // Check if the action is valid
+ // Check if action is valid
if ($this->isActionValid($actionName) === false) {
// This action is invalid!
throw new InvalidActionException(array($this, $actionName), self::EXCEPTION_INVALID_ACTION);
// Is the action empty? Then fall back to default action
if (empty($actionName)) $actionName = $this->getConfigInstance()->readConfig('default_action');
- // Check if the action is valid
+ // Check if action is valid
if ($this->isActionValid($actionName) === false) {
// This action is invalid!
throw new InvalidActionException(array($this, $actionName), self::EXCEPTION_INVALID_ACTION);
*
* @param $commandName The default command we shall execute
* @return $isValid Wether the given command is valid
- * @throws EmptyVariableException Thrown if the given command is not set
+ * @throws EmptyVariableException Thrown if given command is not set
*/
public function isCommandValid ($commandName) {
// By default nothing shall be valid
* @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
+ * @throws EmptyVariableException Thrown if default command is not set
+ * @throws InvalidCommandException Thrown if default command is invalid
*/
public final static function createImageCommandResolver ($commandName, ManageableApplication $appInstance) {
// Create the new instance
// Is the command empty? Then fall back to default command
if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_image_command');
- // Check if the command is valid
+ // Check if command is valid
if ($this->isCommandValid($commandName) === false) {
// This command is invalid!
throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
// Is the command empty? Then fall back to default command
if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_image_command');
- // Check if the command is valid
+ // Check if command is valid
if ($this->isCommandValid($commandName) === false) {
// This command is invalid!
throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
--- /dev/null
+<?php
+/**
+ * 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
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class Web???CommandResolver extends BaseCommandResolver implements CommandResolver {
+ /**
+ * Last successfull resolved command
+ */
+ private $lastCommandInstance = null;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set prefix to "Web"
+ $this->setCommandPrefix("Web");
+ }
+
+ /**
+ * Creates an instance of a Web command resolver with a given default command
+ *
+ * @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 createWeb???CommandResolver ($commandName, ManageableApplication $appInstance) {
+ // Create the new instance
+ $resolverInstance = new Web???CommandResolver();
+
+ // Is the variable $commandName set and the command is valid?
+ if (empty($commandName)) {
+ // Then thrown an exception here
+ 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);
+ }
+
+ // Set the application instance
+ $resolverInstance->setApplicationInstance($appInstance);
+
+ // Return the prepared instance
+ return $resolverInstance;
+ }
+
+ /**
+ * Returns an command instance for a given request class or null if
+ * it was not found
+ *
+ * @param $requestInstance An instance of a request class
+ * @return $commandInstance An instance of the resolved command
+ * @throws InvalidCommandException Thrown if $commandName is
+ * invalid
+ * @throws InvalidCommandInstanceException Thrown if $commandInstance
+ * is an invalid instance
+ */
+ public function resolveCommandByRequest (Requestable $requestInstance) {
+ // Init variables
+ $commandName = "";
+ $commandInstance = null;
+
+ // This goes fine so let's resolv the command
+ $commandName = $requestInstance->getRequestElement('page');
+
+ // Is the command empty? Then fall back to default command
+ if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_web_command');
+
+ // Check if the 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);
+
+ // And validate it
+ if ((!is_object($commandInstance)) || (!$commandInstance instanceof Commandable)) {
+ // This command has an invalid instance!
+ throw new InvalidCommandInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
+ } // END - if
+
+ // Set last command
+ $this->lastCommandInstance = $commandInstance;
+
+ // Return the resolved command instance
+ 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_web_command');
+
+ // Check if the command is valid
+ if ($this->isCommandValid($commandName) === false) {
+ // 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
+ *
+ * @param $commandName A command name we shall look for
+ * @return $commandInstance A loaded command instance
+ * @throws InvalidCommandException Thrown if even the default
+ * command class is missing (bad!)
+ */
+ private function loadCommand ($commandName) {
+ // Cache default command
+ $defaultCommand = $this->getConfigInstance()->readConfig('default_web_command');
+
+ // Init command instance
+ $commandInstance = null;
+
+ // Create command class name
+ $this->setClassName(sprintf("Web%sCommand",
+ $this->convertToClassName($commandName)
+ ));
+
+ // Is this class loaded?
+ 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($this->getClassName(), array($this));
+
+ // Return the result
+ return $commandInstance;
+ }
+}
+
+// [EOF]
+?>
* @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
+ * @throws EmptyVariableException Thrown if default command is not set
+ * @throws InvalidCommandException Thrown if default command is invalid
*/
public final static function createWebCommandResolver ($commandName, ManageableApplication $appInstance) {
// Create the new instance
// Is the command empty? Then fall back to default command
if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_web_command');
- // Check if the command is valid
+ // Check if command is valid
if ($this->isCommandValid($commandName) === false) {
// This command is invalid!
throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
// Is the command empty? Then fall back to default command
if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_web_command');
- // Check if the command is valid
+ // Check if command is valid
if ($this->isCommandValid($commandName) === false) {
// This command is invalid!
throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
*
* @param $controllerName The default controller we shall execute
* @return $isValid Wether the given controller is valid
- * @throws EmptyVariableException Thrown if the given controller is not set
- * @throws DefaultControllerException If the default controller was not found
+ * @throws EmptyVariableException Thrown if given controller is not set
+ * @throws DefaultControllerException Thrown if default controller was not found
*/
public function isControllerValid ($controllerName) {
// By default nothing shall be valid
* @param $controllerName The controller we shall resolve
* @param $appInstance An instance of a manageable application helper class
* @return $resolverInstance The prepared controller resolver instance
- * @throws EmptyVariableException Thrown if the default command is not set
- * @throws InvalidControllerException Thrown if the default controller is invalid
+ * @throws EmptyVariableException Thrown if default command is not set
+ * @throws InvalidControllerException Thrown if default controller is invalid
*/
public final static function createImageControllerResolver ($controllerName, ManageableApplication $appInstance) {
// Create the new instance
* @param $controllerName The controller we shall resolve
* @param $appInstance An instance of a manageable application helper class
* @return $resolverInstance The prepared controller resolver instance
- * @throws EmptyVariableException Thrown if the default command is not set
- * @throws InvalidControllerException Thrown if the default controller is invalid
+ * @throws EmptyVariableException Thrown if default command is not set
+ * @throws InvalidControllerException Thrown if default controller is invalid
*/
public final static function createWebControllerResolver ($controllerName, ManageableApplication $appInstance) {
// Create the new instance
throw new InvalidControllerException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
} // END - if
+ // Set default resolver config name
+ $resolverConfigEntry = "";
+
+ // Try to read a config entry for our resolver including controller name... ;-)
+ try {
+ // Create the resolver name
+ $resolverConfigEntry = sprintf("web_cmd_%s_resolver_class", strtolower($controllerName));
+
+ // Get the config, this will throw an exception if there is no special command resolver
+ $resolverClass = $this->getConfigInstance()->readConfig($resolverConfigEntry);
+ } catch (ConfigEntryNotFoundException $e) {
+ // Use default resolver entry
+ $resolverConfigEntry = "web_cmd_resolver_class";
+ }
+
// Initiate the resolver and controller
- $resolverInstance = ObjectFactory::createObjectByConfiguredName('web_cmd_resolver_class', array($controllerName, $this->getApplicationInstance()));
+ $resolverInstance = ObjectFactory::createObjectByConfiguredName($resolverConfigEntry, array($controllerName, $this->getApplicationInstance()));
$controllerInstance = ObjectFactory::createObjectByName($this->getClassName(), array($resolverInstance));
- // Remove resolver
+ // Remove resolver (we don't need it anymore)
unset($resolverInstance);
// Return the result
/**
* "Iterator" method next() to advance to the next valid entry. This method
- * does also check if the result is invalid
+ * does also check if result is invalid
*
* @return $nextValid Wether the next entry is valid
*/
}
/**
- * Searches for an entry in the data result and returns it
+ * Searches for an entry in data result and returns it
*
* @param $criteriaInstance The criteria to look inside the data set
* @return $result Found result entry
* @return void
*/
public function transferToResponse (Responseable $responseInstance) {
- // Get the content and set it in the response class
+ // Get the content and set it in response class
$responseInstance->writeToBody($this->getCompiledData());
}
}
/**
- * Checks if the supplied password hash in request matches with the stored
- * in database.
+ * Checks if supplied password hash in request matches with the stored in
+ * database.
*
* @param $requestInstance A requestable class instance
* @return $matches Wether the supplied password hash matches
/**
* Creates an instance of this user class by a provided username. This
- * factory method will check if the username is already taken and if not
- * so it will throw an exception.
+ * factory method will check if username is already taken and if not so it
+ * will throw an exception.
*
* @param $userName Username we need a class instance for
* @return $userInstance An instance of this user class
// Set the username
$userInstance->setUserName($userName);
- // Check if the username exists
+ // Check if username exists
if ($userInstance->ifUsernameExists() === false) {
// Throw an exception here
throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND);
/**
* Creates an instance of this user class by a provided email address. This
- * factory method will not check if the email address is there.
+ * factory method will not check if email address is there.
*
* @param $email Email address of the user
* @return $userInstance An instance of this user class
/**
* Creates an instance of this user class by a provided username. This
- * factory method will check if the username is already taken and if not
- * so it will throw an exception.
+ * factory method will check if username is already taken and if not so it
+ * will throw an exception.
*
* @param $userName Username we need a class instance for
* @return $userInstance An instance of this user class
// Set the username
$userInstance->setUserName($userName);
- // Check if the username exists
+ // Check if username exists
if ($userInstance->ifUsernameExists() === false) {
// Throw an exception here
throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND);
/**
* Creates an instance of this user class by a provided email address. This
- * factory method will not check if the email address is there.
+ * factory method will not check if email address is there.
*
* @param $email Email address of the user
* @return $userInstance An instance of this user class
/**
* A class for the configuration stuff implemented in a singleton design paddern
*
- * NOTE: We cannot put this in inc/classes/ because it would be loaded (again)
- * in the class loader. See inc/loader/class_ClassLoader.php for instance
+ * NOTE: We cannot put this in inc/classes/ because it would be loaded (again) in
+ * class loader. See inc/loader/class_ClassLoader.php for instance
*
* @see ClassLoader
* @author Roland Haeder <webmaster@ship-simu.org>