Returns whether a schema has already been processed and stored in
a given collection. This acts as an infinite recursion check.

@param stdClass          $schema
@param SplObjectStorage  $storage

@return bool
778282
private function isProcessed(stdClass $schema, SplObjectStorage $storage)
    {
        if ($storage->contains($schema)) {
            return true;
        }

        $storage->attach($schema);

        return false;
    }
774047
public function postUp(Schema $schema)
    {
        if (!$this->sm->tablesExist(['typo3_flow_resource_resource'])) {
            return;
        }
        $resourcesResult = $this->connection->executeQuery('SELECT persistence_object_identifier, sha1, filename FROM typo3_flow_resource_resource');
        while ($resourceInfo = $resourcesResult->fetch(\PDO::FETCH_ASSOC)) {
            $resourcePathAndFilename = FLOW_PATH_DATA . 'Persistent/Resources/' . $resourceInfo['sha1'];
            $newResourcePathAndFilename = FLOW_PATH_DATA . 'Persistent/Resources/' . $resourceInfo['sha1'][0] . '/' . $resourceInfo['sha1'][1] . '/' . $resourceInfo['sha1'][2] . '/' . $resourceInfo['sha1'][3] . '/' . $resourceInfo['sha1'];

            $mediaType = MediaTypes::getMediaTypeFromFilename($resourceInfo['filename']);
            if (file_exists($resourcePathAndFilename)) {
                $md5 = md5_file($resourcePathAndFilename);
                $filesize = filesize($resourcePathAndFilename);

                if (!file_exists(dirname($newResourcePathAndFilename))) {
                    Files::createDirectoryRecursively(dirname($newResourcePathAndFilename));
                }
                $result = @rename($resourcePathAndFilename, $newResourcePathAndFilename);
            } elseif (file_exists($newResourcePathAndFilename)) {
                $md5 = md5_file($newResourcePathAndFilename);
                $filesize = filesize($newResourcePathAndFilename);

                $result = true;
            } else {
                $this->write(sprintf('Error while migrating database for the new resource management: the resource file "%s" (original filename: %s) was not found, but the resource object with uuid %s needs this file.', $resourcePathAndFilename, $resourceInfo['filename'], $resourceInfo['persistence_object_identifier']));
                continue;
            }

            $this->connection->executeUpdate(
                'UPDATE typo3_flow_resource_resource SET collectionname = ?, mediatype = ?, md5 = ?, filesize = ? WHERE persistence_object_identifier = ?',
                array('persistent', $mediaType, $md5, $filesize, $resourceInfo['persistence_object_identifier'])
            );

            if ($result === false) {
                $this->write(sprintf('Could not move the data file of resource "%s" from its legacy location at %s to the correct location %s.', $resourceInfo['sha1'], $resourcePathAndFilename, $newResourcePathAndFilename));
            }
        }
        $this->connection->exec('ALTER TABLE typo3_flow_resource_resource CHANGE collectionname collectionname VARCHAR(255) NOT NULL, CHANGE mediatype mediatype VARCHAR(100) NOT NULL, CHANGE md5 md5 VARCHAR(32) NOT NULL, CHANGE filesize filesize NUMERIC(20, 0) NOT NULL');
    }
420432
function checkSchemaHasReferences(schema) {
  if (schema.$ref) {
    return true;
  }

  return Object.values(schema).some((value) => {
    if (_.isArray(value)) {
      return value.some(checkSchemaHasReferences);
    } else if (_.isObject(value)) {
      return checkSchemaHasReferences(value);
    }

    return false;
  });
}
1224581
public function visitSchema(Schema $schema)
    {
        $result = $this->result($schema);
        if (null !== $result) {
            return $result;
        }

        $result = $this->register($schema, $this->createResult());

        foreach ($schema->constraints() as $constraint) {
            $result = $result->merge($constraint->accept($this));
        }

        if ($result->isValid()) {
            $result->addMatch($this->createMatch($schema));
        }

        return $result;
    }
993791
private function validateAdditionalItems(array $subject, array $schema): bool
    {
        $subject = \array_slice($subject, count($schema['items']));

        if (\is_bool($schema['additionalItems'])) {
            return $this->validateAdditionalItemsSchemaBoolean($subject, $schema);
        }
        if (\is_int(\array_keys($schema['additionalItems'])[0])) {
            return $this->validateAdditionalItemsSchemaArray($subject, $schema);
        }
        return $this->validateAdditionalItemsSchemaObject($subject, $schema);
    }
1341716
public function validate(SchemaDescriptor $schema)
    {
        if ($prevSchema = SchemaStore::getPreviousSchema($schema->getId())) {
            if (!$prevSchema instanceof SchemaDescriptor) {
                throw new \RuntimeException(sprintf(
                    'Un-parsed schema "%s".',
                    $prevSchema['id']
                ));
            }

            /** @var \Gdbots\Pbjc\Validator\Constraint $constraint */
            foreach ($this->constraints as $constraint) {
                $constraint->validate($prevSchema, $schema);
            }
        }

        $constraint = new Constraint\SchemaDependencyVersion();
        $constraint->validate($schema, $schema);

        $constraint = new Constraint\SchemaInheritanceFields();
        $constraint->validate($schema, $schema);

        $constraint = new Constraint\FieldValidEnumValue();
        $constraint->validate($schema, $schema);
    }
176404
private function normalizeData($data, \stdClass $schema)
    {
        if (\is_array($data)) {
            return $this->normalizeArray(
                $data,
                $schema
            );
        }

        if ($data instanceof \stdClass) {
            return $this->normalizeObject(
                $data,
                $schema
            );
        }

        return $data;
    }
