Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
7d1e96c5
Commit
7d1e96c5
authored
Jun 02, 2016
by
Harm van Tilborg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Included extend() explanation in services documentation chapter
Together with the Twig add global and filter example.
parent
74669cf1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
0 deletions
+25
-0
doc/services.rst
doc/services.rst
+25
-0
No files found.
doc/services.rst
View file @
7d1e96c5
...
@@ -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
-------------
-------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment