Skip to content

Commit

Permalink
Refactored Config array of constructor to hold additional params key.
Browse files Browse the repository at this point in the history
Signed-off-by: Tom McKelvey <tsmckelvey@gmail.com>
  • Loading branch information
beberlei authored and tsmckelvey committed Mar 16, 2009
1 parent 8053185 commit e73367e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
9 changes: 9 additions & 0 deletions Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class Yadif_Container
*/
const CONFIG_ARGUMENTS = 'arguments';

/**
* Parameters
*/
const CONFIG_PARAMETERS = 'params';

/**
* Singleton index key of component $config
*/
Expand Down Expand Up @@ -221,6 +226,10 @@ public function addComponent($name = null, array $config = null)
$config[ self::CONFIG_ARGUMENTS ] = array();
}

if(!isset($config[self::CONFIG_PARAMETERS])) {
$config[self::CONFIG_PARAMETERS] = array();
}

// if class is set and doesn't exist
if (!class_exists( $config[self::CONFIG_CLASS] )) {
throw new Yadif_Exception( 'Class ' . $config[self::CONFIG_CLASS] . ' not found' );
Expand Down
4 changes: 3 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,6 @@ $baz = $yadif->getComponent("YadifBaz");

5. Session Scope: Add a third parameter to the Container which accepts a Zend_Session_Namespace. All objects inside this
namespace are added to the list of instances where the session key corresponds to the Component Name. Instantiated objects
that are scoped "session" are saved inside the session, not just the container.
that are scoped "session" are saved inside the session, not just the container.

6. Currently no loading of the Classes through Zend_Loader::loadClass() - How to handle this?
10 changes: 5 additions & 5 deletions tests/YadifConfigComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public function testCreateNewContainerWithEmptyArray()
public function testAddComponent()
{
$yadif = new Yadif_Container();
$yadif->addComponent("YadifBaz", array("class" => "YadifBaz", "arguments" => array(), 'scope' => Yadif_Container::SCOPE_SINGLETON, 'methods' => array()));
$yadif->addComponent("YadifBaz", array("class" => "YadifBaz", "arguments" => array(), 'params' => array(), 'scope' => Yadif_Container::SCOPE_SINGLETON, 'methods' => array()));

$expected = array("YadifBaz" => array("class" => "YadifBaz", "arguments" => array(), 'scope' => Yadif_Container::SCOPE_SINGLETON, 'methods' => array()));
$expected = array("YadifBaz" => array("class" => "YadifBaz", "arguments" => array(), 'params' => array(), 'scope' => Yadif_Container::SCOPE_SINGLETON, 'methods' => array()));
$this->assertEquals($expected, $this->readAttribute($yadif, '_container'));
}

Expand All @@ -33,7 +33,7 @@ public function testAddComponentWithoutClassAndArgumentsHasDefaultValues()
$yadif = new Yadif_Container();
$yadif->addComponent("YadifBaz");

$expected = array("YadifBaz" => array("class" => "YadifBaz", "arguments" => array(), 'scope' => Yadif_Container::SCOPE_SINGLETON, 'methods' => array()));
$expected = array("YadifBaz" => array("class" => "YadifBaz", "arguments" => array(), 'params' => array(), 'scope' => Yadif_Container::SCOPE_SINGLETON, 'methods' => array()));
$this->assertEquals($expected, $this->readAttribute($yadif, '_container'));
}

Expand Down Expand Up @@ -64,7 +64,7 @@ public function testGetComponent()
$yadif = new Yadif_Container();
$yadif->addComponent("stdClass");

$expected = array("stdClass" => array("class" => "stdClass", "arguments" => array(), 'scope' => Yadif_Container::SCOPE_SINGLETON, 'methods' => array()));
$expected = array("stdClass" => array("class" => "stdClass", "arguments" => array(), 'params' => array(), 'scope' => Yadif_Container::SCOPE_SINGLETON, 'methods' => array()));
$this->assertEquals($expected, $yadif->getContainer());
}

Expand All @@ -76,7 +76,7 @@ public function testAddComponentWithContainerIsMerging()
$yadif2 = new Yadif_Container();
$yadif2->addComponent($yadif1);

$expected = array("stdClass" => array("class" => "stdClass", "arguments" => array(), 'scope' => Yadif_Container::SCOPE_SINGLETON, 'methods' => array()));
$expected = array("stdClass" => array("class" => "stdClass", "arguments" => array(), 'params' => array(), 'scope' => Yadif_Container::SCOPE_SINGLETON, 'methods' => array()));
$this->assertEquals($expected, $this->readAttribute($yadif2, '_container'));
}

Expand Down

0 comments on commit e73367e

Please sign in to comment.