Completed
Push — master ( 8ee6a5...a7d283 )
by Jason
04:00
created

JmsSerializerServiceProvider::setSerializationVisitors()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
crap 6
1
<?php
2
3
namespace JDesrosiers\Silex\Provider;
4
5
use Doctrine\Common\Annotations\AnnotationRegistry;
6
use Pimple\Container;
7
use Pimple\ServiceProviderInterface;
8
use Silex\Api\BootableProviderInterface;
9
use Silex\Application;
10
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
11
12
/**
13
 * JMS Serializer integration for Silex.
14
 */
15
class JmsSerializerServiceProvider implements ServiceProviderInterface, BootableProviderInterface
16
{
17
    /**
18
     * Register the jms/serializer annotations
19
     *
20
     * @param Application $app
21
     */
22
    public function boot(Application $app)
23
    {
24
        if ($app->offsetExists("serializer.srcDir")) {
25
            AnnotationRegistry::registerAutoloadNamespace("JMS\Serializer\Annotation", $app["serializer.srcDir"]);
26
        }
27
    }
28
29
    /**
30
     * Register the serializer and serializer.builder services
31
     *
32
     * @param Container $app
33
     *
34
     * @throws ServiceUnavailableHttpException
35
     */
36 1
    public function register(Container $app)
37
    {
38 1
        $app["serializer.namingStrategy"] = "CamelCase";
39 1
        $app["serializer.namingStrategy.separator"] = "_";
40 1
        $app["serializer.namingStrategy.lowerCase"] = true;
41
42 1
        $app["serializer.propertyNamingStrategy"] = new PropertyNamingStrategyService();
43 1
        $app["serializer.builder"] = new BuilderService();
44 1
        $app["serializer"] = function (Container $app) {
45
            return $app["serializer.builder"]->build();
46
        };
47 1
    }
48
}
49