Skip to content

Commit

Permalink
Dynamic initializer discovery fix
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed May 30, 2024
1 parent 8f7ffcb commit 05f000d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/Container/GenericContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,23 @@ public function setInitializers(array $initializers): self
return $this;
}

public function setDynamicInitializers(array $dynamicInitializers): self
{
$this->dynamicInitializers = new ArrayIterator($dynamicInitializers);

return $this;
}

public function getInitializers(): array
{
return $this->initializers->getArrayCopy();
}

public function getDynamicInitializers(): array
{
return $this->dynamicInitializers->getArrayCopy();
}

public function register(string $className, callable $definition): self
{
$this->definitions[$className] = $definition;
Expand Down
12 changes: 9 additions & 3 deletions src/Discovery/InitializerDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,20 @@ public function hasCache(): bool

public function storeCache(): void
{
file_put_contents(self::CACHE_PATH, serialize($this->container->getInitializers()));
file_put_contents(self::CACHE_PATH, serialize(
[
'initializers' => $this->container->getInitializers(),
'dynamic_initializers' => $this->container->getDynamicInitializers(),
],
));
}

public function restoreCache(Container $container): void
{
$initializers = unserialize(file_get_contents(self::CACHE_PATH));
$data = unserialize(file_get_contents(self::CACHE_PATH));

$this->container->setInitializers($initializers);
$this->container->setInitializers($data['initializers'] ?? []);
$this->container->setDynamicInitializers($data['dynamic_initializers'] ?? []);
}

public function destroyCache(): void
Expand Down

0 comments on commit 05f000d

Please sign in to comment.