Garden\Schema::isValidInternal PHP Method

isValidInternal() protected method

Validate data against the schema and return the result.
protected isValidInternal ( array &$data, array $schema, Validation &$validation = null, string $path = '' ) : boolean
$data array
$schema array The schema array to validate against.
$validation Validation
$path string The path to the current path for nested objects.
return boolean Returns true if the data is valid. False otherwise.
    protected function isValidInternal(array &$data, array $schema, Validation &$validation = null, $path = '')
    {
        if ($validation === null) {
            $validation = new Validation();
        }
        $this->filterData($data, $schema, $validation, $path);
        // Loop through the schema fields and validate each one.
        foreach ($schema as $name => $field) {
            // Prepend the path the field label.
            if ($path) {
                $field['path'] = $path . self::arraySelect(['path', 'name'], $field);
            }
            if (array_key_exists($name, $data)) {
                $this->validateField($data[$name], $field, $validation);
            } elseif (val('required', $field)) {
                $validation->addError('missing_field', self::arraySelect(['path', 'name'], $field));
            }
        }
        // Validate the global validators.
        if ($path == '' && isset($this->validators['*'])) {
            foreach ($this->validators['*'] as $callback) {
                call_user_func($callback, $data, $validation);
            }
        }
        return $validation->isValid();
    }