3 namespace Org\Mxchange\Factory\City\Daemon;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
8 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
9 use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper;
10 use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry;
11 use Org\Mxchange\CoreFramework\Request\Requestable;
12 use Org\Mxchange\CoreFramework\Response\Responseable;
15 * A factory class for cities
17 * @author Roland Haeder <webmaster@ship-simu.org>
19 * @copyright Copyright (c) 2015 - 2023 City Developer Team
20 * @license GNU GPL 3.0 or any newer version
21 * @link http://www.ship-simu.org
23 * This program is free software: you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation, either version 3 of the License, or
26 * (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program. If not, see <http://www.gnu.org/licenses/>.
36 class CityDaemonFactory extends BaseFactory {
38 * Protected constructor
42 protected function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
48 * Returns a singleton (registry-based) CityHelper instance
50 * @param $requestInstance An instance of a class with an Requestable interface
51 * @param $responseInstance An instance of a class with an Responseable interface
52 * @return $cityInstance An instance of a CityHelper class
53 * @throws FactoryRequiredParameterException If not all parameters are set and no instance 'city' is set.
55 public static final function createCityDaemonInstance (Requestable $requestInstance = NULL, Responseable $responseInstance = NULL) {
56 // Get new factory instance
57 $factoryInstance = new CityDaemonFactory();
59 // If there is no handler?
60 if (ObjectRegistry::getRegistry('factory')->instanceExists('city')) {
61 // Get handler from registry
62 $cityInstance = ObjectRegistry::getRegistry('factory')->getInstance('city');
63 } elseif (($requestInstance instanceof Requestable) && ($responseInstance instanceof Responseable)) {
64 // The default city-mode is from our configuration
65 $cityMode = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('city_default_mode');
67 // Is the city 'mode' parameter set?
68 if ($requestInstance->isRequestElementSet('mode')) {
69 // Then use this which overrides the config entry temporarily
70 $cityMode = $requestInstance->getRequestElement('mode');
72 // Set it for easier re-usage
73 $requestInstance->setRequestElement('mode', $cityMode);
76 // Now convert the city-mode in a configuration entry
77 $configEntry = sprintf('city_%s_daemon_mode_class', $cityMode);
79 // Get the city instance
80 $cityInstance = ObjectFactory::createObjectByConfiguredName($configEntry, array($requestInstance));
83 $applicationInstance = ApplicationHelper::getSelfInstance();
85 // Add city-specific filters
86 $cityInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
88 // Throw an exception here
89 throw new FactoryRequiredParameterException($factoryInstance, self::EXCEPTION_FACTORY_REQUIRE_PARAMETER);
92 // Return the instance