Permalink
Browse files

added a way to get the closure defining a service

  • Loading branch information...
1 parent 7133d93 commit dd218be36ca5011b207fc9e772bb978113387821 @fabpot committed Aug 15, 2011
Showing with 25 additions and 0 deletions.
  1. +18 −0 lib/Pimple.php
  2. +7 −0 tests/Pimple/Tests/PimpleTest.php
View
@@ -127,4 +127,22 @@ function protect(Closure $callable)
return $callable;
};
}
+
+ /**
+ * Gets a parameter or the closure defining an object.
+ *
+ * @param string $id The unique identifier for the parameter or object
+ *
+ * @return mixed The value of the parameter or the closure defining an object
+ *
+ * @throws InvalidArgumentException if the identifier is not defined
+ */
+ function raw($id)
+ {
+ if (!isset($this->values[$id])) {
+ throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $id));
+ }
+
+ return $this->values[$id];
+ }
}
@@ -141,4 +141,11 @@ public function testGlobalFunctionNameAsParameterValue()
$pimple['global_function'] = 'strlen';
$this->assertSame('strlen', $pimple['global_function']);
}
+
+ public function testRaw()
+ {
+ $pimple = new Pimple();
+ $pimple['service'] = $definition = function () { return 'foo'; };
+ $this->assertSame($definition, $pimple->raw('service'));
+ }
}

0 comments on commit dd218be

Please sign in to comment.