Last active
September 18, 2015 20:43
-
-
Save philipobenito/b3977c5b5e30fe386c76 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
$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