Definition::addMethodCall()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
/*
3
 * This file is part of the Borobudur-DependencyInjection package.
4
 *
5
 * (c) Hexacodelabs <http://hexacodelabs.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Borobudur\DependencyInjection;
12
13
use Borobudur\DependencyInjection\Definition\Argument;
14
use Borobudur\DependencyInjection\Definition\MethodCall;
15
use Borobudur\DependencyInjection\Definition\Property;
16
use Borobudur\DependencyInjection\Exception\InvalidArgumentException;
17
18
/**
19
 * @author      Iqbal Maulana <[email protected]>
20
 * @created     8/8/15
21
 */
22
class Definition
23
{
24
    /**
25
     * @var string
26
     */
27
    private $class;
28
29
    /**
30
     * @var string
31
     */
32
    private $abstract;
33
34
    /**
35
     * @var Argument
36
     */
37
    private $argument;
38
39
    /**
40
     * @var Property
41
     */
42
    private $property;
43
44
    /**
45
     * @var MethodCall
46
     */
47
    private $call;
48
49
    /**
50
     * @var bool
51
     */
52
    private $shared = false;
53
54
    /**
55
     * @var array
56
     */
57
    private $tags = array();
58
59
    /**
60
     * Constructor.
61
     *
62
     * @param string $class
63
     * @param array  $arguments
64
     */
65
    public function __construct($class, array $arguments = array())
66
    {
67
        $this->class = $class;
68
        $this->argument = new Argument($arguments);
69
        $this->property = new Property();
70
        $this->call = new MethodCall();
71
    }
72
73
    /**
74
     * Get class.
75
     *
76
     * @return string
77
     */
78
    public function getClass()
79
    {
80
        return $this->class;
81
    }
82
83
    /**
84
     * Get abstract class.
85
     *
86
     * @return string
87
     */
88
    public function getAbstract()
89
    {
90
        return $this->abstract;
91
    }
92
93
    /**
94
     * Set abstract class.
95
     *
96
     * @param string $abstract
97
     *
98
     * @return static
99
     */
100
    public function setAbstract($abstract)
101
    {
102
        $this->abstract = $abstract;
103
104
        return $this;
105
    }
106
107
    /**
108
     * Check if definition is abstract.
109
     *
110
     * @return bool
111
     */
112
    public function isAbstract()
113
    {
114
        return null !== $this->abstract;
115
    }
116
117
    /**
118
     * Get property.
119
     *
120
     * @return Property
121
     */
122
    public function getProperty()
123
    {
124
        return $this->property;
125
    }
126
127
    /**
128
     * Shortcut set property.
129
     *
130
     * @param string $property
131
     * @param mixed  $value
132
     *
133
     * @return static
134
     */
135
    public function setProperty($property, $value)
136
    {
137
        $this->property->set($property, $value);
138
139
        return $this;
140
    }
141
142
    /**
143
     * Ger argument.
144
     *
145
     * @return Argument
146
     */
147
    public function getArgument()
148
    {
149
        return $this->argument;
150
    }
151
152
    /**
153
     * Shortcut add argument.
154
     *
155
     * @param mixed $argument
156
     *
157
     * @return static
158
     */
159
    public function addArgument($argument)
160
    {
161
        $this->argument->add($argument);
162
163
        return $this;
164
    }
165
166
    /**
167
     * Get method call.
168
     *
169
     * @return MethodCall
170
     */
171
    public function getMethodCall()
172
    {
173
        return $this->call;
174
    }
175
176
    /**
177
     * Shortcut add method call.
178
     *
179
     * @param string $method
180
     * @param array  $arguments
181
     *
182
     * @return static
183
     */
184
    public function addMethodCall($method, array $arguments = array())
185
    {
186
        $this->call->add($method, $arguments);
187
188
        return $this;
189
    }
190
191
    /**
192
     * Mark this definition as singleton.
193
     *
194
     * @return static
195
     */
196
    public function share()
197
    {
198
        $this->shared = true;
199
200
        return $this;
201
    }
202
203
    /**
204
     * Check if definition shared.
205
     *
206
     * @return bool
207
     */
208
    public function isShared()
209
    {
210
        return $this->shared;
211
    }
212
213
    /**
214
     * Add a tag.
215
     *
216
     * @param string $name
217
     * @param array  $attributes
218
     */
219
    public function addTag($name, array $attributes = array())
220
    {
221
        if (isset($this->tags[$name])) {
222
            throw new InvalidArgumentException(sprintf(
223
                'Tag with name "%s" already added on "%s" definition.',
224
                $name,
225
                $this->class
226
            ));
227
        }
228
229
        $this->tags[$name] = $attributes;
230
    }
231
232
    /**
233
     * Get all tags.
234
     *
235
     * @return array
236
     */
237
    public function getTags()
238
    {
239
        return $this->tags;
240
    }
241
}
242