Commit b550703b authored by Fabien Potencier's avatar Fabien Potencier

added a SymfonyBridgesExtension

For now, it allows the Twig extension to register the Routing Twig extension:

$app = new Application();
$app->register(new SymfonyBridgesExtension(), array(
    'symfony_bridges.class_path' => '...',
));
$app->register(new UrlGeneratorExtension());
$app->register(new SessionExtension());
$app->register(new TwigExtension(), array(...));

You can now use {{ path() }} in templates to generate URLs.

The order of registration of the extensions is significant.
parent 2ff889b6
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Extension;
use Silex\Application;
use Silex\ExtensionInterface;
use Symfony\Component\Routing\Generator\UrlGenerator;
class SymfonyBridgesExtension implements ExtensionInterface
{
public function register(Application $app)
{
$app['symfony_bridges'] = true;
if (isset($app['symfony_bridges.class_path'])) {
$app['autoloader']->registerNamespace('Symfony\\Bridge', $app['symfony_bridges.class_path']);
}
}
}
......@@ -13,6 +13,7 @@ namespace Silex\Extension;
use Silex\Application;
use Silex\ExtensionInterface;
use Symfony\Bridge\Twig\Extension\RoutingExtension;
class TwigExtension implements ExtensionInterface
{
......@@ -25,6 +26,10 @@ class TwigExtension implements ExtensionInterface
$app['twig.configure']($twig);
}
if (isset($app['url_generator']) && isset($app['symfony_bridges'])) {
$twig->addExtension(new RoutingExtension($app['url_generator']));
}
return $twig;
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment