Created
January 29, 2015 13:24
-
-
Save hannesvdvreken/1cafda37716ff4bed709 to your computer and use it in GitHub Desktop.
Named route segments
This file contains 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 | |
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