|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
use MichaelRubel\EnhancedContainer\Call; |
|
6
|
|
|
use MichaelRubel\EnhancedContainer\Core\BindingBuilder; |
|
7
|
|
|
|
|
8
|
|
|
if (! function_exists('call')) { |
|
9
|
|
|
/** |
|
10
|
|
|
* @param string|object $class |
|
11
|
|
|
* @param array $parameters |
|
12
|
|
|
* |
|
13
|
|
|
* @return mixed |
|
14
|
|
|
*/ |
|
15
|
|
|
function call(string|object $class, array $parameters = []): mixed |
|
16
|
|
|
{ |
|
17
|
|
|
return app(Call::class, [$class, $parameters]); |
|
18
|
|
|
} |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
if (! function_exists('bind')) { |
|
22
|
|
|
/** |
|
23
|
|
|
* @param string|object $abstract |
|
24
|
|
|
* |
|
25
|
|
|
* @return BindingBuilder |
|
26
|
|
|
*/ |
|
27
|
|
|
function bind(string|object $abstract): BindingBuilder |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
return new BindingBuilder($abstract); |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
if (! function_exists('singleton')) { |
|
34
|
|
|
/** |
|
35
|
|
|
* @param string $abstract |
|
36
|
|
|
* @param Closure|string|null $concrete |
|
37
|
|
|
* |
|
38
|
|
|
* @return void |
|
39
|
|
|
*/ |
|
40
|
|
|
function singleton(string $abstract, \Closure|string $concrete = null): void |
|
41
|
|
|
{ |
|
42
|
|
|
app()->singleton($abstract, $concrete); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if (! function_exists('scoped')) { |
|
47
|
|
|
/** |
|
48
|
|
|
* @param string $abstract |
|
49
|
|
|
* @param Closure|string|null $concrete |
|
50
|
|
|
* |
|
51
|
|
|
* @return void |
|
52
|
|
|
*/ |
|
53
|
|
|
function scoped(string $abstract, \Closure|string $concrete = null): void |
|
54
|
|
|
{ |
|
55
|
|
|
app()->scoped($abstract, $concrete); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
if (! function_exists('extend')) { |
|
60
|
|
|
/** |
|
61
|
|
|
* @param string $abstract |
|
62
|
|
|
* @param Closure $closure |
|
63
|
|
|
* |
|
64
|
|
|
* @return void |
|
65
|
|
|
*/ |
|
66
|
|
|
function extend(string $abstract, \Closure $closure): void |
|
67
|
|
|
{ |
|
68
|
|
|
app()->extend($abstract, $closure); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
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.