-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContainerContract.php
152 lines (139 loc) · 3.74 KB
/
ContainerContract.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
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
152
<?php
/**
* This file is part of the Zest Framework.
*
* @author Muhammad Umer Farooq (Malik) <[email protected]>
*
* @link https://github.com/zestframework/Zest_Framework
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
* @since 3.0.0
*
* @license MIT
*/
namespace Zest\Container;
interface ContainerContract
{
/**
* Register a type hint.
*
* @param string|array $hint Type hint or array contaning both type hint and alias.
* @param string|\Closure $class Class name or closure.
* @param bool $singleton Should we return the same instance every time?
*
* @since 3.0.0
*
* @return void
*/
public function register($hint, $class, bool $singleton = false);
/**
* Register a type hint and return the same instance every time.
*
* @param string|array $hint Type hint or array contaning both type hint and alias.
* @param string|\Closure $class Class name or closure.
*
* @since 3.0.0
*
* @return 3.0.0
*/
public function registerSingleton($hint, $class);
/**
* Register a singleton instance.
*
* @param string|array $hint Type hint or array contaning both type hint and alias.
* @param object $instance Class instance.
*
* @since 3.0.0
*
* @return void
*/
public function registerInstance($hint, $instance);
/**
* Registers a contextual dependency.
*
* @param string $class Class.
* @param string $interface Interface.
* @param string $implementation Implementation.
*
* @since 3.0.0
*
* @return void
*/
public function registerContextualDependency($class, string $interface, string $implementation);
/**
* Creates a class instance using closure.
*
* @param closure $factory Closuare.
* @param array $parameters Constructor parameters.
*
* @since 3.0.0
*
* @return object
*/
public function closureFactory(\Closure $factory, array $parameters);
/**
* Creates a class instance using reflection.
*
* @param mixed $class Class name.
* @param array $parameters Constructor parameters.
*
* @since 3.0.0
*
* @return object
*/
public function reflectionFactory($class, array $parameters = []);
/**
* Creates a class instance.
*
* @param string|\Closure $class Class name or closure.
* @param array $parameters Constructor parameters.
*
* @since 3.0.0
*
* @return object
*/
public function factory($class, array $parameters = []);
/**
* Checks if a class is registered in the container.
*
* @param string $class Class name.
*
* @since 3.0.0
*
* @return bool
*/
public function has(string $class);
/**
* Returns TRUE if a class has been registered as a singleton and FALSE if not.
*
* @param string $class Class name.
*
* @since 3.0.0
*
* @return bool
*/
public function isSingleton(string $class);
/**
* Returns a class instance.
*
* @param string $class Class name.
* @param array $parameters Constructor parameters.
*
* @since 3.0.0
*
* @return object
*/
public function get($class, array $parameters = []);
/**
* Execute a callable and inject its dependencies.
*
* @param callable $callable Callable.
* @param array $parameters Parameters.
*
* @since 3.0.0
*
* @return object
*/
public function exec(callable $callable, array $parameters = []);
}