Skip to content

Instantly share code, notes, and snippets.

@simensen

simensen/app.php Secret

Created November 6, 2013 15:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save simensen/5bed3ba95cb9154e8ced to your computer and use it in GitHub Desktop.
<?php
$app->get('/hello/{name}', function ($name) use ($app) {
return [
'controller' => 'blog',
'action' => 'hello',
'name' => $name,
'app' => $app,
];
});
$app->on(KernelEvents::VIEW, function ($event) use ($app, $dispatcher) {
$view = $event->getControllerResult();
if (is_null($view) || is_string($view)) {
return;
}
if ( ! is_array($view)) {
// we can only handle array data in the view
return;
}
if (! (isset($view['controller'] && isset($view['action'])))) {
// at this point we don't know what is going on.
return;
}
$response = $dispatcher($view);
if ( ! $response instanceof Response) {
// If the response is not a Response instance, wrap it in one
// and assume that it was something appropriate as a response
// body.
$response = new Response($response);
}
$event->setResponse($response);
});
@harikt
Copy link

harikt commented Nov 6, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment