-
-
Notifications
You must be signed in to change notification settings - Fork 324
Proxies for lazy loaded dependencies are not written to file? #411
Copy link
Copy link
Closed
Description
When:
- configuring objects to be lazily loaded using the ObjectDefinitionHelper as suggested in the docs:
//definitions.php
array(
Class1::class => object()->lazy(),
Class2::class => object()->lazy(),
ClassN::class => object()->lazy(),
)- storing the Definitions in a file and adding them like
$builder->addDefinitions('definitions.php'); - using the
ocramius\proxy-manager - configuring the DI builder to write the proxies to a file:
writeProxiesToFile(true, '/folderName')
Then:
- no files are actually generated in the indicated folder
- performance drops significantly.
When switching back to non-lazy configured objects, performance is back to normal again. After browsing around in the source code, it seems a FileWriterGeneratorStrategy should also be set explicitly, since it defaults to an EvaluatingGeneratorStrategy which removes the generated files afterwards
Adding one line to the ProxyFactory
PHP-DI/src/DI/Proxy/ProxyFactory.php
Lines 72 to 74 in c6c932e
| if ($this->writeProxiesToFile) { | |
| $config->setProxiesTargetDir($this->proxyDirectory); | |
| spl_autoload_register($config->getProxyAutoloader()); |
$config->setGeneratorStrategy(new FileWriterGeneratorStrategy(new \ProxyManager\FileLocator\FileLocator($this->proxyDirectory)));
Also opened #412
Reactions are currently unavailable