Skip to content

Instantly share code, notes, and snippets.

@lorenzo
Created April 24, 2016 06:52
Show Gist options
  • Save lorenzo/4beb4ddfc1e955f87dda0fc63c960b61 to your computer and use it in GitHub Desktop.
Save lorenzo/4beb4ddfc1e955f87dda0fc63c960b61 to your computer and use it in GitHub Desktop.
<?php
namespace App\Routing\Filter;
use Cake\Event\Event;
use Cake\Routing\DispatcherFilter;
class JsonInputFilter extends DispatcherFilter
{
public function beforeDispatch(Event $e)
{
$request = $e->data['request'];
if (!$request->is(['put', 'post', 'patch'])) {
return;
}
if (strpos($request->header('Content-Type'), 'application/json') === false) {
return;
}
$request->data = json_decode($request->input(), true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment