This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/DependencyInjection/Tests
Fabien Potencier dfd605fc1b merged branch Ocramius/feature/proxy-manager-bridge (PR #7890)
This PR was squashed before being merged into the master branch (closes #7890).

Discussion
----------

ProxyManager Bridge

As of @beberlei's suggestion, I re-implemented #7527 as a new bridge to avoid possible hidden dependencies.

Everything is like #7527 except that the new namespace (and possibly package/subtree split) `Symfony\Bridge\ProxyManager` is introduced

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #6140 (supersedes) #5012 #6102 (maybe) #7527 (supersedes)
| License       | MIT (attached code) - BSD-3-Clause (transitive dependency)
| Doc PR        | Please pester me to death so I do it

This PR introduces lazy services along the lines of zendframework/zf2#4146

It introduces an **OPTIONAL** dependency to [ProxyManager](https://github.com/Ocramius/ProxyManager) and transitively to [`"zendframework/zend-code": "2.*"`](https://github.com/zendframework/zf2/tree/master/library/Zend/Code).

## Lazy services: why? A comprehensive example

For those who don't know what this is about, here's an example.

Assuming you have a service class like following:

```php
class MySuperSlowClass
{
    public function __construct()
    {
        // inject large object graph or do heavy computation
        sleep(10);
    }

    public function doFoo()
    {
        echo 'Foo!';
    }
}
```

The DIC will hang for 10 seconds when calling:

```php
$container->get('my_super_slow_class');
```

With this PR, this can be avoided, and the following call will return a proxy immediately.

```php
$container->getDefinitions('my_super_slow_class')->setLazy(true);
$service = $container->get('my_super_slow_class');
```

The 10 seconds wait time will be delayed until the object is actually used:

```php
$service->doFoo(); // wait 10 seconds, then 'Foo!'
```

A more extensive description of the functionality can be found [here](https://github.com/Ocramius/ProxyManager/blob/master/docs/lazy-loading-value-holder.md).

## When do we need it?

Lazy services can be used to optimize the dependency graph in cases like:

 * Webservice endpoints
 * Db connections
 * Objects that cause I/O in general
 * Large dependency graphs that are not always used

This could also help in reducing excessive service location usage as I've explained [here](http://ocramius.github.com/blog/zf2-and-symfony-service-proxies-with-doctrine-proxies/).

## Implementation quirks of this PR

There's a couple of quirks in the implementation:

 * `Symfony\Component\DependencyInjection\CompilerBuilder#createService` is now public because of the limitations of PHP 5.3
 * `Symfony\Component\DependencyInjection\Dumper\PhpDumper` now with extra mess!
 * The proxies are dumped at the end of compiled containers, therefore the container class is not PSR compliant anymore

Commits
-------

78e3710 ProxyManager Bridge
2013-05-06 08:38:39 +02:00
..
Compiler Merge branch '2.1' into 2.2 2013-04-20 21:05:29 +02:00
Dumper Merge branch '2.1' into 2.2 2013-02-11 12:26:43 +01:00
Extension [DIC] Better handling of enableable configurations 2013-01-28 18:21:49 +01:00
Fixtures merged branch Ocramius/feature/proxy-manager-bridge (PR #7890) 2013-05-06 08:38:39 +02:00
LazyProxy ProxyManager Bridge 2013-05-06 08:38:39 +02:00
Loader ProxyManager Bridge 2013-05-06 08:38:39 +02:00
ParameterBag [DependencyInjection] fixed ? position in some exception messages (refs #7861) 2013-05-01 06:24:56 +02:00
ContainerBuilderTest.php ProxyManager Bridge 2013-05-06 08:38:39 +02:00
ContainerTest.php [DependencyInjection] fixed ? position in some exception messages (refs #7861) 2013-05-01 06:24:56 +02:00
CrossCheckTest.php [DependencyInjection] removed hard dependency on the Config component 2012-12-28 11:06:10 +01:00
DefinitionDecoratorTest.php updated license blocks 2012-03-31 18:00:32 -03:00
DefinitionTest.php ProxyManager Bridge 2013-05-06 08:38:39 +02:00
ParameterTest.php moved component and bridge unit tests to the src/ directory 2012-03-29 08:37:22 +02:00
ReferenceTest.php moved component and bridge unit tests to the src/ directory 2012-03-29 08:37:22 +02:00