Skip to content

Instantly share code, notes, and snippets.

@stephaneerard
Created February 15, 2021 19:51
Show Gist options
  • Select an option

  • Save stephaneerard/4ca54605bb4ac45703de11302efcd2a2 to your computer and use it in GitHub Desktop.

Select an option

Save stephaneerard/4ca54605bb4ac45703de11302efcd2a2 to your computer and use it in GitHub Desktop.
<?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;
}
}
#!/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();
{
"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/"
}
}
}
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