@@ -81,21 +81,37 @@ Symfony Standard Edition:
8181 <prototype namespace =" AppBundle\Controller\" resource =" ../../src/AppBundle/Controller" public =" true" >
8282 <tag name =" controller.service_arguments" />
8383 </prototype >
84+
85+ <!-- add more services, or override services that need manual wiring -->
8486 </services >
8587 </container >
8688
8789 .. code-block :: php
8890
8991 // app/config/services.php
92+ use Symfony\Component\DependencyInjection\Definition;
9093
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();
9496
95- $container->autowire(DefaultController::class)
97+ $definition
98+ ->setAutowired(true)
9699 ->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)
97108 ->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
99115
100116 This small bit of configuration contains a paradigm shift of how services
101117are configured in Symfony.
@@ -147,9 +163,18 @@ thanks to the following config:
147163 .. code-block :: php
148164
149165 // app/config/services.php
166+ use Symfony\Component\DependencyInjection\Definition;
167+
168+ // To use as default template
169+ $definition = new Definition();
150170
151- // services cannot be automatically loaded with PHP configuration
152- // you need to define your services one-by-one
171+ $definition
172+ ->setAutowired(true)
173+ ->setAutoconfigured(true)
174+ ->setPublic(false)
175+ ;
176+
177+ $this->registerClasses($definition, 'AppBundle\\', '../../src/AppBundle/*', '../../src/AppBundle/{Entity,Repository}');
153178
154179 This means that every class in ``src/AppBundle/ `` is *available * to be used as a
155180service. And thanks to the ``_defaults `` section at the top of the file, all of
@@ -348,14 +373,12 @@ The third big change is that, in a new Symfony 3.3 project, your controllers are
348373
349374 // app/config/services.php
350375
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;
376+ // ...
377+
378+ // override default template
379+ $definition->setPublic(true);
354380
355- $container->autowire(DefaultController::class)
356- ->setAutoconfigured(true)
357- ->addTag('controller.service_arguments')
358- ->setPublic(true);
381+ $this->registerClasses($definition, 'AppBundle\\Controller\\', '../../src/AppBundle/Controller/*');
359382
360383 But, you might not even notice this. First, your controllers *can * still extend
361384the same base ``Controller `` class or a new :ref: `AbstractController <controller-abstract-versus-controller >`.
@@ -642,7 +665,7 @@ You're now ready to automatically register all services in ``src/AppBundle/``
642665 + AppBundle\:
643666 + resource: '../../src/AppBundle/*'
644667 + exclude: '../../src/AppBundle/{Entity,Repository}'
645- +
668+ +
646669 + AppBundle\Controller\:
647670 + resource: '../../src/AppBundle/Controller'
648671 + public: true
0 commit comments