File tree 1 file changed +23
-5
lines changed
1 file changed +23
-5
lines changed Original file line number Diff line number Diff line change 17
17
18
18
namespace Rade \DI \Attribute ;
19
19
20
+ use Rade \DI \Definitions \Parameter ;
21
+ use Rade \DI \Definitions \TaggedLocator ;
20
22
use Rade \DI \Resolver ;
21
23
22
24
/**
27
29
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::TARGET_FUNCTION | \Attribute::TARGET_PARAMETER )]
28
30
final class Inject
29
31
{
32
+ public const
33
+ VALUE = 0 ,
34
+ REFERENCE = 1 ,
35
+ PARAMETER = 2 ;
36
+
37
+ private int $ type ;
38
+
30
39
/** @var mixed */
31
40
private $ value ;
32
41
33
42
/**
34
43
* @param mixed $value
35
44
*/
36
- public function __construct ($ value = null )
45
+ public function __construct ($ value = null , $ type = self :: REFERENCE )
37
46
{
38
47
$ this ->value = $ value ;
48
+ $ this ->type = $ type ;
39
49
}
40
50
41
51
/**
@@ -45,14 +55,22 @@ public function __construct($value = null)
45
55
*/
46
56
public function resolve (Resolver $ resolver , string $ typeName = null )
47
57
{
48
- if (\is_string ($ value = $ this ->value ?? $ typeName )) {
58
+ if (null === $ value = $ this ->value ?? $ typeName ) {
59
+ return null ;
60
+ }
61
+
62
+ if ($ value instanceof TaggedLocator) {
63
+ throw new \LogicException (\sprintf ('Use the #[%s] attribute instead for lazy loading tags. ' , Tagged::class));
64
+ }
65
+
66
+ if (self ::REFERENCE === $ this ->type ) {
49
67
return $ resolver ->resolveReference ($ value );
50
68
}
51
69
52
- if (null !== $ value ) {
53
- return $ resolver -> resolve ($ value );
70
+ if (self :: PARAMETER === $ this -> type ) {
71
+ $ value = new Parameter ($ value, true );
54
72
}
55
73
56
- return $ value ;
74
+ return $ resolver -> resolve ( $ value) ;
57
75
}
58
76
}
You can’t perform that action at this time.
0 commit comments