Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added constructor arguments.

  • Loading branch information...
commit 2bf06b5111ee1e934bb340ab0c719c3856cb7020 1 parent 22e0244
@marijn marijn authored
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.
Please sign in to comment.
Something went wrong with that request. Please try again.