/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $class_name = ltrim($input->getArgument('class_name'), '\\'); $namespace_root = $input->getArgument('namespace_root_path'); $match = []; preg_match('/([a-zA-Z0-9_]+\\\\[a-zA-Z0-9_]+)\\\\(.+)/', $class_name, $match); if ($match) { $root_namespace = $match[1]; $rest_fqcn = $match[2]; $proxy_filename = $namespace_root . '/ProxyClass/' . str_replace('\\', '/', $rest_fqcn) . '.php'; $proxy_class_name = $root_namespace . '\\ProxyClass\\' . $rest_fqcn; $proxy_class_string = $this->proxyBuilder->build($class_name); $file_string = <<<EOF <?php // @codingStandardsIgnoreFile /** * This file was generated via php core/scripts/generate-proxy-class.php '{$class_name}' "{$namespace_root}". */ {{ proxy_class_string }} EOF; $file_string = str_replace(['{{ proxy_class_name }}', '{{ proxy_class_string }}'], [$proxy_class_name, $proxy_class_string], $file_string); mkdir(dirname($proxy_filename), 0775, TRUE); file_put_contents($proxy_filename, $file_string); $output->writeln(sprintf('Proxy of class %s written to %s', $class_name, $proxy_filename)); } }
/** * {@inheritdoc} */ public function getProxyCode(Definition $definition) { // Maybe the same class is used in different services, which are both marked // as lazy (just think about 2 database connections). // In those cases we should not generate proxy code the second time. if (!isset($this->buildClasses[$definition->getClass()])) { $this->buildClasses[$definition->getClass()] = TRUE; return $this->builder->build($definition->getClass()); } else { return ''; } }
/** * @covers ::buildMethod * @covers ::buildParameter * @covers ::buildMethodBody */ public function testBuildWithPublicStaticMethod() { $class = 'Drupal\\Tests\\Component\\ProxyBuilder\\TestServiceWithPublicStaticMethod'; $result = $this->proxyBuilder->build($class); // Ensure that the static method is not wrapped. $method_body = <<<'EOS' public static function testMethod($parameter) { \Drupal\Tests\Component\ProxyBuilder\TestServiceWithPublicStaticMethod::testMethod($parameter); } EOS; $this->assertEquals($this->buildExpectedClass($class, $method_body), $result); }