Skip to content

Commit

Permalink
[docs] add docs for extend and raw
Browse files Browse the repository at this point in the history
  • Loading branch information
igorw committed Apr 1, 2012
1 parent a687126 commit 6213e14
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.rst
Expand Up @@ -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
-------------------------------------

Expand Down

0 comments on commit 6213e14

Please sign in to comment.