A Symfony 2 event listener for decoding JSON encoded request content
PHP
Latest commit 8d2d108 Jun 14, 2016 @wjzijderveld wjzijderveld committed on GitHub Merge pull request #12 from yosmanyga/patch-1
Fixed comparison to be compatible with php < 5.5
Permalink
Failed to load latest commit information.
src/Qandidate/Common/Symfony/HttpKernel/EventListener Fixed comparison to be compatible with php < 5.5 May 24, 2016
test
.gitignore initial commit Aug 12, 2014
.travis.yml
LICENSE initial commit Aug 12, 2014
README.md Updated README regarding test coverage and supported versions Dec 28, 2015
composer.json Support symfony/http-kernel 3.0 Dec 27, 2015
phpunit.xml.dist initial commit Aug 12, 2014

README.md

symfony-json-request-transformer

A Symfony event listener for decoding JSON encoded request content.

Build Status

About

Read the blog post about this repository at http://labs.qandidate.com/blog/2014/08/13/handling-angularjs-post-requests-in-symfony/

Currently this library supports both Symfony 2 and Symfony 3. Tests run against all LTS versions of Symfony 2 and against Symfony 3. As Symfony 3 requires PHP >5.5.9 and PHP 5.3 and 5.4 have been out of support for a while, we only test against 5.5+.

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.