-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstruction.php
More file actions
130 lines (114 loc) · 2.56 KB
/
Instruction.php
File metadata and controls
130 lines (114 loc) · 2.56 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/**
* This file is part of the Vection package.
*
* (c) David M. Lung <vection@davidlung.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Vection\Component\DependencyInjection;
use Closure;
use Vection\Contracts\DependencyInjection\InstructionInterface;
/**
* Class Instruction
*
* @package Vection\Component\DependencyInjection
*
* @author David M. Lung <vection@davidlung.de>
*/
class Instruction implements InstructionInterface
{
protected string $className;
protected bool $isShared = true;
protected Closure|null $factory = null;
protected string|null $by = null;
/** @var array<string, string> */
protected array $setter = [];
/**
* Instruction constructor.
*
* @param string $className
*/
public function __construct(string $className)
{
$this->className = trim($className, '\\');
}
/**
* @param callable|Closure $closure
*
* @return static
*/
public function viaFactory(callable|Closure $closure): static
{
$this->factory = ($closure instanceof Closure ? $closure : $closure(...));
return $this;
}
/**
* @param string $className
* @param string $setterMethodName
*
* @return static
*/
public function viaSetter(string $setterMethodName, string $className): static
{
$this->setter[$setterMethodName] = $className;
return $this;
}
/**
* @param string $className
*
* @return static
*/
public function by(string $className): static
{
$this->by = $className;
return $this;
}
/**
* @param bool $shared
*
* @return static
*/
public function asShared(bool $shared): static
{
$this->isShared = $shared;
return $this;
}
/**
* @return string
*/
public function getClassName(): string
{
return $this->className;
}
/**
* @return array<string, string>
*/
public function getSetterInjections(): array
{
return $this->setter;
}
/**
* @return string|null
*/
public function getBy(): string|null
{
return $this->by;
}
/**
* @return Closure|null
*/
public function getFactory(): Closure|null
{
return $this->factory;
}
/**
* @return bool
*/
public function isShared(): bool
{
return $this->isShared;
}
}