Created
December 21, 2015 18:19
-
-
Save rossriley/6bdc2ef1fbb754123faa 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 | |
// A method looks like this assuming that you are passed a $request instance that contains all the needed info | |
$builder = new ContainerBuilder(); | |
$builder->addDefinitions(__DIR__."/config/services.php"); | |
$container = $builder->build(); | |
$routeInfo = $this->dispatcher->dispatch($request->getMethod(), $request->getPathInfo()); | |
switch ($routeInfo[0]) { | |
case FastRoute\Dispatcher::NOT_FOUND: | |
// Handle 404 error | |
case FastRoute\Dispatcher::METHOD_NOT_ALLOWED: | |
// Handle 405 error | |
case FastRoute\Dispatcher::FOUND: | |
$handler = $container->get($routeInfo[1]); | |
$vars = array_merge([$request], $routeInfo[2]); | |
return $this->container->call($handler, $vars); | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment