Skip to content
Permalink
Browse files

Simplify #645

  • Loading branch information...
mnapoli committed Feb 24, 2019
1 parent b15f8e7 commit e459f0a91144738731bbd2904c46f64435a56978
@@ -141,14 +141,16 @@ $containerBuilder->writeProxiesToFile(true, __DIR__ . '/tmp/proxies');

You will need to clear the directory every time you deploy to avoid keeping outdated proxies.

### Generating the proxy classes on container build time
### Generating proxy classes when compiling the container

By default the proxies are written to disk the first time they are required. Enabling pre-generation will write the proxy classes to disk when the container is built.
By default proxies are written to disk the first time they are used.

Proxy classes can be pre-generated (for example before deploying) by enabling [container compilation](performances.md):

```php
// Enable writing proxies to file in the var/cache directory at container compile time
$containerBuilder->enableCompilation(__DIR__ . '/var/cache');
$containerBuilder->writeProxiesToFile(true, __DIR__ . '/var/cache');
```

For this functionality to work, both configuration options have to be set.
For this functionality to work, both configuration options have to be set.
@@ -137,7 +137,7 @@ private function compileLazyDefinition(ObjectDefinition $definition) : string
$subDefinition->setLazy(false);
$subDefinition = $this->compiler->compileValue($subDefinition);
$this->compiler->getProxyFactory()->generateProxy($definition->getClassName());
$this->compiler->getProxyFactory()->generateProxyClass($definition->getClassName());
return <<<PHP
\$object = \$this->proxyFactory->createProxy(

This file was deleted.

@@ -5,6 +5,7 @@
namespace DI\Proxy;
use ProxyManager\Configuration;
use ProxyManager\Factory\LazyLoadingValueHolderFactory;
use ProxyManager\FileLocator\FileLocator;
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
use ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy;
@@ -39,10 +40,8 @@ class ProxyFactory
*/
private $proxyManager;
public function __construct(
bool $writeProxiesToFile = false,
string $proxyDirectory = null
) {
public function __construct(bool $writeProxiesToFile = false, string $proxyDirectory = null)
{
$this->writeProxiesToFile = $writeProxiesToFile;
$this->proxyDirectory = $proxyDirectory;
}
@@ -62,15 +61,18 @@ public function createProxy(string $className, \Closure $initializer) : LazyLoad
}
/**
* Generates and writes proxy class to file.
* Generates and writes the proxy class to file.
*
* @param string $className name of the class to be proxied
*/
public function generateProxy(string $className) : string
public function generateProxyClass(string $className)
{
$this->createProxyManager();
return $this->proxyManager->generateProxyClassToFile($className);
// If proxy classes a written to file then we pre-generate the class
// If they are not written to file then there is no point to do this
if ($this->writeProxiesToFile) {
$this->createProxyManager();
$this->createProxy($className, function () {});
}
}
private function createProxyManager()

0 comments on commit e459f0a

Please sign in to comment.
You can’t perform that action at this time.