From 4107551a093631ad30fab68a9fd1f120503a530d Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 7 Feb 2020 19:20:05 +0100 Subject: [PATCH] fixes #214 --- DataStorage/Database/DataMapperAbstract.php | 18 ++++++++++-------- Localization/Localization.php | 20 ++++++++++++++++++++ tests/Localization/LocalizationTest.php | 2 +- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index bd4f22d31..a80afe22c 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -113,12 +113,6 @@ use phpOMS\Utils\ArrayUtils; * One example where this could be useful is the Address/Localization model. * In here the country is stored by ID but you probably don't want to load an entire object and only the country name from the country table. * - * @todo Orange-Management/phpOMS#214 - * Allow to define the model class - * Currently the DataMapper uses the mapper name to find the correct model class. - * This can remain but there should be a member variable or const which allows to define the model::class manually in case the model is different. - * One example could be the Address/Location model in the Address module and phpOMS Localization directory. - * * @todo Orange-Management/Modules#99 * Use binds * Currently databinds are not used. Currently injections are possible. @@ -237,6 +231,14 @@ class DataMapperAbstract implements DataMapperInterface */ protected static string $table = ''; + /** + * Model to use by the mapper. + * + * @var string + * @since 1.0.0 + */ + protected static string $model = ''; + /** * Fields to load. * @@ -2018,7 +2020,7 @@ class DataMapperAbstract implements DataMapperInterface public static function populate(array $result, $obj = null) { $class = static::class; - $class = \str_replace('Mapper', '', $class); + $class = empty(static::$model) ? \str_replace('Mapper', '', $class) : static::$model; // @todo: replace str_replace with substr!!! if (empty($result)) { $parts = \explode('\\', $class); @@ -2450,7 +2452,7 @@ class DataMapperAbstract implements DataMapperInterface private static function getNullModelObj() { $class = static::class; - $class = \str_replace('Mapper', '', $class); + $class = empty(static::$model) ? \str_replace('Mapper', '', $class) : static::$model; // @todo replace str_replace with substr!!! $parts = \explode('\\', $class); $name = $parts[$c = (\count($parts) - 1)]; $parts[$c] = 'Null' . $name; diff --git a/Localization/Localization.php b/Localization/Localization.php index e689de6c1..43f83d693 100644 --- a/Localization/Localization.php +++ b/Localization/Localization.php @@ -140,6 +140,26 @@ class Localization */ private array $volume = []; + /** + * Country id. + * + * @var int + * @since 1.0.0 + */ + private $id = 0; + + /** + * Get id + * + * @return int + * + * @since 1.0.0 + */ + public function getId() : int + { + return $this->id; + } + /** * Load localization from language code * diff --git a/tests/Localization/LocalizationTest.php b/tests/Localization/LocalizationTest.php index dc0d81411..a453749e6 100644 --- a/tests/Localization/LocalizationTest.php +++ b/tests/Localization/LocalizationTest.php @@ -65,7 +65,7 @@ class LocalizationTest extends \PHPUnit\Framework\TestCase self::assertTrue(ISO3166TwoEnum::isValidValue($this->localization->getCountry())); self::assertTrue(TimeZoneEnumArray::isValidValue($this->localization->getTimezone())); self::assertTrue(ISO639x1Enum::isValidValue($this->localization->getLanguage())); - self::assertTrue(ISO4217Enum::isValidValue($this->localization->getCurrency())); + self::assertTrue(ISO4217CharEnum::isValidValue($this->localization->getCurrency())); self::assertEquals('.', $this->localization->getDecimal()); self::assertEquals(',', $this->localization->getThousands()); self::assertEquals([], $this->localization->getDatetime());