Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Illuminate/Database/MigrationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ protected function registerMigrator()

return new Migrator($repository, $app['db'], $app['files'], $app['events']);
});
$this->app->bind(Migrator::class, fn ($app) => $app['migrator']);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would use Container@alias instead of bind.

Besides saving a closure call, as Migrator::class would be an alias to migrator, and migrator is a singleton, it would be automatically considered the same singleton.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe I tried it with a container alias, but because it's a singleton, $app->forget('migrator') still keeps the aliases version in memory.

15d884a

https://github.com/laravel/framework/actions/runs/14579501724/job/40892877095

Copy link
Contributor

Choose a reason for hiding this comment

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

That is weird, maybe we need to call $this->getAlias($abstract) when forgetting instances, much like is done when forgetting extenders:

/**
* Remove a resolved instance from the instance cache.
*
* @param string $abstract
* @return void
*/
public function forgetInstance($abstract)
{
unset($this->instances[$abstract]);
}

/**
* Remove all of the extender callbacks for a given type.
*
* @param string $abstract
* @return void
*/
public function forgetExtenders($abstract)
{
unset($this->extenders[$this->getAlias($abstract)]);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe that makes sense, however, that definitely belongs in a separate PR. Also potentially a breaking-change?

}

/**
Expand Down Expand Up @@ -220,7 +221,7 @@ protected function registerMigrateStatusCommand()
public function provides()
{
return array_merge([
'migrator', 'migration.repository', 'migration.creator',
'migrator', 'migration.repository', 'migration.creator', Migrator::class,
], array_values($this->commands));
}
}
16 changes: 16 additions & 0 deletions tests/Integration/Database/MigrationServiceProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Illuminate\Tests\Integration\Database;

use Illuminate\Database\Migrations\Migrator;

class MigrationServiceProviderTest extends DatabaseTestCase
{
public function testContainerCanBuildMigrator()
{
$fromString = $this->app->make('migrator');
$fromClass = $this->app->make(Migrator::class);

$this->assertSame($fromString, $fromClass);
}
}