From 4161a98ec5558c8dd677240d6b20746f0ee2bdc8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 27 Mar 2010 03:33:08 +0000 Subject: [PATCH] Now the factory method is moved over to the newly introduced PackageFactory class --- .gitattributes | 1 + .../hub/main/factories/package/.htaccess | 1 + .../package/class_PackageFactory.php | 70 +++++++++++++++++++ .../class_HubDescriptorHelper.php | 4 +- .../hub/main/nodes/class_BaseHubNode.php | 36 ---------- 5 files changed, 74 insertions(+), 38 deletions(-) create mode 100644 application/hub/main/factories/package/.htaccess create mode 100644 application/hub/main/factories/package/class_PackageFactory.php diff --git a/.gitattributes b/.gitattributes index 0f747dee3..84a41d66e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -107,6 +107,7 @@ application/hub/main/database/wrapper/class_NodeListDatabaseWrapper.php -text application/hub/main/decorators/.htaccess -text application/hub/main/decorators/class_BaseDecorator.php -text application/hub/main/factories/.htaccess -text +application/hub/main/factories/package/.htaccess -text application/hub/main/factories/states/.htaccess -text application/hub/main/factories/states/class_StateFactory.php -text application/hub/main/filter/.htaccess -text diff --git a/application/hub/main/factories/package/.htaccess b/application/hub/main/factories/package/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/factories/package/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/factories/package/class_PackageFactory.php b/application/hub/main/factories/package/class_PackageFactory.php new file mode 100644 index 000000000..e0b6d7e41 --- /dev/null +++ b/application/hub/main/factories/package/class_PackageFactory.php @@ -0,0 +1,70 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 PackageFactory extends ObjectFactory { + /** + * Returns a singleton network package instance. If an instance is found in + * the registry it will be returned, else a new instance is created and + * stored in the same registry entry. + * + * @return $packageInstance A network package instance + */ + public static final function createPackageInstance () { + // Do we have an instance in the registry? + if (Registry::getRegistry()->instanceExists('network_package')) { + // Then use this instance + $packageInstance = Registry::getRegistry()->getInstance('network_package'); + } else { + /** + * Prepare the compressor for our package, GZIP should be fine but we + * keep it open here so you can experiment with the settings and don't + * need to touch any code. + */ + $compressorInstance = ObjectFactory::createObjectByConfiguredName('raw_package_compressor_class'); + + // Prepare the decorator compressor (for later flawless and easy updates) + $compressorInstance = ObjectFactory::createObjectByConfiguredName('deco_package_compressor_class', array($compressorInstance)); + + // Now prepare the network package for delivery so only need to do this + // once just before the "big announcement loop". + $packageInstance = ObjectFactory::createObjectByConfiguredName('network_package_class', array($compressorInstance)); + + // Set the instance in registry for further use + Registry::getRegistry()->addInstance('network_package', $packageInstance); + } + + // Return the instance + return $packageInstance; + } + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } +} +?> diff --git a/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php b/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php index 83b13ad6c..7388345d9 100644 --- a/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php +++ b/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php @@ -102,8 +102,8 @@ class HubDescriptorHelper extends BaseHubHelper { // Compile the template, this inserts the loaded node data into the gaps. $this->getTemplateInstance()->compileTemplate(); - // Get a package instance - $packageInstance = $this->getNodeInstance()->createPackageInstance(); + // Get a singleton package instance + $packageInstance = PackageFactory::createPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. $packageInstance->enqueueRawDataFromTemplate($this); diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index 5cbe90339..f9d1cdf9c 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -614,42 +614,6 @@ class BaseHubNode extends BaseHubSystem implements Updateable { // Return value return $isActive; } - - /** - * Returns a singleton network package instance. If an instance is found in - * the registry it will be returned, else a new instance is created and - * stored in the same registry entry. - * - * @param $compressorInstance A Compressor instance - * @return $packageInstance A network package instance - */ - public function createPackageInstance (Compressor $compressorInstance) { - // Do we have an instance in the registry? - if (Registry::getRegistry()->instanceExists('network_package')) { - // Then use this instance - $packageInstance = Registry::getRegistry()->getInstance('network_package'); - } else { - /** - * Prepare the compressor for our package, GZIP should be fine but we - * keep it open here so you can experiment with the settings and don't - * need to touch any code. - */ - $compressorInstance = ObjectFactory::createObjectByConfiguredName('raw_package_compressor_class'); - - // Prepare the decorator compressor (for later flawless and easy updates) - $compressorInstance = ObjectFactory::createObjectByConfiguredName('deco_package_compressor_class', array($compressorInstance)); - - // Now prepare the network package for delivery so only need to do this - // once just before the "big announcement loop". - $packageInstance = ObjectFactory::createObjectByConfiguredName('network_package_class', array($compressorInstance)); - - // Set the instance in registry for further use - Registry::getRegistry()->addInstance('network_package', $packageInstance); - } - - // Return the instance - return $packageInstance; - } } // [EOF] -- 2.39.5