Kernel.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace Symfony\Bridge\PsrHttpMessage\Tests\Fixtures\App;
  3. use Nyholm\Psr7\Factory\Psr17Factory;
  4. use Psr\Http\Message\ResponseFactoryInterface;
  5. use Psr\Http\Message\ServerRequestFactoryInterface;
  6. use Psr\Http\Message\StreamFactoryInterface;
  7. use Psr\Http\Message\UploadedFileFactoryInterface;
  8. use Psr\Log\NullLogger;
  9. use Symfony\Bridge\PsrHttpMessage\ArgumentValueResolver\PsrServerRequestResolver;
  10. use Symfony\Bridge\PsrHttpMessage\EventListener\PsrResponseListener;
  11. use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
  12. use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
  13. use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
  14. use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
  15. use Symfony\Bridge\PsrHttpMessage\Tests\Fixtures\App\Controller\PsrRequestController;
  16. use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
  17. use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
  18. use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
  19. use Symfony\Component\HttpKernel\Kernel as SymfonyKernel;
  20. use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
  21. class Kernel extends SymfonyKernel
  22. {
  23. use MicroKernelTrait;
  24. public function registerBundles(): iterable
  25. {
  26. yield new FrameworkBundle();
  27. }
  28. public function getProjectDir(): string
  29. {
  30. return __DIR__;
  31. }
  32. protected function configureRoutes(RoutingConfigurator $routes): void
  33. {
  34. $routes
  35. ->add('server_request', '/server-request')->controller([PsrRequestController::class, 'serverRequestAction'])->methods(['GET'])
  36. ->add('request', '/request')->controller([PsrRequestController::class, 'requestAction'])->methods(['POST'])
  37. ->add('message', '/message')->controller([PsrRequestController::class, 'messageAction'])->methods(['PUT'])
  38. ;
  39. }
  40. protected function configureContainer(ContainerConfigurator $container): void
  41. {
  42. $container->extension('framework', [
  43. 'router' => ['utf8' => true],
  44. 'secret' => 'for your eyes only',
  45. 'test' => true,
  46. ]);
  47. $container->services()
  48. ->set('nyholm.psr_factory', Psr17Factory::class)
  49. ->alias(ResponseFactoryInterface::class, 'nyholm.psr_factory')
  50. ->alias(ServerRequestFactoryInterface::class, 'nyholm.psr_factory')
  51. ->alias(StreamFactoryInterface::class, 'nyholm.psr_factory')
  52. ->alias(UploadedFileFactoryInterface::class, 'nyholm.psr_factory')
  53. ;
  54. $container->services()
  55. ->defaults()->autowire()->autoconfigure()
  56. ->set(HttpFoundationFactoryInterface::class, HttpFoundationFactory::class)
  57. ->set(HttpMessageFactoryInterface::class, PsrHttpFactory::class)
  58. ->set(PsrResponseListener::class)
  59. ->set(PsrServerRequestResolver::class)
  60. ;
  61. $container->services()
  62. ->set('logger', NullLogger::class)
  63. ->set(PsrRequestController::class)->public()->autowire()
  64. ;
  65. }
  66. }