@@ -23,68 +23,68 @@ class Container implements ContainerInterface
23
23
24
24
public function __construct (array $ definitions = [])
25
25
{
26
- foreach ($ definitions as $ name => $ object ) {
27
- $ this ->set ($ name , $ object );
26
+ foreach ($ definitions as $ id => $ object ) {
27
+ $ this ->set ($ id , $ object );
28
28
}
29
29
}
30
30
31
- protected function set (string $ name , $ object ): void
31
+ protected function set (string $ id , $ object ): void
32
32
{
33
- unset($ this ->entries [$ name ], $ this ->factories [$ name ]);
33
+ unset($ this ->entries [$ id ], $ this ->factories [$ id ]);
34
34
35
35
if ($ object instanceof Closure) {
36
36
37
- $ this ->factories [$ name ] = $ object ;
37
+ $ this ->factories [$ id ] = $ object ;
38
38
} else {
39
- $ this ->entries [$ name ] = $ object ;
39
+ $ this ->entries [$ id ] = $ object ;
40
40
}
41
41
}
42
42
43
- public function with (string $ name , $ object ): Container
43
+ public function with (string $ id , $ object ): Container
44
44
{
45
45
$ container = clone $ this ;
46
46
47
- $ container ->set ($ name , $ object );
47
+ $ container ->set ($ id , $ object );
48
48
49
49
return $ container ;
50
50
}
51
51
52
- public function get ($ name )
52
+ public function get (string $ id )
53
53
{
54
- if (isset ($ this ->entries [$ name ]) || array_key_exists ($ name , $ this ->entries )) {
54
+ if (isset ($ this ->entries [$ id ]) || array_key_exists ($ id , $ this ->entries )) {
55
55
56
- return $ this ->entries [$ name ];
56
+ return $ this ->entries [$ id ];
57
57
}
58
58
59
- if (isset ($ this ->factories [$ name ])) {
59
+ if (isset ($ this ->factories [$ id ])) {
60
60
61
- $ this ->entries [$ name ] = $ this ->resolve ($ name );
61
+ $ this ->entries [$ id ] = $ this ->resolve ($ id );
62
62
63
- return $ this ->entries [$ name ];
63
+ return $ this ->entries [$ id ];
64
64
}
65
65
66
- if ($ this ->canCreate ($ name )) {
66
+ if ($ this ->canCreate ($ id )) {
67
67
68
- $ this ->factories [$ name ] = $ this ->getClassFactory ($ name );
69
- $ this ->entries [$ name ] = $ this ->resolve ($ name );
68
+ $ this ->factories [$ id ] = $ this ->getClassFactory ($ id );
69
+ $ this ->entries [$ id ] = $ this ->resolve ($ id );
70
70
71
- return $ this ->entries [$ name ];
71
+ return $ this ->entries [$ id ];
72
72
}
73
73
74
- throw new NotFoundException ("Entry for < $ name > could not be resolved " );
74
+ throw new NotFoundException ("Entry for < $ id > could not be resolved " );
75
75
}
76
76
77
- protected function resolve (string $ name )
77
+ protected function resolve (string $ id )
78
78
{
79
- if (isset ($ this ->resolving [$ name ])) {
80
- throw new CircularReferenceException ("Circular reference detected for < $ name > " );
79
+ if (isset ($ this ->resolving [$ id ])) {
80
+ throw new CircularReferenceException ("Circular reference detected for < $ id > " );
81
81
}
82
82
83
- $ this ->resolving [$ name ] = true ;
83
+ $ this ->resolving [$ id ] = true ;
84
84
85
- $ object = $ this ->factories [$ name ]($ this );
85
+ $ object = $ this ->factories [$ id ]($ this );
86
86
87
- unset($ this ->resolving [$ name ]);
87
+ unset($ this ->resolving [$ id ]);
88
88
89
89
return $ object ;
90
90
}
@@ -145,11 +145,11 @@ protected function canCreate(string $name): bool
145
145
return class_exists ($ name );
146
146
}
147
147
148
- public function has ($ name ): bool
148
+ public function has (string $ id ): bool
149
149
{
150
150
if (
151
- isset ($ this ->entries [$ name ]) || array_key_exists ($ name , $ this ->entries ) ||
152
- isset ($ this ->factories [$ name ]) || $ this ->canCreate ($ name )
151
+ isset ($ this ->entries [$ id ]) || array_key_exists ($ id , $ this ->entries ) ||
152
+ isset ($ this ->factories [$ id ]) || $ this ->canCreate ($ id )
153
153
) {
154
154
return true ;
155
155
}
0 commit comments