From d92066d5ab78811fac63e42c9b88f0a55ce73bd6 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 19 May 2014 19:52:20 +0200 Subject: [PATCH] Added Registerable interface as the FileStackFactory is using it. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- inc/classes/main/factories/stacks/.htaccess | 1 + .../stacks/class_FileStackFactory.php | 69 +++++++++++++++++++ inc/classes/main/stacker/file/class_ | 2 +- .../stacker/file/fifo/class_FiFoFileStack.php | 2 +- 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 inc/classes/main/factories/stacks/.htaccess create mode 100644 inc/classes/main/factories/stacks/class_FileStackFactory.php diff --git a/inc/classes/main/factories/stacks/.htaccess b/inc/classes/main/factories/stacks/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/inc/classes/main/factories/stacks/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/factories/stacks/class_FileStackFactory.php b/inc/classes/main/factories/stacks/class_FileStackFactory.php new file mode 100644 index 00000000..82421879 --- /dev/null +++ b/inc/classes/main/factories/stacks/class_FileStackFactory.php @@ -0,0 +1,69 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub 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 FileStackFactory extends ObjectFactory { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Returns a singleton (registry-based) StackableFile instance + * + * @param $prefix Class prefix + * @param $stackName Name of the stack + * @return $stackInstance An instance of a StackableFile class + */ + public static final function createFileStackInstance ($prefix, $stackName) { + // Construct file stack name + $stackFileName = sprintf('%s%s/%s.%s', + FrameworkConfiguration::getSelfInstance()->getConfigEntry('base_path'), + FrameworkConfiguration::getSelfInstance()->getConfigEntry('base_file_stacks_path'), + $stackName, + FrameworkConfiguration::getSelfInstance()->getConfigEntry('file_stacks_extension') + ); + + // If there is no handler? + if (Registry::getRegistry()->instanceExists($stackName . '_stack')) { + // Get handler from registry + $stackInstance = Registry::getRegistry()->getInstance($stackName . '_stack'); + } else { + // Get the handler instance + $stackInstance = self::createObjectByConfiguredName($prefix . '_' . $stackName . '_stack_class', array($stackFileName)); + + // Add it to the registry + Registry::getRegistry()->addInstance($stackName . '_stack', $stackInstance); + } + + // Return the instance + return $stackInstance; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/stacker/file/class_ b/inc/classes/main/stacker/file/class_ index 8e8510a0..db42e990 100644 --- a/inc/classes/main/stacker/file/class_ +++ b/inc/classes/main/stacker/file/class_ @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class ???FileStack extends BaseFileStack implements StackableFile { +class ???FileStack extends BaseFileStack implements StackableFile, Registerable { /** * Protected constructor * diff --git a/inc/classes/main/stacker/file/fifo/class_FiFoFileStack.php b/inc/classes/main/stacker/file/fifo/class_FiFoFileStack.php index 1a81058c..8d49b74f 100644 --- a/inc/classes/main/stacker/file/fifo/class_FiFoFileStack.php +++ b/inc/classes/main/stacker/file/fifo/class_FiFoFileStack.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class FiFoFileStack extends BaseFileStack implements StackableFile { +class FiFoFileStack extends BaseFileStack implements StackableFile, Registerable { /** * Protected constructor * -- 2.39.5