1<?php
2
3/*
4 * This file is part of the Silex framework.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Silex\Provider;
13
14use Pimple\Container;
15use Pimple\ServiceProviderInterface;
16use Symfony\Component\Serializer\Serializer;
17use Symfony\Component\Serializer\Encoder\JsonEncoder;
18use Symfony\Component\Serializer\Encoder\XmlEncoder;
19use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
20use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
21
22/**
23 * Symfony Serializer component Provider.
24 *
25 * @author Fabien Potencier <fabien@symfony.com>
26 * @author Marijn Huizendveld <marijn@pink-tie.com>
27 */
28class SerializerServiceProvider implements ServiceProviderInterface
29{
30    /**
31     * {@inheritdoc}
32     *
33     * This method registers a serializer service. {@link http://api.symfony.com/master/Symfony/Component/Serializer/Serializer.html
34     * The service is provided by the Symfony Serializer component}.
35     */
36    public function register(Container $app)
37    {
38        $app['serializer'] = function ($app) {
39            return new Serializer($app['serializer.normalizers'], $app['serializer.encoders']);
40        };
41
42        $app['serializer.encoders'] = function () {
43            return array(new JsonEncoder(), new XmlEncoder());
44        };
45
46        $app['serializer.normalizers'] = function () {
47            return array(new CustomNormalizer(), new GetSetMethodNormalizer());
48        };
49    }
50}
51