3 namespace Org\Mxchange\City\Factory\State;
5 // Import application-specific stuff
6 use Org\Mxchange\City\Daemon\Factory\CityDaemonFactory;
8 // Import framework stuff
9 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
10 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
13 use \InvalidArgumentException;
16 * A factory class for city states
18 * @author Roland Haeder <webmaster@shipsimu.org>
20 * @copyright Copyright (c) 2015, 2016 City Developer Team
21 * @license GNU GPL 3.0 or any newer version
22 * @link http://www.shipsimu.org
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.
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.
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/>.
37 class CityStateFactory extends BaseFactory {
39 * Protected constructor
43 protected function __construct () {
44 // Call parent constructor
45 parent::__construct(__CLASS__);
49 * Creates an instance of a configurable city state and sets it in the
50 * given city instance.
52 * @param $stateName Name of the state
53 * @return $stateInstance A Stateable class instance
55 public static final function createCityStateInstanceByName (string $stateName) {
57 if (empty($stateName)) {
59 throw new InvalidArgumentException('Parameter "stateName" is empty');
62 // Get a class from that configuration entry
63 $stateInstance = ObjectFactory::createObjectByConfiguredName(sprintf('city_%s_state_class', $stateName));
66 $cityInstance = CityDaemonFactory::createCityDaemonInstance();
69 self::createDebugInstance(__CLASS__)->debugOutput('CITY-STATE-FACTORY: City daemon state has changed from ' . $cityInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
71 // Once we have that state, set it in the city instance
72 $cityInstance->setStateInstance($stateInstance);
75 $cityInstance->updateCityData();
77 // For any purposes, return the state instance
78 return $stateInstance;