Created
February 15, 2021 19:51
-
-
Save stephaneerard/4ca54605bb4ac45703de11302efcd2a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Command; | |
| use Symfony\Component\Console\Command\Command; | |
| use Symfony\Component\Console\Input\InputInterface; | |
| use Symfony\Component\Console\Output\OutputInterface; | |
| class InitCommand extends Command | |
| { | |
| protected static $defaultName = 'init'; | |
| protected function configure() | |
| { | |
| $this | |
| // the short description shown while running "php bin/console list" | |
| ->setDescription('Creates a new user.') | |
| // the full command description shown when running the command with | |
| // the "--help" option | |
| ->setHelp('This command allows you to create a user...'); | |
| } | |
| protected function execute(InputInterface $input, OutputInterface $output) | |
| { | |
| return Command::SUCCESS; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env php | |
| <?php | |
| // application.php | |
| require __DIR__.'/vendor/autoload.php'; | |
| use Symfony\Component\Console\Application; | |
| use App\Command\InitCommand; | |
| $application = new Application(); | |
| $application->add(new InitCommand()); | |
| $application->run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": test"", | |
| "description": "CLI test", | |
| "type": "cli", | |
| "license": "MIT", | |
| "authors": [ | |
| { | |
| "name": "Stephane Erard", | |
| "email": "stephane.erard.se@gmail.com" | |
| } | |
| ], | |
| "require": { | |
| "symfony/console": "^5.2" | |
| }, | |
| "autoload": { | |
| "psr-0": { | |
| "App\\": "src/" | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PS C:\code\frenchex2\vagranti_i2.php> php .\cli.php | |
| PHP Fatal error: Uncaught Error: Class "App\Command\InitCommand" not found in C:\code\frenchex2\vagranti_i2.php\cli.php:12 | |
| Stack trace: | |
| #0 {main} | |
| thrown in C:\code\frenchex2\vagranti_i2.php\cli.php on line 12 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment