1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace Webdevcave \Yadic ;
4
6
5
7
use Closure ;
@@ -49,14 +51,15 @@ public function __construct(CacheInterface $cache = null)
49
51
*
50
52
* @template T
51
53
*
52
- * @param T $id Identifier of the entry to look for.
54
+ * @param T $id Identifier of the entry to look for.
55
+ * @param array $arguments Predefined arguments.
53
56
*
54
57
* @throws NotFoundExceptionInterface No entry was found for **this** identifier.
55
58
* @throws ContainerExceptionInterface Error while retrieving the entry.
56
59
*
57
60
* @return T
58
61
*/
59
- public function get (string $ id ): mixed
62
+ public function get (string $ id, array $ arguments = [] ): mixed
60
63
{
61
64
if (isset ($ this ->singletons [$ id ])) {
62
65
return $ this ->singletons [$ id ];
@@ -69,10 +72,9 @@ public function get(string $id): mixed
69
72
try {
70
73
$ className = $ this ->aliases [$ id ] ?? $ id ;
71
74
$ reflectionClass = new ReflectionClass ($ className );
72
- $ arguments = [];
73
75
74
76
if ($ constructor = $ reflectionClass ->getConstructor ()) {
75
- $ arguments = $ this ->createArguments ($ constructor );
77
+ $ arguments = $ this ->createArguments ($ constructor, $ arguments );
76
78
}
77
79
78
80
$ instance = $ reflectionClass ->newInstanceArgs ($ arguments );
@@ -118,7 +120,8 @@ public function has(string $id): bool
118
120
private function createArguments (
119
121
ReflectionMethod |ReflectionFunction $ reflectionMethod ,
120
122
array $ arguments = []
121
- ): array {
123
+ ): array
124
+ {
122
125
foreach ($ reflectionMethod ->getParameters () as $ reflectionParameter ) {
123
126
$ argumentName = $ reflectionParameter ->getName ();
124
127
0 commit comments