1221925
private function isFirstLevelIsDto(\JSONSchema\Structure\Schema $schema)
    {
        $isFirstLevelIsDto = false;

        foreach ($schema->getProperties() as $propertie) {
            if (in_array($propertie->getType(), array('object', 'array')) === false) {
                $isFirstLevelIsDto = true;
            }
        }

        return $isFirstLevelIsDto;
    }
106696
public boolean sameTypes(Schema schema) {
        if (schema.numColumns() != numColumns())
            return false;
        for (int i = 0; i < schema.numColumns(); i++) {
            if (getType(i) != schema.getType(i))
                return false;
        }

        return true;
    }
1147496
private function getCreateQueryFromSchema(GetSchema\Schema $schema)
    {
        $definition = $schema->getTableDefinition($this->fromExpr);
        $defSchema = $definition->getSchema();
        $parser = new PHPSQLParser(false, false, [Options::CONSISTENT_SUB_TREES => true]);
        $query = new CreateQuery(new Query($defSchema, $parser->parse($defSchema)));

        return $query->getObjectExpression();
    }
788400
protected function validateSchema(&$document_data, &$data, array $data_pointer, array $parent_data_pointer, ISchema $document, $schema, ValidationResult $bag): bool
    {
        if (is_bool($schema)) {
            if ($schema) {
                return true;
            }
            $bag->addError(new ValidationError($data, $data_pointer, $parent_data_pointer, $schema, '$schema', [
                'schema' => $schema
            ]));
            return false;
        }

        if (!is_object($schema)) {
            throw new InvalidSchemaException($schema);
        }

        if (property_exists($schema, '$ref') && is_string($schema->{'$ref'})) {
            return $this->validateRef($document_data, $data, $data_pointer, $parent_data_pointer, $document, $schema, $bag);
        }

        return $this->validateKeywords($document_data, $data, $data_pointer, $parent_data_pointer, $document, $schema, $bag);
    }
1036869
public static boolean isCreateTableAppropriate(final Datastore datastore, final Schema schema) {
        if (datastore == null || schema == null) {
            return false;
        }
        if (!(datastore instanceof UpdateableDatastore)) {
            return false;
        }
        if (datastore instanceof CsvDatastore) {
            // see issue https://issues.apache.org/jira/browse/METAMODEL-31 - as
            // long as this is an issue we do not want to expose "create table"
            // functionality to CSV datastores.
            return false;
        }
        if (MetaModelHelper.isInformationSchema(schema)) {
            return false;
        }
        return true;
    }
1083571
private function withSparseInternal($schema, \SplObjectStorage $schemas) {
        if ($schema instanceof Schema) {
            if ($schemas->contains($schema)) {
                return $schemas[$schema];
            } else {
                $schemas[$schema] = $sparseSchema = new Schema();
                $sparseSchema->schema = $schema->withSparseInternal($schema->schema, $schemas);
                if ($id = $sparseSchema->getID()) {
                    $sparseSchema->setID($id.'Sparse');
                }

                return $sparseSchema;
            }
        }

        unset($schema['required']);

        if (isset($schema['items'])) {
            $schema['items'] = $this->withSparseInternal($schema['items'], $schemas);
        }
        if (isset($schema['properties'])) {
            foreach ($schema['properties'] as $name => &$property) {
                $property = $this->withSparseInternal($property, $schemas);
            }
        }

        return $schema;
    }
310930
JMFSchema findSchema(long schemaId) throws MessageStoreException {
    Long storeId = schemaIndex.get(Long.valueOf(schemaId));
    if (storeId != null) {
      AbstractItem item = findById(storeId.longValue());
      return ((SchemaStoreItem)item).getSchema();
    } else
      throw new MessageStoreException("Schema not found in store: " + schemaId);
  }
846506
public function has(string $field): bool
    {
        if (is_array($this->storage)) {
            return array_key_exists($field, $this->storage);
        }

        return $this->storage->offsetExists($field);
    }
349175
public function hasTable($table)
    {
        [$schema, $table] = $this->parseSchemaAndTable($table);

        $table = $this->connection->getTablePrefix().$table;

        return count($this->connection->select(
            $this->grammar->compileTableExists(), [$schema, $table]
        )) > 0;
    }
179296
public function upgradeSchema(Schema $schema)
    {
        /* refresh CollectionVersionBlocks, CollectionVersionBlocksCacheSettings tables */
        $cvb = $schema->getTable('CollectionVersionBlocks');
        if (!$cvb->hasColumn('cbOverrideBlockTypeCacheSettings')) {
            $cvb->addColumn('cbOverrideBlockTypeCacheSettings', 'boolean', ['default' => 0]);
        }

        if (!$schema->hasTable('CollectionVersionBlocksCacheSettings')) {
            $cvbcs = $schema->createTable('CollectionVersionBlocksCacheSettings');
            $cvbcs->addColumn('cID', 'integer', ['notnull' => true, 'unsigned' => true, 'default' => 0]);
            $cvbcs->addColumn('cvID', 'integer', ['notnull' => true, 'unsigned' => true, 'default' => 1]);
            $cvbcs->addColumn('bID', 'integer', ['notnull' => true, 'unsigned' => true, 'default' => 0]);
            $cvbcs->addColumn('arHandle', 'string', ['notnull' => false]);
            $cvbcs->addColumn('btCacheBlockOutput', 'boolean', ['default' => 0]);
            $cvbcs->addColumn('btCacheBlockOutputOnPost', 'boolean', ['default' => 0]);
            $cvbcs->addColumn('btCacheBlockOutputForRegisteredUsers', 'boolean', ['default' => 0]);
            $cvbcs->addColumn('btCacheBlockOutputLifetime', 'integer', ['notnull' => true, 'unsigned' => true, 'default' => 0]);
            $cvbcs->setPrimaryKey(['cID', 'cvID', 'bId', 'arHandle']);
        }
    }