0 follower

Final Class Yiisoft\Yii\Cycle\Command\Schema\SchemaPhpCommand

InheritanceYiisoft\Yii\Cycle\Command\Schema\SchemaPhpCommand » Symfony\Component\Console\Command\Command

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Yiisoft\Aliases\Aliases $aliases, Yiisoft\Yii\Cycle\Command\CycleDependencyProxy $promise )
$aliases \Yiisoft\Aliases\Aliases
$promise Yiisoft\Yii\Cycle\Command\CycleDependencyProxy

                public function __construct(
    private readonly Aliases $aliases,
    private readonly CycleDependencyProxy $promise,
) {
    parent::__construct();
}

            
configure() protected method

protected void configure ( )

                #[\Override]
protected function configure(): void
{
    $this->addArgument('file', InputArgument::OPTIONAL, 'file');
}

            
execute() protected method

protected integer execute ( \Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output )
$input \Symfony\Component\Console\Input\InputInterface
$output \Symfony\Component\Console\Output\OutputInterface

                #[\Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
    /** @var string|null $file */
    $file = $input->getArgument('file');
    $converter = new SchemaToArrayConverter();
    $schemaArray = $converter->convert($this->promise->getSchema());
    $content = (new PhpSchemaRenderer())->render($schemaArray);
    if ($file === null) {
        $output->write($content);
        return self::SUCCESS;
    }
    $file = $this->aliases->get($file);
    $output->writeln("Destination: <fg=cyan>$file</>");
    $dir = dirname($file);
    if (!is_dir($dir)) {
        $output->writeln('Destination directory not found.');
        return self::FAILURE;
    }
    if (file_put_contents($file, $content) === false) {
        $output->writeln('<fg=red>Failed to write content to file.</>');
        return self::FAILURE;
    }
    return self::SUCCESS;
}