@param DataSources\DataSourceInterface $dataSource
@param Schema                          $schema
@param int                             $numPeekRows

@return array of validation errors
962983
public static function validate($dataSource, $schema, $numPeekRows = 10, $csvDialect = null)
    {
        try {
            $table = new static($dataSource, $schema, $csvDialect);
        } catch (Exceptions\DataSourceException $e) {
            return [new SchemaValidationError(SchemaValidationError::LOAD_FAILED, $e->getMessage())];
        }
        if ($numPeekRows > 0) {
            $i = 0;
            try {
                foreach ($table as $row) {
                    if (++$i > $numPeekRows) {
                        break;
                    }
                }
            } catch (Exceptions\DataSourceException $e) {
                // general error in getting the next row from the data source
                return [new SchemaValidationError(SchemaValidationError::ROW_VALIDATION, [
                    'row' => $i,
                    'error' => $e->getMessage(),
                ])];
            } catch (Exceptions\FieldValidationException $e) {
                // validation error in one of the fields
                return array_map(function ($validationError) use ($i) {
                    return new SchemaValidationError(SchemaValidationError::ROW_FIELD_VALIDATION, [
                        'row' => $i + 1,
                        'field' => $validationError->extraDetails['field'],
                        'error' => $validationError->extraDetails['error'],
                        'value' => $validationError->extraDetails['value'],
                    ]);
                }, $e->validationErrors);
            }
        }

        return [];
    }
726144
public function makeSchemaValidator(EventInterface $event, $schema)
    {
        // we can't validate on an array, only an object
        // so we need to convert the event payload to an object
        $payload = $event->toMessage();
        $payload = json_encode($payload); // back to json
        $payload = json_decode($payload); // from json to an object

        return new Validator($payload, $schema);
    }
1129406
public function getUpdateErrors(array $data, array &$errors = [], $fieldset = null)
    {
        $schema = $this->schema;

        if (!is_null($fieldset)) {
            $schema = $fieldset;
        }

        $fields = $schema->getFields();
        $table = $schema->getName();
        $primary = $schema->getPrimaryFieldName();

        if ((!isset($data[$primary]) || !is_numeric($data[$primary])) && !is_null($primary)) {
            $errors[$primary] = 'Invalid ID';
        }

        foreach ($fields as $name => $field) {
            if ($field['field']['type'] === 'fieldset') {
                if (!isset($data[$name])) {
                    continue;
                }

                if (!isset($errors[$name])) {
                    $errors[$name] = [];
                }

                if (isset($field['field']['attributes']['data-multiple'])
                    && !$field['field']['attributes']['data-multiple']
                ) {
                    $errors[$name] = $this->getUpdateErrors(
                        $data[$name],
                        $errors[$name],
                        Fieldset::i($field['field']['parameters'])
                    );

                    if (empty($errors[$name])) {
                        unset($errors[$name]);
                    }

                    continue;
                }

                foreach($data[$name] as $index => $row) {
                    if (!isset($errors[$name][$index])) {
                        $errors[$name][$index] = [];
                    }

                    $errors[$name][$index] = $this->getUpdateErrors(
                        $row,
                        $errors[$name][$index],
                        Fieldset::i($field['field']['parameters'])
                    );

                    if (empty($errors[$name][$index])) {
                        unset($errors[$name][$index]);
                    }
                }

                if (empty($errors[$name])) {
                    unset($errors[$name]);
                }

                continue;
            }

            if (!isset($field['validation'])) {
                continue;
            }

            foreach ($field['validation'] as $validation) {
                if ($validation['method'] === 'required'
                    && array_key_exists($name, $data)
                    && empty($data[$name])
                ) {
                    $errors[$name] = $validation['message'];
                }
            }
        }

        return $this->getOptionalErrors($data, $errors, $fieldset);
    }
720682
private function filterConstraintsForSchema(array $constraints, stdClass $schema)
    {
        $filtered = [];

        foreach ($constraints as $constraint) {
            foreach ($constraint->keywords() as $keyword) {
                if (property_exists($schema, $keyword)) {
                    $filtered[] = $constraint;
                    break;
                }
            }
        }

        return $filtered;
    }
47922
public DataValidationEvent[] validateDataSourceBackendData()
            throws DataSourceFailedDataValidationException,
            DataSourceValidationIncompleteException {
        KnowledgeSource knowledgeSource = getKnowledgeSource();
        List<DataValidationEvent> validationEvents = new ArrayList<>();
        try {
            for (DataSourceBackend backend : getDataSource().getBackends()) {
                CollectionUtils.addAll(validationEvents,
                        backend.validateData(knowledgeSource));
            }
        } catch (DataSourceBackendFailedDataValidationException ex) {
            throw new DataSourceFailedDataValidationException(
                    "Data source failed validation", ex, validationEvents.toArray(new DataValidationEvent[validationEvents.size()]));
        } catch (KnowledgeSourceReadException ex) {
            throw new DataSourceValidationIncompleteException(
                    "An error occurred during validation", ex);
        }
        return validationEvents.toArray(new DataValidationEvent[validationEvents.size()]);
    }
838597
protected function checkEnum($entity, $schema, $entityName)
    {
        $valid = true;
        if (isset($schema->enum) && $schema->enum) {
            if (!is_array($schema->enum)) {
                throw new SchemaException(sprintf('Enum property must be an array for [%s]', $entityName));
            }
            if (is_array($entity)) {
                foreach ($entity as $val) {
                    if (!in_array($val, $schema->enum)) {
                        $valid = false;
                    }
                }
            } else {
                if (!in_array($entity, $schema->enum)) {
                    $valid = false;
                }
            }
        }

        if (!$valid) {
            throw new ValidationException(sprintf('Invalid value(s) for [%s], allowable values are [%s]', $entityName, implode(',', $schema->enum)));
        }

        return $this;
    }
442831
protected function validateNumber(/** @noinspection PhpUnusedParameterInspection */
        &$document_data, &$data, array $data_pointer, array $parent_data_pointer, ISchema $document, $schema, ValidationResult $bag): bool
    {
        $ok = true;

        // minimum, exclusiveMinimum
        if (property_exists($schema, 'minimum')) {
            if (!is_int($schema->minimum) && !is_float($schema->minimum)) {
                throw new SchemaKeywordException(
                    $schema,
                    'minimum',
                    $schema->minimum,
                    "'minimum' keyword must be an integer or a float, " . gettype($schema->minimum) . " given"
                );
            }

            $exclusive = false;
            if (property_exists($schema, 'exclusiveMinimum')) {
                if (!is_bool($schema->exclusiveMinimum)) {
                    throw new SchemaKeywordException(
                        $schema,
                        'exclusiveMinimum',
                        $schema->exclusiveMinimum,
                        "'exclusiveMinimum' keyword must be a boolean if 'minimum' keyword is present, " . gettype($schema->exclusiveMinimum) . " given"
                    );
                }
                $exclusive = $schema->exclusiveMinimum;
            }

            if ($exclusive && $data == $schema->minimum) {
                $ok = false;
                $bag->addError(new ValidationError($data, $data_pointer, $parent_data_pointer, $schema, 'exclusiveMinimum', [
                    'min' => $schema->minimum
                ]));
                if ($bag->isFull()) {
                    return false;
                }
            } elseif ($data < $schema->minimum) {
                $ok = false;
                $bag->addError(new ValidationError($data, $data_pointer, $parent_data_pointer, $schema, 'minimum', [
                    'min' => $schema->minimum
                ]));
                if ($bag->isFull()) {
                    return false;
                }
            }
        } elseif (property_exists($schema, 'exclusiveMinimum')) {
            if (!is_int($schema->exclusiveMinimum) && !is_float($schema->exclusiveMinimum)) {
                throw new SchemaKeywordException(
                    $schema,
                    'exclusiveMinimum',
                    $schema->exclusiveMinimum,
                    "'exclusiveMinimum' keyword must be an integer or a float if 'minimum' keyword is not present, " . gettype($schema->exclusiveMinimum) . " given"
                );
            }
            if ($data <= $schema->exclusiveMinimum) {
                $ok = false;
                $bag->addError(new ValidationError($data, $data_pointer, $parent_data_pointer, $schema, 'exclusiveMinimum', [
                    'min' => $schema->exclusiveMinimum
                ]));
                if ($bag->isFull()) {
                    return false;
                }
            }
        }

        // maximum, exclusiveMaximum
        if (property_exists($schema, 'maximum')) {
            if (!is_int($schema->maximum) && !is_float($schema->maximum)) {
                throw new SchemaKeywordException(
                    $schema,
                    'maximum',
                    $schema->maximum,
                    "'maximum' keyword must be an integer or a float, " . gettype($schema->maximum) . " given"
                );
            }

            $exclusive = false;
            if (property_exists($schema, 'exclusiveMaximum')) {
                if (!is_bool($schema->exclusiveMaximum)) {
                    throw new SchemaKeywordException(
                        $schema,
                        'exclusiveMaximum',
                        $schema->exclusiveMaximum,
                        "'exclusiveMaximum' keyword must be a boolean is 'maximum' keyword is present, " . gettype($schema->exclusiveMaximum) . " given"
                    );
                }
                $exclusive = $schema->exclusiveMaximum;
            }

            if ($exclusive && $data == $schema->maximum) {
                $ok = false;
                $bag->addError(new ValidationError($data, $data_pointer, $parent_data_pointer, $schema, 'exclusiveMaximum', [
                    'max' => $schema->maximum
                ]));
                if ($bag->isFull()) {
                    return false;
                }
            } elseif ($data > $schema->maximum) {
                $ok = false;
                $bag->addError(new ValidationError($data, $data_pointer, $parent_data_pointer, $schema, 'maximum', [
                    'max' => $schema->maximum
                ]));
                if ($bag->isFull()) {
                    return false;
                }
            }
        } elseif (property_exists($schema, 'exclusiveMaximum')) {
            if (!is_int($schema->exclusiveMaximum) && !is_float($schema->exclusiveMaximum)) {
                throw new SchemaKeywordException(
                    $schema,
                    'exclusiveMaximum',
                    $schema->exclusiveMaximum,
                    "'exclusiveMaximum' keyword must be an integer or a float if 'maximum' keyword is not present, " . gettype($schema->exclusiveMaximum) . " given"
                );
            }
            if ($data >= $schema->exclusiveMaximum) {
                $ok = false;
                $bag->addError(new ValidationError($data, $data_pointer, $parent_data_pointer, $schema, 'exclusiveMaximum', [
                    'max' => $schema->exclusiveMaximum
                ]));
                if ($bag->isFull()) {
                    return false;
                }
            }
        }

        // multipleOf
        if (property_exists($schema, 'multipleOf')) {
            if (!is_int($schema->multipleOf) && !is_float($schema->multipleOf)) {
                throw new SchemaKeywordException(
                    $schema,
                    'multipleOf',
                    $schema->multipleOf,
                    "'multipleOf' keyword must be an integer or a float, " . gettype($schema->multipleOf) . " given"
                );
            }
            if ($schema->multipleOf <= 0) {
                throw new SchemaKeywordException(
                    $schema,
                    'multipleOf',
                    $schema->multipleOf,
                    "'multipleOf' keyword must be greater than 0"
                );
            }
            if (!$this->helper->isMultipleOf($data, $schema->multipleOf)) {
                $ok = false;
                $bag->addError(new ValidationError($data, $data_pointer, $parent_data_pointer, $schema, 'multipleOf', [
                    'divisor' => $schema->multipleOf
                ]));
                if ($bag->isFull()) {
                    return false;
                }
            }
        }

        return $ok;
    }
