Skip to content

Conversation

AdamLenda
Copy link

@AdamLenda AdamLenda commented Mar 26, 2021

These changes extend the work that was done in https://github.com/reliese/laravel/pull/200/files

The new classes define a (hopefully) "idealized" representation of meta data from a database.

In the case of SchemaBlueprint it is a wrapper around a the existing Schema implementations.

The reason it is implemented as a "wrapper" is to ensure that previous implementations can be "adapted" to fit a new object model that organizes blueprints as a hierarchy of blueprints.

intended usage:

    public function handle()
    {
        $connection = $this->getConnection();
        $schema = $this->getSchema($connection);
        $table = $this->getTable();

        $schemaBlueprint = $this->blueprintFactory->database($connection)->schema($schema);

        $tableBlueprints = [];
        // Check whether we just need to generate one table
        if ($table) {
            $tableBlueprints[] = $schemaBlueprint->table($table);
        } else {
            $tableBlueprints = $schemaBlueprint->allTables($table);
        }
        
        /* TODO: allow command options to override the blueprint definition */

        // convert Blueprints into Model definitions
        $modelManager = new ModelManager($config);
        foreach ($tableBlueprints as $tableBlueprint) {
            $model = $this->modelFactory->fromTableBlueprint($tableBlueprint);
            $modelManager->addModel($model);
        }
        
        $modelManager->generateModelFiles();
        
    }

/**
* @var SchemaBlueprint[]
*/
private $schemaBlueprints;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though PHP might work this way, we should give an initial value to our variables.

Suggested change
private $schemaBlueprints;
private $schemaBlueprints = [];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants