diff --git a/docs/Package.md b/docs/Package.md index 9fc7bd1..13875ac 100644 --- a/docs/Package.md +++ b/docs/Package.md @@ -171,7 +171,7 @@ $plugin->boot(); static::assertTrue($myService->isBooted()); ``` -### Deprecated boot parameters +### Removed boot parameters Before Modularity v1.7.0, it was an accepted practice to pass default modules to `Package::boot()`, as in: @@ -185,14 +185,17 @@ add_action( ); ``` -This is now deprecated to allow a better separation of the "building" and "booting" steps. +This is now removed to allow a better separation of the "building" and "booting" steps. While it still works (and it will work up to version 2.0), it will emit a deprecation notice. The replacement is using `Package::addModule()`: ```php -plugin()->addModule(new ModuleOne())->addModule(new ModuleTwo())->boot(); +plugin() + ->addModule(new ModuleOne()) + ->addModule(new ModuleTwo()) + ->boot(); ``` There's only one case in which calling `Package::boot()` with default modules will throw an diff --git a/src/Package.php b/src/Package.php index 91b7654..2184d96 100644 --- a/src/Package.php +++ b/src/Package.php @@ -357,15 +357,16 @@ public function build(): Package } /** - * @param Module ...$defaultModules Deprecated, use `addModule()` to add default modules. * @return bool */ - public function boot(Module ...$defaultModules): bool + public function boot(): bool { try { // Call build() if not called yet, and ensure any new module passed here is added // as well, throwing if the container was already built. - $this->doBuild(...$defaultModules); + if (!$this->built) { + $this->build(); + } // Don't allow booting the application multiple times. $this->assertStatus(self::STATUS_BOOTING, 'boot application', '<'); @@ -392,60 +393,6 @@ public function boot(Module ...$defaultModules): bool return true; } - /** - * @param Module ...$defaultModules - * @return void - */ - private function doBuild(Module ...$defaultModules): void - { - if ($defaultModules) { - $this->deprecatedArgument( - sprintf( - 'Passing default modules to %1$s::boot() is deprecated since version 1.7.0.' - . ' Please add modules via %1$s::addModule().', - __CLASS__ - ), - __METHOD__, - '1.7.0' - ); - } - - if (!$this->built) { - $defaultModules and array_map([$this, 'addModule'], $defaultModules); - $this->build(); - - return; - } - - if ( - !$defaultModules - || ($this->checkStatus(self::STATUS_INITIALIZED, '>')) - || ($this->statusIs(self::STATUS_FAILED)) - ) { - // If we don't have default modules, there's nothing to do, and if the status is beyond - // initialized or is failed, we do nothing as well and let `boot()` throw. - return; - } - - $backup = $this->status; - - try { - // simulate idle status to prevent `addModule()` from throwing - // only if we don't have a container yet - $this->hasContainer or $this->status = self::STATUS_IDLE; - - foreach ($defaultModules as $defaultModule) { - // If a module was added by `build()` or `addModule()` we can skip it, a - // deprecation was trigger to make it noticeable without breakage - if (!$this->moduleIs($defaultModule->id(), self::MODULE_ADDED)) { - $this->addModule($defaultModule); - } - } - } finally { - $this->status = $backup; - } - } - /** * @param Module $module * @param string $status diff --git a/tests/unit/PackageTest.php b/tests/unit/PackageTest.php index 75a9811..0c07711 100644 --- a/tests/unit/PackageTest.php +++ b/tests/unit/PackageTest.php @@ -231,29 +231,6 @@ public function testBootWithExecutableModuleFailed(): void static::assertTrue($package->moduleIs($moduleId, Package::MODULE_EXECUTION_FAILED)); } - /** - * @test - * @runInSeparateProcess - */ - public function testBootPassingModulesEmitDeprecation(): void - { - $module1 = $this->stubModule('module_1', ServiceModule::class); - $module1->allows('services')->andReturn($this->stubServices('service_1')); - - $package = Package::new($this->stubProperties('test', true)); - - $this->convertDeprecationsToExceptions(); - try { - $count = 0; - $package->boot($module1); - } catch (\Throwable $throwable) { - $count++; - $this->assertThrowableMessageMatches($throwable, 'boot().+?deprecated.+?1\.7'); - } finally { - static::assertSame(1, $count); - } - } - /** * @test */ @@ -821,35 +798,6 @@ public function run(ContainerInterface $container): bool static::assertSame('Works!', $actual); } - /** - * @test - */ - public function testBuildPassingModulesToBoot(): void - { - $module1 = $this->stubModule('module_1', ServiceModule::class); - $module1->expects('services')->andReturn($this->stubServices('service_1')); - - $module2 = $this->stubModule('module_2', ServiceModule::class); - $module2->expects('services')->andReturn($this->stubServices('service_2')); - - $module3 = $this->stubModule('module_3', ServiceModule::class); - $module3->expects('services')->andReturn($this->stubServices('service_3')); - - $package = Package::new($this->stubProperties('test', true)) - ->addModule($module1) - ->addModule($module2) - ->build(); - - $this->ignoreDeprecations(); - $package->boot($module2, $module3); - - $container = $package->container(); - - static::assertSame('service_1', $container->get('service_1')['id']); - static::assertSame('service_2', $container->get('service_2')['id']); - static::assertSame('service_3', $container->get('service_3')['id']); - } - /** * @test */ @@ -875,8 +823,7 @@ public function testBootFailsIfPassingNotAddedModulesAfterContainer(): void static::assertSame('service_2', $container->get('service_2')['id']); $this->expectExceptionMessageMatches("/can't add module module_3/i"); - $this->ignoreDeprecations(); - $package->boot($module2, $module3); + $package->addModule($module3); } /**