|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony MakerBundle package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[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 | +namespace Symfony\Bundle\MakerBundle\Maker; |
| 13 | + |
| 14 | +use Symfony\Bundle\MakerBundle\ConsoleStyle; |
| 15 | +use Symfony\Bundle\MakerBundle\DependencyBuilder; |
| 16 | +use Symfony\Bundle\MakerBundle\Generator; |
| 17 | +use Symfony\Bundle\MakerBundle\InputConfiguration; |
| 18 | +use Symfony\Component\Console\Command\Command; |
| 19 | +use Symfony\Component\Console\Input\InputArgument; |
| 20 | +use Symfony\Component\Console\Input\InputInterface; |
| 21 | +use Symfony\Component\Serializer\Serializer; |
| 22 | + |
| 23 | +/** |
| 24 | + * @author Grégoire Pineau <[email protected]> |
| 25 | + */ |
| 26 | +final class MakeSerializerNormalizer extends AbstractMaker |
| 27 | +{ |
| 28 | + public static function getCommandName(): string |
| 29 | + { |
| 30 | + return 'make:serializer:normalizer'; |
| 31 | + } |
| 32 | + |
| 33 | + public function configureCommand(Command $command, InputConfiguration $inputConf) |
| 34 | + { |
| 35 | + $command |
| 36 | + ->setDescription('Creates a new serializer normalizer class') |
| 37 | + ->addArgument('name', InputArgument::OPTIONAL, 'Choose a class name for your normalizer (e.g. <fg=yellow>UserNormalizer</>)') |
| 38 | + ->setHelp(file_get_contents(__DIR__.'/../Resources/help/MakeSerializerNormalizer.txt')) |
| 39 | + ; |
| 40 | + } |
| 41 | + |
| 42 | + public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator) |
| 43 | + { |
| 44 | + $normalizerClassNameDetails = $generator->createClassNameDetails( |
| 45 | + $input->getArgument('name'), |
| 46 | + 'Serializer\\Normalizer\\', |
| 47 | + 'Normalizer' |
| 48 | + ); |
| 49 | + |
| 50 | + $generator->generateClass( |
| 51 | + $normalizerClassNameDetails->getFullName(), |
| 52 | + 'serializer/Normalizer.tpl.php' |
| 53 | + ); |
| 54 | + |
| 55 | + $generator->writeChanges(); |
| 56 | + |
| 57 | + $this->writeSuccessMessage($io); |
| 58 | + |
| 59 | + $io->text([ |
| 60 | + 'Next: Open your new serializer normalizer class and start customizing it.', |
| 61 | + // Wait for https://github.com/symfony/symfony-docs/pull/10515 |
| 62 | + // 'Find the documentation at <fg=yellow>http://symfony.com/doc/current/serializer/custom_normalizers.html</>', |
| 63 | + ]); |
| 64 | + } |
| 65 | + |
| 66 | + public function configureDependencies(DependencyBuilder $dependencies) |
| 67 | + { |
| 68 | + $dependencies->addClassDependency( |
| 69 | + Serializer::class, |
| 70 | + 'serializer' |
| 71 | + ); |
| 72 | + } |
| 73 | +} |
0 commit comments