Skip to content

Proxies for lazy loaded dependencies are not written to file? #411

@holtkamp

Description

@holtkamp

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions