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 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
|
|
|
{ |
50
|
|
|
if (isset($pimple[$key])) |
51
|
|
|
{ |
52
|
|
|
$pimple[$key] = $value; |
53
|
|
|
} |
54
|
1 |
|
} |
55
|
|
|
|
56
|
3 |
|
foreach ($this->providers as $provider) |
57
|
|
|
{ |
58
|
3 |
|
$provider->register($pimple); |
59
|
1 |
|
} |
60
|
|
|
|
61
|
3 |
|
return $container->set(self::CONTAINER, $pimple); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Returns a Pimple container with default parameters. |
66
|
|
|
* |
67
|
|
|
* @param \Pimple\Container $pimple |
68
|
|
|
* @return \Pimple\Container |
69
|
|
|
*/ |
70
|
3 |
|
protected function defaults(Container $pimple) |
71
|
|
|
{ |
72
|
3 |
|
$pimple['request.http_port'] = 80; |
73
|
|
|
|
74
|
3 |
|
$pimple['request.https_port'] = 443; |
75
|
|
|
|
76
|
3 |
|
$pimple['debug'] = false; |
77
|
|
|
|
78
|
3 |
|
$pimple['charset'] = 'UTF-8'; |
79
|
|
|
|
80
|
3 |
|
$pimple['logger'] = null; |
81
|
|
|
|
82
|
3 |
|
return $pimple; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|