T
T
tigra2020-07-16 23:35:33
symfony
tigra, 2020-07-16 23:35:33

How to implement service connection in Symfony for HttpKernel?

I want to make my own structure using symfony components, without the symfony/framework-bundle package.

<?php

use App\Controllers\OrderController;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
use Symfony\Component\HttpKernel\EventListener\RouterListener;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

require_once __DIR__ . '/../vendor/autoload.php';

$routes = new RouteCollection();
$routes->add('index', new Route('/order', ['_controller' => [OrderController::class, 'index']]));

$request = Request::createFromGlobals();

$matcher = new UrlMatcher($routes, new RequestContext());

$dispatcher = new EventDispatcher();
$dispatcher->addSubscriber(new RouterListener($matcher, new RequestStack()));

$controllerResolver = new ControllerResolver();
$argumentResolver = new ArgumentResolver();

$kernel = new HttpKernel($dispatcher, $controllerResolver, new RequestStack(), $argumentResolver);

$response = $kernel->handle($request);
$response->send();

$kernel->terminate($request, $response);

It works. But how can I connect services like DI Autowiring here. This is possible in the Kernel class, the MicroKernelTrait trait is used there and there is the registerContainerConfiguration(LoaderInterface $loader) method, but there is nothing in the HttpKernel, although the documentation agrees on the method https://symfony.com/doc/current/components/http_ke...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question