Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[docs] add docs for extend and raw

  • Loading branch information...
commit 6213e14d6fa2ee29a00ca7d4c2ae6ad966e3e123 1 parent a687126
Igor Wiedler igorw authored

Showing 1 changed file with 28 additions and 0 deletions. Show diff stats Hide diff stats

  1. +28 0 README.rst
28 README.rst
Source Rendered
@@ -74,6 +74,34 @@ function::
74 74
75 75 $c['random'] = $c->protect(function () { return rand(); });
76 76
  77 +Modifying Objects after creation
  78 +--------------------------------
  79 +
  80 +In some cases you may want to modify an object after it has been created. You
  81 +can use the ``extend()`` method to do just that::
  82 +
  83 + $c['twig'] = $c->share(function ($c) {
  84 + return new Twig_Environment($c['twig.loader'], $c['twig.options']);
  85 + });
  86 +
  87 + $c['twig'] = $c->extend(function ($twig, $c) {
  88 + $twig->addExtension(new MyTwigExtension());
  89 + return $twig;
  90 + });
  91 +
  92 +Fetching the Object creation function
  93 +-------------------------------------
  94 +
  95 +When you access an Object, Pimple automatically calls the function that you
  96 +defined, which creates the Object for you. If you want to get this function,
  97 +you can use the ``raw()`` method::
  98 +
  99 + $c['session'] = $c->share(function ($c) {
  100 + return new Session($c['session_storage']);
  101 + });
  102 +
  103 + $sessionFunction = $c->raw('session');
  104 +
77 105 Packaging a Container for reusability
78 106 -------------------------------------
79 107

0 comments on commit 6213e14

Please sign in to comment.
Something went wrong with that request. Please try again.