-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainerAdapter.php
More file actions
115 lines (98 loc) · 2.76 KB
/
ContainerAdapter.php
File metadata and controls
115 lines (98 loc) · 2.76 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php declare(strict_types=1);
namespace StellarWP\Foundation\Container;
use Closure;
use lucatume\DI52\Container as DI52Container;
use lucatume\DI52\ContainerException;
use StellarWP\Foundation\Container\Contracts\Container;
/**
* @method mixed make(string $id)
* @method mixed getVar(string $key, mixed|null $default = null)
* @method void singletonDecorators($id, array<string> $decorators, ?array<string> $afterBuildMethods = null)
* @method void bindDecorators($id, array<string> $decorators, ?array<string> $afterBuildMethods = null)
*/
final class ContainerAdapter implements Container
{
public function __construct(
private readonly DI52Container $container
) {
}
/**
* @param string[]|null $afterBuildMethods
*
* @throws \lucatume\DI52\ContainerException
*/
public function bind(string $id, mixed $implementation = null, ?array $afterBuildMethods = null): void {
$this->container->bind($id, $implementation, $afterBuildMethods);
}
/**
* {@inheritDoc}
*/
public function get(string $id): mixed {
return $this->container->get($id);
}
/**
* @codeCoverageIgnore
*/
public function get_container(): DI52Container {
return $this->container;
}
/**
* {@inheritDoc}
*
* @codeCoverageIgnore
*/
public function has(string $id): bool {
return $this->container->has($id);
}
/**
* @param string[]|null $afterBuildMethods
*
* @throws \lucatume\DI52\ContainerException
*/
public function singleton(string $id, mixed $implementation = null, ?array $afterBuildMethods = null): void {
$this->container->singleton($id, $implementation, $afterBuildMethods);
}
/**
* {@inheritDoc}
*/
public function register(string $serviceProviderClass, ...$alias): void {
$this->container->register($serviceProviderClass, ...$alias);
}
/**
* {@inheritDoc}
*/
public function when(string $class): Container {
$this->container->when($class);
return $this;
}
/**
* {@inheritDoc}
*/
public function needs(string $id): Container {
$this->container->needs($id);
return $this;
}
public function give(mixed $implementation): void {
$this->container->give($implementation);
}
public function instance(mixed $id, array $buildArgs = [], ?array $afterBuildMethods = null): Closure {
// @phpstan-ignore-next-line invalid DocBlock comments in DI52
return $this->container->instance($id, $buildArgs, $afterBuildMethods);
}
/**
* @param class-string|string|object $id
*
* @throws ContainerException
*/
public function callback(object|string $id, string $method): callable {
return $this->container->callback($id, $method);
}
/**
* Defer all other calls to the container object.
*
* @param mixed[] $args
*/
public function __call(string $name, array $args): mixed {
return $this->container->{$name}(...$args);
}
}