inc/classes/interfaces/.htaccess -text
inc/classes/interfaces/application/.htaccess -text
inc/classes/interfaces/application/class_ManageableApplication.php -text
+inc/classes/interfaces/cache/.htaccess -text
+inc/classes/interfaces/cache/class_Cacheable.php -text
inc/classes/interfaces/class_ -text
inc/classes/interfaces/class_FrameworkInterface.php -text
inc/classes/interfaces/commands/.htaccess -text
inc/classes/interfaces/user/.htaccess -text
inc/classes/interfaces/user/class_ManageableUser.php -text
inc/classes/main/.htaccess -text
+inc/classes/main/cache/.htaccess -text
+inc/classes/main/cache/class_MemoryCache.php -text
inc/classes/main/class_ -text
inc/classes/main/class_BaseFrameworkSystem.php -text
inc/classes/main/class_FrameworkArrayObject.php -text
inc/classes/main/extended/class_ObjectLimits.php -text
inc/classes/main/extended/class_SerializationContainer.php -text
inc/classes/main/factories/.htaccess -text
+inc/classes/main/factories/cache/.htaccess -text
+inc/classes/main/factories/cache/class_CacheFactory.php -text
inc/classes/main/factories/class_BaseFactory.php -text
inc/classes/main/factories/objects/.htaccess -text
inc/classes/main/factories/objects/class_ObjectFactory.php -text
*/
public final function entryPoint () {
// Create a new request object
- $requestInstance = HttpRequest::createHttpRequest();
+ $requestInstance = ObjectFactory::createObjectByName('HttpRequest');
// ... and a new response object
$responseInstance = HttpResponse::createHttpResponse($this);
$controllerInstance = $resolverInstance->getControllerInstance();
// @TODO Add some more pre/post filters to the controller
- $controllerInstance->addPreFilter(UserNameValidatorFilter::createUserNameValidatorFilter());
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByName('UserNameValidatorFilter'));
// Return the prepared instance
return $commandInstance;
/**
* The constructor
*
- * @param $message Message from the exception
+ * @param $msgArray Message from the exception
* @param $code Code number for the exception
* @return void
*/
- public function __construct (BaseFrameworkSystem $class, $code) {
+ public function __construct (array $msgArray, $code) {
// Add a message around the missing class
- $message = sprintf("Die interne Script-Klasse <u>%s</u> konnte nicht gefunden werden!", $class);
+ $message = sprintf("[%s:%d] Internal class <u>%s</u> not found.",
+ $msgArray[0]->__toString(),
+ $this->getLine(),
+ $msgArray[1]
+ );
// Call parent constructor
parent::__construct($message, $code);
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for classes which are "able" to cache
+ *
+ * @author Roland Haeder <webmaster@mxchange.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/>.
+ */
+interface Cacheable extends FrameworkInterface {
+ /**
+ * Does the specified offset exist in cache?
+ *
+ * @param $offset The offsrt we are looking for
+ * @return $exists Wether the offset exists
+ */
+ function offsetExists ($offset);
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A simple memory cache (similar to a registry)
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.3.0
+ * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.mxchange.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 MemoryCache extends BaseFrameworkSystem implements Cacheable {
+ /**
+ * The "memory cache" is simply a wrapped object array
+ */
+ private $dataCache = null;
+
+ /**
+ * Private constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set part description
+ $this->setObjectDescription("Memory cache");
+
+ // Create unique ID number
+ $this->createUniqueID();
+
+ // Clean up a little
+ $this->removeNumberFormaters();
+ $this->removeSystemArray();
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $cacheInstance An instance of this cache class
+ */
+ public final static function createMemoryCache () {
+ // Get a new instance
+ $cacheInstance = new MemoryCache();
+
+ // Initialize the cache
+ $cacheInstance->initCache();
+
+ // Return the prepared instance
+ return $cacheInstance;
+ }
+
+ /**
+ * Initialize this cache by creating an object array
+ *
+ * @return void
+ */
+ protected function initCache () {
+ // Now create the "data cache"
+ $this->dataCache = new FrameworkArrayObject();
+ }
+
+ /**
+ * Does the specified offset exist in cache?
+ *
+ * @param $offset The offsrt we are looking for
+ * @return $exists Wether the offset exists
+ */
+ public final function offsetExists ($offset) {
+ $exists = $this->dataCache->offsetExists($offset);
+ return $exists;
+ }
+}
+
+// [EOF]
+?>
*
* @return void
*/
- private function __construct () {
+ protected function __construct () {
// Call parent constructor
- parent::constructor(__CLASS__);
+ parent::__construct(__CLASS__);
// Set part description
$this->setObjectDescription("");
$this->removeSystemArray();
// Initialize both filter chains
- $this->preFilterChain = FilterChain::createFilterChain();
- $this->postFilterChain = FilterChain::createFilterChain();
+ $this->preFilterChain = ObjectFactory::createObjectByConfiguredName('filter_chain');
+ $this->postFilterChain = ObjectFactory::createObjectByConfiguredName('filter_chain');
}
/**
<?php
/**
- * A database client for the User class
+ * A database wrapper for the User class
*
* @see DatabaseFrontendInterface - An interface for database frontends (front-end to the application)
* @author Roland Haeder <webmaster@ship-simu.org>
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class UserDatabaseWrapper extends BaseDatabaseWrapper {
+ /**
+ * Cache instance
+ */
+ private $cacheInstance = null;
+
// Constants
const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0xe00;
parent::__construct(__CLASS__);
// Set part description
- $this->setObjectDescription("Database client for user objects");
+ $this->setObjectDescription("Database wrapper for user objects");
// Create unique ID number
$this->createUniqueID();
+
+ // Initialize the cache instance
+ $this->initCacheInstance();
}
/**
- * Creates an instance of this database client by a provided user class
+ * Creates an instance of this database wrapper by a provided user class
*
* @param $userInstance An instance of a user class
- * @return $clientInstance An instance of the created client class
- * @throws WrapperUserNameNotFoundException If the supplied username
+ * @return $wrapperInstance An instance of the created wrapper class
+ * @throws WrapperUserNameNotFoundException If the supplied username
* does not exist
*/
public final static function createUserDatabaseWrapper (ManageableUser $userInstance) {
// Get a new instance
- $clientInstance = new UserDatabaseWrapper();
+ $wrapperInstance = new UserDatabaseWrapper();
// Does the username exists?
- if (!$clientInstance->ifUserNameExists($userInstance->getUserName())) {
+ if (!$wrapperInstance->ifUserNameExists($userInstance->getUserName())) {
// Throw an exception here
- throw new WrapperUserNameNotFoundException (array($clientInstance, $userInstance), self::EXCEPTION_CLIENT_USERNAME_NOT_FOUND);
+ throw new WrapperUserNameNotFoundException (array($wrapperInstance, $userInstance), self::EXCEPTION_CLIENT_USERNAME_NOT_FOUND);
}
// The user exists
- $clientInstance->partialStub("Add loading of full user details");
+ $wrapperInstance->partialStub("Add loading of full user details");
// Return the instance
- return $clientInstance;
+ return $wrapperInstance;
+ }
+
+ /**
+ * Initializes the cache instance with a new object
+ *
+ * @return void
+ */
+ private function initCacheInstance () {
+ // Set the new instance
+ $this->cacheInstance = CacheFactory::getFactory()->createConfiguredCache();
+ }
+
+ /**
+ * Checks wether the given username is already used
+ *
+ * @param $userName The username we shall look up
+ * @return $exists Wether the username exists
+ */
+ public function ifUserNameExists ($userName) {
+ // By default no entry exist
+ $exists = false;
+
+ // Does this entry exist?
+ if ($this->cacheInstance->offsetExists($userName)) {
+ // Then we have a user!
+ $exists = true;
+ } else {
+ // Create a search criteria
+ $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria');
+
+ // Add the username as a criteria and set limit to one entry
+ $criteriaInstance->add(self::DB_USERNAME, $userName);
+ $criteriaInstance->setLimit(1);
+
+ // Get a search result
+ $result = $this->doSelectByCriteria($criteriaInstance);
+
+ // Search for it
+ if ($result->next()) {
+ // Get the result
+ $this->cacheInstance->add($userName, $result->getResultArray());
+
+ // Entry found, so all is fine
+ $exists = true;
+ }
+ }
+
+ // Return the result
+ return $exists;
}
}
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A cache factory
+ *
+ * @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 CacheFactory extends BaseFactory {
+ /**
+ * Singleton instance
+ */
+ private static $selfInstance = null;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set object description
+ $this->setObjectDescription("Factory for cache objects");
+
+ // Create unique ID number
+ $this->createUniqueID();
+ }
+
+ /**
+ * Singleton getter for this class
+ *
+ * @return $selfInstance An instance of this class
+ */
+ public final static function getFactory () {
+ // Is the instance null?
+ if (is_null(self::$selfInstance)) {
+ // Set a new one
+ self::$selfInstance = new CacheFactory();
+ }
+
+ // Return the instance
+ return self::$selfInstance;
+ }
+
+ /**
+ * Creates a configured cache instance
+ *
+ * @return $cacheInstance An instance of the configured cache
+ */
+ public function createConfiguredCache () {
+ // Read the config entry
+ $cacheType = $this->getConfigInstance()->readConfig("cache_type");
+
+ // And get a new instance
+ $cacheInstance = ObjectFactory::createObjectByName($cacheType);
+
+ // Return the instance
+ return $cacheInstance;
+ }
+}
+
+// [EOF]
+?>
// Call parent constructor
parent::__construct($class);
- // Create unique ID number
- $this->createUniqueID();
-
// Clean up a little
$this->removeNumberFormaters();
$this->removeSystemArray();
/**
* Protected constructor
*
- * @param $class Name of the real class (not BaseFactory)
* @return void
*/
protected function __construct () {
// Set object description
$this->setObjectDescription("Simple generic object factory");
+
+ // Create unique ID number
+ $this->createUniqueID();
}
/**
throw new EmptyVariableException(array($factoryInstance, 'className'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
} elseif (!class_exists($className)) {
// Then throw an exception
- throw new ClassNotFoundException($className, self::EXCEPTION_CLASS_NOT_FOUND);
+ throw new ClassNotFoundException(array($factoryInstance, $className), self::EXCEPTION_CLASS_NOT_FOUND);
}
// Then Prepare the eval() command
// Return the prepared instance
return $objectInstance;
}
+
+ /**
+ * Creates an object by it's configured name
+ *
+ * @param $configEnttry Configuration entry to read
+ * @return $objectInstance An instance of the requested object
+ */
+ public final static function createObjectByConfiguredName ($configEntry) {
+ // Read the configuration entry
+ $className = FrameworkConfiguration::getInstance()->readConfig($configEntry);
+
+ // Send this to the other factory...
+ $objectInstance = self::createObjectByName($className);
+
+ // Return the instance
+ return $objectInstance;
+ }
}
// [EOF]
// Set part description
$this->setObjectDescription("Factory for webpages with news");
+
+ // Create unique ID number
+ $this->createUniqueID();
}
/**
|| (!method_exists($cInstance->getCompressor(), 'compressStream'))
|| (!method_exists($cInstance->getCompressor(), 'decompressStream'))
) {
- // Set the null compressor handler
- $cInstance->setCompressor(NullCompressor::createNullCompressor());
+ // Set the null compressor handler. This should not be configureable!
+ $cInstance->setCompressor(ObjectFactory::createObjectByName('NullCompressor'));
}
// Return the compressor instance
$ioHandler = new FileIoHandler();
// Set the *real* file IO instances (both the same)
- $ioHandler->setInputStream(FileIoStream::createFileIoStream());
- $ioHandler->setOutputStream(FileIoStream::createFileIoStream());
+ $ioHandler->setInputStream(ObjectFactory::createObjectByConfiguredName('file_input_stream'));
+ $ioHandler->setOutputStream(ObjectFactory::createObjectByConfiguredName('file_output_stream'));
// Return instance
return $ioHandler;
$cfg->defineDatabaseType('local');
// CFG: LOCAL-DB-PATH
-$cfg->setConfigEntry('local_db_path', 'db/');
+$cfg->setConfigEntry('local_db_path', "db/");
// CFG: TIME-ZONE
$cfg->setDefaultTimezone("Europe/Berlin");
// CFG: VERBOSE-LEVEL
$cfg->setConfigEntry('verbose_level', 0);
+// CFG: CACHE-TYPE
+$cfg->setConfigEntry('cache_type', "MemoryCache");
+
+// CFG: SEARCH-CRITERIA
+$cfg->setConfigEntry('search_criteria', "SearchCriteria");
+
+// CFG: FILE-IO-HANDLER
+$cfg->setConfigEntry('file_io_handler', "FileIoHandler");
+
+// CFG: FILTER-CHAIN
+$cfg->setConfigEntry('filter_chain', "FilterChain");
+
+// CFG: FILE-INPUT-STREAM
+$cfg->setConfigEntry('file_input_stream', "FileIoStream");
+
+// CFG: FILE-OUTPUT-STREAM
+$cfg->setConfigEntry('file_output_stream', "FileIoStream");
+
// [EOF]
?>
*/
// Get the instance
-$io = FileIoHandler::createFileIoHandler();
+$io = ObjectFactory::createObjectByConfiguredName('file_io_handler');
// [EOF]
?>