Created
August 26, 2016 13:46
-
-
Save romaricdrigon/f3a06a198b6d5d94e32ae24bfd090dda to your computer and use it in GitHub Desktop.
Symfony 2.8 MicroKernel
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 | |
| // 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!'); | |
| } | |
| } |
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 | |
| // 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