Permalink
Browse files

Added constructor arguments.

  • Loading branch information...
1 parent 22e0244 commit 2bf06b5111ee1e934bb340ab0c719c3856cb7020 @marijn marijn committed Oct 9, 2011
Showing with 21 additions and 1 deletion.
  1. +13 −1 lib/Pimple.php
  2. +8 −0 tests/Pimple/Tests/PimpleTest.php
View
14 lib/Pimple.php
@@ -32,7 +32,19 @@
*/
class Pimple implements ArrayAccess
{
- private $values = array();
+ private $values;
+
+ /**
+ * Instantiate the container.
+ *
+ * Objects and parameters can be passed as argument to the constructor.
+ *
+ * @param array $values The parameters or objects.
+ */
+ function __construct (array $values = array())
+ {
+ $this->values = $values;
+ }
/**
* Sets a parameter or an object.
View
8 tests/Pimple/Tests/PimpleTest.php
@@ -97,6 +97,14 @@ public function testIsset()
$this->assertFalse(isset($pimple['non_existent']));
}
+ public function testConstructorInjection ()
+ {
+ $params = array("param" => "value");
+ $pimple = new Pimple($params);
+
+ $this->assertSame($params['param'], $pimple['param']);
+ }
+
/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Identifier "foo" is not defined.

0 comments on commit 2bf06b5

Please sign in to comment.