Repository navigation
Expand file tree
/
Copy pathContainer.php
More file actions
151 lines (133 loc) · 4.32 KB
/
Copy pathContainer.php
File metadata and controls
151 lines (133 loc) · 4.32 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
* Container Contract
*
* @package Mantle
*/
namespace Mantle\Contracts;
use ArrayAccess;
use Closure;
use Psr\Container\ContainerInterface;
/**
* Container Contract
*/
interface Container extends ArrayAccess, ContainerInterface {
/**
* Determine if the given abstract type has been bound.
*
* @param string $abstract Abstract name.
*/
public function bound( string $abstract ): bool;
/**
* Alias a type to a different name.
*
* @param string $abstract Abstract name.
* @param string $alias Alias name.
*/
public function alias( string $abstract, string $alias ): void;
/**
* Register a binding with the container.
*
* @param string $abstract Abstract name.
* @param \Closure|string|null $concrete Concrete to bind.
* @param bool $shared Shared flag.
*/
public function bind( string $abstract, Closure|string|null $concrete = null, bool $shared = false ): void;
/**
* Register a binding if it hasn't already been registered.
*
* @param string $abstract Abstract name.
* @param \Closure|string|null $concrete Concrete to bind.
* @param bool $shared Shared flag.
*/
public function bind_if( string $abstract, Closure|string|null $concrete = null, bool $shared = false ): void;
/**
* Register a shared binding in the container.
*
* @param string $abstract Abstract name.
* @param \Closure|string|null $concrete Concrete to bind.
* @phpstan-param (\Closure(static, array<mixed>): mixed)|string|null $concrete
*/
public function singleton( string $abstract, Closure|string|null $concrete = null ): void;
/**
* Register a shared binding if it hasn't already been registered.
*
* @param string $abstract Abstract name.
* @param \Closure|string|null $concrete Concrete name.
* @phpstan-param (\Closure(static, array<mixed>): mixed)|string|null $concrete
*/
public function singleton_if( string $abstract, Closure|string|null $concrete = null ): void;
/**
* "Extend" an abstract type in the container.
*
* @param string $abstract Abstract name.
* @param \Closure $closure Closure callback.
*/
public function extend( string $abstract, Closure $closure ): void;
/**
* Register an existing instance as shared in the container.
*
* @param string $abstract Abstract name.
* @param mixed $instance Interface instance.
*/
public function instance( string $abstract, mixed $instance ): mixed;
/**
* Get a closure to resolve the given type from the container.
*
* @param string $abstract Abstract name.
*/
public function factory( string $abstract ): Closure;
/**
* Flush the container of all bindings and resolved instances.
*/
public function flush(): void;
/**
* Call the given Closure / class@method and inject its dependencies.
*
* @param array|string|callable $callback
* @param array<mixed> $parameters
* @param string|null $default_method
*/
public function call( $callback, array $parameters = [], $default_method = null ): mixed;
/**
* Resolve the given type from the container.
*
* @param string $abstract Abstract name.
* @param array<mixed> $parameters Parameters to pass.
*/
public function make( $abstract, array $parameters = [] ): mixed;
/**
* Create a new class instance from the container.
*
* Similar to make() but specifically for passing a class name and returning
* an instance of it. This is useful for PHPStan.
*
* @template TAbstract of object
*
* @param string $class
* @phpstan-param class-string<TAbstract> $class
* @param array<mixed> $parameters
* @phpstan-return TAbstract
*/
public function class( string $class, array $parameters = [] ): object;
/**
* Determine if the given abstract type has been resolved.
*
* @param string $abstract Abstract name.
*/
public function resolved( string $abstract ): bool;
/**
* Register a new resolving callback.
*
* @param \Closure|string $abstract Abstract name.
* @param \Closure|null $callback Callback.
*/
public function resolving( $abstract, ?Closure $callback = null ): void;
/**
* Register a new after resolving callback.
*
* @param \Closure|string $abstract Abstract name.
* @param \Closure|null $callback Callback.
*/
public function after_resolving( $abstract, ?Closure $callback = null ): void;
}