-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Lazy services - service proxies #7527
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
Changes from 1 commit
f503ad8
67aef45
f4a19c7
d2760f1
4a13f82
a6a6572
35fdded
bec7774
468e92e
4ecd5ad
11a1da9
5870fed
695e3c5
c5a5af0
29899ec
b5d0298
cda390b
1eb4cf7
b417969
1e24767
450635a
File filter
Filter by extension
Conversations
Jump to
Diff view
8000Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,9 @@ | |
|
||
namespace Symfony\Component\DependencyInjection; | ||
|
||
use ProxyManager\Configuration; | ||
use ProxyManager\Factory\LazyLoadingValueHolderFactory; | ||
use ProxyManager\Proxy\LazyLoadingInterface; | ||
use Symfony\Component\DependencyInjection\Compiler\Compiler; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\Compiler\PassConfig; | ||
|
@@ -873,8 +876,22 @@ public function findDefinition($id) | |
* @throws RuntimeException When the service is a synthetic service | ||
* @throws InvalidArgumentException When configure callable is not callable | ||
*/ | ||
private function createService(Definition $definition, $id) | ||
public function createService(Definition $definition, $id, $tryProxy = true) | ||
{ | ||
if ($tryProxy && ($className = $definition->getClass()) && $definition->isLazy()) { | ||
$factory = new LazyLoadingValueHolderFactory(new Configuration()); | ||
$container = $this; | ||
|
||
return $factory->createProxy( | ||
$className, | ||
function (& $wrappedInstance, LazyLoadingInterface $proxy) use ($container, $definition, $id) { | ||
$proxy->setProxyInitializer(null); | ||
|
||
$wrappedInstance = $container->createService($definition, $id, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would the call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this has also a test for it, see $this->assertSame($foo1, $builder->get('foo1'), 'The same proxy is retrieved after initialization'); |
||
} | ||
); | ||
} | ||
|
||
if ($definition->isSynthetic()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be done before creating the lazy proxy IMO. |
||
throw new RuntimeException(sprintf('You have requested a synthetic service ("%s"). The DIC does not know how to construct this service.', $id)); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,4 @@ services: | |
class: Request | ||
synthetic: true | ||
synchronized: true | ||
lazy: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to update the phpdoc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And you should add
@internal
in the phpdoc to explain that it is only public because of the internal use in a closure, and should not be called by other code