Skip to content

Commit

Permalink
Merge pull request #5 from i-ekho/develop
Browse files Browse the repository at this point in the history
Added cleanArgs method to Definition
  • Loading branch information
Phil Sturgeon committed Mar 18, 2014
2 parents 3556777 + a1c7761 commit 5ab9752
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,5 +1,6 @@
build
.idea
atlassian-ide-plugin.xml
vendor
composer.lock
phpunit.xml
17 changes: 10 additions & 7 deletions src/League/Di/Container.php
Expand Up @@ -34,7 +34,7 @@ class Container
/**
* Constructor
*
* @param object $parent Container
* @param Container $parent Container
*/
public function __construct(Container $parent = null)
{
Expand All @@ -55,11 +55,10 @@ public function createChild()
/**
* Method to bind a concrete class to an abstract class or interface.
*
* @param string $abstract Class to bind.
* @param mixed $concrete Concrete definition to bind to $abstract.
* Can be a \Closure or a string.
* @param string $abstract Class to bind.
* @param \Closure|string $concrete Concrete definition to bind to $abstract.
*
* @return mixed The concrete class for adding method calls / constructor arguments if desired.
* @return Definition|\Closure The concrete class for adding method calls / constructor arguments if desired.
*/
public function bind($abstract, $concrete = null)
{
Expand All @@ -82,6 +81,7 @@ public function bind($abstract, $concrete = null)
* parent Container's until it finds the $binding.
*
* @param string $binding The binding to check.
* @return bool
*/
public function bound($binding)
{
Expand All @@ -94,6 +94,7 @@ public function bound($binding)
* @param string $concrete The name of the class to buld.
*
* @return mixed The instantiated class.
* @throws \InvalidArgumentException
*/
public function build($concrete)
{
Expand All @@ -118,9 +119,10 @@ public function build($concrete)
* Extend an existing binding.
*
* @param string $binding The name of the binding to extend.
* @param Closure $closure The function to use to extend the existing binding.
* @param \Closure $closure The function to use to extend the existing binding.
*
* @return void
* @throws \InvalidArgumentException
*/
public function extend($binding, \Closure $closure)
{
Expand All @@ -141,6 +143,7 @@ public function extend($binding, \Closure $closure)
* @param \ReflectionMethod $method The method for which to obtain dependencies.
*
* @return array An array containing the method dependencies.
* @throws \InvalidArgumentException
*/
protected function getDependencies(\ReflectionMethod $method)
{
Expand Down Expand Up @@ -170,7 +173,7 @@ protected function getDependencies(\ReflectionMethod $method)
*
* @param string $binding The $binding key to get the raw value from.
*
* @return mixed Value of the $binding.
* @return Definition|\Closure Value of the $binding.
*/
public function getRaw($binding)
{
Expand Down
14 changes: 13 additions & 1 deletion src/League/Di/Definition.php
Expand Up @@ -122,6 +122,18 @@ public function addArgs(array $args)
return $this;
}

/**
* Remove all available arguments
*
* @return Definition
*/
public function cleanArgs()
{
$this->arguments = array();

return $this;
}

/**
* Adds a method call to be executed after instantiating.
*
Expand All @@ -142,7 +154,7 @@ public function withMethod($method, array $args = array())
*
* @param object $object The instatiated $class on which to call the methods.
*
* @return The created object
* @return mixed The created object
*/
protected function callMethods($object)
{
Expand Down
21 changes: 21 additions & 0 deletions test/League/Di/Test/DefinitionTest.php
Expand Up @@ -224,6 +224,27 @@ public function testAddArgs()
);
}

/**
* Tests removing arguments from a Defintion.
*
* @return void
*/
public function testCleanArgs()
{
$definition = new Definition($this->container, 'League\\Di\\Stub\\Foo');

$definition->addArgs(array('foo', 'bar'));

$definition->cleanArgs();

$this->assertAttributeEquals(
array(),
'arguments',
$definition,
'All arguments should be removed from the arguments array.'
);
}

public function testWithMethod()
{
$definition = new Definition($this->container, 'League\\Di\\Stub\\Qux');
Expand Down

0 comments on commit 5ab9752

Please sign in to comment.