Skip to content

Instantly share code, notes, and snippets.

@hannesvdvreken
Created January 29, 2015 13:24
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/1cafda37716ff4bed709 to your computer and use it in GitHub Desktop.
Save hannesvdvreken/1cafda37716ff4bed709 to your computer and use it in GitHub Desktop.
Named route segments
<?php
use League\Container\Container;
use League\Route\RouteCollection;
use League\Route\Strategy\MethodArgumentStrategy;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
require 'vendor/autoload.php';
$container = new Container();
$router = new RouteCollection($container);
$router->setStrategy(new MethodArgumentStrategy());
class Tmp
{
public function action(Request $request, $name)
{
return new JsonResponse(compact('name'));
}
}
$router->get('/test/{name}', 'Tmp::action');
$response = $router->getDispatcher()->dispatch('GET', '/test/hannes');
echo $response->getContent().PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment