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 Provider |
12
|
|
|
* |
13
|
|
|
* @package Zapheus |
14
|
|
|
* @author Rougin Royce Gutib <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class IlluminateProvider 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
|
3 |
|
public function __construct(array $providers) |
33
|
|
|
{ |
34
|
3 |
|
$this->providers = $providers; |
35
|
3 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Registers the bindings in the container. |
39
|
|
|
* |
40
|
|
|
* @param \Zapheus\Container\WritableInterface $container |
41
|
|
|
* @return \Zapheus\Container\ContainerInterface |
42
|
|
|
*/ |
43
|
3 |
|
public function register(WritableInterface $container) |
44
|
|
|
{ |
45
|
3 |
|
$illuminate = $this->container($container); |
46
|
|
|
|
47
|
3 |
|
foreach ($this->providers as $item) { |
48
|
3 |
|
$provider = new $item($illuminate); |
49
|
|
|
|
50
|
3 |
|
$exists = method_exists($provider, 'boot'); |
51
|
|
|
|
52
|
3 |
|
$provider->register(); |
53
|
|
|
|
54
|
3 |
|
$exists === true && $provider->boot(); |
55
|
1 |
|
} |
56
|
|
|
|
57
|
3 |
|
$container->set(self::CONTAINER, $illuminate); |
58
|
|
|
|
59
|
3 |
|
return $container; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Returns a \Illuminate\Container\Container instance. |
64
|
|
|
* |
65
|
|
|
* @param \Zapheus\Container\WritableInterface $container |
66
|
|
|
* @return \Illuminate\Container\Container |
67
|
|
|
*/ |
68
|
3 |
|
protected function container(WritableInterface $container) |
69
|
|
|
{ |
70
|
3 |
|
$laravel = new IlluminateContainer; |
71
|
|
|
|
72
|
3 |
|
if (interface_exists(self::LOADER) === false) { |
73
|
3 |
|
$config = $container->get(self::CONFIG); |
74
|
|
|
|
75
|
3 |
|
$items = $config->get('illuminate', array()); |
76
|
|
|
|
77
|
3 |
|
$laravel['config'] = new Repository($items); |
78
|
1 |
|
} |
79
|
|
|
|
80
|
3 |
|
return $laravel; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|