Validates an array of References.

@param array $arguments An array of Reference objects

@throws RuntimeException when there is a reference to an abstract definition.
964515
private function validateReferences(array $arguments)
    {
        foreach ($arguments as $argument) {
            if (is_array($argument)) {
                $this->validateReferences($argument);
            } elseif ($argument instanceof Reference) {
                $targetDefinition = $this->getDefinition((string) $argument);

                if (null !== $targetDefinition && $targetDefinition->isAbstract()) {
                    throw new RuntimeException(sprintf(
                        'The definition "%s" has a reference to an abstract definition "%s". '
                       .'Abstract definitions cannot be the target of references.',
                       $this->currentId,
                       $argument
                    ));
                }
            }
        }
    }
490019
public static function validate($argument, $argumentName = null)
    {
        if (trim($argument) != null && !is_numeric($argument)) {
            throw new \InvalidArgumentException("$argumentName is not a valid numeric value");
        }
        return true;
    }
1357232
protected function doValidate()
    {
        if ($this->argumentTypes === false) {
            throw new CallableFunctionValidatorException('Variable $argumentTypes must be defined.');
        }

        $argumentCount = count($this->argumentTypes);

        $reflectionFunction = new \ReflectionFunction($this->callableFunction);
        $reflectionParams = $reflectionFunction->getParameters();

        // Checking argument count.
        if (count($reflectionParams) != $argumentCount) {
            throw new CallableFunctionValidatorException(sprintf(
                'There is not sufficient argument count (required %s arguments).', $argumentCount
            ));
        }

        // Checking argument types.
        foreach ($this->argumentTypes as $k => $type) {
            if (!array_key_exists('type', $type)) {
                throw new \InvalidArgumentException('Key "type" must be defined.');
            }

            $parameter = $reflectionParams[$k];
            $class = $parameter->getClass();

            if ($type['type'] !== null) {
                if ($class === null || $type['type'] !== $class->getName()) {
                    throw new CallableFunctionValidatorException(sprintf(
                        'Argument %s must be type of "%s".', $k, $type['type']
                    ));
                }
            }

            if (array_key_exists('array', $type) && $type['array'] === true) {
                if ($class !== null) {
                    throw new CallableFunctionValidatorException(sprintf('Argument %s must be type of null.', $k));
                }

                if (!$parameter->isArray()) {
                    throw new CallableFunctionValidatorException(sprintf('Argument %s must be an array.', $k));
                }
            }
        }
    }
708090
public function setArguments(array $arguments)
    {
        $this->checkStringArgument($arguments, 2);
        $this->checkStringArguments($arguments);
        $this->arguments = $arguments;
    }
1015587
public function setArguments($arguments = [])
    {
        $this->arguments = [];
        $this->requiredCount = 0;
        $this->hasOptional = false;
        $this->hasAnArrayArgument = false;
        $this->addArguments($arguments);
    }
884197
public function execute(array $variables = null)
    {
        if (null === $variables) {
            $variables = $_SERVER;
        }

        $arguments = $this->arguments($variables);
        if (count($arguments) < 1) {
            throw new RuntimeException('No arguments provided.');
        }

        switch ($arguments[0]) {
            case '-h':
            case '--help':
                $this->executeUsage();

                return;

            case '-v':
            case '--version':
                $this->executeVersion();

                return;
        }

        $this->executeLaunch($arguments);
    }
