From 66d682179d9fefde0fa6d8868430cb721469bc33 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 3 Jul 2020 19:16:30 -0700 Subject: [PATCH] Add TypeRegistry constructor --- lib/Doctrine/DBAL/Types/Type.php | 6 +++--- lib/Doctrine/DBAL/Types/TypeRegistry.php | 10 +++++++++- tests/Doctrine/Tests/DBAL/Types/TypeRegistryTest.php | 7 ++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index 6dd4e9abb30..8a6a7cd7466 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -208,13 +208,13 @@ final public static function getTypeRegistry(): TypeRegistry private static function createTypeRegistry(): TypeRegistry { - $registry = new TypeRegistry(); + $instances = []; foreach (self::BUILTIN_TYPES_MAP as $name => $class) { - $registry->register($name, new $class()); + $instances[$name] = new $class(); } - return $registry; + return new TypeRegistry($instances); } /** diff --git a/lib/Doctrine/DBAL/Types/TypeRegistry.php b/lib/Doctrine/DBAL/Types/TypeRegistry.php index 362a5ccc9a4..4c2e31ecbcf 100644 --- a/lib/Doctrine/DBAL/Types/TypeRegistry.php +++ b/lib/Doctrine/DBAL/Types/TypeRegistry.php @@ -18,7 +18,15 @@ final class TypeRegistry { /** @var array Map of type names and their corresponding flyweight objects. */ - private $instances = []; + private $instances; + + /** + * @param array $instances + */ + public function __construct(array $instances = []) + { + $this->instances = $instances; + } /** * Finds a type by the given name. diff --git a/tests/Doctrine/Tests/DBAL/Types/TypeRegistryTest.php b/tests/Doctrine/Tests/DBAL/Types/TypeRegistryTest.php index be4ba0dddfe..98b0fd99a40 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TypeRegistryTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TypeRegistryTest.php @@ -31,9 +31,10 @@ protected function setUp(): void $this->testType = new BlobType(); $this->otherTestType = new BinaryType(); - $this->registry = new TypeRegistry(); - $this->registry->register(self::TEST_TYPE_NAME, $this->testType); - $this->registry->register(self::OTHER_TEST_TYPE_NAME, $this->otherTestType); + $this->registry = new TypeRegistry([ + self::TEST_TYPE_NAME => $this->testType, + self::OTHER_TEST_TYPE_NAME => $this->otherTestType, + ]); } public function testGet(): void