@@ -81,21 +81,37 @@ Symfony Standard Edition:
81
81
<prototype namespace =" AppBundle\Controller\" resource =" ../../src/AppBundle/Controller" public =" true" >
82
82
<tag name =" controller.service_arguments" />
83
83
</prototype >
84
+
85
+ <!-- add more services, or override services that need manual wiring -->
84
86
</services >
85
87
</container >
86
88
87
89
.. code-block :: php
88
90
89
91
// app/config/services.php
92
+ use Symfony\Component\DependencyInjection\Definition;
90
93
91
- // _defaults and loading entire directories is not possible with PHP configuration
92
- // you need to define your services one-by-one
93
- use AppBundle\Controller\DefaultController;
94
+ // To use as default template
95
+ $definition = new Definition();
94
96
95
- $container->autowire(DefaultController::class)
97
+ $definition
98
+ ->setAutowired(true)
96
99
->setAutoconfigured(true)
100
+ ->setPublic(false)
101
+ ;
102
+
103
+ $this->registerClasses($definition, 'AppBundle\\', '../../src/AppBundle/*', '../../src/AppBundle/{Entity,Repository}');
104
+
105
+ // Changes default config
106
+ $definition
107
+ ->setPublic(true)
97
108
->addTag('controller.service_arguments')
98
- ->setPublic(true);
109
+ ;
110
+
111
+ // $this is a reference to the current loader
112
+ $this->registerClasses($definition, 'AppBundle\\Controller\\', '../../src/AppBundle/Controller/*');
113
+
114
+ // add more services, or override services that need manual wiring
99
115
100
116
This small bit of configuration contains a paradigm shift of how services
101
117
are configured in Symfony.
@@ -147,9 +163,18 @@ thanks to the following config:
147
163
.. code-block :: php
148
164
149
165
// app/config/services.php
166
+ use Symfony\Component\DependencyInjection\Definition;
150
167
151
- // services cannot be automatically loaded with PHP configuration
152
- // you need to define your services one-by-one
168
+ // To use as default template
169
+ $definition = new Definition();
170
+
171
+ $definition
172
+ ->setAutowired(true)
173
+ ->setAutoconfigured(true)
174
+ ->setPublic(false)
175
+ ;
176
+
177
+ $this->registerClasses($definition, 'AppBundle\\', '../../src/AppBundle/*', '../../src/AppBundle/{Entity,Repository}');
153
178
154
179
This means that every class in ``src/AppBundle/ `` is *available * to be used as a
155
180
service. And thanks to the ``_defaults `` section at the top of the file, all of
@@ -347,15 +372,14 @@ The third big change is that, in a new Symfony 3.3 project, your controllers are
347
372
.. code-block :: php
348
373
349
374
// app/config/services.php
375
+ use Symfony\Component\DependencyInjection\Definition;
350
376
351
- // loading entire directories is not possible with PHP configuration
352
- // you need to define your services one-by-one
353
- use AppBundle\Controller\DefaultController;
377
+ // To use as default template
378
+ $definition = new Definition();
354
379
355
- $container->autowire(DefaultController::class)
356
- ->setAutoconfigured(true)
357
- ->addTag('controller.service_arguments')
358
- ->setPublic(true);
380
+ $definition->setPublic(true);
381
+
382
+ $this->registerClasses($definition, 'AppBundle\\Controller\\', '../../src/AppBundle/Controller/*');
359
383
360
384
But, you might not even notice this. First, your controllers *can * still extend
361
385
the same base ``Controller `` class or a new :ref: `AbstractController <controller-abstract-versus-controller >`.
@@ -642,7 +666,7 @@ You're now ready to automatically register all services in ``src/AppBundle/``
642
666
+ AppBundle\:
643
667
+ resource: '../../src/AppBundle/*'
644
668
+ exclude: '../../src/AppBundle/{Entity,Repository}'
645
- +
669
+ +
646
670
+ AppBundle\Controller\:
647
671
+ resource: '../../src/AppBundle/Controller'
648
672
+ public: true
0 commit comments