|
| 1 | +<?php |
| 2 | + |
| 3 | +use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; |
| 4 | +use Symfony\Component\Config\Loader\LoaderInterface; |
| 5 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 6 | +use Symfony\Component\HttpFoundation\JsonResponse; |
| 7 | +use Symfony\Component\HttpFoundation\Request; |
| 8 | +use Symfony\Component\HttpKernel\Kernel; |
| 9 | +use Symfony\Component\Routing\RouteCollectionBuilder; |
| 10 | + |
| 11 | +// require Composer's autoloader |
| 12 | +require __DIR__.'/../vendor/autoload.php'; |
| 13 | + |
| 14 | +class AppKernel extends Kernel |
| 15 | +{ |
| 16 | + use MicroKernelTrait; |
| 17 | + |
| 18 | + public function registerBundles() |
| 19 | + { |
| 20 | + return [ |
| 21 | + new Symfony\Bundle\FrameworkBundle\FrameworkBundle() |
| 22 | + ]; |
| 23 | + } |
| 24 | + |
| 25 | + protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader) |
| 26 | + { |
| 27 | + $c->loadFromExtension('framework', ['secret' => 'S0ME_SECRET']); |
| 28 | + $loader->load(__DIR__.'/config.yml'); |
| 29 | + $loader->load(__DIR__.'/services.xml'); |
| 30 | + } |
| 31 | + |
| 32 | + protected function configureRoutes(RouteCollectionBuilder $routes) |
| 33 | + { |
| 34 | + // kernel is a service that points to this class |
| 35 | + // optional 3rd argument is the route name |
| 36 | + $routes->add('/echo', 'kernel:echoAction')->setDefault('_jsonSchema', ['request' => 'schema.json']); |
| 37 | + $routes->add('/exception', 'kernel:exceptionAction'); |
| 38 | + } |
| 39 | + |
| 40 | + public function echoAction(Request $request) |
| 41 | + { |
| 42 | + return new JsonResponse($request->request->all() + $request->attributes->all()); |
| 43 | + } |
| 44 | + |
| 45 | + public function exceptionAction(Request $request) |
| 46 | + { |
| 47 | + if ($request->query->has('supported')) { |
| 48 | + throw new \Rezzza\SymfonyRestApiJson\Tests\Fixtures\MyOtherException('This is my app message'); |
| 49 | + } |
| 50 | + |
| 51 | + throw new \RuntimeException('Something wrong'); |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +$kernel = new AppKernel('dev', true); |
| 56 | +$request = Request::createFromGlobals(); |
| 57 | +$response = $kernel->handle($request); |
| 58 | +$response->send(); |
| 59 | +$kernel->terminate($request, $response); |
0 commit comments