In order to use JsonMapper with your Symfony application you only need JsonMapper's SymfonyBundle.
Installation#
The installation of JsonMapper Symfony package can easily be done with Composer
$ composer require json-mapper/symfony-bundle
The example shown above assumes that composer is on your $PATH.
Configuration#
If your application does not use Symfony Flex, you need to manually enable the bundle in your config/bundles.php file:
<?php return [ // ... JsonMapper\SymfonyBundle\JsonMapperBundle::class => ['all' => true],];
Example#
Now JsonMapper will be automatically injected if it is provided as one of the constructor arguments.
<?php namespace App\Service; use JsonMapper\JsonMapper; class ApiClient{ /** @var JsonMapper */ private $mapper; public function __construct(JsonMapper $mapper) { $this->mapper = $mapper; }}