qandidate / symfony-json-request-transformer
A Symfony event listener for decoding JSON encoded request content
Installs: 1 450 323
Dependents: 3
Suggesters: 0
Security: 0
Stars: 125
Watchers: 9
Forks: 17
Open Issues: 0
Requires
- symfony/http-kernel: ^4.4.49||^5.4.16||^6.0.16
Requires (Dev)
- broadway/coding-standard: ^1.2
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2023-12-20 12:40:16 UTC
README
🚨 This repository is archived as it has served its purpose. Symfony has built-in support for this: https://symfony.com/doc/current/components/http_foundation.html#accessing-request-data
$request->getPayload()->get('foo');
A Symfony event listener for decoding JSON encoded request content.
About
Read the blog post about this repository at http://labs.qandidate.com/blog/2014/08/13/handling-angularjs-post-requests-in-symfony/
Install
Install qandidate/symfony-json-request-transformer through composer.
composer require qandidate/symfony-json-request-transformer
Register the event listener as a service:
<service id="kernel.event_listener.json_request_transformer" class="Qandidate\Common\Symfony\HttpKernel\EventListener\JsonRequestTransformerListener"> <tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="100" /> </service>
services: kernel.event_listener.json_request_transformer: class: Qandidate\Common\Symfony\HttpKernel\EventListener\JsonRequestTransformerListener tags: - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest, priority: 100 }
Example
A request with JSON content like:
{ "foo": "bar" }
will be decoded automatically so can access the foo
property like:
echo $request->request->get('foo');
License
MIT, see LICENSE.