Skip to content

Instantly share code, notes, and snippets.

@weaverryan
Created October 29, 2015 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weaverryan/3a3f879c65ab7785114c to your computer and use it in GitHub Desktop.
Save weaverryan/3a3f879c65ab7785114c to your computer and use it in GitHub Desktop.
Potential Symfony MicroKernel example
<?php
require_once __DIR__.'/../vendor/autoload.php';
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\MicroKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
class AppKernel extends MicroKernel
{
public function home()
{
return new Response('Foo');
}
public function registerBundles()
{
return array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
);
}
protected function configureRoutes(RouteCollectionBuilder $routes)
{
$routes->add('/', 'kernel:home');
}
protected function configureServices(ContainerBuilder $c, LoaderInterface $loader)
{
$c->setParameter('kernel.secret', 'foo');
}
}
$kernel = new AppKernel('dev', true);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment