Skip to content

Commit

Permalink
create schema cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
oliwierptak committed Jan 29, 2022
1 parent cfaf32e commit 576e8d3
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/Popo/Command/CreateSchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ protected function configure(): void
*/
protected function executeCommand(InputInterface $input, OutputInterface $output): int
{
$yn = '<fg=gray>[</><fg=white>y</><fg=gray>/n]</>';
$configurator = new PopoConfigurator();
$output->writeln('');
$helper = $this->getHelper('question');
Expand All @@ -54,7 +53,7 @@ protected function executeCommand(InputInterface $input, OutputInterface $output
$configurator->setSchemaPath($helper->ask($input, $output, $question));

$question = new Question('<fg=green>namespace</> <fg=gray>[Popo]</>: ', 'Popo');
$question->setAutocompleterValues(['\Popo']);
$question->setAutocompleterValues(['Popo']);
$namespace = $helper->ask($input, $output, $question);
$configurator->setNamespace($namespace);

Expand Down Expand Up @@ -90,7 +89,7 @@ protected function executeCommand(InputInterface $input, OutputInterface $output
BarItem:
property: [
{name: id, type: integer}
{name: id, type: int}
{name: title, default: A bar item}
]}}
',
Expand Down Expand Up @@ -119,9 +118,7 @@ protected function executeCommand(InputInterface $input, OutputInterface $output
}
}

$h = fopen($configurator->getSchemaPath(), 'w');
fputs($h, $generatedSchema);
fclose($h);
$this->saveSchemaFile($configurator, $generatedSchema);

$output->writeln('');
$output->writeln('<fg=green>Saved schema file under</>: ' . $configurator->getSchemaPath());
Expand All @@ -131,6 +128,25 @@ protected function executeCommand(InputInterface $input, OutputInterface $output

$configurator->setSchemaFilenameMask('*.yml');

return $this->runCommand($configurator, $output);
}

protected function saveSchemaFile(PopoConfigurator $configurator, string $generatedSchema): void
{
$handle = fopen($configurator->getSchemaPath(), 'w');
fputs($handle, $generatedSchema);
fclose($handle);
}

/**
* @param \Popo\PopoConfigurator $configurator
* @param \Symfony\Component\Console\Output\OutputInterface $output
*
* @return int
* @throws \Exception
*/
protected function runCommand(PopoConfigurator $configurator, OutputInterface $output): int
{
$command = $this->getApplication()->find(GenerateCommand::COMMAND_NAME);

$arguments = [
Expand All @@ -142,18 +158,4 @@ protected function executeCommand(InputInterface $input, OutputInterface $output

return $command->run($parameters, $output);
}

protected function generateFooProperties(): string
{
return '';
}

protected function generateBarProperties(): string
{
return '
{name: id, type: integer}
{name: title, default: Lorem Ipsum}
{name: bar, type: popo, default: Bar::class}
';
}
}

0 comments on commit 576e8d3

Please sign in to comment.