-
Notifications
You must be signed in to change notification settings - Fork 0
/
Builder.php
45 lines (38 loc) · 893 Bytes
/
Builder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
declare(strict_types = 1);
namespace Innmind\DI;
/**
* @psalm-immutable
*/
final class Builder
{
/** @var array<string, callable(Container): object> */
private array $definitions = [];
/**
* @param array<string, callable(Container): object> $definitions
*/
private function __construct(array $definitions)
{
$this->definitions = $definitions;
}
/**
* @psalm-pure
*/
public static function new(): self
{
return new self([]);
}
/**
* @param callable(Container): object $definition
*/
public function add(string $name, callable $definition): self
{
$definitions = $this->definitions;
$definitions[$name] = $definition;
return new self($definitions);
}
public function build(): Container
{
return Container::of($this->definitions);
}
}