|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* The MIT License (MIT) |
|
4
|
|
|
* Copyright © 2017 Marcos Lois Bermudez <[email protected]> |
|
5
|
|
|
* * |
|
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
|
7
|
|
|
* documentation files (the “Software”), to deal in the Software without restriction, including without limitation |
|
8
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, |
|
9
|
|
|
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
|
10
|
|
|
* * |
|
11
|
|
|
* The above copyright notice and this permission notice shall be included in all copies or substantial portions |
|
12
|
|
|
* of the Software. |
|
13
|
|
|
* * |
|
14
|
|
|
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
|
15
|
|
|
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
|
16
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
|
17
|
|
|
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|
18
|
|
|
* DEALINGS IN THE SOFTWARE. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TTIC\Interop\Pimple; |
|
22
|
|
|
|
|
23
|
|
|
use Interop\Container\ContainerInterface; |
|
24
|
|
|
use Pimple\Container as PimpleContainer; |
|
25
|
|
|
use TTIC\Interop\Container\DelegateContainerTrait; |
|
26
|
|
|
use TTIC\Interop\Container\Exception\ContainerException; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Extends a Pimple container to implement ContainerInterface and |
|
30
|
|
|
* delegate container resolution. |
|
31
|
|
|
* |
|
32
|
|
|
* @package TTIC\Interop\Pimple |
|
33
|
|
|
* @author Marcos Lois Bermúdez <[email protected]> |
|
34
|
|
|
*/ |
|
35
|
|
|
class Container extends PimpleContainer implements ContainerInterface |
|
36
|
|
|
{ |
|
37
|
|
|
use DelegateContainerTrait; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* {@inheritDoc} |
|
41
|
|
|
*/ |
|
42
|
6 |
|
public function offsetGet($id) |
|
43
|
|
|
{ |
|
44
|
6 |
|
if (!$this->offsetExists($id) && $this->delegateHas($id)) { |
|
45
|
3 |
|
return $this->delegateGet($id); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
6 |
|
return parent::offsetGet($id); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritDoc} |
|
53
|
|
|
*/ |
|
54
|
6 |
|
public function has($id) |
|
55
|
|
|
{ |
|
56
|
6 |
|
return $this->offsetExists($id); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritDoc} |
|
61
|
|
|
*/ |
|
62
|
9 |
|
public function get($id) |
|
63
|
|
|
{ |
|
64
|
9 |
|
if (!$this->offsetExists($id) && !$this->delegateHas($id)) { |
|
65
|
3 |
|
throw new ContainerException(sprintf('Identifier "%s" is not defined.', $id)); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
6 |
|
return $this->offsetGet($id); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|