1224067
public function setDatasources(DatasourceFactory $factory, array $datasources) {
        $this->datasourceFactory = $factory;
        $this->datasources = $datasources;
    }
1204666
public function postDown(Schema $schema)
    {
        if (!$this->sm->tablesExist(['typo3_flow_resource_resource'])) {
            return;
        }
        $resourcesResult = $this->connection->executeQuery('SELECT DISTINCT resourcepointer FROM typo3_flow_resource_resource');
        while ($resourceInfo = $resourcesResult->fetch(\PDO::FETCH_ASSOC)) {
            $this->connection->executeQuery(
                'INSERT INTO typo3_flow_resource_resourcepointer (hash) VALUES (?)',
                array($resourceInfo['resourcepointer'])
            );

            $resourcePathAndFilename = FLOW_PATH_DATA . 'Persistent/Resources/' . $resourceInfo['resourcepointer'][0] . '/' . $resourceInfo['resourcepointer'][1] . '/' . $resourceInfo['resourcepointer'][2] . '/' . $resourceInfo['resourcepointer'][3] . '/' . $resourceInfo['resourcepointer'];
            if (!file_exists($resourcePathAndFilename)) {
                $this->write(sprintf('Error while migrating database for the old resource management: the resource file "%s" was not found.', $resourcePathAndFilename));
                continue;
            }
            $newResourcePathAndFilename = FLOW_PATH_DATA . 'Persistent/Resources/' . $resourceInfo['resourcepointer'];
            $result = @rename($resourcePathAndFilename, $newResourcePathAndFilename);
            if ($result === false) {
                $this->write(sprintf('Could not move the data file of resource "%s" from its location at %s to the legacy location %s.', $resourceInfo['resourcepointer'], $resourcePathAndFilename, $newResourcePathAndFilename));
            }
            Files::removeEmptyDirectoriesOnPath(dirname($resourcePathAndFilename));
        }

        $this->connection->exec('UPDATE typo3_flow_resource_resource SET fileextension =  SUBSTRING_INDEX(filename, \'.\', -1)');
        $this->connection->exec('ALTER TABLE typo3_flow_resource_resource ADD CONSTRAINT typo3_flow_resource_resource_ibfk_1 FOREIGN KEY (resourcepointer) REFERENCES typo3_flow_resource_resourcepointer (hash)');
    }
