|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +namespace App\Command; |
| 5 | + |
| 6 | +use Cake\Command\Command; |
| 7 | +use Cake\Console\Arguments; |
| 8 | +use Cake\Console\ConsoleIo; |
| 9 | +use Cake\Console\ConsoleOptionParser; |
| 10 | +use Sandbox\Model\Enum\UserStatus; |
| 11 | +use Templating\View\Html; |
| 12 | + |
| 13 | +/** |
| 14 | + * FooBar command. |
| 15 | + */ |
| 16 | +class FooBarCommand extends Command { |
| 17 | + |
| 18 | + /** |
| 19 | + * The name of this command. |
| 20 | + * |
| 21 | + * @var string |
| 22 | + */ |
| 23 | + protected string $name = 'foo_bar'; |
| 24 | + |
| 25 | + /** |
| 26 | + * Get the default command name. |
| 27 | + * |
| 28 | + * @return string |
| 29 | + */ |
| 30 | + public static function defaultName(): string { |
| 31 | + return 'foo_bar'; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Get the command description. |
| 36 | + * |
| 37 | + * @return string |
| 38 | + */ |
| 39 | + public static function getDescription(): string { |
| 40 | + return 'Command description here.'; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Hook method for defining this command's option parser. |
| 45 | + * |
| 46 | + * @see https://book.cakephp.org/5/en/console-commands/commands.html#defining-arguments-and-options |
| 47 | + * @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined |
| 48 | + * @return \Cake\Console\ConsoleOptionParser The built parser. |
| 49 | + */ |
| 50 | + public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { |
| 51 | + return parent::buildOptionParser($parser) |
| 52 | + ->setDescription(static::getDescription()); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Implement this method with your command's logic. |
| 57 | + * |
| 58 | + * @param \Cake\Console\Arguments $args The command arguments. |
| 59 | + * @param \Cake\Console\ConsoleIo $io The console io |
| 60 | + * @return int|null|void The exit code or null for success |
| 61 | + */ |
| 62 | + public function execute(Arguments $args, ConsoleIo $io) { |
| 63 | + $data = [ |
| 64 | + 'src/' => [ |
| 65 | + 'Command/', |
| 66 | + 'Controller/' => [ |
| 67 | + 'DefaultController.php', |
| 68 | + ], |
| 69 | + 'Kernel.php', |
| 70 | + (string)Html::create('<b>x</b>'), |
| 71 | + UserStatus::Active->label(), |
| 72 | + ], |
| 73 | + 'templates/' => [ |
| 74 | + 'base.html.twig', |
| 75 | + ], |
| 76 | + ]; |
| 77 | + |
| 78 | + $io->helper('Tree')->output($data); |
| 79 | + } |
| 80 | + |
| 81 | +} |
0 commit comments