Repository navigation
Expand file tree
/
Copy pathMethodInjection.php
More file actions
67 lines (56 loc) · 1.54 KB
/
Copy pathMethodInjection.php
File metadata and controls
67 lines (56 loc) · 1.54 KB
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
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Di\Definition;
use Stringable;
class MethodInjection implements Stringable, DefinitionInterface
{
public function __construct(private string $methodName, private array $parameters = [])
{
}
public function __toString(): string
{
return sprintf('method(%s)', $this->methodName);
}
public function getName(): string
{
return '';
}
public function setName(string $name)
{
// The name does not matter for method injections, so do nothing.
}
public function getParameters(): array
{
return $this->parameters;
}
public function merge(self $definition)
{
// In case of conflicts, the current definition prevails.
$this->parameters = $this->parameters + $definition->parameters;
}
/**
* Reset the target should be resolved.
* If it is the FactoryDefinition, then the target means $factory property,
* If it is the ObjectDefinition, then the target means $className property.
*/
public function setTarget(string $value)
{
$this->methodName = $value;
}
/**
* Determine if the definition need to transfer to a proxy class.
*/
public function isNeedProxy(): bool
{
// Method injection does not has proxy.
return false;
}
}