<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
danilovl / symfony-console-input-validation example snippets
return function (array $context): Application {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
return new \Danilovl\SymfonyConsoleInputValidation\Console\Application($kernel);
};
declare(strict_types=1);
namespace App\Application\Command;
use Danilovl\SymfonyConsoleInputValidation\Console\Input\InputOption as InputOptionValidation;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\InvalidOptionException;
use Symfony\Component\Console\Input\{
InputOption,
InputInterface
};
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(name: 'app:command-test')]
class TestCommand extends Command
{
protected function configure(): void
{
$validation = static function (mixed $value): void {
if (empty($value)) {
return;
}
if (!in_array($value, ['encrypt', 'decrypt'])) {
throw new InvalidOptionException(sprintf('"%s" is not a valid type.', $value));
}
};
$inputOption = new InputOptionValidation(
name: 'type',
mode: InputOption::VALUE_REQUIRED,
description: 'Encryption type.',
suggestedValues: ['encrypt', 'decrypt'],
validation: $validation
);
$this->getDefinition()->addOption($inputOption);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$input->getOption('type');
return Command::SUCCESS;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.