Skip to content

Instantly share code, notes, and snippets.

@lyrixx
Last active August 29, 2015 14:13
Show Gist options
  • Save lyrixx/5a807d97c77c496e871a to your computer and use it in GitHub Desktop.
Save lyrixx/5a807d97c77c496e871a to your computer and use it in GitHub Desktop.
Symfony in a single file, for melody
<?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