Commit 7d1e96c5 authored by Harm van Tilborg's avatar Harm van Tilborg

Included extend() explanation in services documentation chapter

Together with the Twig add global and filter example.
parent 74669cf1
...@@ -161,6 +161,31 @@ using the ``protect`` method:: ...@@ -161,6 +161,31 @@ using the ``protect`` method::
Note that protected closures do not get access to the container. Note that protected closures do not get access to the container.
Modify services after definition
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sometimes you want to alter a service after its definition. Pimple facilitates
this by ``extend``-ing the already defined service.
First argument of the ``extend`` method is the name of the service you want to
modify. Second argument is a callable. This callable is executed with the service
you want to alter as its first argument, the service container self is provided
in the second argument.
.. note::
Be sure to return the modified service in the callable.
You can use this pattern to add functionality to :doc:Twig <providers/twig> for
example::
$app->extend('twig', function($twig, $app) {
$twig->addGlobal('pi', 3.14);
$twig->addFilter('levenshtein', new \Twig_Filter_Function('levenshtein'));
return $twig;
});
Core services Core services
------------- -------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment