File tree Expand file tree Collapse file tree 8 files changed +66
-29
lines changed Expand file tree Collapse file tree 8 files changed +66
-29
lines changed Original file line number Diff line number Diff line change 99 cs :
1010 uses : ray-di/.github/.github/workflows/coding-standards.yml@v1
1111 with :
12- php_version : 8.1
12+ php_version : 8.3
Original file line number Diff line number Diff line change 1616 - name : Setup PHP
1717 uses : shivammathur/setup-php@v2
1818 with :
19- php-version : 8.1
19+ php-version : 8.3
2020 tools : cs2pr
2121 coverage : none
2222
Original file line number Diff line number Diff line change 99 sa :
1010 uses : ray-di/.github/.github/workflows/static-analysis.yml@v1
1111 with :
12- php_version : 8.1
12+ php_version : 8.3
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ parameters:
99 - tests/di/tmp/*
1010 - tests/Di/tmp/*
1111 - tests/di/Fake/*
12+ - tests/di/Ray_Di_*
1213 ignoreErrors :
1314 - ' #contains generic class ReflectionAttribute but does not specify its types:#'
1415 - ' #generic class ReflectionAttribute but does not specify its types:#'
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Ray \Di ;
6+
7+ use Ray \Di \Di \Set ;
8+
9+ /**
10+ * @implements ProviderInterface<mixed>
11+ * @template T of object
12+ */
13+ final class ProviderProvider implements ProviderInterface
14+ {
15+ /** @var InjectorInterface */
16+ private $ injector ;
17+
18+ /** @var Set<T> */
19+ private $ set ;
20+
21+ /** @param Set<T> $set */
22+ public function __construct (InjectorInterface $ injector , Set $ set )
23+ {
24+ $ this ->injector = $ injector ;
25+ $ this ->set = $ set ;
26+ }
27+
28+ /** @return mixed */
29+ public function get ()
30+ {
31+ return $ this ->injector ->getInstance ($ this ->set ->interface , $ this ->set ->name );
32+ }
33+ }
Original file line number Diff line number Diff line change @@ -48,30 +48,6 @@ public function get()
4848 throw new SetNotFound ((string ) $ this ->ip ->getParameter ());
4949 }
5050
51- return new class ($ this ->injector , $ set ) implements ProviderInterface
52- {
53- /** @var InjectorInterface */
54- private $ injector ;
55-
56- /** @var Set<object> */
57- private $ set ;
58-
59- /**
60- * @param Set<object> $set
61- */
62- public function __construct (InjectorInterface $ injector , Set $ set )
63- {
64- $ this ->injector = $ injector ;
65- $ this ->set = $ set ;
66- }
67-
68- /**
69- * @return mixed
70- */
71- public function get ()
72- {
73- return $ this ->injector ->getInstance ($ this ->set ->interface , $ this ->set ->name );
74- }
75- };
51+ return new ProviderProvider ($ this ->injector , $ set );
7652 }
7753}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Ray \Di ;
6+
7+ use PHPUnit \Framework \TestCase ;
8+ use Ray \Di \Di \Set ;
9+
10+ class ProviderProviderTest extends TestCase
11+ {
12+ public function testGet (): void
13+ {
14+ $ injector = new Injector (
15+ new class extends AbstractModule {
16+ protected function configure ()
17+ {
18+ $ this ->bind (FakeEngineInterface::class)->toInstance (new FakeEngine ());
19+ }
20+ }
21+ );
22+ $ set = new Set (FakeEngineInterface::class);
23+ $ provider = new ProviderProvider ($ injector , $ set );
24+ $ instance = $ provider ->get ();
25+ $ this ->assertInstanceOf (FakeEngine::class, $ instance );
26+ }
27+ }
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ class VisitorTest extends TestCase
3030 public function setUp (): void
3131 {
3232 $ this ->visitor = new NullVisitor ();
33- $ this ->container = (new ContainerFactory ())(new FakeCarModule (), __DIR__ );
33+ $ this ->container = (new ContainerFactory ())(new FakeCarModule (), __DIR__ . ' /tmp ' );
3434 $ container = $ this ->container ->getContainer ();
3535 $ dependency = $ container ['Ray\Di\FakeCarInterface- ' ];
3636 assert ($ dependency instanceof Dependency);
You can’t perform that action at this time.
0 commit comments