Generates the mapping table between table names and class names.
@param CDbSchema $schema the database schema
@param string $pattern a regular expression that may be used to filter table names
192482
protected function generateClassNames($schema,$pattern=null)
	{
		$this->_tables=array();
		foreach($schema->getTableNames() as $name)
		{
			if($pattern===null)
				$this->_tables[$name]=$this->generateClassName($this->removePrefix($name));
			elseif(preg_match($pattern,$name,$matches))
			{
				if(count($matches)>1 && !empty($matches[1]))
					$className=$this->generateClassName($matches[1]);
				else
					$className=$this->generateClassName($matches[0]);
				$this->_tables[$name]=empty($className) ? $name : $className;
			}
		}
	}
522233
public function execute(Schema $schema)
    {
        $tables = $this->getSchemaTables();
        $instance = $this->getInstance();
        foreach ($tables as $table) {
            $columns = $this->getTableColumns($table['name']);
            $this->parseProperty($table['name'], $table['comment'], $columns, $schema, $instance);
        }
    }
33761
public function generate($schema, $className, Context $context)
    {
        $files = [];

        foreach ($schema->getClasses() as $class) {
            $properties = [];
            $methods    = [];

            foreach ($class->getProperties() as $property) {
                $properties[] = $this->createProperty($property->getName(), $property->getType(), $schema->getNamespace()."\\Model");
                $methods[]    = $this->createGetter($property->getName(), $property->getType(), $schema->getNamespace()."\\Model");
                $methods[]    = $this->createSetter($property->getName(), $property->getType(), $schema->getNamespace()."\\Model");
            }

            $model = $this->createModel(
                $class->getName(),
                $properties,
                $methods
            );

            $namespace = new Stmt\Namespace_(new Name($schema->getNamespace()."\\Model"), [$model]);

            $files[] = new File($schema->getDirectory().'/Model/'.$class->getName().'.php', $namespace, self::FILE_TYPE_MODEL);
        }

        return $files;
    }
452522
public function visitSchema(Schema $schema)
    {
        return new Schema(
            $this->transformConstraintArray($schema->constraints()),
            $schema->defaultValue(),
            $schema->title(),
            $schema->description()
        );
    }
1094481
protected String convertSchemaPattern(final String pattern) {
    if ((pattern == null) || pattern.isEmpty()) {
      return convertPattern("%", true);
    } else {
      return convertPattern(pattern, true);
    }
  }
818706
public function apply($schema, $columns = null, $notation = null)
    {
        //
        if (is_string($schema)) {
            $schema = [
                $schema => is_string($columns)
                    ? [$columns => $notation]
                    : $columns,
            ];
        }

        //
        if (!$schema || count($schema) == 0 || !is_array($schema)) {
            $this->error('generic', 'empty schema not allowed');
        }

        //
        foreach ($schema as $model => $attributes) {
            if (!$attributes || count($attributes) == 0 || !is_array($attributes)) {
                $this->error('generic', "empty model '{$model}' not allowed");
            }
        }

        // retrive queries
        $queries = $this->diff($schema);

        // send all queries to align database
        if (count($queries) > 0) {
            foreach ($queries as $sql) {
                $this->execute($sql);
            }
        }

        return $queries;
    }
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;
    }
562646
protected function execSchema(Schema $schema)
    {
        $query = $schema->build($this->database);

        return $this->database->exec(trim($query));
    }
953812
private function getSchemaByClass(string $schemaClass): JsonSchemaInterface
    {
        assert(static::classImplements($schemaClass, JsonSchemaInterface::class));

        if (array_key_exists($schemaClass, $this->schemaInstances) === false) {
            $this->schemaInstances[$schemaClass] =
                ($schema = new $schemaClass($this->getFactory(), $this, $this->getModelSchemas()));

            return $schema;
        }

        return $this->schemaInstances[$schemaClass];
    }
