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);
}
geecu

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    -
Published in #Living on the edge