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