1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Phossa Project |
4
|
|
|
* |
5
|
|
|
* PHP version 5.4 |
6
|
|
|
* |
7
|
|
|
* @category Library |
8
|
|
|
* @package Phossa2\Di |
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\Di\Traits; |
16
|
|
|
|
17
|
|
|
use Phossa2\Di\Interfaces\ScopeInterface; |
18
|
|
|
use Phossa2\Di\Interfaces\FactoryInterface; |
19
|
|
|
use Phossa2\Di\Interfaces\ResolverInterface; |
20
|
|
|
use Phossa2\Di\Interfaces\ExtendedContainerInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* ExtendedContainerTrait |
24
|
|
|
* |
25
|
|
|
* Implementation of ExtendedContainerInterface |
26
|
|
|
* |
27
|
|
|
* @package Phossa2\Di |
28
|
|
|
* @author Hong Zhang <[email protected]> |
29
|
|
|
* @see ExtendedContainerInterface |
30
|
|
|
* @version 2.0.0 |
31
|
|
|
* @since 2.0.0 added |
32
|
|
|
*/ |
33
|
|
|
trait ExtendedContainerTrait |
34
|
|
|
{ |
35
|
|
|
// ExtendedContainerInterface related |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritDoc} |
39
|
|
|
*/ |
40
|
|
|
public function one(/*# string */ $id, array $arguments = []) |
41
|
|
|
{ |
42
|
|
|
return $this->get( |
43
|
|
|
$this->scopedId($id, ScopeInterface::SCOPE_SINGLE), $arguments |
|
|
|
|
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritDoc} |
49
|
|
|
*/ |
50
|
|
|
public function run($callable, array $arguments = []) |
51
|
|
|
{ |
52
|
|
|
$this->resolve($callable); |
53
|
|
|
$this->resolve($arguments); |
54
|
|
|
|
55
|
|
|
return $this->getFactory()->executeCallable($callable, $arguments); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritDoc} |
60
|
|
|
*/ |
61
|
|
|
public function param(/*# string */ $name, $value) |
62
|
|
|
{ |
63
|
|
|
$this->getResolver()->set((string) $name, $value); |
64
|
|
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
// AutoWiringInterface related |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritDoc} |
71
|
|
|
*/ |
72
|
|
|
public function auto(/*# bool */ $flag = true) |
73
|
|
|
{ |
74
|
|
|
$this->getResolver()->auto($flag); |
75
|
|
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritDoc} |
80
|
|
|
*/ |
81
|
|
|
public function isAuto()/*# : bool */ |
82
|
|
|
{ |
83
|
|
|
return $this->getResolver()->isAuto(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
// ReferenceResolveInterface related |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritDoc} |
90
|
|
|
*/ |
91
|
|
|
public function resolve(&$toResolve) |
92
|
|
|
{ |
93
|
|
|
$this->getResolver()->resolve($toResolve); |
94
|
|
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* From ContainerInterface |
99
|
|
|
* |
100
|
|
|
* @param string $id Identifier of the entry to look for. |
101
|
|
|
* @return mixed Entry. |
102
|
|
|
*/ |
103
|
|
|
abstract public function get($id); |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* From ContainerHelperTrait |
107
|
|
|
* |
108
|
|
|
* @return ResolverInterface |
109
|
|
|
*/ |
110
|
|
|
abstract protected function getResolver()/*# : ResolverInterface */; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* From ContainerHelperTrait |
114
|
|
|
* |
115
|
|
|
* @return FactoryInterface |
116
|
|
|
*/ |
117
|
|
|
abstract protected function getFactory()/*# : FactoryInterface */; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* From ScopeTrait |
121
|
|
|
* |
122
|
|
|
* @param string $id |
123
|
|
|
* @param string $scope |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
abstract protected function scopedId( |
127
|
|
|
/*# string */ $id, |
128
|
|
|
/*# string */ $scope |
129
|
|
|
)/*# : string */; |
130
|
|
|
} |
131
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.