Returns the native class path for the SchemaDescriptor
by combining native namespace and class name with major.

@example
es6: @acme/schemas/acme/blog/node/ArticleV1
php: Acme\Schemas\Blog\Node\ArticleV1

@param SchemaDescriptor $schema

@return string
506896
public function schemaToNativeClassPath(SchemaDescriptor $schema)
    {
        $path = $this->schemaToNativeNamespace($schema);
        $class = $this->schemaToClassName($schema, true);
        $delim = 'php' === static::LANGUAGE ? '\\' : '/';
        return "{$path}{$delim}{$class}";
    }
1094385
public function getFieldDefinition(Schema $schema, ObjectType $parentType, string $fieldName): ?Field
    {
        if ($fieldName === '__schema' && $schema->getQueryType() === $parentType) {
            return SchemaMetaFieldDefinition();
        }

        if ($fieldName === '__type' && $schema->getQueryType() === $parentType) {
            return TypeMetaFieldDefinition();
        }

        if ($fieldName === '__typename') {
            return TypeNameMetaFieldDefinition();
        }

        $fields = $parentType->getFields();

        return $fields[$fieldName] ?? null;
    }
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;
    }
1171733
private function getMixinSchemas(SchemaDescriptor $schema)
    {
        $schemaIds = [];

        foreach ($schema->getMixins() as $mixin) {
            $schemaIds[] = $mixin->getId()->getCurieWithMajorRev();

            $schemaIds = array_merge(
                $schemaIds,
                $this->getExtendsSchemas($mixin),
                $this->getMixinSchemas($mixin)
            );
        }

        return $schemaIds;
    }
1133511
public function getSchemaTableRecordCount($schema = null)
    {
        // information schema query
        $query = sprintf(
            'SELECT table_name, table_rows FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = "%s"',
            $schema
        );

        // send query
        return $this->resource->query($query);
    }
1305022
public function getDescriptor(string $classNamespace): ?Descriptor
    {
        if (!$this->isEmpty()) {
            /** @var Descriptor $descriptor */
            foreach ($this as $rootNamespace => $descriptor) {
                $rootNamespace = $descriptor->getRootNamespace();

                $doubleSlashed = str_replace('\\', '\\\\', $rootNamespace);
                $pattern = sprintf('|^%s\\.*|', $doubleSlashed);

                if (preg_match($pattern, $classNamespace)) {
                    return $descriptor;
                }
            }
        }

        return null;
    }
1345820
public function getTypeForDOMNode( $node )
	{
		$ns = $node->namespaceURI;
		if ( ! $ns )
		{
			if ( $node instanceof \DOMElement )
			{
				// Get the default namespace for the DOMNode
				$doc = $node->ownerDocument;
				/**
				 * @var DOMNode $firstChild
				 */
				$firstChild = $doc->documentElement;
				$ns = $firstChild->getAttributeNode('xmlns')
					? $firstChild->getAttributeNode('xmlns')->nodeValue
					: "";
			}
			else if ( $node instanceof \DOMAttr )
			{
				$parent = $node->parentNode;
				if ( $parent )
				{
					$ns = $parent->namespaceURI;
				}
			}
		}

		$prefix = $this->getPrefixForNamespace( $ns );
		$types;

		if ( is_a( $node, "DOMElement" ) )
		{
			$el = $this->getElement( $node->localName, $prefix );
			if ( $el === false ) throw new SchemaException( "Unable to locate element '{$node->localName}' in the schema types" );
			$types = isset( $el['types'] ) ? $el['types'] : array();
		}
		else if ( is_a( $node, "DOMAttr" ) )
		{
			$attr = $this->getAttribute( $node->localName, $prefix );
			if ( $attr === false ) throw new SchemaException( "Unable to locate attribute '{$node->localName}' in the schema types" );
			$types = isset( $attr['types'] ) ? $attr['types'] : array();
		}
		else if ( is_a( $node, "DOMDocument" ) )
		{
			throw new SchemaException("Getting the type for a Document node is not supported");
		}
		else if ( is_a( $node, "DOMComment" ) )
		{
			// BMS 2018-04-09 Test candidates changed.
			return "xs:string";
		}
		else if ( is_a( $node, "DOMProcessingInstruction" ) )
		{
			throw new SchemaException("Getting the type for a Processing Instruction node is not supported");
		}
		else if ( is_a( $node, "DOMText" ) )
		{
			// BMS 2018-04-09 Test candidates changed.
			return "xs:string";
		}
		else if ( is_a( $node, "DOMNameSpaceNode" ) )
		{
			throw new SchemaException("Getting the type for a Namespace node is not supported");
		}

		// Get the first simple type
		$type = null;
		foreach ( $types as $xmlType )
		{
			if ( is_array( $xmlType ) )
			{
				if ( isset( $xmlType['class'] ) && $xmlType['class'] == "complex" )
				{
					continue;
				}

				if ( isset( $xmlType['contentType'] ) && $xmlType['contentType'] == "extension" && isset( $xmlType['base'] ) )
				{
					return $xmlType['parent'];
				}

				if ( isset( $xmlType['contentType'] ) && $xmlType['contentType'] == "restriction" && isset( $xmlType['base'] ) )
				{
					return $xmlType['parent'];
				}
			}

			return $xmlType;
		}

		return false;
	}
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);
    }
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;
    }
