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/ */
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;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.