307526
public function explain(array $matchers, array $arguments): MatcherResult
    {
        $isMatch = true;
        $matcherMatches = [];
        $argumentMatches = [];
        $argumentCount = count($arguments);
        $index = 0;

        foreach ($matchers as $matcher) {
            if ($matcher instanceof WildcardMatcher) {
                $matcherIsMatch = true;
                $innerMatcher = $matcher->matcher();
                $minimumArguments = $matcher->minimumArguments();
                $maximumArguments = $matcher->maximumArguments();

                for ($count = 0; $count < $minimumArguments; ++$count) {
                    if ($index >= $argumentCount) {
                        $matcherIsMatch = false;
                        $argumentMatches[] = false;

                        break;
                    }

                    if ($innerMatcher->matches($arguments[$index])) {
                        $argumentMatches[] = true;
                    } else {
                        $matcherIsMatch = false;
                        $argumentMatches[] = false;
                    }

                    ++$index;
                }

                if ($maximumArguments < 0) {
                    while (
                        $index < $argumentCount &&
                        $innerMatcher->matches($arguments[$index])
                    ) {
                        $argumentMatches[] = true;
                        ++$index;
                    }
                } else {
                    for (; $count < $maximumArguments; ++$count) {
                        if (
                            $index >= $argumentCount ||
                            !$innerMatcher->matches($arguments[$index])
                        ) {
                            break;
                        }

                        $argumentMatches[] = true;
                        ++$index;
                    }
                }

                $isMatch = $isMatch && $matcherIsMatch;
                $matcherMatches[] = $matcherIsMatch;

                continue;
            }

            $matcherIsMatch =
                $index < $argumentCount &&
                $matcher->matches($arguments[$index]);

            $isMatch = $isMatch && $matcherIsMatch;
            $matcherMatches[] = $matcherIsMatch;
            $argumentMatches[] = $matcherIsMatch;
            ++$index;
        }

        for (; $index < $argumentCount; ++$index) {
            $argumentMatches[] = false;
            $isMatch = false;
        }

        return new MatcherResult($isMatch, $matcherMatches, $argumentMatches);
    }
1150025
public function setArguments(array $arguments)
    {
        foreach ($arguments as $arg) {
            if (!is_scalar($arg)) {
                $type = gettype($arg);
                throw new DomainException("Arguments array should be an array of scalar, but found $type");
            }
        }

        $this->arguments = $arguments;

        return $this;
    }
1133635
public function validate($value, array $arguments = [])
    {
        $min = Arr::get($arguments, 'min', false);
        $max = Arr::get($arguments, 'max', false);
        $callable = Arr::get($arguments, 'callable', false);
        $json = Arr::get($arguments, 'json', false);
        $filter = Arr::get($arguments, 'filter', false);

        if ($json && $this->isJson($value)) {
            $value = json_decode($value);
        }

        $isArray = is_array($value);

        if (!$isArray) {
            throw new Exception("O atributo '{$this->getAttribute()}' não é um array!");
        }

        $count = count($value);

        if ($min) {
            $min = intval($min);
        } else {
            $min = false;
        }

        if ($max) {
            $max = intval($max);
        } else {
            $max = false;
        }

        if ($min) {

            if ($count < $min) {
                throw new Exception("O atributo '{$this->getAttribute()}' deve ter no minimo '{$min}' elemento(s)!");
            } elseif ($max && $count > $max) {
                throw new Exception("O atributo '{$this->getAttribute()}' deve ter no máximo '{$max}' elemento(s)!");
            }
        }

        if ($callable) {
            $false = 0;

            if (is_string($callable) && function_exists($callable)) {
                foreach ($value as $item) {
                    if (!call_user_func($callable, $item)) {
                        $false++;
                    }
                }
            } elseif (is_callable($callable)) {
                foreach ($value as $item) {
                    if (!$callable($item)) {
                        $false++;
                    }
                }
            } else {
                throw new Exception("Não foi possivel aplicar a validação no atributo '{$this->getAttribute()}'!");
            }

            if ($false > 0) {
                throw new Exception("{$false} elemento(s) do atributo'{$this->getAttribute()}' não passou(passaram) na validação!");
            }
        }

        if ($filter && $filter instanceof \Closure) {
            $value = $filter($value);
        } elseif ($filter) {
            $value = call_user_func($filter, $value);
        }

        return $value;
    }
325932
public function setArguments($arguments)
    {
        $this->package->setParsedArguments($arguments);
        $this->inputCollector->setArguments($arguments);
    }
442165
public static function validate($argument, $argumentName = null)
    {
        if (!is_array($argument)) {
            throw new \InvalidArgumentException("Argument with name $argumentName is not an array");

        }
        foreach ($argument as $item) {
            if ($item === null) {
                // Error if Object Null
                throw new \InvalidArgumentException("Argument with name $argumentName item cannot be null");
            } else if (gettype($item) == 'string' && trim($item) == '') {
                // Error if String Empty
                throw new \InvalidArgumentException("Argument with name $argumentName item string cannot be empty");
            }
        }
        return true;
    }
