-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDIContainerWrapper.php
64 lines (55 loc) · 1.52 KB
/
DIContainerWrapper.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
63
64
<?php
/**
* @author Marco van 't Wout <[email protected]>
* @copyright Copyright © Tremani, 2015
*/
/**
* PHP-DI integration through application component for Yii 1.
*/
class DIContainerWrapper extends CApplicationComponent
{
/**
* @var \DI\Container
*/
protected $container;
/**
* @var array
*/
public $definitions = array();
/**
* Initialize application component.
*/
public function init()
{
$builder = new \DI\ContainerBuilder;
if (!empty($this->definitions)) {
$builder->addDefinitions(new \DI\Definition\Source\ArrayDefinitionSource($this->definitions));
}
// @todo, more settings depending on environment and requirements
// @link http://php-di.org/doc/container-configuration.html
//$builder->useAutowiring(false);
//$builder->useAnnotations(false);
//$builder->ignorePhpDocErrors(true);
//$builder->setDefinitionCache(new Doctrine\Common\Cache\FilesystemCache());
//$builder->writeProxiesToFile(true, 'tmp/proxies');
$this->container = $builder->build();
}
/**
* Forward call to \DI\Container.
*
* @param string $name
* @param array $parameters
* @return mixed
*/
public function __call($name, $parameters)
{
return call_user_func_array(array($this->container, $name), $parameters);
}
/**
* @return \DI\Container
*/
public function getContainer()
{
return $this->container;
}
}