Skip to content

Commit 56f68d7

Browse files
committed
PoC
1 parent 93c8431 commit 56f68d7

4 files changed

Lines changed: 1950 additions & 1089 deletions

File tree

src/Container/Configuration.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Patchlevel\EventSourcing\Subscription\RetryStrategy\RetryStrategy;
1818
use Patchlevel\EventSourcing\Subscription\Subscriber\ArgumentResolver\ArgumentResolver;
1919
use Patchlevel\Hydrator\Extension;
20+
use Patchlevel\Hydrator\Guesser\Guesser;
2021
use Throwable;
2122

2223
use function array_values;
@@ -218,6 +219,9 @@ final class Configuration
218219
/** @var StoreOptions */
219220
public array $storeMigrationOptions = [];
220221

222+
/** @var array<Guesser> */
223+
public array $guesser = [];
224+
221225
public function withAggregates(string ...$aggregates): self
222226
{
223227
$newConfiguration = clone $this;
@@ -383,18 +387,23 @@ public function withSnapshotAdapters(array $snapshotAdapters): self
383387
return $newConfiguration;
384388
}
385389

386-
public function withHydratorDefaultLazy(bool $hydratorDefaultLazy): self
390+
/**
391+
* @param array<Guesser> $guesser
392+
*/
393+
public function withLegacyHydrator(array $guesser = []): self
387394
{
388395
$newConfiguration = clone $this;
389-
$newConfiguration->hydratorDefaultLazy = $hydratorDefaultLazy;
396+
$newConfiguration->hydratorMode = self::HYDRATOR_MODE_LEGACY;
397+
$newConfiguration->guesser = $guesser;
390398

391399
return $newConfiguration;
392400
}
393401

394-
public function withHydratorMode(string $hydratorMode): self
402+
403+
public function withLazyHydrator(bool $hydratorDefaultLazy): self
395404
{
396405
$newConfiguration = clone $this;
397-
$newConfiguration->hydratorMode = $hydratorMode;
406+
$newConfiguration->hydratorDefaultLazy = $hydratorDefaultLazy;
398407

399408
return $newConfiguration;
400409
}

src/Container/Container.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@ final class Container implements ContainerInterface
2727
*/
2828
public function __construct(
2929
private array $services = [],
30-
private readonly array $factories = [],
31-
private readonly array $aliases = [],
30+
private array $factories = [],
31+
private array $aliases = [],
3232
) {
3333
}
3434

35+
/**
36+
* @template T object
37+
*
38+
* @param string|class-string<T> $id
39+
*
40+
* @return ($id is class-string<T> ? T : object)
41+
*/
3542
public function get(string $id): mixed
3643
{
3744
$id = $this->resolveAlias($id);
@@ -83,4 +90,20 @@ private function resolveAlias(string $id): string
8390

8491
return $resolved;
8592
}
93+
94+
public function bind(string $id, object|callable $service): void
95+
{
96+
if (is_callable($service)) {
97+
$this->factories[$id] = $service;
98+
99+
return;
100+
}
101+
102+
$this->services[$id] = $service;
103+
}
104+
105+
public function alias(string $id, string $alias): void
106+
{
107+
$this->aliases[$id] = $alias;
108+
}
86109
}

0 commit comments

Comments
 (0)