From 515ca53255390582c70b5b1748fc901a752144e8 Mon Sep 17 00:00:00 2001 From: Schiopu Alexandru <44147615+thenotsoft@users.noreply.github.com> Date: Mon, 16 Sep 2024 09:33:22 +0300 Subject: [PATCH] Add method `addVendorDirectory` in `MigrationsBootloader` (#94) --- src/Bootloader/MigrationsBootloader.php | 18 ++++++++++++++++-- .../Bootloader/MigrationsBootloaderTest.php | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Bootloader/MigrationsBootloader.php b/src/Bootloader/MigrationsBootloader.php index ac4059f..7d14e22 100644 --- a/src/Bootloader/MigrationsBootloader.php +++ b/src/Bootloader/MigrationsBootloader.php @@ -17,6 +17,7 @@ use Spiral\Boot\DirectoriesInterface; use Spiral\Boot\EnvironmentInterface; use Spiral\Config\ConfiguratorInterface; +use Spiral\Config\Patch\Append; use Spiral\Tokenizer\Bootloader\TokenizerBootloader; final class MigrationsBootloader extends Bootloader @@ -33,8 +34,12 @@ final class MigrationsBootloader extends Bootloader GeneratorStrategyInterface::class => [self::class, 'initGeneratorStrategy'], ]; + public function __construct( + private readonly ConfiguratorInterface $config, + ) { + } + public function init( - ConfiguratorInterface $config, EnvironmentInterface $env, DirectoriesInterface $dirs ): void { @@ -42,10 +47,11 @@ public function init( $dirs->set('migrations', $dirs->get('app') . 'migrations'); } - $config->setDefaults( + $this->config->setDefaults( MigrationConfig::CONFIG, [ 'directory' => $dirs->get('migrations'), + 'vendorDirectories' => [], 'strategy' => SingleFileStrategy::class, 'nameGenerator' => NameBasedOnChangesGenerator::class, 'table' => 'migrations', @@ -54,6 +60,14 @@ public function init( ); } + public function addVendorDirectory(string $directory): void + { + $this->config->modify( + MigrationConfig::CONFIG, + new Append('vendorDirectories', null, $directory), + ); + } + private function initGeneratorStrategy( MigrationConfig $config, ContainerInterface $container diff --git a/tests/src/Bootloader/MigrationsBootloaderTest.php b/tests/src/Bootloader/MigrationsBootloaderTest.php index a3bbc1e..3a6e342 100644 --- a/tests/src/Bootloader/MigrationsBootloaderTest.php +++ b/tests/src/Bootloader/MigrationsBootloaderTest.php @@ -30,6 +30,7 @@ public function testGetsDefaultConfig(): void $this->assertDirectoryAliasDefined('migrations'); $this->assertSame([ 'directory' => $this->getDirectoryByAlias('migrations'), + 'vendorDirectories' => [], 'strategy' => SingleFileStrategy::class, 'nameGenerator' => NameBasedOnChangesGenerator::class, 'table' => 'migrations',