<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
digitalrevolution / symfony-console-validation example snippets
use DigitalRevolution\SymfonyConsoleValidation\AbstractValidatedInput;
use DigitalRevolution\SymfonyConsoleValidation\ValidationRules;
class ExampleInput extends AbstractValidatedInput
{
public static function getValidationRules(): ValidationRules
{
return new ValidationRules([
'arguments' => [
'email' => '== null ? null : (int)$value;
}
}
class ExampleCommand extends Command
{
public function __construct(private InputValidator $inputValidator, ?string $name = null)
{
parent::__construct($name);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
// third argument will throw exception if input is invalid. Set to `false` if you want to handle the validation yourself.
$validatedInput = $this->inputValidator->validate($input, ExampleInput::class, true);
...
}
}
class ExampleCommand extends Command
{
...
protected function execute(InputInterface $input, OutputInterface $output): int
{
$validatedInput = $this->inputValidator->validate($input, ExampleInput::class, false);
if ($validatedInput->isValid() === false) {
$violations = $validatedInput->getViolations();
...
}
...
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.