PHP code example of devlop / laravel-console-input-validation

1. Go to this page and download the library: Download devlop/laravel-console-input-validation 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/ */

    

devlop / laravel-console-input-validation example snippets


use Devlop\Laravel\Console\ValidateInput;
use Symfony\Component\Console\Input\InputInterface;

class DemoCommand extends Command
{
    use ValidateInput;

    /**
     * Validate the console command input.
     *
     * @throws InvalidArgumentException
     */
    protected function validate(InputInterface $input) : void
    {
        // Example using manual validation
        if (! is_numeric($input->getOption('limit'))) {
            throw new InvalidArgumentException('--limit must be numeric');
        }

        // Example using webmozarts/assert
        Assert::numeric($input->getOption('limit')); // assert that the --limit option got a numeric value
        Assert::greaterThan($input->getOption('limit'), 0); // assert that the --limit option get a value greater than 0
    }

    public function handle() : int
    {
        // ...
    }
}