1414
1515use ArrayAccess ;
1616use IteratorAggregate ;
17+ use SplObjectStorage ;
1718use Psr \Container \ContainerInterface ;
1819use BitFrame \Exception \{
1920 ContainerItemNotFoundException ,
2728use function gettype ;
2829use function sprintf ;
2930use function is_callable ;
30- use function spl_object_hash ;
3131use function array_key_exists ;
3232
3333class Container implements ContainerInterface, ArrayAccess, IteratorAggregate
@@ -38,12 +38,12 @@ class Container implements ContainerInterface, ArrayAccess, IteratorAggregate
3838
3939 private array $ instantiated = [];
4040
41- private array $ factories = [] ;
41+ private SplObjectStorage $ factories ;
4242
43- /* public function __construct()
43+ public function __construct ()
4444 {
4545 $ this ->factories = new SplObjectStorage ();
46- }*/
46+ }
4747
4848 /**
4949 * @param string $id
@@ -101,8 +101,7 @@ public function offsetUnset($id): void
101101 unset($ this ->bag [$ id ], $ this ->frozen [$ id ]);
102102
103103 if (is_object ($ this ->instantiated [$ id ])) {
104- $ hash = spl_object_hash ($ this ->bag [$ id ]);
105- unset($ this ->factories [$ hash ]);
104+ unset($ this ->factories [$ this ->bag [$ id ]]);
106105 }
107106 }
108107
@@ -124,8 +123,7 @@ public function freeze(string $id): self
124123
125124 public function factory (object $ factory ): object
126125 {
127- $ hash = spl_object_hash ($ factory );
128- $ this ->factories [$ hash ] = $ factory ;
126+ $ this ->factories ->attach ($ factory );
129127
130128 return $ factory ;
131129 }
@@ -160,9 +158,7 @@ public function get($id)
160158 }
161159
162160 if (isset ($ this ->instantiated [$ id ])) {
163- $ hash = spl_object_hash ($ this ->bag [$ id ]);
164-
165- if (isset ($ this ->factories [$ hash ])) {
161+ if (isset ($ this ->factories [$ this ->bag [$ id ]])) {
166162 return $ this ->bag [$ id ]($ this );
167163 }
168164
0 commit comments