Created
March 25, 2020 14:09
-
-
Save klaussilveira/8985d86a309f4393b60d5e89a1e3968c to your computer and use it in GitHub Desktop.
This file contains 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 | |
require '../vendor/autoload.php'; | |
$request = Symfony\Component\HttpFoundation\Request::createFromGlobals(); | |
$context = (new Symfony\Component\Routing\RequestContext())->fromRequest($request); | |
$configLocator = new Symfony\Component\Config\FileLocator(__DIR__ . '/../config'); | |
$file = '../var/cache/container.php'; | |
if (\file_exists($file)) { | |
require_once $file; | |
$container = new ProjectServiceContainer(); | |
} else { | |
$container = new Symfony\Component\DependencyInjection\ContainerBuilder(); | |
$container->addCompilerPass(new \Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass()); | |
$container->register('event_dispatcher', \Symfony\Component\EventDispatcher\EventDispatcher::class); | |
$loader = new Symfony\Component\DependencyInjection\Loader\YamlFileLoader($container, $configLocator); | |
$loader->load('services.yaml'); | |
$container->compile(); | |
\file_put_contents($file, (new Symfony\Component\DependencyInjection\Dumper\PhpDumper($container))->dump()); | |
} | |
$file = '../var/cache/routes.php'; | |
if (\file_exists($file)) { | |
$matcher = new Symfony\Component\Routing\Matcher\CompiledUrlMatcher(require($file), $context); | |
} else { | |
$loader = new Symfony\Component\Routing\Loader\YamlFileLoader($configLocator); | |
$routes = $loader->load('routes.yaml'); | |
$dumper = new \Symfony\Component\Routing\Matcher\Dumper\CompiledUrlMatcherDumper($routes); | |
\file_put_contents($file, $dumper->dump()); | |
$matcher = new Symfony\Component\Routing\Matcher\UrlMatcher($routes, $context); | |
} | |
$params = $matcher->matchRequest($request); | |
$request->attributes->add($params); | |
$response = $container->get($params['_controller'])($request); | |
$response->send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment