-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApplication.php
62 lines (56 loc) · 1.29 KB
/
Application.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace Darya\Service;
use Darya\Service\Contracts\Application as ApplicationInterface;
use Darya\Service\Contracts\Provider;
/**
* Darya's application implementation.
*
* A service container that registers and boots service providers.
*
* @author Chris Andrew <[email protected]>
*/
class Application extends Container implements ApplicationInterface
{
/**
* Set of service providers registered with the application.
*
* @var array
*/
protected $providers = array();
/**
* Instantiate an application.
*
* @param array $services [optional] Initial set of services and/or aliases
*/
public function __construct(array $services = array())
{
$this->register(array(
'Darya\Service\Contracts\Application' => $this,
'Darya\Service\Application' => $this
));
parent::__construct($services);
}
/**
* Register a service provider with the application.
*
* @param Provider $provider
*/
public function provide(Provider $provider)
{
$this->providers[] = $provider;
$provider->register($this);
}
/**
* Boot all registered service providers.
*
* TODO: Bootable interface.
*/
public function boot()
{
foreach ($this->providers as $provider) {
if (method_exists($provider, 'boot')) {
$this->call(array($provider, 'boot'));
}
}
}
}