Completed
Push — master ( b879f8...a4072e )
by Taosikai
14:58
created

ClassDefinition::getProperty()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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