class LazyService

Same name in this branch
  1. main core/tests/Drupal/Tests/Core/DependencyInjection/Fixture/LazyService.php \Drupal\Tests\Core\DependencyInjection\Fixture\LazyService
Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/ProxyClass/Core/DependencyInjection/Fixture/LazyService.php \Drupal\Tests\ProxyClass\Core\DependencyInjection\Fixture\LazyService
  2. 11.x core/tests/Drupal/Tests/Core/DependencyInjection/Fixture/LazyService.php \Drupal\Tests\Core\DependencyInjection\Fixture\LazyService

Provides a proxy class for \Drupal\Tests\Core\DependencyInjection\Fixture\LazyService.

Hierarchy

  • class \Drupal\Tests\ProxyClass\Core\DependencyInjection\Fixture\LazyService

Expanded class hierarchy of LazyService

See also

\Drupal\Component\ProxyBuilder

1 file declares its use of LazyService
ProxyServicesPassTest.php in core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php

File

core/tests/Drupal/Tests/ProxyClass/Core/DependencyInjection/Fixture/LazyService.php, line 15

Namespace

Drupal\Tests\ProxyClass\Core\DependencyInjection\Fixture
View source
class LazyService {
  
  /**
   * The id of the original proxied service.
   *
   * @var string
   */
  protected $drupalProxyOriginalServiceId;
  
  /**
   * The real proxied service, after it was lazy loaded.
   *
   * @var \Drupal\Tests\Core\DependencyInjection\Fixture\LazyService
   */
  protected $service;
  
  /**
   * The service container.
   *
   * @var \Symfony\Component\DependencyInjection\ContainerInterface
   */
  protected $container;
  
  /**
   * Constructs a ProxyClass Drupal proxy object.
   *
   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
   *   The container.
   * @param string $drupal_proxy_original_service_id
   *   The service ID of the original service.
   */
  public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container, $drupal_proxy_original_service_id) {
    $this->container = $container;
    $this->drupalProxyOriginalServiceId = $drupal_proxy_original_service_id;
  }
  
  /**
   * Lazy loads the real service from the container.
   *
   * @return object
   *   Returns the constructed real service.
   */
  protected function lazyLoadItself() {
    if (!isset($this->service)) {
      $this->service = $this->container
        ->get($this->drupalProxyOriginalServiceId);
    }
    return $this->service;
  }
  
  /**
   * {@inheritdoc}
   */
  public function getValue() : string {
    return $this->lazyLoadItself()
      ->getValue();
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.