Completed
Push — master ( 943bb4...e299e4 )
by Taosikai
13:53
created

Definition::getArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the slince/di package.
5
 *
6
 * (c) Slince <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Slince\Di;
13
14
class Definition
15
{
16
    /**
17
     * @var string
18
     */
19
    protected $class;
20
21
    /**
22
     * Array of arguments
23
     * @var array
24
     */
25
    protected $arguments = [];
26
27
    /**
28
     * Array of setters
29
     * @var array
30
     */
31
    protected $calls = [];
32
33
    /**
34
     * Array of properties
35
     * @var array
36
     */
37
    protected $properties = [];
38
39
    public function __construct($class, array $arguments = [], array $methods = [], array $properties = [])
40
    {
41
        $this->class = $class;
42
        $this->arguments = $arguments;
43
        $this->calls = $methods;
44
        $this->properties = $properties;
45
    }
46
47
    /**
48
     * Sets a argument
49
     * @param int|string $index
50
     * @param mixed $value
51
     * @return $this
52
     */
53
    public function setArgument($index, $value)
54
    {
55
        $this->arguments[$index] = $value;
56
        return $this;
57
    }
58
59
60
    /**
61
     * Sets array of arguments
62
     * @param array $arguments
63
     * @return $this
64
     */
65
    public function setArguments(array $arguments)
66
    {
67
        $this->arguments = $arguments;
68
        return $this;
69
    }
70
71
    /**
72
     * Gets all arguments of constructor
73
     * @return array
74
     */
75
    public function getArguments()
76
    {
77
        return $this->arguments;
78
    }
79
80
    /**
81
     * Gets the argument at the specified position of constructor
82
     * @param int|string $index
83
     * @return mixed
84
     */
85
    public function getArgument($index)
86
    {
87
        return isset($this->arguments[$index]) ? $this->arguments[$index] : null;
88
    }
89
90
    /**
91
     * Adds a setter
92
     * @param string $method
93
     * @param string|array $arguments
94
     * @return $this
95
     */
96
    public function setMethodCall($method, $arguments)
97
    {
98
        $this->calls[$method] = (array)$arguments;
99
        return $this;
100
    }
101
102
    /**
103
     * Sets array of setter
104
     * @param array $calls
105
     * @return $this
106
     */
107
    public function setMethodCalls(array $calls)
108
    {
109
        $this->calls = array_merge($this->calls, $calls);
110
        return $this;
111
    }
112
113
    /**
114
     * Add a method
115
     *
116
     * @param $method
117
     * @param $arguments
118
     * @return self
119
     */
120
    public function addMethodCall($method, $arguments)
121
    {
122
        $this->calls[] = [
123
            $method,
124
            $arguments
125
        ];
126
        return $this;
127
    }
128
129
    /**
130
     * Gets all methods
131
     *
132
     * @return array
133
     */
134
    public function getMethodCalls()
135
    {
136
        return $this->calls;
137
    }
138
139
    /**
140
     * Gets the parameters of one setter
141
     * @param string $method
142
     * @return array|null
143
     */
144
    public function getMethodCall($method)
145
    {
146
        return isset($this->calls[$method]) ? $this->calls[$method] : null;
147
    }
148
149
    /**
150
     * @param array $properties
151
     */
152
    public function setProperties($properties)
153
    {
154
        $this->properties = $properties;
155
    }
156
157
    /**
158
     * Gets all properties
159
     * @return array
160
     */
161
    public function getProperties()
162
    {
163
        return $this->properties;
164
    }
165
166
    /**
167
     * Adds a property
168
     * @param int|string $name
169
     * @param mixed $value
170
     * @return $this
171
     */
172
    public function setProperty($name, $value)
173
    {
174
        $this->properties[$name] = $value;
175
        return $this;
176
    }
177
178
    /**
179
     * Gets the property by given name
180
     * @param string $name
181
     * @return mixed
182
     */
183
    public function getProperty($name)
184
    {
185
        return isset($this->properties[$name]) ? $this->properties[$name] : null;
186
    }
187
188
189
    /**
190
     * Gets the class
191
     * @return string
192
     */
193
    public function getClass()
194
    {
195
        return $this->class;
196
    }
197
}
198