This repository was archived by the owner on May 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompositeContainer.php
134 lines (116 loc) · 3.32 KB
/
CompositeContainer.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
131
132
133
134
<?php
namespace Dhii\Data\Container;
use ArrayAccess;
use Dhii\Exception\CreateInvalidArgumentExceptionCapableTrait;
use Dhii\Exception\CreateOutOfRangeExceptionCapableTrait;
use Dhii\I18n\StringTranslatingTrait;
use Dhii\Util\Normalization\NormalizeIterableCapableTrait;
use Dhii\Util\Normalization\NormalizeStringCapableTrait;
use Psr\Container\ContainerInterface as BaseContainerInterface;
use stdClass;
use Traversable;
/**
* A container that contains other containers.
*
* It uses a list of child containers. Every time `has()` or `get()` is invoked, it iterates through the list,
* and gives the first matching result. This means that results of containers that come before will override results
* from containers that come after. The results are not cached, meaning that if the list of containers changes
* (such as if a traversable object), then the result of `has()` or `get()` may also change.
*
* @since [*next-version*]
*/
class CompositeContainer implements ContainerInterface
{
/* Awareness of a list of containers.
*
* @since [*next-version*]
*/
use ContainerListAwareTrait;
/* Ability to retrieve a service from a list of containers.
*
* @since [*next-version*]
*/
use ContainerListGetCapableTrait;
/* Ability to check a list of containers for a key.
*
* @since [*next-version*]
*/
use ContainerListHasCapableTrait;
/* Ability to retrieve a value from a container.
*
* @since [*next-version*]
*/
use ContainerGetCapableTrait;
/* Ability to check for a value in a container.
*
* @since [*next-version*]
*/
use ContainerHasCapableTrait;
/* Basic i18n capability.
*
* @since [*next-version*]
*/
use StringTranslatingTrait;
/* Ability to normalize values to string.
*
* @since [*next-version*]
*/
use NormalizeStringCapableTrait;
/* Ability to normalize values to iterable.
*
* @since [*next-version*]
*/
use NormalizeIterableCapableTrait;
/* Ability to normalize container keys.
*
* @since [*next-version*]
*/
use NormalizeKeyCapableTrait;
/* Factory of Invalid Argument exception.
*
* @since [*next-version*]
*/
use CreateInvalidArgumentExceptionCapableTrait;
/* Factory of Container exception.
*
* @since [*next-version*]
*/
use CreateContainerExceptionCapableTrait;
/* Factory of Not Found exception.
*
* @since [*next-version*]
*/
use CreateNotFoundExceptionCapableTrait;
/* Factory of Out of Range exception.
*
* @since [*next-version*]
*/
use CreateOutOfRangeExceptionCapableTrait;
/**
* @since [*next-version*]
*
* @param BaseContainerInterface[]|array[]|stdClass[]|ArrayAccess[]|stdClass|Traversable $containers A list of containers.
*/
public function __construct($containers)
{
$this->_setContainerList($containers);
}
/**
* {@inheritdoc}
*
* @since [*next-version*]
*/
public function get($key)
{
return $this->_containerListGet($key, $this->_getContainerList());
}
/**
* {@inheritdoc}
*
* @since [*next-version*]
*/
public function has($key)
{
return $this->_containerListHas($key, $this->_getContainerList());
}
}