333711
private function describeTable($name, $schema)
    {
        $data = $this->connector->getQueryAsSingleRow(
                'SELECT t.table_schema AS table_schema, t.table_name AS table_name, t.engine AS engine,
                        t.auto_increment AS auto_increment, t.table_collation AS table_collation,
                        t.table_comment AS table_comment, cs.character_set_name AS table_charset,
                        t.create_options AS create_options
                   FROM information_schema.tables t, information_schema.character_sets cs
                  WHERE t.table_schema=\'%schema$s\'
                    AND t.table_name = \'%table$s\'
                    AND t.table_collation = cs.default_collate_name',
                array(
                    'schema' => $schema,
                    'table' => $name
                )
        );

        if (is_array($data)) {
            $fields = $this->describeTableFields($name, $schema);
            $table['schema'] = $data['table_schema'];
            $table['name'] = $data['table_name'];
            $table['engine'] = $data['engine'];
            $table['type'] = CMySQLConnector::TYPE_TABLE;
            $table['autoincrement'] = $this->validateAutoIncrement($data['auto_increment'], $fields);
            $table['charset'] = $data['table_charset'];
            $table['collation'] = $data['table_collation'];
            $table['create_options'] = $data['create_options'];
            $table['comment'] = $data['table_comment'];
            $table['fields'] = $fields;
            $table['constraints'] = $this->describeTableConstraints($name, $table['fields'], $schema);
            $descriptor = new CMySQLDescriptor($this->connector, $table);
        } else {
            $descriptor = null;
        }

        return $descriptor;
    }
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;
    }
115508
public static function schema(){
        $classname = get_called_class();
        if(!array_key_exists($classname, self::$schemas)){
            $schema = new SchemaBuilder(static::table());
            static::define($schema);
            self::$schemas[$classname] = $schema;
        }
        return self::$schemas[$classname];
    }
940978
public function getTableFieldInformationName($schema, $name)
    {
        return $this
            ->getTableFieldInformationWhere(
                Where::create("cla.relname = $*", [$name])
                    ->andWhere("clns.nspname = $*", [$schema])
            );
    }
301328
public static function fromTableSchema(TableSchema $schema)
    {
        $properties = [];
        $required = [];
        foreach ($schema->getColumns() as $column) {
            if ($column->getRequired()) {
                $required[] = $column->getName();
            }

            $properties[$column->getName()] = static::fromColumnSchema($column);
        }

        return [
            'type'       => 'object',
            'required'   => $required,
            'properties' => $properties
        ];
    }
610342
public function parse($schema)
    {
        $fields = $this->splitIntoFields($schema);

        foreach ($fields as $field) {
            $segments = $this->parseSegments($field);

            if ($this->fieldNeedsForeignConstraint($segments)) {
                unset($segments['options']['foreign']);

                // If the user wants a foreign constraint, then
                // we'll first add the regular field.
                $this->addField($segments);

                // And then add another field for the constraint.
                $this->addForeignConstraint($segments);

                continue;
            }

            $this->addField($segments);
        }

        return $this->schema;
    }
69637
public function getClassPath($class)
    {
        $segments          = explode('_', $class);
        $namespaceTopLevel = $this->getNamespace();
        $namespace         = '';

        if (!empty($namespaceTopLevel)) {
            $namespace = array();
            $topLevelSegments = count(explode('_', $namespaceTopLevel));
            for ($i = 0; $i < $topLevelSegments; $i++) {
                $namespace[] = array_shift($segments);
            }
            $namespace = implode('_', $namespace);
            if ($namespace != $namespaceTopLevel) {
                // wrong prefix? we're done
                return false;
            }
        }

        if (count($segments) < 2) {
            // assumes all resources have a component and class name, minimum
            return false;
        }

        $final     = array_pop($segments);
        $component = $namespace;
        $lastMatch = false;
        do {
            $segment    = array_shift($segments);
            $component .= empty($component) ? $segment : '_' . $segment;
            if (isset($this->_components[$component])) {
                $lastMatch = $component;
            }
        } while (count($segments));

        if (!$lastMatch) {
            return false;
        }

        $final = substr($class, strlen($lastMatch) + 1);
        $path = $this->_components[$lastMatch];
        $classPath = $path . '/' . str_replace('_', '/', $final) . '.php';

        if (Zend_Loader::isReadable($classPath)) {
            return $classPath;
        }

        return false;
    }
1272591
def fromSchema(self, schema):
        ''' 
        '''  
        ns = schema.getTargetNamespace()
        assert self.targetNamespace is None or self.targetNamespace == ns,\
            'SchemaDescription instance represents %s, not %s'\
            %(self.targetNamespace, ns)

        if self.targetNamespace is None:
            self.targetNamespace = ns
 
        self.classHead.ns = self.classFoot.ns = ns
        for item in [t for t in schema.types if t.getAttributeName() not in self.__types]:
            self.__types.append(item.getAttributeName())
            self.items.append(TypeWriter(do_extended=self.do_extended, extPyClasses=self.extPyClasses))
            self.items[-1].fromSchemaItem(item)

        for item in [e for e in schema.elements if e.getAttributeName() not in self.__elements]:
            self.__elements.append(item.getAttributeName())
            self.items.append(ElementWriter(do_extended=self.do_extended))
            self.items[-1].fromSchemaItem(item)