use Symfony\Component\HttpKernel\EventListener\RouterListener; use Symfony\Component\Routing\Matcher\UrlMatcher; use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\Route; ! $routes = new RouteCollection(); $routes->add('foo', new Route('/foo', [ '_controller' => function (Request $request) { return new Response('foo!'); }, ])); ! $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new RouterListener( new UrlMatcher($routes, new RequestContext()) )); ! $kernel = new HttpKernel($dispatcher, new ControllerResolver()); ! $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send();