745975
protected function generateClassName($tableName, $useSchemaName = null)
    {
        if (isset($this->classNames[$tableName])) {
            return $this->classNames[$tableName];
        }

        $schemaName = '';
        $fullTableName = $tableName;
        if (($pos = strrpos($tableName, '.')) !== false) {
            if (($useSchemaName === null && $this->useSchemaName) || $useSchemaName) {
                $schemaName = substr($tableName, 0, $pos) . '_';
            }
            $tableName = substr($tableName, $pos + 1);
        }

        $db = $this->getDbConnection();
        $patterns = [];
        $patterns[] = "/^{$db->tablePrefix}(.*?)$/";
        $patterns[] = "/^(.*?){$db->tablePrefix}$/";
        if (strpos($this->tableName, '*') !== false) {
            $pattern = $this->tableName;
            if (($pos = strrpos($pattern, '.')) !== false) {
                $pattern = substr($pattern, $pos + 1);
            }
            $patterns[] = '/^' . str_replace('*', '(\w+)', $pattern) . '$/';
        }
        $className = $tableName;
        foreach ($patterns as $pattern) {
            if (preg_match($pattern, $tableName, $matches)) {
                $className = $matches[1];
                break;
            }
        }

        if ($this->standardizeCapitals) {
            $schemaName = ctype_upper(preg_replace('/[_-]/', '', $schemaName)) ? strtolower($schemaName) : $schemaName;
            $className = ctype_upper(preg_replace('/[_-]/', '', $className)) ? strtolower($className) : $className;
            $this->classNames[$fullTableName] = Inflector::camelize(Inflector::camel2words($schemaName.$className));
        } else {
            $this->classNames[$fullTableName] = Inflector::id2camel($schemaName.$className, '_');
        }

        if ($this->singularize) {
            $this->classNames[$fullTableName] = Inflector::singularize($this->classNames[$fullTableName]);
        }

        return $this->classNames[$fullTableName];
    }
453025
private function createTable(Schema $schema)
    {
        $table = $schema->createTable(RdsDeliveryExecutionService::TABLE_NAME);

        $table->addOption("engine", "InnoDB");
        $table->addOption("charset", "utf8");
        $table->addOption("collate", "utf8_unicode_ci");

        $this->createColumns($table);

        /**
         * Create index for the following methods
         * @see RdsDeliveryExecutionService::getExecutionsByDelivery()
         * @see RdsDeliveryExecutionService::getUserExecutions()
         */
        $this->createIndex($table, [
            RdsDeliveryExecutionService::COLUMN_DELIVERY_ID,
            RdsDeliveryExecutionService::COLUMN_USER_ID,
        ]);

        /**
         * Create index for the following methods
         * @see RdsDeliveryExecutionService::getDeliveryExecutionsByStatus()
         */
        $this->createIndex($table, [
            RdsDeliveryExecutionService::COLUMN_USER_ID,
        ]);
    }
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)
            ));
        }
    }
559673
protected static function annotateSchema($schema, $annotation, $path = '')
	{
		if (isset($schema['type']) && !isset($schema['_annotation'])) {
			$schema['_annotation'] = $annotation;
		}

		foreach (['properties', 'patternProperties'] as $p) {
			if (isset($schema[$p])) {
				foreach($schema[$p] as $k => & $v) {
					$v = static::annotateSchema($v, $annotation, $path.'/'.$p.'/'.$k);
				}
			}
		}

		foreach (['items', 'additionalProperties'] as $p) {
			if (isset($schema[$p])) {
				$schema[$p] = static::annotateSchema($schema[$p], $annotation, $path.'/'.$p);
			}
		}

		return $schema;
	}
1113488
public function addSchema(string $schema) : void
    {
        $work = $schema;
        if ($work{0} != '/') {
            $work = getcwd()."/$work";
        }
        if (!file_exists($work)) {
            $this->notice("`\"$schema\"` for `{$this->database}` not found, skipping.");
            return;
        }
        $this->schemas[] = file_get_contents($work);
        $this->success("Loaded $schema.");
    }
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;
    }
794875
protected function addRelationToSchema(array $schema, string $module): array
    {
        if (isset($schema['definitions']['relation'])) {
            $relations = Utility::getRealRelationFields($module);
            if (!empty($relations)) {
                $schema['definitions']['relation']['enum'] = $relations;
            }
        }

        return $schema;
    }
982406
public function createTable($table, $schema)
    {
        //
        $columnsArray = [];

        // loop throut schema
        foreach ($schema as $field => $attributes) {
            if (is_numeric($field) && is_string($attributes)) {
                $field = $attributes;
                $attributes = [];
            }

            //
            $column = $this->columnDefinition($attributes, false);

            //
            $columnsArray[] = "`{$field}` {$column}";
        }

        // implode
        $columns = implode(',', $columnsArray);

        // template sql to create table
        $sql = "CREATE TABLE `{$table}` ({$columns})";

        // return the sql
        return $sql;
    }