Skip to content

Instantly share code, notes, and snippets.

@romaricdrigon
Created August 26, 2016 13:46
Show Gist options
  • Select an option

  • Save romaricdrigon/f3a06a198b6d5d94e32ae24bfd090dda to your computer and use it in GitHub Desktop.

Select an option

Save romaricdrigon/f3a06a198b6d5d94e32ae24bfd090dda to your computer and use it in GitHub Desktop.
Symfony 2.8 MicroKernel
<?php
// app/MicroKernel.php
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
class MicroKernel extends Kernel
{
use MicroKernelTrait;
public function registerBundles()
{
return array(new Symfony\Bundle\FrameworkBundle\FrameworkBundle());
}
protected function configureRoutes(RouteCollectionBuilder $routes)
{
$routes->add('/', 'kernel:indexAction', 'index'); }
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
{
// framework.secret est le seul paramètre obligatoire pour le framework
$c->loadFromExtension('framework', ['secret' => '12345']);
}
public function indexAction()
{
return new Response('Bonjour Aramis!');
}
}
<?php
// web/api.php
use Symfony\Component\HttpFoundation\Request;
$loader = require __DIR__.'/../app/autoload.php';
require_once __DIR__.'/../app/MicroKernel.php';
// Vous voulez bien sur changer la valeur de l'environnement en-dessous !
$app = new MicroKernel('prod', false);
$app->loadClassCache();
$app->handle(Request::createFromGlobals())->send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment