Skip to content

Commit

Permalink
Merge pull request #4145 from morozov/type-registry-constructor
Browse files Browse the repository at this point in the history
Add TypeRegistry constructor
  • Loading branch information
morozov authored Jul 5, 2020
2 parents d7df55d + 66d6821 commit 034ed25
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Types/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
10 changes: 9 additions & 1 deletion lib/Doctrine/DBAL/Types/TypeRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@
final class TypeRegistry
{
/** @var array<string, Type> Map of type names and their corresponding flyweight objects. */
private $instances = [];
private $instances;

/**
* @param array<string, Type> $instances
*/
public function __construct(array $instances = [])
{
$this->instances = $instances;
}

/**
* Finds a type by the given name.
Expand Down
7 changes: 4 additions & 3 deletions tests/Doctrine/Tests/DBAL/Types/TypeRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 034ed25

Please sign in to comment.