1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Phossa Project |
4
|
|
|
* |
5
|
|
|
* PHP version 5.4 |
6
|
|
|
* |
7
|
|
|
* @category Library |
8
|
|
|
* @package Phossa2\Config |
9
|
|
|
* @copyright Copyright (c) 2016 phossa.com |
10
|
|
|
* @license http://mit-license.org/ MIT License |
11
|
|
|
* @link http://www.phossa.com/ |
12
|
|
|
*/ |
13
|
|
|
/*# declare(strict_types=1); */ |
14
|
|
|
|
15
|
|
|
namespace Phossa2\Config; |
16
|
|
|
|
17
|
|
|
use Phossa2\Shared\Base\ObjectAbstract; |
18
|
|
|
use Phossa2\Shared\Reference\DelegatorTrait; |
19
|
|
|
use Phossa2\Shared\Reference\DelegatorInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Delegator |
23
|
|
|
* |
24
|
|
|
* Implmentation of DelegatorInterface |
25
|
|
|
* |
26
|
|
|
* @package Phossa2\Config |
27
|
|
|
* @author Hong Zhang <[email protected]> |
28
|
|
|
* @see ObjectAbstract |
29
|
|
|
* @see DelegatorInterface |
30
|
|
|
* @version 2.0.0 |
31
|
|
|
* @since 2.0.0 added |
32
|
|
|
*/ |
33
|
|
|
class Delegator extends ObjectAbstract implements DelegatorInterface, ConfigInterface |
34
|
|
|
{ |
35
|
|
|
use DelegatorTrait; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritDoc} |
39
|
|
|
*/ |
40
|
|
|
public function get(/*# string */ $key, $default = null) |
41
|
|
|
{ |
42
|
|
|
if ($this->hasInLookup($key)) { |
43
|
|
|
return $this->getFromLookup($key); |
44
|
|
|
} |
45
|
|
|
return $default; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritDoc} |
50
|
|
|
*/ |
51
|
|
|
public function has(/*# string */ $key)/*# : bool */ |
52
|
|
|
{ |
53
|
|
|
return $this->hasInLookup($key); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritDoc} |
58
|
|
|
*/ |
59
|
|
|
protected function isValidContainer($container)/*# : bool */ |
60
|
|
|
{ |
61
|
|
|
return $container instanceof ConfigInterface; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritDoc} |
66
|
|
|
*/ |
67
|
|
|
protected function hasInContainer( |
68
|
|
|
$container, |
69
|
|
|
/*# string */ $key |
70
|
|
|
)/*# : bool */ { |
71
|
|
|
/* @var $container ConfigInterface */ |
72
|
|
|
return $container->has($key); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritDoc} |
77
|
|
|
*/ |
78
|
|
|
protected function getFromContainer( |
79
|
|
|
$container, |
80
|
|
|
/*# string */ $key |
81
|
|
|
) { |
82
|
|
|
/* @var $container ConfigInterface */ |
83
|
|
|
return $container->get($key); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|