Completed
Push — master ( 33027c...a18c56 )
by Rougin
02:14
created

BridgeProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Zapheus\Bridge\Silex;
4
5
use Pimple\Container;
6
use Zapheus\Container\WritableInterface;
7
use Zapheus\Provider\ProviderInterface;
8
9
/**
10
 * Bridge Provider
11
 *
12
 * @package Zapheus
13
 * @author  Rougin Royce Gutib <[email protected]>
14
 */
15
class BridgeProvider implements ProviderInterface
16
{
17
    const CONTAINER = 'Pimple\Container';
18
19
    /**
20
     * @var \Pimple\ServiceProviderInterface[]
21
     */
22
    protected $providers;
23
24
    /**
25
     * Initializes the provider instance.
26
     *
27
     * @param \Pimple\ServiceProviderInterface[] $providers
28
     */
29 3
    public function __construct($providers)
30
    {
31 3
        $this->providers = $providers;
32 3
    }
33
34
    /**
35
     * Registers the bindings in the container.
36
     *
37
     * @param  \Zapheus\Container\WritableInterface $container
38
     * @return \Zapheus\Container\ContainerInterface
39
     */
40 3
    public function register(WritableInterface $container)
41
    {
42 3
        $pimple = $this->defaults(new Container);
43
44 3
        $config = $container->get(self::CONFIG);
45
46 3
        $silex = $config->get('silex', array(), true);
47
48 3
        foreach ((array) $silex as $key => $value) {
49
            $exists = isset($pimple[$key]);
50
51
            $exists && $pimple[$key] = $value;
52 2
        }
53
54 3
        foreach ($this->providers as $provider) {
55 3
            $provider->register($pimple);
56 2
        }
57
58 3
        return $container->set(self::CONTAINER, $pimple);
59
    }
60
61
    /**
62
     * Returns a Pimple container with default parameters.
63
     *
64
     * @param  \Pimple\Container $pimple
65
     * @return \Pimple\Container
66
     */
67 3
    protected function defaults(Container $pimple)
68
    {
69 3
        $pimple['request.http_port'] = 80;
70
71 3
        $pimple['request.https_port'] = 443;
72
73 3
        $pimple['debug'] = false;
74
75 3
        $pimple['charset'] = 'UTF-8';
76
77 3
        $pimple['logger'] = null;
78
79 3
        return $pimple;
80
    }
81
}
82