Created
April 24, 2016 06:52
-
-
Save lorenzo/4beb4ddfc1e955f87dda0fc63c960b61 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