275265
public function validate(...$args)
    {
        foreach ($args as $key) {
            $value = $this->getParameter($key);
            if (!isset($value)) {
                throw new InvalidRequestException("The $key parameter is required");
            }
        }
    }
539994
public function setArguments(array $arguments)
    {
        switch ($this->argumentsType) {
            case self::ARGUMENTS_TYPE_EMPTY:
                if (!empty($arguments)) {
                    throw new InvalidCommandArgumentException($this, $arguments);
                }
                $arguments = [];
                break;
            case self::ARGUMENTS_TYPE_STRING:
                $this->checkStringArgument($arguments);
                $arguments = [$arguments[0]];
                break;
            case self::ARGUMENTS_TYPE_STRING_INT:
                $this->checkStringArgument($arguments, 2);
                if (!is_int($arguments[1])) {
                    throw new InvalidCommandArgumentException($this, $arguments);
                }
                $arguments = [$arguments[0], (int) $arguments[1]];
                break;
            case self::ARGUMENTS_TYPE_STRINGS:
                $this->checkStringArguments($arguments);
                break;
            // A fallback in case a non-existing argument type is defined.
            // This could be prevented by using an Enum as the argument type
            default:
                throw new InvalidCommandArgumentException($this, $arguments);
        }
        $this->arguments = $arguments;
    }
175949
private function invokeConstructorIfDeclared(array $arguments)
    {
        $methodName = 'construct';

        try {
            $method = new ReflectionMethod($this, $methodName);

            if (true === $method->isPublic()) {
                throw new RuntimeException(
                    'The constructor of an enumeration type may not be public.'
                );
            }

            $method->setAccessible(true);
            $method->invokeArgs($this, $arguments);
        } catch (ReflectionException $ex) {
            // empty block.
        }
    }
925740
protected function validateRow(array $row)
    {
        foreach ($row as $k => $v)
        {
            if (WF::is_array_like($v))
                throw new InvalidArgumentException("CSVWriter does not support nested arrays");
        }
    }
1075110
protected function getArgumentsWithDriver(...$arguments): array
    {
        \array_unshift($arguments, 'driver');

        $resolvedArguments = [];

        $this->validateMissingArguments($arguments);

        if (empty($this->argument(\end($arguments)))) {
            $driver = $this->getDriverFromConfig();

            if (empty($driver)) {
                throw new RuntimeException('Not enough arguments (missing: "driver").');
            }

            $resolvedArguments['driver'] = $driver;

            for ($i = 1; $i < \count($arguments); $i++) {
                $resolvedArguments[$arguments[$i]] = $this->argument($arguments[$i - 1]);
            }
        } else {
            foreach ($arguments as $argument) {
                $resolvedArguments[$argument] = $this->argument($argument);
            }
        }

        return $resolvedArguments;
    }
193413
public function eachValidator(array $values, ...$args): bool
    {
        if (!$validator = \array_shift($args)) {
            throw new \InvalidArgumentException('must setting a validator for \'each\' validate.');
        }

        foreach ($values as $value) {
            $passed = false;

            if (\is_object($validator) && \method_exists($validator, '__invoke')) {
                $passed = $validator($value, ...$args);
            } elseif (\is_string($validator)) {
                // special for required
                if ('required' === $validator) {
                    $passed = !Validators::isEmpty($value);

                } elseif (isset($this->_validators[$validator])) {
                    $callback = $this->_validators[$validator];
                    $passed   = $callback($value, ...$args);

                } elseif (\method_exists($this, $method = $validator . 'Validator')) {
                    $passed = $this->$method($value, ...$args);

                } elseif (\method_exists(Validators::class, $validator)) {
                    $passed = Validators::$validator($value, ...$args);

                    // it is function name
                } elseif (\function_exists($validator)) {
                    $passed = $validator($value, ...$args);
                } else {
                    throw new \InvalidArgumentException("The validator [$validator] don't exists!");
                }
            }

            if (!$passed) {
                return false;
            }
        }

        return true;
    }