Skip to content

Commit

Permalink
Fix laravel configurator
Browse files Browse the repository at this point in the history
  • Loading branch information
jsor committed Oct 11, 2014
1 parent 5ee3cab commit fe2d931
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"symfony/http-foundation": "~2.1",
"symfony/http-kernel": "~2.1",
"symfony/event-dispatcher": "~2.1",
"nocarrier/hal": "~0.9"
"nocarrier/hal": "~0.9",
"laravel/laravel": "~4.1"
},
"suggest": {
"willdurand/negotiation": "~1.3",
Expand Down
14 changes: 9 additions & 5 deletions src/Configurator/LaravelConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace Jsor\Stack\Hal\Configurator;

use Illuminate\Routing\Router;
use Jsor\Stack\Hal\Response\HalResponse;
use Jsor\Stack\Hal\ResponseConverter;
use Nocarrier\Hal;
use Symfony\Component\HttpKernel\HttpKernelInterface;

class LaravelConfigurator implements ConfiguratorInterface
Expand All @@ -12,11 +14,13 @@ public function configureResponseConversion(HttpKernelInterface $app, $prettyPri
{
$app->extend('router', function (Router $router) use ($prettyPrint) {
$router->filter('JsorStackHalResponseConverter', function ($route, $request) use ($prettyPrint) {
return ResponseConverter::convert(
$route->run($request),
$request,
$prettyPrint
);
$hal = $route->run($request);

if (!$hal instanceof Hal) {
return $hal;
}

return HalResponse::create($hal, 200, [], $prettyPrint);
});

$router->when('*', 'JsorStackHalResponseConverter');
Expand Down

0 comments on commit fe2d931

Please sign in to comment.