ProxyDumper.php in Service Container 7.2
File
lib/Drupal/Component/ProxyBuilder/ProxyDumper.php
View source
<?php
namespace Drupal\Component\ProxyBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;
class ProxyDumper implements DumperInterface {
protected $buildClasses = [];
protected $builder;
public function __construct(ProxyBuilder $builder) {
$this->builder = $builder;
}
public function isProxyCandidate(Definition $definition) {
return $definition
->isLazy() && ($class = $definition
->getClass()) && class_exists($class);
}
public function getProxyFactoryCode(Definition $definition, $id) {
$output = <<<'EOS'
if ($lazyLoad) {
return $this->services['{{ id }}'] = new {{ class_name }}($this, '{{ id }}');
}
EOS;
$output = str_replace('{{ id }}', $id, $output);
$output = str_replace('{{ class_name }}', $this->builder
->buildProxyClassName($definition
->getClass()), $output);
return $output;
}
public function getProxyCode(Definition $definition) {
if (!isset($this->buildClasses[$definition
->getClass()])) {
$this->buildClasses[$definition
->getClass()] = TRUE;
return $this->builder
->build($definition
->getClass());
}
else {
return '';
}
}
}
Classes
Name |
Description |
ProxyDumper |
Dumps the proxy service into the dumped PHP container file. |