proxyBuilder = $proxy_builder; } /** * {@inheritdoc} */ protected function configure() { $this->setName('generate-proxy-class') ->setDefinition([ new InputArgument('class_name', InputArgument::REQUIRED, 'The class to be proxied'), new InputArgument('namespace_root_path', InputArgument::REQUIRED, 'The filepath to the root of the namespace.'), ]) ->setDescription('Dumps a generated proxy class into its appropriate namespace.') ->addUsage('\'Drupal\Core\Batch\BatchStorage\' "core/lib/Drupal/Core"') ->addUsage('\'Drupal\block\BlockRepository\' "core/modules/block/src"') ->addUsage('\'Drupal\my_module\MyClass\' "modules/contrib/my_module/src"'); } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output): int { $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 = <<writeln(sprintf('Proxy of class %s written to %s', $class_name, $proxy_filename)); } return 0; } }