1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zapheus\Bridge\Illuminate; |
4
|
|
|
|
5
|
|
|
use Illuminate\Config\Repository; |
6
|
|
|
use Illuminate\Container\Container as IlluminateContainer; |
7
|
|
|
use Zapheus\Container\WritableInterface; |
8
|
|
|
use Zapheus\Provider\ProviderInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Illuminate Bridge Provider |
12
|
|
|
* |
13
|
|
|
* @package Zapheus |
14
|
|
|
* @author Rougin Gutib <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class BridgeProvider implements ProviderInterface |
17
|
|
|
{ |
18
|
|
|
const CONTAINER = 'Illuminate\Container\Container'; |
19
|
|
|
|
20
|
|
|
const LOADER = 'Illuminate\Config\LoaderInterface'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string[] |
24
|
|
|
*/ |
25
|
|
|
protected $providers; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Initializes the provider instance. |
29
|
|
|
* |
30
|
|
|
* @param string[] $providers |
31
|
|
|
*/ |
32
|
5 |
|
public function __construct(array $providers) |
33
|
|
|
{ |
34
|
5 |
|
$this->providers = $providers; |
35
|
5 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Registers the bindings in the container. |
39
|
|
|
* |
40
|
|
|
* @param \Zapheus\Container\WritableInterface $container |
41
|
|
|
* @return \Zapheus\Container\ContainerInterface |
42
|
|
|
*/ |
43
|
5 |
|
public function register(WritableInterface $container) |
44
|
|
|
{ |
45
|
5 |
|
$illuminate = $this->container($container); |
46
|
|
|
|
47
|
5 |
|
foreach ($this->providers as $item) |
48
|
|
|
{ |
49
|
5 |
|
$provider = new $item($illuminate); |
50
|
|
|
|
51
|
5 |
|
$exists = method_exists($provider, 'boot'); |
52
|
|
|
|
53
|
5 |
|
$provider->register(); |
54
|
|
|
|
55
|
5 |
|
$exists === true && $provider->boot(); |
56
|
3 |
|
} |
57
|
|
|
|
58
|
5 |
|
$container->set(self::CONTAINER, $illuminate); |
59
|
|
|
|
60
|
5 |
|
return $container; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Returns a \Illuminate\Container\Container instance. |
65
|
|
|
* |
66
|
|
|
* @param \Zapheus\Container\WritableInterface $container |
67
|
|
|
* @return \Illuminate\Container\Container |
68
|
|
|
*/ |
69
|
5 |
|
protected function container(WritableInterface $container) |
70
|
|
|
{ |
71
|
5 |
|
$laravel = new IlluminateContainer; |
72
|
|
|
|
73
|
5 |
|
if (interface_exists(self::LOADER) === false) |
74
|
3 |
|
{ |
75
|
4 |
|
$config = $container->get(self::CONFIG); |
76
|
|
|
|
77
|
4 |
|
$items = $config->get('illuminate', array()); |
78
|
|
|
|
79
|
4 |
|
$laravel['config'] = new Repository($items); |
80
|
2 |
|
} |
81
|
|
|
|
82
|
5 |
|
return $laravel; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|