buildProxyNamespace example


  public function build($class_name) {
    $reflection = new \ReflectionClass($class_name);

    $proxy_class_name = $this->buildProxyClassName($class_name);
    $proxy_namespace = $this->buildProxyNamespace($class_name);
    $proxy_class_shortname = str_replace($proxy_namespace . '\\', '', $proxy_class_name);

    $output = '';
    $class_documentation = <<<'EOS' namespace {{ namespace }}{ /** * Provides a proxy class for \{{ class_name }}. * * @see \Drupal\Component\ProxyBuilder */

  protected function buildExpectedClass($class$expected_methods_body$interface_string = '') {
    $reflection = new \ReflectionClass($class);
    $namespace = ProxyBuilder::buildProxyNamespace($class);
    $proxy_class = $reflection->getShortName();
    $expected_string = <<<'EOS' namespace {{ namespace }} { /** * Provides a proxy class for \{{ class }}. * * @see \Drupal\Component\ProxyBuilder */ class {{ proxy_class }}{{ interface_string }} { use \Drupal\Core\DependencyInjection\DependencySerializationTrait; /** * The id of the original proxied service. * * @var string */ protected $drupalProxyOriginalServiceId; /** * The real proxied service, after it was lazy loaded. * * @var \{{ class }} */ 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; } {{ expected_methods_body }} } }

  public function testBuildProxyClassNameForModule() {
    $class_name = $this->proxyBuilder->buildProxyClassName('Drupal\views_ui\ParamConverter\ViewUIConverter');
    $this->assertEquals('Drupal\views_ui\ProxyClass\ParamConverter\ViewUIConverter', $class_name);
  }

  /** * @covers ::buildProxyNamespace */
  public function testBuildProxyNamespace() {
    $class_name = $this->proxyBuilder->buildProxyNamespace('Drupal\Tests\Component\ProxyBuilder\TestServiceNoMethod');
    $this->assertEquals('Drupal\Tests\ProxyClass\Component\ProxyBuilder', $class_name);
  }

  /** * Tests the basic methods like the constructor and the lazyLoadItself method. * * @covers ::build * @covers ::buildConstructorMethod * @covers ::buildLazyLoadItselfMethod */
  public function testBuildNoMethod() {
    
Home | Imprint | This part of the site doesn't use cookies.