@@ -34,6 +34,22 @@ interface DIModule
3434 public function configure (DIContainer $ container ): void ;
3535}
3636
37+ interface DIContainerInterface extends ContainerInterface
38+ {
39+ public function new (string $ class , array $ arguments = []): ?object ;
40+
41+ public function bind (string $ interface , string $ class = '' ): DIContainerInterface ;
42+
43+ public function singleton (string $ class , array $ arguments = []): object ;
44+
45+ public function share (object $ instance , array $ exclude = []): DIContainerInterface ;
46+
47+ public function named (string $ name , $ value ): DIContainerInterface ;
48+
49+ public function getStorage ();
50+ }
51+
52+
3753/**
3854 * The entry point of the DIContainer that draws the lines between the
3955 * APIs, implementation of these APIs, modules that configure these
@@ -44,14 +60,14 @@ public function configure(DIContainer $container): void;
4460 * ($container)([AppEntry::class, 'method']);
4561 * ```
4662 */
47- final class DIContainer implements ContainerInterface
63+ class DIContainer implements DIContainerInterface
4864{
4965 public const SINGLETONS = 'singletons ' ;
5066 public const BINDINGS = 'bindings ' ;
5167 public const EXCLUDE = 'exclude ' ;
5268 public const NAMED = 'named ' ;
5369
54- private $ reflection ;
70+ protected $ reflection ;
5571 private $ inProgress = [];
5672
5773 private $ singletons = [];
@@ -145,7 +161,7 @@ public function singleton(string $class, array $arguments = []): object
145161 *
146162 * @return DIContainer
147163 */
148- public function share (object $ instance , array $ exclude = []): DIContainer
164+ public function share (object $ instance , array $ exclude = []): DIContainerInterface
149165 {
150166 $ class = get_class ($ instance );
151167 $ this ->bindInterfaces ($ instance , $ class );
@@ -171,7 +187,7 @@ public function share(object $instance, array $exclude = []): DIContainer
171187 *
172188 * @return DIContainer
173189 */
174- public function bind (string $ interface , string $ class = '' ): DIContainer
190+ public function bind (string $ interface , string $ class = '' ): DIContainerInterface
175191 {
176192 assert (false === empty ($ interface ), 'Dependency name for bind() method ' );
177193
@@ -193,7 +209,7 @@ public function bind(string $interface, string $class = ''): DIContainer
193209 *
194210 * @return DIContainer
195211 */
196- public function named (string $ name , $ value ): DIContainer
212+ public function named (string $ name , $ value ): DIContainerInterface
197213 {
198214 if (1 !== preg_match ('/\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/ ' , $ name )) {
199215 throw DIException::forInvalidParameterName ($ name );
0 commit comments