Created
May 15, 2016 12:05
-
-
Save lorenzo/e1f756af3d7bf47d9eec3aee42954e79 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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