-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIContainer.php
More file actions
111 lines (99 loc) · 4.13 KB
/
IContainer.php
File metadata and controls
111 lines (99 loc) · 4.13 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
<?php
/*
* Opulence
*
* @link https://www.opulencephp.com
* @copyright Copyright (C) 2021 David Young
* @license https://github.com/opulencephp/Opulence/blob/1.2/LICENSE.md
*/
namespace Opulence\Ioc;
/**
* Defines the interface for dependency injection containers to implement
*/
interface IContainer
{
/**
* Binds a factory that will return a concrete instance of the interface
*
* @param string|array $interfaces The interface or interfaces to bind to
* @param callable $factory The factory to bind
* @param bool $resolveAsSingleton Whether or not to resolve the factory as a singleton
*/
public function bindFactory($interfaces, callable $factory, bool $resolveAsSingleton = false);
/**
* Binds a concrete instance to the interface
*
* @param string|array $interfaces The interface or interfaces to bind to
* @param object $instance The instance to bind
*/
public function bindInstance($interfaces, $instance);
/**
* Binds a non-singleton concrete class to an interface
*
* @param string|array $interfaces The interface or interfaces to bind to
* @param string|null $concreteClass The concrete class to bind, or null if the interface actually is a concrete class
* @param array $primitives The list of primitives to inject (must be in same order they appear in constructor)
*/
public function bindPrototype($interfaces, string $concreteClass = null, array $primitives = []);
/**
* Binds a singleton concrete class to an interface
*
* @param string|array $interfaces The interface or interfaces to bind to
* @param string|null $concreteClass The concrete class to bind, or null if the interface actually is a concrete class
* @param array $primitives The list of primitives to inject (must be in same order they appear in constructor)
*/
public function bindSingleton($interfaces, string $concreteClass = null, array $primitives = []);
/**
* Resolves a closure's parameters and calls it
*
* @param callable $closure The closure to resolve
* @param array $primitives The list of primitives to inject (must be in same order they appear in closure)
* @return mixed The result of the call
* @throws IocException Thrown if there was an error calling the method
*/
public function callClosure(callable $closure, array $primitives = []);
/**
* Resolves a method's parameters and calls it
*
* @param object|string $instance The instance (or class name if the method is static) whose method we're calling
* @param string $methodName The name of the method we're calling
* @param array $primitives The list of primitives to inject (must be in same order they appear in closure)
* @param bool $ignoreMissingMethod Whether or not we ignore if the method does not exist
* @return mixed The result of the call
* @throws IocException Thrown if there was an error calling the method
*/
public function callMethod(
$instance,
string $methodName,
array $primitives = [],
bool $ignoreMissingMethod = false
);
/**
* Sets a target for all calls in the callback
*
* @param string $targetClass The target class
* @param callable $callback The callback containing targeted container method calls
*/
public function for(string $targetClass, callable $callback);
/**
* Gets whether or not an interface has a binding
*
* @param string $interface The interface to check
* @return bool True if the interface has a binding, otherwise false
*/
public function hasBinding(string $interface) : bool;
/**
* Resolve an instance of the interface
*
* @param string $interface The interface to resolve
* @return mixed The resolved instance
* @throws IocException Thrown if there was an error resolving the interface
*/
public function resolve(string $interface);
/**
* Unbinds the interface from the container
*
* @param string|array $interfaces The interface or interfaces to unbind from
*/
public function unbind($interfaces);
}