You are here

public function ProxyDumper::getProxyFactoryCode in Service Container 7

Same name and namespace in other branches
  1. 7.2 lib/Drupal/Component/ProxyBuilder/ProxyDumper.php \Drupal\Component\ProxyBuilder\ProxyDumper::getProxyFactoryCode()

Generates the code to be used to instantiate a proxy in the dumped factory code.

Parameters

Definition $definition:

string $id service identifier:

Return value

string

Overrides DumperInterface::getProxyFactoryCode

File

lib/Drupal/Component/ProxyBuilder/ProxyDumper.php, line 46
Contains \Drupal\Component\ProxyBuilder\ProxyDumper.

Class

ProxyDumper
Dumps the proxy service into the dumped PHP container file.

Namespace

Drupal\Component\ProxyBuilder

Code

public function getProxyFactoryCode(Definition $definition, $id) {

  // Note: the specific get method is called initially with $lazyLoad=TRUE;
  // When you want to retrieve the actual service, the code generated in
  // ProxyBuilder calls the method with lazy loading disabled.
  $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;
}