]> git.mxchange.org Git - city.git/blob - application/city/classes/factories/states/city/class_CityStateFactory.php
3ae6a87b9e5a4136cc3724691008973914aac220
[city.git] / application / city / classes / factories / states / city / class_CityStateFactory.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\City\Factory\State;
4
5 // Import application-specific stuff
6 use Org\Mxchange\Factory\City\Daemon\CityDaemonFactory;
7
8 // Import framework stuff
9 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
10 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
11
12 // Import SPL stuff
13 use \InvalidArgumentException;
14
15 /**
16  * A factory class for city states
17  *
18  * @author              Roland Haeder <webmaster@shipsimu.org>
19  * @version             0.0.0
20  * @copyright   Copyright (c) 2015 - 2023 City Developer Team
21  * @license             GNU GPL 3.0 or any newer version
22  * @link                http://www.shipsimu.org
23  *
24  * This program is free software: you can redistribute it and/or modify
25  * it under the terms of the GNU General Public License as published by
26  * the Free Software Foundation, either version 3 of the License, or
27  * (at your option) any later version.
28  *
29  * This program is distributed in the hope that it will be useful,
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32  * GNU General Public License for more details.
33  *
34  * You should have received a copy of the GNU General Public License
35  * along with this program. If not, see <http://www.gnu.org/licenses/>.
36  */
37 class CityStateFactory extends BaseFactory {
38         /**
39          * Protected constructor
40          *
41          * @return      void
42          */
43         protected function __construct () {
44                 // Call parent constructor
45                 parent::__construct(__CLASS__);
46         }
47
48         /**
49          * Creates an instance of a configurable city state and sets it in the
50          * given city instance.
51          *
52          * @param       $stateName              Name of the state
53          * @return      $stateInstance  A Stateable class instance
54          */
55         public static final function createCityStateInstanceByName (string $stateName) {
56                 // Validate parameter
57                 if (empty($stateName)) {
58                         // Throw IAE
59                         throw new InvalidArgumentException('Parameter "stateName" is empty');
60                 }
61
62                 // Get a class from that configuration entry
63                 $stateInstance = ObjectFactory::createObjectByConfiguredName(sprintf('city_%s_state_class', $stateName));
64
65                 // Get city instance
66                 $cityInstance = CityDaemonFactory::createCityDaemonInstance();
67
68                 // Debug message
69                 self::createDebugInstance(__CLASS__)->debugOutput('CITY-STATE-FACTORY: City daemon state has changed from ' . $cityInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
70
71                 // Once we have that state, set it in the city instance
72                 $cityInstance->setStateInstance($stateInstance);
73
74                 // Update city data
75                 $cityInstance->updateCityData();
76
77                 // For any purposes, return the state instance
78                 return $stateInstance;
79         }
80 }