|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
use MichaelRubel\EnhancedContainer\Core\BindingBuilder; |
|
6
|
|
|
use MichaelRubel\EnhancedContainer\Core\CallProxy; |
|
7
|
|
|
|
|
8
|
|
|
if (! function_exists('call')) { |
|
9
|
|
|
/** |
|
10
|
|
|
* @param string|object $class |
|
11
|
|
|
* @param array $parameters |
|
12
|
|
|
* @param string|null $context |
|
13
|
|
|
* |
|
14
|
|
|
* @return CallProxy |
|
15
|
|
|
*/ |
|
16
|
|
|
function call(string|object $class, array $parameters = [], ?string $context = null): CallProxy |
|
17
|
|
|
{ |
|
18
|
64 |
|
return app(CallProxy::class, [ |
|
19
|
|
|
'class' => $class, |
|
20
|
|
|
'dependencies' => $parameters, |
|
21
|
|
|
'context' => $context, |
|
22
|
|
|
]); |
|
23
|
|
|
} |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
if (! function_exists('bind')) { |
|
27
|
|
|
/** |
|
28
|
|
|
* @param string|object $abstract |
|
29
|
|
|
* |
|
30
|
|
|
* @return BindingBuilder |
|
31
|
|
|
*/ |
|
32
|
|
|
function bind(string|object $abstract): BindingBuilder |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
37 |
|
return app(BindingBuilder::class, ['abstract' => $abstract]); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
if (! function_exists('singleton')) { |
|
39
|
|
|
/** |
|
40
|
|
|
* @param string $abstract |
|
41
|
|
|
* @param Closure|string|null $concrete |
|
42
|
|
|
* |
|
43
|
|
|
* @return void |
|
44
|
|
|
*/ |
|
45
|
|
|
function singleton(string $abstract, Closure|string $concrete = null): void |
|
|
|
|
|
|
46
|
|
|
{ |
|
47
|
1 |
|
app()->singleton($abstract, $concrete); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if (! function_exists('scoped')) { |
|
52
|
|
|
/** |
|
53
|
|
|
* @param string $abstract |
|
54
|
|
|
* @param Closure|string|null $concrete |
|
55
|
|
|
* |
|
56
|
|
|
* @return void |
|
57
|
|
|
*/ |
|
58
|
|
|
function scoped(string $abstract, Closure|string $concrete = null): void |
|
59
|
|
|
{ |
|
60
|
1 |
|
app()->scoped($abstract, $concrete); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if (! function_exists('extend')) { |
|
65
|
|
|
/** |
|
66
|
|
|
* @param string $abstract |
|
67
|
|
|
* @param Closure $closure |
|
68
|
|
|
* |
|
69
|
|
|
* @return void |
|
70
|
|
|
*/ |
|
71
|
|
|
function extend(string $abstract, Closure $closure): void |
|
72
|
|
|
{ |
|
73
|
1 |
|
app()->extend($abstract, $closure); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
if (! function_exists('instance')) { |
|
78
|
|
|
/** |
|
79
|
|
|
* @param string $abstract |
|
80
|
|
|
* @param mixed $instance |
|
81
|
|
|
* |
|
82
|
|
|
* @return void |
|
83
|
|
|
*/ |
|
84
|
|
|
function instance(string $abstract, mixed $instance): void |
|
85
|
|
|
{ |
|
86
|
1 |
|
app()->instance($abstract, $instance); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.