Skip to content

Instantly share code, notes, and snippets.

@philipobenito
Last active September 18, 2015 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipobenito/b3977c5b5e30fe386c76 to your computer and use it in GitHub Desktop.
Save philipobenito/b3977c5b5e30fe386c76 to your computer and use it in GitHub Desktop.
<?php
$container = new League\Container\Container;
$container->add('Zend\Diactoros\ServerRequest', function () {
return Zend\Diactoros\ServerRequestFactory::fromGlobals(
$_SERVER,
$_GET,
$_POST,
$_COOKIE,
$_FILES
);
});
$container->add('Zend\Diactoros\Response');
// add your controllers to the container
$router = new League\Route\RouteCollection($container);
$router->map('GET', '/example', 'Some\Controller::action') // also still have convenience http methods (get, post, put etc)
->setName('example') // optional
->setScheme('http') // optional
->setHost('sub.example.com'); // optional
$router->group('/prefix', function ($router) {
// route below will match on GET /prefix/example
$router->map('GET', '/example', 'Some\Controller::action') // also still have convenience http methods (get, post, put etc)
->setName('example') // optional
->setScheme('http') // optional (will override the group conditions added below)
->setHost('sub.example.com'); // optional (will override the group conditions added below)
})
->setScheme('http') // optional
->setHost('sub.example.com'); // optional;
$response = $router->dispatch(
$container->get('Zend\Diactoros\ServerRequest'),
$container->get('Zend\Diactoros\Response')
);
(new Zend\Diactoros\Response\SapiEmitter)->emit($response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment