Unverified Commit 034ed255 authored by Sergei Morozov's avatar Sergei Morozov Committed by GitHub

Merge pull request #4145 from morozov/type-registry-constructor

Add TypeRegistry constructor
parents d7df55d6 66d68217
......@@ -208,13 +208,13 @@ abstract class Type
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);
}
/**
......
......@@ -18,7 +18,15 @@ use function in_array;
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.
......
......@@ -31,9 +31,10 @@ class TypeRegistryTest extends TestCase
$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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment