File tree Expand file tree Collapse file tree 7 files changed +126
-0
lines changed Expand file tree Collapse file tree 7 files changed +126
-0
lines changed Original file line number Diff line number Diff line change @@ -22,3 +22,23 @@ services:
22
22
23
23
# add more service definitions when explicit configuration is needed
24
24
# please note that last definitions always *replace* previous ones
25
+
26
+ foo :
27
+ class : App\Service\Foo
28
+ tags : ['my_tag']
29
+
30
+ debug.foo :
31
+ decorates : foo
32
+ class : App\Service\Decorator
33
+
34
+ debug.debug.foo :
35
+ decorates : debug.foo
36
+ class : App\Service\Decorator
37
+
38
+ bar :
39
+ class : App\Service\Bar
40
+ tags : ['my_tag']
41
+
42
+ debug.App\Service\Bar :
43
+ decorates : App\Service\Bar
44
+ class : App\Service\Decorator
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Controller ;
4
+
5
+ use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
6
+ use Symfony \Component \DependencyInjection \Argument \ServiceLocator ;
7
+ use Symfony \Component \DependencyInjection \Attribute \TaggedLocator ;
8
+ use Symfony \Component \HttpFoundation \Response ;
9
+ use Symfony \Component \Routing \Annotation \Route ;
10
+
11
+ class HomepageController extends AbstractController
12
+ {
13
+ public function __construct (
14
+ #[TaggedLocator('my_tag ' )]
15
+ private readonly ServiceLocator $ serviceLocator ,
16
+ ) {
17
+ }
18
+
19
+ #[Route('/ ' )]
20
+ public function index (): Response
21
+ {
22
+ $ services = [];
23
+ foreach ($ this ->serviceLocator ->getProvidedServices () as $ key => $ class ) {
24
+ $ services [] = [
25
+ '$key ' => $ key ,
26
+ '$class ' => $ class ,
27
+ 'instance ' => $ this ->serviceLocator ->get ($ key ),
28
+ ];
29
+ }
30
+
31
+ dd ($ services );
32
+
33
+ return $ this ->render ('homepage/index.html.twig ' , [
34
+ 'controller_name ' => 'HomepageController ' ,
35
+ ]);
36
+ }
37
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Service ;
4
+
5
+ use Symfony \Component \DependencyInjection \Attribute \AutoconfigureTag ;
6
+
7
+ #[AutoconfigureTag('my_tag ' )]
8
+ final readonly class Bar implements MyInterface
9
+ {
10
+ public function myMethod (): string
11
+ {
12
+ return 'Hello from Bar! ' ;
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Service ;
4
+
5
+ final readonly class Decorator implements MyInterface
6
+ {
7
+ public function __construct (
8
+ private MyInterface $ myInterface ,
9
+ ) {
10
+ }
11
+
12
+ public function myMethod (): string
13
+ {
14
+ return 'Decorated: ' . $ this ->myInterface ->myMethod ();
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Service ;
4
+
5
+ final readonly class Foo implements MyInterface
6
+ {
7
+ public function myMethod (): string
8
+ {
9
+ return 'Hello from Foo! ' ;
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Service ;
4
+
5
+ interface MyInterface
6
+ {
7
+ public function myMethod (): string ;
8
+ }
Original file line number Diff line number Diff line change
1
+ {% extends ' base.html.twig' %}
2
+
3
+ {% block title %}Hello HomepageController!{% endblock %}
4
+
5
+ {% block body %}
6
+ <style >
7
+ .example-wrapper { margin : 1em auto ; max-width : 800px ; width : 95% ; font : 18px /1.5 sans-serif ; }
8
+ .example-wrapper code { background : #F5F5F5 ; padding : 2px 6px ; }
9
+ </style >
10
+
11
+ <div class =" example-wrapper" >
12
+ <h1 >Hello {{ controller_name }}! ✅</h1 >
13
+
14
+ This friendly message is coming from:
15
+ <ul >
16
+ <li >Your controller at <code ><a href =" {{ ' /home/gregoire/dev/labs/symfony/symfony-5.4/src/Controller/HomepageController.php' | file_link(0 ) }}" >src/Controller/HomepageController.php</a ></code ></li >
17
+ <li >Your template at <code ><a href =" {{ ' /home/gregoire/dev/labs/symfony/symfony-5.4/templates/homepage/index.html.twig' | file_link(0 ) }}" >templates/homepage/index.html.twig</a ></code ></li >
18
+ </ul >
19
+ </div >
20
+ {% endblock %}
You can’t perform that action at this time.
0 commit comments