|
| 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\Messenger\MessageBusInterface; |
| 22 | + |
| 23 | +/** |
| 24 | + * @author Imad ZAIRIG <[email protected]> |
| 25 | + * |
| 26 | + * @internal |
| 27 | + */ |
| 28 | +final class MakeMiddleware extends AbstractMaker |
| 29 | +{ |
| 30 | + public static function getCommandName(): string |
| 31 | + { |
| 32 | + return 'make:middleware'; |
| 33 | + } |
| 34 | + |
| 35 | + public function configureCommand(Command $command, InputConfiguration $inputConfig) |
| 36 | + { |
| 37 | + $command |
| 38 | + ->setDescription('Creates a new messenger middleware') |
| 39 | + ->addArgument('name', InputArgument::OPTIONAL, 'The name of the middleware class (e.g. <fg=yellow>CustomMiddleware</>)') |
| 40 | + ->setHelp(file_get_contents(__DIR__.'/../Resources/help/MakeMessage.txt')); |
| 41 | + } |
| 42 | + |
| 43 | + public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator) |
| 44 | + { |
| 45 | + $middlewareClassNameDetails = $generator->createClassNameDetails( |
| 46 | + $input->getArgument('name'), |
| 47 | + 'Middleware\\', |
| 48 | + 'Middleware' |
| 49 | + ); |
| 50 | + |
| 51 | + $generator->generateClass( |
| 52 | + $middlewareClassNameDetails->getFullName(), |
| 53 | + 'middleware/Middleware.tpl.php' |
| 54 | + ); |
| 55 | + |
| 56 | + $generator->writeChanges(); |
| 57 | + |
| 58 | + $this->writeSuccessMessage($io); |
| 59 | + |
| 60 | + $io->text([ |
| 61 | + 'Next: Open your new middleware class and add the code you need.', |
| 62 | + 'Find the documentation at <fg=yellow>https://symfony.com/doc/current/messenger.html</>', |
| 63 | + ]); |
| 64 | + } |
| 65 | + |
| 66 | + public function configureDependencies(DependencyBuilder $dependencies) |
| 67 | + { |
| 68 | + $dependencies->addClassDependency( |
| 69 | + MessageBusInterface::class, |
| 70 | + 'messenger' |
| 71 | + ); |
| 72 | + } |
| 73 | +} |
0 commit comments