|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the API Platform project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace ApiPlatform\Symfony\Maker; |
| 15 | + |
| 16 | +use Symfony\Bundle\MakerBundle\ConsoleStyle; |
| 17 | +use Symfony\Bundle\MakerBundle\DependencyBuilder; |
| 18 | +use Symfony\Bundle\MakerBundle\Generator; |
| 19 | +use Symfony\Bundle\MakerBundle\InputConfiguration; |
| 20 | +use Symfony\Bundle\MakerBundle\Maker\AbstractMaker; |
| 21 | +use Symfony\Component\Console\Command\Command; |
| 22 | +use Symfony\Component\Console\Input\InputArgument; |
| 23 | +use Symfony\Component\Console\Input\InputInterface; |
| 24 | + |
| 25 | +final class MakeStateProcessor extends AbstractMaker |
| 26 | +{ |
| 27 | + /** |
| 28 | + * {@inheritdoc} |
| 29 | + */ |
| 30 | + public static function getCommandName(): string |
| 31 | + { |
| 32 | + return 'make:state-processor'; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * {@inheritdoc} |
| 37 | + */ |
| 38 | + public static function getCommandDescription(): string |
| 39 | + { |
| 40 | + return 'Creates an API Platform state processor'; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * {@inheritdoc} |
| 45 | + */ |
| 46 | + public function configureCommand(Command $command, InputConfiguration $inputConfig) |
| 47 | + { |
| 48 | + $command |
| 49 | + ->addArgument('name', InputArgument::REQUIRED, 'Choose a class name for your state processor (e.g. <fg=yellow>AwesomeStateProcessor</>)') |
| 50 | + ->setHelp(file_get_contents(__DIR__.'/Resources/help/MakeStateProcessor.txt')); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * {@inheritdoc} |
| 55 | + */ |
| 56 | + public function configureDependencies(DependencyBuilder $dependencies) |
| 57 | + { |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * {@inheritdoc} |
| 62 | + */ |
| 63 | + public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator) |
| 64 | + { |
| 65 | + $stateProcessorClassNameDetails = $generator->createClassNameDetails( |
| 66 | + $input->getArgument('name'), |
| 67 | + 'State\\' |
| 68 | + ); |
| 69 | + |
| 70 | + $generator->generateClass( |
| 71 | + $stateProcessorClassNameDetails->getFullName(), |
| 72 | + __DIR__.'/Resources/skeleton/StateProcessor.tpl.php' |
| 73 | + ); |
| 74 | + $generator->writeChanges(); |
| 75 | + |
| 76 | + $this->writeSuccessMessage($io); |
| 77 | + $io->text([ |
| 78 | + 'Next: Open your new state processor class and start customizing it.', |
| 79 | + ]); |
| 80 | + } |
| 81 | +} |
0 commit comments