LazyRecord\Schema\SchemaBase::getReferenceSchemas PHP Method

getReferenceSchemas() public method

For schema class, get its reference schema classes recursively.
public getReferenceSchemas ( boolean $recursive = true )
$recursive boolean
    public function getReferenceSchemas($recursive = true)
    {
        $schemas = [];
        foreach ($this->relations as $relKey => $rel) {
            if (!isset($rel['foreign_schema'])) {
                continue;
            }
            $class = ltrim($rel['foreign_schema'], '\\');
            if (isset($schemas[$class])) {
                continue;
            }
            if (!class_exists($class, true)) {
                throw new RuntimeException("Foreign schema class '{$class}' not found in schema {$this}.");
            }
            if (is_a($class, 'LazyRecord\\BaseModel', true)) {
                // bless model class to schema object.
                if (!method_exists($class, 'schema')) {
                    throw new Exception(get_class($this) . ": You need to define schema method in {$class} class.");
                }
                $schemas[$class] = 1;
                $model = new $class();
                $schema = new DynamicSchemaDeclare($model);
                if ($recursive) {
                    $schemas = array_merge($schemas, $schema->getReferenceSchemas(false));
                }
            } elseif (is_subclass_of($class, 'LazyRecord\\Schema\\DeclareSchema', true)) {
                $schemas[$class] = 1;
                $fs = new $class();
                if ($recursive) {
                    $schemas = array_merge($schemas, $fs->getReferenceSchemas(false));
                }
            } else {
                throw new InvalidArgumentException("Foreign schema class '{$class}' is not a SchemaDeclare class");
            }
        }
        return $schemas;
    }