Last active
August 29, 2015 14:13
Symfony in a single file, for melody
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
<<<CONFIG | |
packages: | |
- "symfony/symfony: 2.7.x-dev@dev" | |
CONFIG; | |
use Symfony\Component\HttpKernel\Kernel; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\Config\Loader\LoaderInterface; | |
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; | |
use Symfony\Bundle\TwigBundle\TwigBundle; | |
class SimpleKernel extends Kernel | |
{ | |
public function registerBundles() | |
{ | |
return array(new FrameworkBundle(), new TwigBundle()); | |
} | |
public function registerContainerConfiguration(LoaderInterface $loader) | |
{ | |
$loader->load(function ($container) { | |
$container->loadFromExtension('framework', array('secret' => '$ecret')); | |
}); | |
} | |
} | |
$kernel = new SimpleKernel('prod', false); | |
$kernel->boot(); | |
$container = $kernel->getContainer(); | |
$twig = $container->get('twig'); | |
$twig->setLoader(new Twig_Loader_Array(array( | |
'index.html.twig' => "hello {{ name|default('world') }}!\n", | |
))); | |
echo $twig->render('index.html.twig', array( | |
'name' => isset($argv[1]) ? $argv[1] : null, | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment