Adds extra settings values from the schema as they may be used by the validator as well as other things.

@param mixed $params
@param array $schema

@return array
488940
static function parseParams($params, $schema) {
    $params = (array) $params;

    foreach (array_diff_key($schema, ['_validate' => 1]) as $k => $v) if (preg_match('/^_/', $k)) $params[$k] = $v;

    return $params;
  }
486085
function setOptions(schema, options) {
  function setDefaults(array) {
    if (!array.length) {
      if (options.find) { array.push('find'); }
      if (options.findOne || !options.find) { array.push('findOne'); }
    }
  }

  options = options || {};

  options.only = options.only || [];
  options.validateBeforeSave = options.validateBeforeSave === undefined
                                ? schema.options.validateBeforeSave
                                : Boolean(options.validateBeforeSave);

  ['virtual', 'attach', 'modify'].filter(prop => options[prop])
    .forEach(
      prop => {
        if (typeof options[prop] !== 'object') {
          options[prop] = {};
        }
        options[prop].properties = options[prop].properties || {};
        options[prop].only = options[prop].only || Object.keys(options[prop].properties);
      }
    );

  if (options.modify) {
    delete options.modify.properties;
    options.modify.on = options.modify.on || [];
    setDefaults(options.modify.on);
  }
  if (options.attach) {
    Object.keys(options.attach.properties).forEach(property => {
      options.attach.properties[property].on = options.attach.properties[property].on || [];
      setDefaults(options.attach.properties[property].on);
    });
  }

  return options;
}
508103
protected function callSchema($schema)
    {
        if (!$schema instanceof Schema && is_callable($schema)) {
            $s = $this->getSchema();

            $schema($s);

            $schema = $s;
        }

        if (!$schema instanceof Schema) {
            throw new \InvalidArgumentException('Argument 1 should be Schema object.');
        }

        return $schema;
    }
1313092
public function setSchema(Schema $schema)
    {
        $this->schema = $schema;

        if (!$this->getSchema()->hasTable($this->getName())) {
            $this->getSchema()->addTable($this);
        }
    }
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;
    }
268208
public function add($schema, $definition)
    {
        if(is_array($definition)) $definition = (object)$definition;
        $this->__schemas__[$schema] = $definition;
        $this->compile();
        return $this;
    }
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;
    }
1306929
protected function validateObjectSchema($schema)
    {
        if (empty($schema->getAttributeMap())) {
            throw new SchemaParserException(sprintf('Object type "%s" has no attributes defined.', $schema->getObjectType()));
        } elseif (!((bool)count(array_filter(array_keys($schema->getAttributeMap()), '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)
            ));
        }
    }
81625
private function getExtendsSchemas(SchemaDescriptor $schema)
    {
        $schemaIds = [];

        $check = $schema->getExtends();
        while ($check) {
            $schemaIds[] = $check->getId()->getCurieWithMajorRev();

            $check = $check->getExtends();
        }

        return $schemaIds;
    }
1302625
protected function validateSchema($schema)
    {
        if (!is_string($schema) || trim($schema) == '') {
            throw new Exception\InvalidArgumentException(__METHOD__ . ': Schema name must be a valid string or an empty string detected');
        }

        return $this;
    }
455086
protected function addFieldsToSchema(array $schema, string $module): array
    {
        if (isset($schema['definitions']['fieldName'])) {
            $fields = Utility::getRealModuleFields($module, false);
            if (!empty($fields)) {
                $schema['definitions']['fieldName']['enum'] = $fields;
            }
        }

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

        return $this->database->exec(trim($query));
    }
85449
private function diffTableQueries($table, &$schema)
    {
        // first order queries used as output array
        $foQueries = [];

        // second order queries used as output array
        $soQueries = [];

        // describe table get current table description
        $fields = $this->descTable($table);

        // test field definition
        foreach ($schema as $field => &$attributes) {
            $this->diffTableField(
                $table,
                $field,
                $attributes,
                $fields,
                $foQueries,
                $soQueries
            );
        }

        return $this->diffTableMergeQueries(
            $table,
            $fields,
            $foQueries,
            $soQueries
        );
    }
1182650
public function getSchemaTables(Schema $schema)
    {
        $tables = [];
        foreach ($this->tables->keys() as $name) {
            /** @var BaseTable $table */
            $table = $this->tables[$name];
            $tables[$name] = $table->buildTable($schema, $name, $this->charset, $this->collate);
        }

        return $tables;
    }
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;
    }
1043542
public function updateDataSchema(&$schema)
    {
        // The keys from the SecurityAlert model that we need in the React component
        $keysToPass = ['Identifier', 'ExternalLink'];

        $alerts = [];
        foreach ($this->owner->SecurityAlerts()->toNestedArray() as $alert) {
            $alerts[] = array_intersect_key($alert, array_flip($keysToPass));
        }

        $schema['securityAlerts'] = $alerts;
    }
45891
public function parse($schema)
    {
        $this->schema = $schema;
        $parsed = [];
        foreach ($this->getSchemas() as $schemaArray) {
            $column = $this->getColumn($schemaArray);
            $attributes = $this->getAttributes($column, $schemaArray);
            $parsed[$column] = $attributes;
        }

        return $parsed;
    }