create symfony command code example

Example 1: create symfony project

symfony new my_project_name --full

Example 2: php bin console

php bin console

Example 3: symfony create command

// ...
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;

class CreateUserCommand extends Command
{
    // ...

    public function __construct(bool $requirePassword = false)
    {
        // best practices recommend to call the parent constructor first and
        // then set your own properties. That wouldn't work in this case
        // because configure() needs the properties set in this constructor
        $this->requirePassword = $requirePassword;

        parent::__construct();
    }

    protected function configure()
    {
        $this
            // ...
            ->addArgument('password', $this->requirePassword ? InputArgument::REQUIRED : InputArgument::OPTIONAL, 'User password')
        ;
    }
}

Example 4: create symfony project

/usr/bin/composer create-project symfony/skeleton /home/handwork/symfony
#create symfony projet de base
# un dossier cacher du meme nom du projet serai creer