PHP code example of fidry / console

1. Go to this page and download the library: Download fidry/console library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fidry / console example snippets


 declare(strict_types=1);
// config/bundles.php

return [
    // ...
    // Symfony\Bundle\FrameworkBundle\Symfony\Bundle\FrameworkBundle()
    // ...
    Fidry\Console\FidryConsoleBundle::class => ['all' => true],
];


 declare(strict_types=1);

namespace Acme;

use Acme\MyService;
use Fidry\Console\{ Command\Command, Command\Configuration, ExitCode, IO };
use Symfony\Component\Console\Input\InputArgument;

final class CommandWithService implements Command
{
    private MyService $service;

    public function __construct(MyService $service)
    {
        $this->service = $service;
    }

    public function getConfiguration(): Configuration
    {
        return new Configuration(
            'app:foo',
            'Calls MyService',
            <<<'EOT'
            The <info>%command.name</info> command calls MyService
            EOT,
            [
                new InputArgument(
                    'username',
                    InputArgument::REQUIRED,
                    'Name of the user',
                ),
                new InputArgument(
                    'age',
                    InputArgument::OPTIONAL,
                    'Age of the user',
                ),
            ],
        );
    }

    public function execute(IO $io): int
    {
        $this->service->call(
            $io->getTypedArgument('username')->asStringNonEmptyList(),
            $io->getTypedArgument('age')->asNullablePositiveInteger(),
        );

        return ExitCode::SUCCESS;
    }
}