927206
public function validate(array $object, Schema $schema, array $schemaExtensions = [])
    {
        $validationResult = new ValidationResult();
        /** @var Schema[] $otherSchemas */
        $otherSchemas = [];
        foreach ($schemaExtensions as $schemaExtension) {
            $otherSchemas[$schemaExtension->getId()] = $schemaExtension;
        }

        $this->validateByAttributes($object, $schema->getId(), $schema->getAttributes(), $otherSchemas, $validationResult, null);

        foreach ($otherSchemas as $schemaId => $otherSchema) {
            if (isset($object[$schemaId])) {
                $this->validateByAttributes($object[$schemaId], $otherSchema->getId(), $otherSchema->getAttributes(), [], $validationResult, null);
            }
        }

        return $validationResult;
    }
264179
public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource['data']['items'])) {
            $config = $this->getConfiguration();
            $name   = $config['fieldName'] ?? $this->getName();
            foreach ($dataSource['data']['items'] as & $item) {
                $item[$name] = ($item[$name] ? __('Yes') : __('No'));
            }
        }

        return parent::prepareDataSource($dataSource);
    }
1202035
public static void createSchema(DataSource dataSource, String name) {
        try (Connection connection = dataSource.getConnection();
             Statement statement = connection.createStatement()) {
            statement.executeUpdate(String.format(Constants.DDL_CREATE_SCHEMA, name));
        } catch (SQLException e) {
            throw new RuntimeException("Can not connect to database", e);
        }
    }
451161
private function validateAdditionalItemsSchemaObject(array $subject, array $schema): bool
    {
        for ($i = 0; $i < count($subject); $i++) {
            $nodeValidator = new NodeValidator($schema['additionalItems'], $this->rootSchema);
            if (!$nodeValidator->validate($subject[$i])) {
                return false;
            }
        }
        return true;
    }
118913
public void addDataSource(int groupno, DataSource datasource) {
    // the loader takes care of validation
    if (groupno == 0)
      datasources.add(datasource);
    else if (groupno == 1)
      group1.add(datasource);
    else if (groupno == 2)
      group2.add(datasource);
  }
263308
public function validateWithSchemas(Schemas $schemas)
    {
        // create the schemas collection, then validate the document against the schemas
        if (! $schemas->count()) {
            return;
        }
        // build the unique importing schema
        $xsd = $schemas->getImporterXsd();
        LibXmlException::useInternalErrors(function () use ($xsd) {
            $this->document->schemaValidateSource($xsd);
        });
    }
1037044
protected function validateType($entity, $schema, $entityName)
    {
        if (isset($schema->type)) {
	        $types = $schema->type;
		} else {
			$types = 'any';
            //throw new ValidationException(sprintf('No type given for [%s]', $entityName));
        }

        if (!is_array($types)) {
            $types = array($types);
        }

        $valid = false;

        foreach ($types as $type) {
            switch ($type) {
                case 'object':
                    if (is_object($entity)) {
                        $this->checkTypeObject($entity, $schema, $entityName);
                        $valid = true;
                    }
                    break;
                case 'string':
                    if (is_string($entity)) {
                        $this->checkTypeString($entity, $schema, $entityName);
                        $valid = true;
                    }
                    break;
                case 'array':
                    if (is_array($entity)) {
                        $this->checkTypeArray($entity, $schema, $entityName);
                        $valid = true;
                    }
                    break;
                case 'integer':
                    if (!is_string($entity) && is_int($entity)) {
                        $this->checkTypeInteger($entity, $schema, $entityName);
                        $valid = true;
                    }
                    break;
                case 'number':
                    if (!is_string($entity) && is_numeric($entity)) {
                        $this->checkTypeNumber($entity, $schema, $entityName);
                        $valid = true;
                    }
                    break;
                case 'boolean':
                    if (!is_string($entity) && is_bool($entity)) {
                        $this->checkTypeBoolean($entity, $schema, $entityName);
                        $valid = true;
                    }
                    break;
                case 'null':
                    if (is_null($entity)) {
                        $this->checkTypeNull($entity, $schema, $entityName);
                        $valid = true;
                    }
                    break;
                case 'any':
                    $this->checkTypeAny($entity, $schema, $entityName);
                    $valid = true;
                    break;
                default:
                    // Do nothing
                    $valid = true;
                    break;
            }
        }

        if (!$valid) {
            throw new ValidationException(sprintf('Property [%s] must be one of the following types: [%s]', $entityName, implode(', ', $types)));
        }

        return $this;
    }
1220953
public function setDataSource(DataSourceInterface $dataSource)
    {
        $this->dataSource = $dataSource;
        $this->dataSource->initialize($this);
    }