src/Koldy/Validator.php
protected function validateArray($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        $count = $args[0] ?? null;

        if ($count !== null) {
            if ($count == '' || !is_numeric($count)) {
                throw new ValidatorConfigException("Invalid array count definition for parameter {$parameter}");
            }

            $count = (int)$count;

            if ($count < 0) {
                throw new ValidatorConfigException("Invalid array count definition for parameter {$parameter}, argument can not be negative");
            }
        }

        //$value = $this->getValue($parameter);

        if ($value === null) {
            return null;
        }

        if (is_string($value) && $value === '') {
            return null;
        }

        if (!is_array($value)) {
            return Message::getMessage(Message::IS_NOT_ARRAY, [
                'param' => $parameter
            ]);
        }

        if ($count !== null) {
            $currentCount = count($value);

            if ($currentCount != $count) {
                if (ctype_digit($parameter)) {
                    $parameter = "Element on position {$parameter}";
                }

                return Message::getMessage(Message::ARRAY_WRONG_COUNT, [
                    'param' => $parameter,
                    'requiredCount' => $count,
                    'currentCount' => $currentCount
                ]);
            }
        }

        return null;
    }
protected function validateArray($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        $count = $args[0] ?? null;

        if ($count !== null) {
            if ($count == '' || !is_numeric($count)) {
                throw new ValidatorConfigException("Invalid array count definition for parameter {$parameter}");
            }

            $count = (int)$count;

            if ($count < 0) {
                throw new ValidatorConfigException("Invalid array count definition for parameter {$parameter}, argument can not be negative");
            }
        }

        //$value = $this->getValue($parameter);

        if ($value === null) {
            return null;
        }

        if (is_string($value) && $value === '') {
            return null;
        }

        if (!is_array($value)) {
            return Message::getMessage(Message::IS_NOT_ARRAY, [
                'param' => $parameter
            ]);
        }

        if ($count !== null) {
            $currentCount = count($value);

            if ($currentCount != $count) {
                if (ctype_digit($parameter)) {
                    $parameter = "Element on position {$parameter}";
                }

                return Message::getMessage(Message::ARRAY_WRONG_COUNT, [
                    'param' => $parameter,
                    'requiredCount' => $count,
                    'currentCount' => $currentCount
                ]);
            }
        }

        return null;
    }
protected function validateArray ( $ value , string $ parameter , array $ args = [ ] , array $ rules = null , array $ context = null ) : ? string { $ count = $ args [ 0 ] ?? null ; if ( $ count !== null ) { if ( $ count == '' || ! is_numeric ( $ count ) ) { throw new ValidatorConfigException ( "Invalid array count definition for parameter {$parameter}" ) ; } $ count = ( int ) $ count ; if ( $ count < 0 ) { throw new ValidatorConfigException ( "Invalid array count definition for parameter {$parameter}, argument can not be negative" ) ; } } //$value = $this->getValue($parameter); if ( $ value === null ) { return null ; } if ( is_string ( $ value ) && $ value === '' ) { return null ; } if ( ! is_array ( $ value ) ) { return Message :: getMessage ( Message :: IS_NOT_ARRAY , [ 'param' => $ parameter ] ) ; } if ( $ count !== null ) { $ currentCount = count ( $ value ) ; if ( $ currentCount != $ count ) { if ( ctype_digit ( $ parameter ) ) { $ parameter = "Element on position {$parameter}" ; } return Message :: getMessage ( Message :: ARRAY_WRONG_COUNT , [ 'param' => $ parameter , 'requiredCount' => $ count , 'currentCount' => $ currentCount ] ) ; } } return null ; }
Validate if given value is PHP array

@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules

@return null|string
@throws ValidatorConfigException
@example 'param' => 'array'
@example 'param' => 'array:5'
Validate if given value is PHP array