How to get the current route and URL in Symfony2

To get the current URL in a Symfony2 project, use the following code.

In a controller:

public function someAction(\Symfony\Component\HttpFoundation\Request $request)
    $route = $request->get('_route');
    $url = $request->getUri();

In a TWIG template:

{{ app.request.get('_route') }}

{{ app.request.getUri }}

Why would you need this? For example to setup social share buttons for the current page.