Skip to content

Instantly share code, notes, and snippets.

@cspray
Created August 23, 2015 00:32
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 cspray/143765b968e21082bcb4 to your computer and use it in GitHub Desktop.
Save cspray/143765b968e21082bcb4 to your computer and use it in GitHub Desktop.
Labrador HTTP - Possible Route Handlers
<?php
use Symfony\Component\HttpFoundation\Response;
// Have a simple enough Response? No fuss, no muss just pass a Response object
$engine->get('/', new Response('Hello World'));
// Need something a tad more advanced? How about an anonymous functions!
$engine->get('/', function() {
return new Response('Hello World');
});
// Maybe an object is more up your alley?
class MyController {
public function action() {
return new Response('Hello World');
}
}
// The ControllerActionResolver will instantiate this controller using the
// Auryn\Injector for the given request.
$engine->get('/', MyController::class . '#action');
// If you need your own fancy handler that can't fit into one of the above patterns
// you can implement your own Cspray\Labrador\Http\Router\HandlerResolver. It can
// then be added to the ResolverChain or can completely take place of the HandlerResolver
// used for routing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment