Skip to content

Instantly share code, notes, and snippets.

@rossriley
Created December 21, 2015 18:19
Show Gist options
  • Save rossriley/6bdc2ef1fbb754123faa to your computer and use it in GitHub Desktop.
Save rossriley/6bdc2ef1fbb754123faa to your computer and use it in GitHub Desktop.
<?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