Permalink
Browse files

[docs] add docs for extend and raw

  • Loading branch information...
1 parent a687126 commit 6213e14d6fa2ee29a00ca7d4c2ae6ad966e3e123 @igorw igorw committed Apr 1, 2012
Showing with 28 additions and 0 deletions.
  1. +28 −0 README.rst
View
28 README.rst
@@ -74,6 +74,34 @@ function::
$c['random'] = $c->protect(function () { return rand(); });
+Modifying Objects after creation
+--------------------------------
+
+In some cases you may want to modify an object after it has been created. You
+can use the ``extend()`` method to do just that::
+
+ $c['twig'] = $c->share(function ($c) {
+ return new Twig_Environment($c['twig.loader'], $c['twig.options']);
+ });
+
+ $c['twig'] = $c->extend(function ($twig, $c) {
+ $twig->addExtension(new MyTwigExtension());
+ return $twig;
+ });
+
+Fetching the Object creation function
+-------------------------------------
+
+When you access an Object, Pimple automatically calls the function that you
+defined, which creates the Object for you. If you want to get this function,
+you can use the ``raw()`` method::
+
+ $c['session'] = $c->share(function ($c) {
+ return new Session($c['session_storage']);
+ });
+
+ $sessionFunction = $c->raw('session');
+
Packaging a Container for reusability
-------------------------------------

0 comments on commit 6213e14

Please sign in to comment.