Skip to content

Instantly share code, notes, and snippets.

@davedevelopment
Created March 27, 2012 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davedevelopment/2220859 to your computer and use it in GitHub Desktop.
Save davedevelopment/2220859 to your computer and use it in GitHub Desktop.
Example of overriding service, without unnecessary loading
<?php
require_once __DIR__.'/vendor/.composer/autoload.php';
use Silex\Application;
$app = new Application;
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/views',
'twig.class_path' => __DIR__.'/vendor/twig/lib',
));
/**
* Redefine twig service without loading unnecessarily
*/
$app['twig.super'] = $app->raw('twig');
$app['twig'] = $app->share(function($c) {
$twig = $c['twig.super'];
// add loaders, extensions etc
return $twig;
});
$app->get('/', function(Application $app) {
return $app['twig']->render('index.html.twig', array());
});
$app->get('/notwig', function(Application $app) {
return 'Hello World';
});
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment