From: Roland Häder Date: Tue, 11 Aug 2009 21:17:24 +0000 (+0000) Subject: State (see State Pattern) prepared, a lot reworked/refactured X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2c0148a84570f1a8343fa6b98a279e903b3e4fa2;p=core.git State (see State Pattern) prepared, a lot reworked/refactured - New interfaces and exceptions added for states - Dead-loop fixed (was caused by previous refacturing - Misc cleanups/fixes --- diff --git a/.gitattributes b/.gitattributes index cdcec144..4827646e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -63,6 +63,7 @@ inc/classes/exceptions/io/class_FileReadProtectedException.php -text inc/classes/exceptions/io/class_InvalidDataLengthException.php -text inc/classes/exceptions/io/class_InvalidDirectoryResourceException.php -text inc/classes/exceptions/io/class_InvalidMD5ChecksumException.php -text +inc/classes/exceptions/io/class_InvalidResourceException.php -text inc/classes/exceptions/io/class_PathIsEmptyException.php -text inc/classes/exceptions/io/class_PathIsNoDirectoryException.php -text inc/classes/exceptions/io/class_PathReadProtectedException.php -text @@ -103,6 +104,8 @@ inc/classes/exceptions/result/class_InvalidDatabaseResultException.php -text inc/classes/exceptions/result/class_ResultUpdateException.php -text inc/classes/exceptions/socket/.htaccess -text inc/classes/exceptions/socket/class_InvalidSocketException.php -text +inc/classes/exceptions/state/.htaccess -text +inc/classes/exceptions/state/class_InvalidStateException.php -text inc/classes/exceptions/template/.htaccess -text inc/classes/exceptions/template/class_BasePathIsEmptyException.php -text inc/classes/exceptions/template/class_BasePathIsNoDirectoryException.php -text @@ -199,11 +202,15 @@ inc/classes/interfaces/resolver/commands/.htaccess -text inc/classes/interfaces/resolver/commands/class_CommandResolver.php -text inc/classes/interfaces/resolver/controller/.htaccess -text inc/classes/interfaces/resolver/controller/class_ControllerResolver.php -text +inc/classes/interfaces/resolver/state/.htaccess -text +inc/classes/interfaces/resolver/state/class_StateResolver.php -text inc/classes/interfaces/response/.htaccess -text inc/classes/interfaces/response/class_Responseable.php -text inc/classes/interfaces/result/.htaccess -text inc/classes/interfaces/result/class_SearchableResult.php -text inc/classes/interfaces/result/class_UpdateableResult.php -text +inc/classes/interfaces/state/.htaccess -text +inc/classes/interfaces/state/class_Stateable.php -text inc/classes/interfaces/streams/.htaccess -text inc/classes/interfaces/streams/class_Streamable.php -text inc/classes/interfaces/streams/crypto/.htaccess -text diff --git a/inc/classes/exceptions/io/class_InvalidDirectoryResourceException.php b/inc/classes/exceptions/io/class_InvalidDirectoryResourceException.php index f0430782..84994342 100644 --- a/inc/classes/exceptions/io/class_InvalidDirectoryResourceException.php +++ b/inc/classes/exceptions/io/class_InvalidDirectoryResourceException.php @@ -7,6 +7,8 @@ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org + * @deprecated + * @see InvalidResourceException * * 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 diff --git a/inc/classes/exceptions/io/class_InvalidResourceException.php b/inc/classes/exceptions/io/class_InvalidResourceException.php new file mode 100644 index 00000000..7546920e --- /dev/null +++ b/inc/classes/exceptions/io/class_InvalidResourceException.php @@ -0,0 +1,45 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @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 . + */ +class InvalidResourceException extends FrameworkException { + /** + * The constructor + * + * @param $class Class throwing this exception + * @param $code Code number for the exception + * @return void + */ + public function __construct (FrameworkInterface $class, $code) { + // Add a message around the missing class + $message = sprintf("[%s:%d] Has an invalid resource.", + $class->__toString(), + $this->getLine() + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/state/.htaccess b/inc/classes/exceptions/state/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/inc/classes/exceptions/state/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/exceptions/state/class_InvalidStateException.php b/inc/classes/exceptions/state/class_InvalidStateException.php new file mode 100644 index 00000000..1aeefefb --- /dev/null +++ b/inc/classes/exceptions/state/class_InvalidStateException.php @@ -0,0 +1,450 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @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 . + */ +class InvalidStateException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $msgArray An array with message parts + * @param $code An optional code for better debugging + * @return void + */ + public function __construct(array $msgArray, $code) { + // Prepare the message + $message = sprintf("[%s:%d] Cannot resolve state %s (class name: %s).", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1], + $msgArray[0]->getClassName() + ); + + // Set extra data + $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine()); + + // Call parent contructor with message + parent::__construct($message, $code); + } +} + +// [EOF] +?> + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @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 . + */ +class InvalidStateException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $msgArray An array with message parts + * @param $code An optional code for better debugging + * @return void + */ + public function __construct(array $msgArray, $code) { + // Prepare the message + $message = sprintf("[%s:%d] Cannot resolve state %s (class name: %s).", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1], + $msgArray[0]->getClassName() + ); + + // Set extra data + $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine()); + + // Call parent contructor with message + parent::__construct($message, $code); + } +} + +// [EOF] +?> + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @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 . + */ +class InvalidStateException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $msgArray An array with message parts + * @param $code An optional code for better debugging + * @return void + */ + public function __construct(array $msgArray, $code) { + // Prepare the message + $message = sprintf("[%s:%d] Cannot resolve state %s (class name: %s).", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1], + $msgArray[0]->getClassName() + ); + + // Set extra data + $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine()); + + // Call parent contructor with message + parent::__construct($message, $code); + } +} + +// [EOF] +?> + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @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 . + */ +class InvalidStateException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $msgArray An array with message parts + * @param $code An optional code for better debugging + * @return void + */ + public function __construct(array $msgArray, $code) { + // Prepare the message + $message = sprintf("[%s:%d] Cannot resolve state %s (class name: %s).", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1], + $msgArray[0]->getClassName() + ); + + // Set extra data + $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine()); + + // Call parent contructor with message + parent::__construct($message, $code); + } +} + +// [EOF] +?> + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @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 . + */ +class InvalidStateException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $msgArray An array with message parts + * @param $code An optional code for better debugging + * @return void + */ + public function __construct(array $msgArray, $code) { + // Prepare the message + $message = sprintf("[%s:%d] Cannot resolve state %s (class name: %s).", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1], + $msgArray[0]->getClassName() + ); + + // Set extra data + $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine()); + + // Call parent contructor with message + parent::__construct($message, $code); + } +} + +// [EOF] +?> + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @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 . + */ +class InvalidStateException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $msgArray An array with message parts + * @param $code An optional code for better debugging + * @return void + */ + public function __construct(array $msgArray, $code) { + // Prepare the message + $message = sprintf("[%s:%d] Cannot resolve state %s (class name: %s).", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1], + $msgArray[0]->getClassName() + ); + + // Set extra data + $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine()); + + // Call parent contructor with message + parent::__construct($message, $code); + } +} + +// [EOF] +?> + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @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 . + */ +class InvalidStateException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $msgArray An array with message parts + * @param $code An optional code for better debugging + * @return void + */ + public function __construct(array $msgArray, $code) { + // Prepare the message + $message = sprintf("[%s:%d] Cannot resolve state %s (class name: %s).", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1], + $msgArray[0]->getClassName() + ); + + // Set extra data + $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine()); + + // Call parent contructor with message + parent::__construct($message, $code); + } +} + +// [EOF] +?> + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @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 . + */ +class InvalidStateException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $msgArray An array with message parts + * @param $code An optional code for better debugging + * @return void + */ + public function __construct(array $msgArray, $code) { + // Prepare the message + $message = sprintf("[%s:%d] Cannot resolve state %s (class name: %s).", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1], + $msgArray[0]->getClassName() + ); + + // Set extra data + $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine()); + + // Call parent contructor with message + parent::__construct($message, $code); + } +} + +// [EOF] +?> + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @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 . + */ +class InvalidStateException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $msgArray An array with message parts + * @param $code An optional code for better debugging + * @return void + */ + public function __construct(array $msgArray, $code) { + // Prepare the message + $message = sprintf("[%s:%d] Cannot resolve state %s (class name: %s).", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1], + $msgArray[0]->getClassName() + ); + + // Set extra data + $this->setExtraData($msgArray[0]->getClassName().':'.$this->getLine()); + + // Call parent contructor with message + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/interfaces/resolver/state/.htaccess b/inc/classes/interfaces/resolver/state/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/inc/classes/interfaces/resolver/state/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/resolver/state/class_StateResolver.php b/inc/classes/interfaces/resolver/state/class_StateResolver.php new file mode 100644 index 00000000..cb882c16 --- /dev/null +++ b/inc/classes/interfaces/resolver/state/class_StateResolver.php @@ -0,0 +1,45 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @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 . + */ +interface StateResolver extends Resolver { + /** + * Returns an state instance for a given package class and raw data + * + * @param $packageInstance An instance of a package class + * @param $rawData The raw data to handle + * @return $stateInstance An instance of the resolved state + */ + function resolveStateByPackage (Networkable $packageInstance, $rawData); + + /** + * Checks wether the given state is valid + * + * @param $stateName The default state we shall execute + * @return $isValid Wether the given state is valid + * @throws EmptyVariableException Thrown if given state is not set + */ + function isStateValid ($stateName); +} + +// +?> diff --git a/inc/classes/interfaces/state/.htaccess b/inc/classes/interfaces/state/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/inc/classes/interfaces/state/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/state/class_Stateable.php b/inc/classes/interfaces/state/class_Stateable.php new file mode 100644 index 00000000..c6621fdf --- /dev/null +++ b/inc/classes/interfaces/state/class_Stateable.php @@ -0,0 +1,28 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @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 . + */ +interface Stateable extends FrameworkInterface { +} + +// +?> diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 9e7f247b..e15af400 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -128,7 +128,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { const EXCEPTION_WRITE_PROTECED_PATH = 0x018; const EXCEPTION_DIR_POINTER_INVALID = 0x019; const EXCEPTION_FILE_POINTER_INVALID = 0x01a; - const EXCEPTION_INVALID_DIRECTORY_POINTER = 0x01b; + const EXCEPTION_INVALID_RESOURCE = 0x01b; const EXCEPTION_UNEXPECTED_OBJECT = 0x01c; const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d; const EXCEPTION_GETTER_IS_MISSING = 0x01e; @@ -171,10 +171,10 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Set real class $this->setRealClass($className); - // Initialize the class if class Registry is there - if ((class_exists('Registry')) && (Registry::isInitialized() === false)) { - // Initialize the registry automatically - $this->initInstance(); + // Set configuration instance if no registry + if (!$this instanceof Register) { + // Because registries doesn't need to be configured + $this->setConfigInstance(FrameworkConfiguration::getInstance()); } // END - if } @@ -245,16 +245,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { return null; } - /** - * Private initializer for this class - * - * @return void - */ - private final function initInstance () { - // Set configuration instance - $this->setConfigInstance(FrameworkConfiguration::getInstance()); - } - /** * Setter for database result instance * @@ -388,7 +378,10 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput */ public final function getDebugInstance () { + // Get debug instance $debugInstance = Registry::getRegistry()->getInstance('debug'); + + // Return it return $debugInstance; } @@ -429,13 +422,8 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return $dbInstance The database layer instance */ public final function getDatabaseInstance () { - // Default is invalid db instance - $dbInstance = null; - - // Is the registry there and initialized? - if ((class_exists('Registry')) && (Registry::isInitialized() === true)) { - $dbInstance = Registry::getRegistry()->getInstance('db_instance'); - } // END - if + // Get instance + $dbInstance = Registry::getRegistry()->getInstance('db_instance'); // Return instance return $dbInstance; diff --git a/inc/classes/main/commands/web/class_WebResendLinkCommand.php b/inc/classes/main/commands/web/class_WebResendLinkCommand.php index 73aa5350..633a2016 100644 --- a/inc/classes/main/commands/web/class_WebResendLinkCommand.php +++ b/inc/classes/main/commands/web/class_WebResendLinkCommand.php @@ -55,18 +55,11 @@ class WebResendLinkCommand extends BaseCommand implements Commandable { * @param $requestInstance An instance of a class with an Requestable interface * @param $responseInstance An instance of a class with an Responseable interface * @return void - * @throws InvalidInterfaceException If the user class does not implement ManageableMember */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get user instance from registry $userInstance = Registry::getRegistry()->getInstance('user'); - // Does the user instance implement ManageableMember? - if (!$userInstance instanceof ManageableMember) { - // Throw exception here - throw new InvalidInterfaceException(array($userInstance, 'ManageableMember'), self::EXCEPTION_REQUIRED_INTERFACE_MISSING); - } // END - if - // Get an application instance $appInstance = $this->getResolverInstance()->getApplicationInstance(); diff --git a/inc/classes/main/crypto/class_CryptoHelper.php b/inc/classes/main/crypto/class_CryptoHelper.php index cbac7d7b..db352844 100644 --- a/inc/classes/main/crypto/class_CryptoHelper.php +++ b/inc/classes/main/crypto/class_CryptoHelper.php @@ -183,7 +183,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { */ public function encryptString ($str) { // Encrypt the string through the stream - $encryted = $this->cryptoStreamInstance->encryptStream($str); + $encrypted = $this->cryptoStreamInstance->encryptStream($str); // Return the string return $encrypted; diff --git a/inc/classes/main/database/class_BaseDatabaseFrontend.php b/inc/classes/main/database/class_BaseDatabaseFrontend.php index 514b8ec6..bc1c7f61 100644 --- a/inc/classes/main/database/class_BaseDatabaseFrontend.php +++ b/inc/classes/main/database/class_BaseDatabaseFrontend.php @@ -40,9 +40,6 @@ abstract class BaseDatabaseFrontend extends BaseFrameworkSystem implements Datab protected function __construct ($className) { // Call parent constructor parent::__construct($className); - - // Clean up a little - $this->removeNumberFormaters(); } } diff --git a/inc/classes/main/database/databases/class_LocalFileDatabase.php b/inc/classes/main/database/databases/class_LocalFileDatabase.php index d4c45e97..1298ff8b 100644 --- a/inc/classes/main/database/databases/class_LocalFileDatabase.php +++ b/inc/classes/main/database/databases/class_LocalFileDatabase.php @@ -99,17 +99,23 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend */ public final static function createLocalFileDatabase ($savePath, FileIoHandler $ioInstance) { // Get an instance - $dbInstance = new LocalFileDatabase(); + $databaseInstance = new LocalFileDatabase(); // Set save path and IO instance - $dbInstance->setSavePath($savePath); - $dbInstance->setFileIoInstance($ioInstance); + $databaseInstance->setSavePath($savePath); + $databaseInstance->setFileIoInstance($ioInstance); + + // Set the compressor channel + $databaseInstance->setCompressorChannel(CompressorChannel::createCompressorChannel( + $databaseInstance->getConfigInstance()->getConfigEntry('base_path'). + $databaseInstance->getConfigInstance()->getConfigEntry('compressor_base_path') + )); // "Connect" to the database - $dbInstance->connectToDatabase(); + $databaseInstance->connectToDatabase(); // Return database instance - return $dbInstance; + return $databaseInstance; } /** @@ -119,11 +125,8 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend * @return void */ public final function setSavePath ($savePath) { - // Secure string - $savePath = (string) $savePath; - // Set save path - $this->savePath = $savePath; + $this->savePath = (string) $savePath; } /** diff --git a/inc/classes/main/filter/verifier/class_ConfirmCodeVerifierFilter.php b/inc/classes/main/filter/verifier/class_ConfirmCodeVerifierFilter.php index 7702aabc..6086de89 100644 --- a/inc/classes/main/filter/verifier/class_ConfirmCodeVerifierFilter.php +++ b/inc/classes/main/filter/verifier/class_ConfirmCodeVerifierFilter.php @@ -51,7 +51,6 @@ class ConfirmCodeVerifierFilter extends BaseFilter implements Filterable { * @param $requestInstance An instance of a class with an Requestable interface * @param $responseInstance An instance of a class with an Responseable interface * @return void - * @throws NullPointerException If the user instance from registry is null * @throws FilterChainException If this filter fails to operate */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { @@ -82,12 +81,6 @@ class ConfirmCodeVerifierFilter extends BaseFilter implements Filterable { // Get a user instance from registry $userInstance = Registry::getRegistry()->getInstance('user'); - // Is the instance there? - if (is_null($userInstance)) { - // Throw an exception here - throw new NullPointerException ($this, self::EXCEPTION_IS_NULL_POINTER); - } // END - if - // Get the confirm code from user for comparison $userCode = $userInstance->getField(UserDatabaseWrapper::DB_COLUMN_CONFIRM_HASH); diff --git a/inc/classes/main/helper/web/links/class_WebLinkHelper.php b/inc/classes/main/helper/web/links/class_WebLinkHelper.php index 484d2fe6..69eeb7e9 100644 --- a/inc/classes/main/helper/web/links/class_WebLinkHelper.php +++ b/inc/classes/main/helper/web/links/class_WebLinkHelper.php @@ -59,7 +59,6 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate { * @param $linkName Name of the link we shall generate * @param $linkBase Link base for the link. This parameter is deprecated. * @return $helperInstance A prepared instance of this helper - * @throws NullPointerException Thrown if an instance is null * @throws ConfigEntryNotFoundException A deprecated exception at this point */ public final static function createWebLinkHelper (CompileableTemplate $templateInstance, $linkName, $linkBase = null) { @@ -75,12 +74,6 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate { // Get the application instance $applicationInstance = Registry::getRegistry()->getInstance('application'); - // Sanity-check on it - if (is_null($applicationInstance)) { - // Throw an exception here - throw new NullPointerException($helperInstance, self::EXCEPTION_IS_NULL_POINTER); - } // END - if - // Get the request instance $requestInstance = $applicationInstance->getRequestInstance(); diff --git a/inc/classes/main/io/class_FrameworkDirectoryPointer.php b/inc/classes/main/io/class_FrameworkDirectoryPointer.php index 98fe305a..c25e97bb 100644 --- a/inc/classes/main/io/class_FrameworkDirectoryPointer.php +++ b/inc/classes/main/io/class_FrameworkDirectoryPointer.php @@ -196,7 +196,7 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem { $this->dirPointer = $dirPointer; } else { // Throw exception - throw new InvalidDirectoryResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER); + throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE); } } diff --git a/inc/classes/main/io/class_FrameworkFileInputPointer.php b/inc/classes/main/io/class_FrameworkFileInputPointer.php index 7f4466ce..b296421b 100644 --- a/inc/classes/main/io/class_FrameworkFileInputPointer.php +++ b/inc/classes/main/io/class_FrameworkFileInputPointer.php @@ -105,7 +105,7 @@ class FrameworkFileInputPointer extends BaseFrameworkSystem { * @return mixed The result of fread() * @throws NullPointerException If the file pointer instance * is not set by setPointer() - * @throws InvalidFileResourceException If there is being set + * @throws InvalidResourceException If there is being set * an invalid file resource */ public function readFromFile () { @@ -114,7 +114,7 @@ class FrameworkFileInputPointer extends BaseFrameworkSystem { throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); } elseif (!is_resource($this->getPointer())) { // Pointer is not a valid resource! - throw new InvalidFileResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER); + throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE); } // Read data from the file pointer and return it @@ -127,7 +127,7 @@ class FrameworkFileInputPointer extends BaseFrameworkSystem { * @return mixed The result of fread() * @throws NullPointerException If the file pointer instance * is not set by setPointer() - * @throws InvalidFileResourceException If there is being set + * @throws InvalidResourceException If there is being set * an invalid file resource */ public function readLinesFromFile () { @@ -136,7 +136,7 @@ class FrameworkFileInputPointer extends BaseFrameworkSystem { throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); } elseif (!is_resource($this->getPointer())) { // Pointer is not a valid resource! - throw new InvalidFileResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER); + throw new InvalidResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER); } // Read data from the file pointer and return it @@ -150,7 +150,7 @@ class FrameworkFileInputPointer extends BaseFrameworkSystem { * @return void * @throws NullPointerException If the file pointer instance * is not set by setPointer() - * @throws InvalidFileResourceException If there is being set + * @throws InvalidResourceException If there is being set */ public function closeFile () { if (is_null($this->getPointer())) { @@ -158,7 +158,7 @@ class FrameworkFileInputPointer extends BaseFrameworkSystem { throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); } elseif (!is_resource($this->getPointer())) { // Pointer is not a valid resource! - throw new InvalidFileResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER); + throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE); } // Close the file pointer and reset the instance variable @@ -180,7 +180,7 @@ class FrameworkFileInputPointer extends BaseFrameworkSystem { $this->filePointer = $filePointer; } else { // Throw exception - throw new InvalidFileResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER); + throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE); } } diff --git a/inc/classes/main/io/class_FrameworkFileOutputPointer.php b/inc/classes/main/io/class_FrameworkFileOutputPointer.php index 8ea8a0d1..bc69bea5 100644 --- a/inc/classes/main/io/class_FrameworkFileOutputPointer.php +++ b/inc/classes/main/io/class_FrameworkFileOutputPointer.php @@ -97,7 +97,7 @@ class FrameworkFileOutputPointer extends BaseFrameworkSystem { * @return mixed The result of fwrite() * @throws NullPointerException If the file pointer instance * is not set by setPointer() - * @throws InvalidFileResourceException If there is being set + * @throws InvalidResourceException If there is being set * an invalid file resource */ public function writeToFile ($dataStream) { @@ -106,7 +106,7 @@ class FrameworkFileOutputPointer extends BaseFrameworkSystem { throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); } elseif (!is_resource($this->getPointer())) { // Pointer is not a valid resource! - throw new InvalidFileResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER); + throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE); } // Read data from the file pointer and return it @@ -120,7 +120,7 @@ class FrameworkFileOutputPointer extends BaseFrameworkSystem { * @return void * @throws NullPointerException If the file pointer instance * is not set by setPointer() - * @throws InvalidFileResourceException If there is being set + * @throws InvalidResourceException If there is being set */ public function closeFile () { if (is_null($this->getPointer())) { @@ -128,7 +128,7 @@ class FrameworkFileOutputPointer extends BaseFrameworkSystem { throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); } elseif (!is_resource($this->getPointer())) { // Pointer is not a valid resource! - throw new InvalidFileResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER); + throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE); } // Close the file pointer and reset the instance variable @@ -150,7 +150,7 @@ class FrameworkFileOutputPointer extends BaseFrameworkSystem { $this->filePointer = $filePointer; } else { // Throw exception - throw new InvalidFileResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER); + throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE); } } diff --git a/inc/classes/main/registry/class_Registry.php b/inc/classes/main/registry/class_Registry.php index 876f7e38..35867f05 100644 --- a/inc/classes/main/registry/class_Registry.php +++ b/inc/classes/main/registry/class_Registry.php @@ -28,11 +28,6 @@ class Registry extends BaseFrameworkSystem implements Register { */ private static $registryInstance = null; - /** - * Wether the registry is initialized - */ - private static $initialized = false; - /** * Instance registry */ @@ -65,26 +60,6 @@ class Registry extends BaseFrameworkSystem implements Register { return self::$registryInstance; } - /** - * Checks or sets wether the registry has been initialized. This had only - * be done once. - * - * @param $initialized Wether the registry is initialized - * @return $initialized Wether the registry is initialized - */ - public final static function isInitialized ($initialized = null) { - // If no parameter (null by default) is provided we want to get the - // parameter. If set to e.g. 'OK' then the registry is set to - // "initialized". - if (is_null($initialized)) { - // Get status if initialized - return self::$initialized; - } else { - // Registry is initialized! - self::$initialized = true; - } - } - /** * Checks wether an instance key was found * @@ -115,6 +90,7 @@ class Registry extends BaseFrameworkSystem implements Register { * * @param $instanceKey The key to identify the instance * @return $objectInstance An instance we shall store + * @throws NullPointerException If the requested key is not found */ public function getInstance ($instanceKey) { // By default the instance is not in registry @@ -125,6 +101,12 @@ class Registry extends BaseFrameworkSystem implements Register { $objectInstance = $this->instanceRegistry[$instanceKey]; } // END - if + // Still not fetched? + if (is_null($objectInstance)) { + // This might happen if a non-registered key was requested + throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + } // END - if + // Return the result return $objectInstance; } diff --git a/inc/classes/main/resolver/class_BaseResolver.php b/inc/classes/main/resolver/class_BaseResolver.php index d15ef310..c485a619 100644 --- a/inc/classes/main/resolver/class_BaseResolver.php +++ b/inc/classes/main/resolver/class_BaseResolver.php @@ -31,6 +31,7 @@ class BaseResolver extends BaseFrameworkSystem { const EXCEPTION_INVALID_COMMAND = 0x1d0; const EXCEPTION_INVALID_CONTROLLER = 0x1d1; const EXCEPTION_INVALID_ACTION = 0x1d2; + const EXCEPTION_INVALID_STATE = 0x1d3; /** * Protected constructor diff --git a/inc/classes/main/resolver/command/web/class_ b/inc/classes/main/resolver/command/web/class_ index 2f6a2b37..57955f97 100644 --- a/inc/classes/main/resolver/command/web/class_ +++ b/inc/classes/main/resolver/command/web/class_ @@ -36,8 +36,8 @@ class Web???CommandResolver extends BaseCommandResolver implements CommandResolv // Call parent constructor parent::__construct(__CLASS__); - // Set prefix to "Web" - $this->setCommandPrefix("Web"); + // Set prefix to 'Web' + $this->setCommandPrefix('Web'); } /** diff --git a/inc/classes/main/resolver/controller/image/class_ImageControllerResolver.php b/inc/classes/main/resolver/controller/image/class_ImageControllerResolver.php index fea3a826..7cbdfbc0 100644 --- a/inc/classes/main/resolver/controller/image/class_ImageControllerResolver.php +++ b/inc/classes/main/resolver/controller/image/class_ImageControllerResolver.php @@ -41,8 +41,8 @@ class ImageControllerResolver extends BaseControllerResolver implements Controll // Call parent constructor parent::__construct(__CLASS__); - // Set prefix to "Image" - $this->setControllerPrefix("Image"); + // Set prefix to 'Image' + $this->setControllerPrefix('Image'); } /** diff --git a/inc/classes/main/resolver/controller/web/class_WebControllerResolver.php b/inc/classes/main/resolver/controller/web/class_WebControllerResolver.php index b43274d3..5cf6b417 100644 --- a/inc/classes/main/resolver/controller/web/class_WebControllerResolver.php +++ b/inc/classes/main/resolver/controller/web/class_WebControllerResolver.php @@ -41,8 +41,8 @@ class WebControllerResolver extends BaseControllerResolver implements Controller // Call parent constructor parent::__construct(__CLASS__); - // Set prefix to "Web" - $this->setControllerPrefix("Web"); + // Set prefix to 'Web' + $this->setControllerPrefix('Web'); } /** diff --git a/inc/classes/middleware/debug/class_DebugMiddleware.php b/inc/classes/middleware/debug/class_DebugMiddleware.php index dec9b06f..e7945986 100644 --- a/inc/classes/middleware/debug/class_DebugMiddleware.php +++ b/inc/classes/middleware/debug/class_DebugMiddleware.php @@ -45,6 +45,9 @@ class DebugMiddleware extends BaseMiddleware implements Registerable { // Set own instance self::$thisInstance = $this; + + // Set it so all can use it + $this->setDebugInstance($this); } /** diff --git a/inc/loader/class_ClassLoader.php b/inc/loader/class_ClassLoader.php index 97a477e5..06e1b1dd 100644 --- a/inc/loader/class_ClassLoader.php +++ b/inc/loader/class_ClassLoader.php @@ -228,23 +228,6 @@ class ClassLoader { } // END - if } - /** - * Fall-back method. Please replace loadClasses() with scanClassPath() ! - * - * @param $basePath The relative base path to 'base_path' constant for all classes - * @param $ignoreList An optional list (array forced) of directory and file names which shall be ignored - * @return void - * @deprecated - * @todo Rewrite your apps to scanClassPath() - */ - public function loadClasses ($basePath, array $ignoreList = array() ) { - // This outputs an ugly message because you need to change to scanClassPath - print __METHOD__." is deprecated. Use scanClassPath() to make this warning go away.
\n"; - - // Call our new method - $this->scanClassPath($basePath, $ignoreList); - } - /** * Scans recursively a local path for class files which must have a prefix and a suffix as given by $this->suffix and $this->prefix * diff --git a/inc/selector.php b/inc/selector.php index a441dafc..18985579 100644 --- a/inc/selector.php +++ b/inc/selector.php @@ -25,12 +25,12 @@ // Try to load these includes in the given order $configAppIncludes = array( 'class_' . FrameworkConfiguration::getInstance()->getConfigEntry('app_helper_class'), // The ApplicationHelper class + 'debug', // Some debugging stuff + 'exceptions', // The application's own exception handler + 'loader', // The application's class loader 'config', // The application's own configuration 'data', // Application data 'init', // The application initializer - 'loader', // The application's class loader - 'debug', // Some debugging stuff - 'exceptions', // The application's own exception handler 'starter', // The application starter (calls entryPoint(), etc.) );