|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of slick/di |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Slick\Di\Definition\Object; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Definition Data for object creation |
|
14
|
|
|
* |
|
15
|
|
|
* @package Slick\Di\Definition\Object |
|
16
|
|
|
*/ |
|
17
|
|
|
class DefinitionData |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
const METHOD = 'method'; |
|
21
|
|
|
const PROPERTY = 'property'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $className; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $arguments = []; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var array |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $calls = []; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Definition Data |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $className |
|
42
|
|
|
* @param array $arguments |
|
43
|
|
|
* @param array $calls |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct($className, array $arguments = [], array $calls = []) |
|
46
|
|
|
{ |
|
47
|
|
|
|
|
48
|
|
|
$this->className = $className; |
|
49
|
|
|
$this->arguments = $arguments; |
|
50
|
|
|
$this->calls = $calls; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Adds a call to the stack |
|
55
|
|
|
* |
|
56
|
|
|
* @param string $type |
|
57
|
|
|
* @param string $name |
|
58
|
|
|
* @param array $arguments |
|
59
|
|
|
* |
|
60
|
|
|
* @return DefinitionData |
|
61
|
|
|
*/ |
|
62
|
|
|
public function addCall($type, $name, $arguments = []) |
|
63
|
|
|
{ |
|
64
|
|
|
array_push($this->calls, [ |
|
65
|
|
|
'type' => $type, |
|
66
|
|
|
'name' => $name, |
|
67
|
|
|
'arguments' => $arguments |
|
68
|
|
|
]); |
|
69
|
|
|
return $this; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Updated the arguments of the last defined method |
|
74
|
|
|
* |
|
75
|
|
|
* @param array $arguments |
|
76
|
|
|
* |
|
77
|
|
|
* @return DefinitionData |
|
78
|
|
|
*/ |
|
79
|
|
|
public function updateLastMethod($arguments) |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->update(self::METHOD, $arguments); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Updated the arguments of the last defined property |
|
86
|
|
|
* |
|
87
|
|
|
* @param mixed $value |
|
88
|
|
|
* |
|
89
|
|
|
* @return DefinitionData |
|
90
|
|
|
*/ |
|
91
|
|
|
public function updateLastProperty($value) |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->update(self::PROPERTY, $value); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param string $type |
|
98
|
|
|
* @param mixed $arguments |
|
99
|
|
|
* |
|
100
|
|
|
* @return DefinitionData |
|
101
|
|
|
*/ |
|
102
|
|
|
protected function update($type, $arguments) |
|
103
|
|
|
{ |
|
104
|
|
|
$reversed = array_reverse($this->calls); |
|
105
|
|
|
foreach ($reversed as &$call) { |
|
106
|
|
|
if ($call['type'] == $type) { |
|
107
|
|
|
$call['arguments'] = $arguments; |
|
108
|
|
|
break; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
$this->calls = array_reverse($reversed); |
|
112
|
|
|
return $this; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function arguments() |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->arguments; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function withArguments(array $arguments) |
|
121
|
|
|
{ |
|
122
|
|
|
$this->arguments = $arguments; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function className() |
|
126
|
|
|
{ |
|
127
|
|
|
return $this->className; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function calls() |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->calls; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|