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
Gunther Konig
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.
Minimizing the web profiler menu
The Symfony web profiler is very useful when you need to understand what's going on when Symfony renders a URL. In Symfony 2.2, many tweaks have been made to the profiler, and to give more space to the useful information it gives you, you can now click on the new "minimize" button to, well, minimize the left menu.
Contributed by
Bart van den Burg
in #4937 .
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 -
The link to the "Getting tagged services" PR is incorrect. Here is the right one:
https://github.com/symfony/symfony/pull/4937
Setting default values at right places is a great thing!
Good job! :) The "default value" one is a great idea...
It's nice to see all these little improvements!
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.
Hey :) Thanks !
waiting symfony 2.2...