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
|
if ($this->writeProxiesToFile) { |
|
$config->setProxiesTargetDir($this->proxyDirectory); |
|
spl_autoload_register($config->getProxyAutoloader()); |
resolves this:
$config->setGeneratorStrategy(new FileWriterGeneratorStrategy(new \ProxyManager\FileLocator\FileLocator($this->proxyDirectory)));
Also opened #412
When:
$builder->addDefinitions('definitions.php');ocramius\proxy-managerwriteProxiesToFile(true, '/folderName')Then:
When switching back to non-lazy configured objects, performance is back to normal again. After browsing around in the source code, it seems a
FileWriterGeneratorStrategyshould also be set explicitly, since it defaults to anEvaluatingGeneratorStrategywhich removes the generated files afterwardsAdding one line to the
ProxyFactoryPHP-DI/src/DI/Proxy/ProxyFactory.php
Lines 72 to 74 in c6c932e
Also opened #412