protected function GenerateProxyClassCommand::execute in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Command/GenerateProxyClassCommand.php \Drupal\Core\Command\GenerateProxyClassCommand::execute()
Executes the current command.
This method is not abstract because you can use this class as a concrete class. In this case, instead of defining the execute() method, you set the code to execute by passing a Closure to the setCode() method.
Parameters
InputInterface $input An InputInterface instance:
OutputInterface $output An OutputInterface instance:
Return value
null|int null or 0 if everything went fine, or an error code
Throws
\LogicException When this abstract method is not implemented
Overrides Command::execute
See also
setCode()
File
- core/
lib/ Drupal/ Core/ Command/ GenerateProxyClassCommand.php, line 58 - Contains \Drupal\Core\Command\GenerateProxyClassCommand.
Class
- GenerateProxyClassCommand
- Provides a console command to generate proxy classes.
Namespace
Drupal\Core\CommandCode
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
/**
* @file
* Contains \\{{ proxy_class_name }}.
*/
/**
* This file was generated via php core/scripts/generate-proxy-class.php '{<span class="php-variable">$class_name</span>}' "{<span class="php-variable">$namespace_root</span>}".
*/
{{ 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));
}
}