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

JmsSerializerServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 57.14%

Importance

Changes 7
Bugs 0 Features 1
Metric Value
wmc 3
c 7
b 0
f 1
lcom 0
cbo 4
dl 0
loc 34
ccs 8
cts 14
cp 0.5714
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 2
A register() 0 12 1
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