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
|
|
|
use Slick\Common\Base; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Definition Data for object creation |
16
|
|
|
* |
17
|
|
|
* @package Slick\Di\Definition\Object |
18
|
|
|
* @author Filipe Silva <[email protected]> |
19
|
|
|
* |
20
|
|
|
* @property string $className |
21
|
|
|
* @property array $arguments |
22
|
|
|
* @property array $calls |
23
|
|
|
*/ |
24
|
|
|
class DefinitionData extends Base |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
const METHOD = 'method'; |
28
|
|
|
const PROPERTY = 'property'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @readwrite |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $className; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @readwrite |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
protected $arguments = []; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @readwrite |
44
|
|
|
* @var array |
45
|
|
|
*/ |
46
|
|
|
protected $calls = []; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Definition Data |
50
|
|
|
* |
51
|
|
|
* @param string $className |
52
|
|
|
* @param array $arguments |
53
|
|
|
* @param array $calls |
54
|
|
|
*/ |
55
|
|
|
public function __construct($className, array $arguments = [], array $calls = []) |
56
|
|
|
{ |
57
|
|
|
$options = [ |
58
|
|
|
'className' => $className, |
59
|
|
|
'arguments' => $arguments, |
60
|
|
|
'calls' => $calls |
61
|
|
|
]; |
62
|
|
|
parent::__construct($options); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Adds a call to the stack |
67
|
|
|
* |
68
|
|
|
* @param string $type |
69
|
|
|
* @param string $name |
70
|
|
|
* @param array $arguments |
71
|
|
|
* |
72
|
|
|
* @return DefinitionData |
73
|
|
|
*/ |
74
|
|
|
public function addCall($type, $name, $arguments = []) |
75
|
|
|
{ |
76
|
|
|
array_push($this->calls, [ |
77
|
|
|
'type' => $type, |
78
|
|
|
'name' => $name, |
79
|
|
|
'arguments' => $arguments |
80
|
|
|
]); |
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Updated the arguments of the last defined method |
86
|
|
|
* |
87
|
|
|
* @param array $arguments |
88
|
|
|
* |
89
|
|
|
* @return DefinitionData |
90
|
|
|
*/ |
91
|
|
|
public function updateLastMethod($arguments) |
92
|
|
|
{ |
93
|
|
|
return $this->update(self::METHOD, $arguments); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Updated the arguments of the last defined property |
98
|
|
|
* |
99
|
|
|
* @param mixed $value |
100
|
|
|
* |
101
|
|
|
* @return DefinitionData |
102
|
|
|
*/ |
103
|
|
|
public function updateLastProperty($value) |
104
|
|
|
{ |
105
|
|
|
return $this->update(self::PROPERTY, $value); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param string $type |
110
|
|
|
* @param mixed $arguments |
111
|
|
|
* |
112
|
|
|
* @return DefinitionData |
113
|
|
|
*/ |
114
|
|
|
protected function update($type, $arguments) |
115
|
|
|
{ |
116
|
|
|
$reversed = array_reverse($this->calls); |
117
|
|
|
foreach ($reversed as &$call) { |
118
|
|
|
if ($call['type'] == $type) { |
119
|
|
|
$call['arguments'] = $arguments; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
$this->calls = array_reverse($reversed); |
123
|
|
|
return $this; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|