Skip to content

update cookbook for couch and phpcr and give some more hints and background #2668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Applying changes suggested by @wouterj, adding lazy_services to compo…
…nents map
  • Loading branch information
Ocramius committed May 9, 2013
commit 931091d8e3aa0b9d4f1393d313388d5ee1a5d47d
17 changes: 8 additions & 9 deletions components/dependency_injection/lazy_services.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,35 @@ In some particular cases where a very heavy service is always requested,
but not always used, you may want to mark it as ``lazy`` to delay its instantiation.

In order to have services to lazily instantiate, you will first need to install
the `ProxyManager bridge`_::
the `ProxyManager bridge`_:

php composer.phar require symfony/proxy-manager-bridge:2.3.*
.. code-block:: bash
$ php composer.phar require symfony/proxy-manager-bridge:2.3.*

You can mark the service as ``lazy`` by manipulating its definitions:


.. configuration-block::

.. code-block:: yaml

services:
foo:
class: Example\Foo
class: Acme\Foo
lazy: true

.. code-block:: xml

<service id="foo" class="Example\Foo" lazy="true" />
<service id="foo" class="Acme\Foo" lazy="true" />

.. code-block:: php

$definition = new Definition('Example\Foo');
$definition = new Definition('Acme\Foo');
$definition->setLazy(true);
$container->setDefinition('foo', $definition);

You can then require the service from the container::

$service = $container->get($serviceId);
$service = $container->get('foo');

At this point the retrieved ``$service`` should be a virtual `proxy`_ with the same
signature of the class representing the service.
Expand All @@ -55,10 +55,9 @@ signature of the class representing the service.
The proxy gets initialized and the actual service is instantiated as soon as you interact
in any way with this object.

Additional resources
Additional Resources
--------------------


You can read more about how proxies are instantiated, generated and initialized in
the `documentation of ProxyManager`_.

Expand Down
1 change: 1 addition & 0 deletions components/map.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* :doc:`/components/dependency_injection/configurators`
* :doc:`/components/dependency_injection/parentservices`
* :doc:`/components/dependency_injection/advanced`
* :doc:`/components/dependency_injection/lazy_services`
* :doc:`/components/dependency_injection/workflow`

* **DOM Crawler**
Expand Down