The associative array may contain the given values.
@param array $schema The optional schema.
@return Schemer\Validator\Assoc
353633
public function optional(array $schema) : Assoc
    {
        return $this->pipe(function (array $values) use ($schema) : Result {
            $result = Result::success();

            foreach ($schema as $key => $validator) {
                if (!isset($values[$key])) {
                    continue;
                }

                $result = $result->concat(
                    $validator
                        ->validate($values[$key])
                        ->map(function ($error) use ($key) {
                            return "$key: $error";
                        })
                );
            }

            return $result;
        });
    }
1167967
protected function validateSchemaType(LdapObjectSchema $schema, array $schemaArray)
    {
        if (!((bool)count(array_filter(array_keys($schemaArray['attributes']), 'is_string')))) {
            throw new SchemaParserException('The attributes for a schema should be an associative array.');
        }
        if ($schema->getScope() && !in_array($schema->getScope(), QueryOperation::SCOPE)) {
            throw new SchemaParserException(sprintf(
                'The scope "%s" is not valid. Valid types are: %s',
                $schema->getScope(),
                implode(', ', QueryOperation::SCOPE)
            ));
        }
    }
1374500
public static function definition($schema = null)
    {
        if (func_num_args()) {
            if (is_string($schema)) {
                static::$_definition = $schema;
            } elseif($schema) {
                static::$_definitions[static::class] = $schema;
            } else {
                unset(static::$_definitions[static::class]);
            }
            return;
        }
        $self = static::class;
        if (isset(static::$_definitions[$self])) {
            return static::$_definitions[$self];
        }
        $conventions = static::conventions();
        $config = [
            'connection'  => static::$_connection,
            'conventions' => $conventions,
            'class'       => $self,
            'locked'      => Document::class !== $self
        ];
        $config += ['source' => $conventions->apply('source', $self)];

        $class = static::$_definition;
        $schema = static::$_definitions[$self] = new $class($config);
        static::_define($schema);
        return $schema;
    }
1306511
public function schema($schema = null)
    {
        if (func_num_args() === 0) {
            return $this->collection->schema();
        }

        return $this->collection->schema($schema);
    }
1015491
public static function make($schema)
    {
        return new self(
            $schema,
            StringValidator::make($schema->getMeta()),
            FloatValidator::make($schema->getMeta()),
            IntValidator::make($schema->getMeta()),
            JsonValidator::make($schema->getMeta())
        );
    }
1161724
protected function addConversionToSchema(array $schema): array
    {
        if (isset($schema['definitions']['conversionItem'])) {
            $modules = Utility::getModules();
            if (!empty($modules)) {
                $rule = $schema['definitions']['conversionItem']['properties']['modules']['additionalProperties']['anyOf'][0];
                foreach ($modules as $module) {
                    $schema['definitions']['conversionItem']['properties']['modules']['additionalProperties'] = false;
                    $schema['definitions']['conversionItem']['properties']['modules']['properties'][$module] = $rule;
                }
            }
        }

        return $schema;
    }
1166113
private function findTableSchemas($schema = null)
    {
        $tableNames = $this->getTableNames($schema, true);

        if (is_callable($this->tableNameFilter)) {
            $tableNames = array_filter($tableNames,
                function($tableName) use ($schema) {
                    return call_user_func($this->tableNameFilter, $tableName, $schema);
                }
            );
        }

        $tableSchemas = array_map(
            function($tableName) use ($schema) {
                $tableSchema = new TableSchema();
                $tableNameFull = $schema === null ? $tableName : "$schema.$tableName";
                $this->resolveTableNames($tableSchema, $tableNameFull);
                return $tableSchema;
            },
            $tableNames);

        return $tableSchemas;
    }
1302054
public function normalize(Schema $schema): array
    {
        $this->schema = $schema;
        $schemaDesc = [];
        $schemaDesc['tables'] = [];
        foreach ($schema->getTables() as $table) {
            $schemaDesc['tables'][$table->getName()] = $this->normalizeTable($table);
        }
        return $schemaDesc;
    }
1000226
public function getSchema(): Schema
    {
        if ($this->schema === null) {
            $this->schema = new Schema($this);
        }

        return $this->schema;
    }
275876
protected function mapToSchema($value, string $schemaClass)
    {
        $value = (array) $value;
        $schema = Ioc::make($schemaClass);
        $mapper = Ioc::makeWith(self::class, compact('schema'));

        if (!isset($value[0])) {
            $value = [$value];
        }

        foreach ($value as $key => $subValue) {
            $value[$key] = $mapper->map($subValue);
        }

        return $value;
    }
912386
public function setSchema($schema)
    {
        $schema = array($schema);
        if (func_num_args() > 0) {
            $schema = func_get_args();
        }
        
        $error = Argument::i();
        foreach ($schema as $i => $name) {
            $error->test($i + 1, 'string');
        }
        
        $schema = implode(',', $schema);
        
        $query = $this->utility()->setSchema($schema);
        $this->query($query);
        
        return $this;
    }
65655
public static function create( $schema, $returnHtml = true )
    {
        $_schema = $schema;

        if ( !is_array( $_schema ) || ( is_string( $_schema ) && false === ( $_schema = json_decode( $schema, true ) ) ) )
        {
            throw new \InvalidArgumentException( 'You must provide a schema in either an array or a JSON string.' );
        }

        return static::_buildFormFields( $_schema, $returnHtml );
    }
904059
protected function hydrateSchemaFromAssoc(array $schema) {
		/** @var \Cake\ORM\AssociationCollection|\Cake\ORM\Association[] $associations */
		$associations = $this->getConfig('associations');

		foreach ($associations as $association) {
			try {
				$entityClass = '\\' . ltrim($association->getTarget()->getEntityClass(), '\\');

				if ($entityClass === '\Cake\ORM\Entity') {
					$namespace = Configure::read('App.namespace');

					list($plugin) = pluginSplit($association->getTarget()->getRegistryAlias());
					if ($plugin !== null) {
						$namespace = $plugin;
					}
					$namespace = str_replace('/', '\\', trim($namespace, '\\'));

					$entityClass = $this->_entityName($association->getTarget()->getAlias());
					$entityClass = '\\' . $namespace . '\Model\Entity\\' . $entityClass;

					if (!class_exists($entityClass)) {
						$entityClass = '\Cake\ORM\Entity';
					}
				}

				$schema[$association->getProperty()] = [
					'kind' => 'association',
					'association' => $association,
					'type' => $entityClass
				];
			} catch (Exception $exception) {
				continue;
			}
		}

		return $schema;
	}
378624
protected static function getDbKey($schema)
    {
        static $keys = [];
        
        if ($schema === null) {
            return null;
        }
        if (!$keys) {
            foreach (self::getDbConfig() as $key => $conf) {
                $keys[$conf['database']] = $key;
            }
        }
        return isset($keys[$schema]) ? $keys[$schema] : null;
    }
107750
private function replaceSchemas($array, $schemas)
    {
        if (!\is_array($array)) {
            return $array;
        }
        foreach ($array as $key => $value) {
            if ('schema' === $key) {
                if (isset($schemas[$value])) {
                    $array[$key] = $schemas[$value];
                }
            } else {
                $array[$key] = $this->replaceSchemas($value, $schemas);
            }
        }

        return $array;
    }
1363186
public function setSchema($schema)
    {
        if (!\is_string($schema) && !$schema instanceof SchemaDefinitionInterface) {
            throw new InvalidSchemaDefinitionException();
        }

        $this->schema = $schema;
    }
562646
protected function execSchema(Schema $schema)
    {
        $query = $schema->build($this->database);

        return $this->database->exec(trim($query));
    }