Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hannesvdvreken
Created March 3, 2015 19:00
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 hannesvdvreken/8b83f00ebf0c69cb4555 to your computer and use it in GitHub Desktop.
Save hannesvdvreken/8b83f00ebf0c69cb4555 to your computer and use it in GitHub Desktop.
league/route with methodargumentstrategy and registered callables
<?php
use League\Container\Container;
use League\Route\RouteCollection;
use League\Route\Strategy\MethodArgumentStrategy;
use Symfony\Component\HttpFoundation\Request;
require 'vendor/autoload.php';
$container = new Container();
$router = new RouteCollection($container);
$router->setStrategy(new MethodArgumentStrategy());
$router->post('/user/{username}', 'create_controller');
$container->add(Request::class, function () {
return Request::create('/user/philipobenito', 'POST');
});
$container->invokable('create_controller', function (Request $request, $username) {
var_dump('invokable', $request->getMethod(), $username); exit;
})->withArgument(Request::class);
$router->getDispatcher()->dispatch('POST', '/user/philipobenito');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment