New in Symfony 2.2: Small things matter
New Symfony versions are not just about big new features, but also about small tweaks... and we have many of them in Symfony 2.2. Today, let me show you just four small things that were introduced in Symfony 2.2.
Contributed by
Grégoire Pineau
in #5904.
Defining default values when using the @Route
annotation¶
If you are using annotations to define your routes, you like the conciseness
that it brings to your code. And defining a default value for a route
placeholder can be done with the defaults
key from the annotation:
1 2 3 4 5 6 7 | /**
* @Route("/hi/{name}", name="hi", defaults={"name"="Bob"})
*/
public function hiAction($name)
{
return new Response($name);
}
|
Easy enough, but as of Symfony 2.2, you can simplify this code more by defining the default value from the PHP code directly, which is easier, cleaner, and "semantically" more correct:
1 2 3 4 5 6 7 | /**
* @Route("/hi/{name}", name="hi")
*/
public function hiAction($name = "Bob")
{
return new Response($name);
}
|

Contributed by
geecu
in #5558.
Using aliases with the help command¶
When you want to get some help for a Symfony command (like getting the
available options and arguments), you can use the help
command or add the
--help
option to any command:
1 2 | $ ./app/console doctrine:schema:generate --help
$ ./app/console help doctrine:schema:generate
|
And if you are too lazy to type the command name, you can use an alias:
1 2 | $ ./app/console do:sc:ge --help
$ ./app/console help do:sc:ge
|
Well, the last example only works as of Symfony 2.2.
Contributed by
Florin Patan
in #5518.
Getting tagged services¶
When you need to debug your service configuration, the container:debug
command can help you a lot. But what if you want to list all services tagged
with a given tag? That's now possible in Symfony 2.2:
1 2 3 4 5 6 7 8 9 10 | app/console container:debug --tag=form.type
[container] Public services
Service Id Scope Class Name
form.type.birthday container Symfony\Component\Form\Extension\Core\Type\BirthdayType
form.type.checkbox container Symfony\Component\Form\Extension\Core\Type\CheckboxType
form.type.choice container Symfony\Component\Form\Extension\Core\Type\ChoiceType
form.type.collection container Symfony\Component\Form\Extension\Core\Type\CollectionType
form.type.country container Symfony\Component\Form\Extension\Core\Type\CountryType
[ ... ]
|
And when getting information about a specific service, the information about the tags are more precise:
1 2 3 4 5 6 7 8 9 10 11 12 13 | > app/console container:debug data_collector.request
[container] Information for service data_collector.request
Service Id data_collector.request
Class Symfony\Bundle\FrameworkBundle\DataCollector\RequestDataCollector
Tags
- kernel.event_listener (event: kernel.controller, method: onKernelController)
- data_collector (template: WebProfilerBundle:Collector:request, id: request, priority: 255)
Scope container
Public yes
Synthetic no
Required File -
|
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
New in Symfony 2.2: Small things matter symfony.com/index.php/blog/new-in-symfony-2-2-small-things-matter
Tweet thisComments
As big things matter as well, I hope some official implementation (using an external lib or not) for a Cache Component will make it as well in Symfony 2.2.
The ongoing discussion on GitHub and the wait for a potential PSR on cache implementation will lead to something great but maybe not on time before the feature freeze.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
Bart van den Burg Certified said on Dec 13, 2012 at 13:24 #1
https://github.com/symfony/symfony/pull/4937