New in Symfony 3.3: Added new shortcut methods
In addition to some large new features, Symfony 3.3 will also contain minor tweaks to make your work a bit easier.
Added a shortcut to create autowired definitions¶
Creating service definitions in PHP via the ContainerBuilder work as follows:
1 2 3 4
$container->register('app.twig_extension', AppExtension::class) ->setAutowired(true) ->addTag('twig.extension') ;
Given that autowiring is all about working more quickly, in Symfony 3.3 you can
use the new
autowire() shortcut method to achieve the same result:
1 2 3
$container->autowire('app.twig_extension', AppExtension::class) ->addTag('twig.extension') ;
Added shorthand methods for Config prototypes¶
prototype() method of the
ArrayNodeDefinition class allows you to
create different types of prototypes for integers, floats, booleans, arrays, etc.
The problem is that this method always returns a
NodeDefinition object instead
of the specific object created (
This makes IDEs unable to understand code like the following, where the
max() method is undefined for the
$node = new ArrayNodeDefinition('name'); $node->prototype('integer')->max(10);
In Symfony 3.3 we added a dedicated shortcut method for each of the possible
prototypes. Now you can refactor the previous example as follows and your IDE
will recognize the
$node = new ArrayNodeDefinition('name'); $node->integerPrototype()->max(10);
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.