Skip to content

Commit 5ab9752

Browse files
author
Phil Sturgeon
committed
Merge pull request #5 from i-ekho/develop
Added cleanArgs method to Definition
2 parents 3556777 + a1c7761 commit 5ab9752

4 files changed

Lines changed: 45 additions & 8 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
build
22
.idea
3+
atlassian-ide-plugin.xml
34
vendor
45
composer.lock
56
phpunit.xml

src/League/Di/Container.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Container
3434
/**
3535
* Constructor
3636
*
37-
* @param object $parent Container
37+
* @param Container $parent Container
3838
*/
3939
public function __construct(Container $parent = null)
4040
{
@@ -55,11 +55,10 @@ public function createChild()
5555
/**
5656
* Method to bind a concrete class to an abstract class or interface.
5757
*
58-
* @param string $abstract Class to bind.
59-
* @param mixed $concrete Concrete definition to bind to $abstract.
60-
* Can be a \Closure or a string.
58+
* @param string $abstract Class to bind.
59+
* @param \Closure|string $concrete Concrete definition to bind to $abstract.
6160
*
62-
* @return mixed The concrete class for adding method calls / constructor arguments if desired.
61+
* @return Definition|\Closure The concrete class for adding method calls / constructor arguments if desired.
6362
*/
6463
public function bind($abstract, $concrete = null)
6564
{
@@ -82,6 +81,7 @@ public function bind($abstract, $concrete = null)
8281
* parent Container's until it finds the $binding.
8382
*
8483
* @param string $binding The binding to check.
84+
* @return bool
8585
*/
8686
public function bound($binding)
8787
{
@@ -94,6 +94,7 @@ public function bound($binding)
9494
* @param string $concrete The name of the class to buld.
9595
*
9696
* @return mixed The instantiated class.
97+
* @throws \InvalidArgumentException
9798
*/
9899
public function build($concrete)
99100
{
@@ -118,9 +119,10 @@ public function build($concrete)
118119
* Extend an existing binding.
119120
*
120121
* @param string $binding The name of the binding to extend.
121-
* @param Closure $closure The function to use to extend the existing binding.
122+
* @param \Closure $closure The function to use to extend the existing binding.
122123
*
123124
* @return void
125+
* @throws \InvalidArgumentException
124126
*/
125127
public function extend($binding, \Closure $closure)
126128
{
@@ -141,6 +143,7 @@ public function extend($binding, \Closure $closure)
141143
* @param \ReflectionMethod $method The method for which to obtain dependencies.
142144
*
143145
* @return array An array containing the method dependencies.
146+
* @throws \InvalidArgumentException
144147
*/
145148
protected function getDependencies(\ReflectionMethod $method)
146149
{
@@ -170,7 +173,7 @@ protected function getDependencies(\ReflectionMethod $method)
170173
*
171174
* @param string $binding The $binding key to get the raw value from.
172175
*
173-
* @return mixed Value of the $binding.
176+
* @return Definition|\Closure Value of the $binding.
174177
*/
175178
public function getRaw($binding)
176179
{

src/League/Di/Definition.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ public function addArgs(array $args)
122122
return $this;
123123
}
124124

125+
/**
126+
* Remove all available arguments
127+
*
128+
* @return Definition
129+
*/
130+
public function cleanArgs()
131+
{
132+
$this->arguments = array();
133+
134+
return $this;
135+
}
136+
125137
/**
126138
* Adds a method call to be executed after instantiating.
127139
*
@@ -142,7 +154,7 @@ public function withMethod($method, array $args = array())
142154
*
143155
* @param object $object The instatiated $class on which to call the methods.
144156
*
145-
* @return The created object
157+
* @return mixed The created object
146158
*/
147159
protected function callMethods($object)
148160
{

test/League/Di/Test/DefinitionTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,27 @@ public function testAddArgs()
224224
);
225225
}
226226

227+
/**
228+
* Tests removing arguments from a Defintion.
229+
*
230+
* @return void
231+
*/
232+
public function testCleanArgs()
233+
{
234+
$definition = new Definition($this->container, 'League\\Di\\Stub\\Foo');
235+
236+
$definition->addArgs(array('foo', 'bar'));
237+
238+
$definition->cleanArgs();
239+
240+
$this->assertAttributeEquals(
241+
array(),
242+
'arguments',
243+
$definition,
244+
'All arguments should be removed from the arguments array.'
245+
);
246+
}
247+
227248
public function testWithMethod()
228249
{
229250
$definition = new Definition($this->container, 'League\\Di\\Stub\\Qux');

0 commit comments

Comments
 (0)