This repository has been archived by the owner on May 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ContainerAwareCachingContainer.php
130 lines (113 loc) · 3.33 KB
/
ContainerAwareCachingContainer.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
namespace Dhii\Di;
use ArrayAccess;
use stdClass;
use Psr\Container\ContainerInterface as BaseContainerInterface;
use Dhii\Data\Container\ContainerAwareInterface;
use Dhii\Data\Container\ContainerAwareTrait;
use Dhii\Data\Container\ResolveContainerCapableTrait;
use Dhii\Exception\CreateInvalidArgumentExceptionCapableTrait;
use Dhii\Exception\CreateOutOfRangeExceptionCapableTrait;
use Dhii\Exception\CreateRuntimeExceptionCapableTrait;
use Dhii\Exception\CreateInternalExceptionCapableTrait;
use Dhii\Invocation\CreateInvocationExceptionCapableTrait;
use Dhii\Validation\CreateValidationFailedExceptionCapableTrait;
use Dhii\I18n\StringTranslatingTrait;
use Dhii\Cache\ContainerInterface as CacheContainerInterface;
use Dhii\Util\Normalization\NormalizeIntCapableTrait;
/**
* A DI container that is aware of a parent container.
*
* Will resolve callable definitions, and cache the result.
* While resolving, will retrieve the inner-most container from the
* ancestor chain, and pass it to the definition.
*
* @since [*next-version*]
*/
class ContainerAwareCachingContainer extends AbstractBaseCachingContainer implements ContainerAwareInterface
{
/* Awareness of an outer container.
*
* @since [*next-version*]
*/
use ContainerAwareTrait;
/* Ability to resolve inner-most container.
*
* @since [*next-version*]
*/
use ResolveContainerCapableTrait;
/*
* Basic ability to i18n strings.
*
* @since [*next-version*]
*/
use StringTranslatingTrait;
/* Ability to normalize into an integer.
*
* @since [*next-version*]
*/
use NormalizeIntCapableTrait;
/* Factory of Validation Failed exception.
*
* @since [*next-version*]
*/
use CreateValidationFailedExceptionCapableTrait;
/* Factory of Runtime exception.
*
* @since [*next-version*]
*/
use CreateRuntimeExceptionCapableTrait;
/* Factory of Invalid Argument exception.
*
* @since [*next-version*]
*/
use CreateInvalidArgumentExceptionCapableTrait;
/* Factory of Out of Range exception.
*
* @since [*next-version*]
*/
use CreateOutOfRangeExceptionCapableTrait;
/* Factory of Invocation exception.
*
* @since [*next-version*]
*/
use CreateInvocationExceptionCapableTrait;
/* Factory of Internal exception.
*
* @since [*next-version*]
*/
use CreateInternalExceptionCapableTrait;
/**
* @since [*next-version*]
*
* @param array|ArrayAccess|stdClass|BaseContainerInterface $services The services container.
*/
public function __construct($services, CacheContainerInterface $serviceCache, $parentContainer = null)
{
if (is_array($services)) {
$services = (object) $services;
}
$this->_setDataStore($services);
$this->_setServiceCache($serviceCache);
!is_null($parentContainer) && $this->_setContainer($parentContainer);
}
/**
* {@inheritdoc}
*
* @since [*next-version*]
*/
public function getContainer()
{
return $this->_getContainer();
}
/**
* {@inheritdoc}
*
* @since [*next-version*]
*/
protected function _getArgsForDefinition($definition)
{
$container = $this->_resolveContainer($this);
return [$container];
}
}