diff --git a/src/Http/Validation/Custom/ArtisanCommand.php b/src/Http/Validation/Custom/ArtisanCommand.php index 19b4dde5d..8d5d7815d 100644 --- a/src/Http/Validation/Custom/ArtisanCommand.php +++ b/src/Http/Validation/Custom/ArtisanCommand.php @@ -23,6 +23,8 @@ namespace Seat\Web\Http\Validation\Custom; use Artisan; +use Symfony\Component\Console\Input\ArgvInput; +use Symfony\Component\Console\Exception\RuntimeException; /** * Class ArtisanCommand. @@ -48,12 +50,30 @@ public static function validate($attribute, $value, $parameters, $validator) //split arguments $argv = explode(' ', $value); - //get command name and check if it exists - $commandName = $argv[0] ?? null; - if($commandName === null) return false; + //check if a command name is included and get it + if(count($argv) === 0) return false; + $commandName = array_shift($argv); + + //check if the command exists and get it if(! array_key_exists($commandName, $allCommands)) return false; + $command = $allCommands[$commandName]; + + //extract the argument definition off the command + $argumentDefinition = $command->getDefinition(); - //I haven't found a way to validate the arguments, so we assume they are alright + //validate our arguments + try { + //create an argument parser and supply it with the provided arguments. + // Also supply the argument definition to check if it complies with the command + // ArgvInput ignores the first element of the array(usually the executable name when calling it from the console), so just supply an empty string + $input = new ArgvInput(["", ...$argv], $argumentDefinition); + //I guess this validates the input? + $input->validate(); + } + // instead of returning false in ->validate(), it throws an exception + catch (\RuntimeException $e){ + return false; + } //all checks have passed, we can allow it return true;