3 * A factory class for network packages
5 * @author Roland Haeder <webmaster@shipsimu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.shipsimu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class PackageFilterChainFactory extends ObjectFactory {
26 * Protected constructor
30 protected function __construct () {
31 // Call parent constructor
32 parent::__construct(__CLASS__);
36 * Returns a filter chain by given tags array.
38 * @param $tags An array with tags from a package
39 * @return $chainInstance An instance of a filter chain class
41 public static final function createChainByTagsArray (array $tags) {
42 // Get a registry key from tags array, this does mostly call implode()
43 $registryKey = Registry::getRegistryKeyFromArray('package_filter_chain', $tags);
45 // Is the registry key there?
46 if (Registry::getRegistry()->instanceExists($registryKey)) {
47 // Yes, then use that instance
48 $chainInstance = Registry::getRegistry()->getInstance($registryKey);
50 // Initialize a filter chain class
51 $chainInstance = self::createObjectByConfiguredName('package_filter_chain_class');
53 // "Walk" through all tags entries
54 foreach ($tags as $tag) {
56 * Now create a filter instance of this tag. This way all tags
57 * got rudymentary verified, if an exception is coming here, it
58 * simply means the tag is not valid. This however should be
59 * handled some calls before this method is called.
61 $filterInstance = self::createObjectByConfiguredName('package_tag_' . $tag . '_filter');
63 // Add this filter to the chain
64 $chainInstance->addFilter($filterInstance);
67 // Add filter for handling hash to miner queue
68 $filterInstance = self::createObjectByConfiguredName('package_hash_to_miner_filter');
70 // Add this post-filter to the chain
71 $chainInstance->addPostFilter($filterInstance);
73 // Add the finished chain to the registry
74 Registry::getRegistry()->addInstance($registryKey, $chainInstance);
77 // Return the chain instance
78 return $chainInstance;