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\Laravel\Bridge\Container; |
22
|
|
|
|
23
|
|
|
use Exception; |
24
|
|
|
use Illuminate\Container\Container as LaravelContainer; |
25
|
|
|
use Interop\Container\ContainerInterface; |
26
|
|
|
use TTIC\Interop\Container\DelegateContainerTrait; |
27
|
|
|
use TTIC\Interop\Container\Exception\ContainerException; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Extends a Laravel container to implement ContainerInterface and |
32
|
|
|
* delegate container resolution. |
33
|
|
|
* |
34
|
|
|
* @package TTIC\Container |
35
|
|
|
* @author Marcos Lois Bermúdez <[email protected]> |
36
|
|
|
*/ |
37
|
|
|
class Container extends LaravelContainer implements ContainerInterface |
38
|
|
|
{ |
39
|
|
|
use DelegateContainerTrait; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritDoc} |
43
|
|
|
*/ |
44
|
141 |
|
public function make($abstract, array $parameters = []) |
45
|
|
|
{ |
46
|
141 |
|
$abstract = $this->getAlias($this->normalize($abstract)); |
47
|
|
|
|
48
|
141 |
|
if (!$this->bound($abstract) && $this->delegateHas($abstract)) { |
49
|
6 |
|
return $this->delegateGet($abstract); |
50
|
|
|
} |
51
|
|
|
|
52
|
141 |
|
return parent::make($abstract, $parameters); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritDoc} |
57
|
|
|
*/ |
58
|
6 |
|
public function has($id) |
59
|
|
|
{ |
60
|
6 |
|
return $this->bound($id); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritDoc} |
65
|
|
|
*/ |
66
|
9 |
|
public function get($id) |
67
|
|
|
{ |
68
|
|
|
try { |
69
|
9 |
|
return $this->make($id); |
70
|
3 |
|
} catch(Exception $e) { |
71
|
3 |
|
throw ContainerException::fromPrevious($id, $e); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|