Skip to content

Commit d57f03e

Browse files
authored
Merge pull request vyuldashev#57 from zlodes/service-provider-refactoring
Move bindings to the register method
2 parents 177693c + 1e2a985 commit d57f03e

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

src/OpenApiServiceProvider.php

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Vyuldashev\LaravelOpenApi;
66

7+
use Illuminate\Contracts\Foundation\Application;
78
use Illuminate\Support\Collection;
89
use Illuminate\Support\ServiceProvider;
910
use Vyuldashev\LaravelOpenApi\Builders\Components\CallbacksBuilder;
@@ -19,13 +20,12 @@
1920

2021
class OpenApiServiceProvider extends ServiceProvider
2122
{
22-
public function boot(): void
23+
public function register(): void
2324
{
24-
if ($this->app->runningInConsole()) {
25-
$this->publishes([
26-
__DIR__.'/../config/openapi.php' => config_path('openapi.php'),
27-
], 'openapi-config');
28-
}
25+
$this->mergeConfigFrom(
26+
__DIR__.'/../config/openapi.php',
27+
'openapi'
28+
);
2929

3030
$this->app->bind(CallbacksBuilder::class, function () {
3131
return new CallbacksBuilder($this->getPathsFromConfig('callbacks'));
@@ -47,29 +47,19 @@ public function boot(): void
4747
return new SecuritySchemesBuilder($this->getPathsFromConfig('security_schemes'));
4848
});
4949

50-
$this->app->singleton(Generator::class, static function ($app) {
50+
$this->app->singleton(Generator::class, static function (Application $app) {
5151
$config = config('openapi');
5252

5353
return new Generator(
5454
$config,
55-
$app[InfoBuilder::class],
56-
$app[ServersBuilder::class],
57-
$app[TagsBuilder::class],
58-
$app[PathsBuilder::class],
59-
$app[ComponentsBuilder::class]
55+
$app->make(InfoBuilder::class),
56+
$app->make(ServersBuilder::class),
57+
$app->make(TagsBuilder::class),
58+
$app->make(PathsBuilder::class),
59+
$app->make(ComponentsBuilder::class)
6060
);
6161
});
6262

63-
$this->loadRoutesFrom(__DIR__.'/../routes/api.php');
64-
}
65-
66-
public function register(): void
67-
{
68-
$this->mergeConfigFrom(
69-
__DIR__.'/../config/openapi.php',
70-
'openapi'
71-
);
72-
7363
$this->commands([
7464
Console\GenerateCommand::class,
7565
]);
@@ -87,6 +77,17 @@ public function register(): void
8777
}
8878
}
8979

80+
public function boot(): void
81+
{
82+
if ($this->app->runningInConsole()) {
83+
$this->publishes([
84+
__DIR__.'/../config/openapi.php' => config_path('openapi.php'),
85+
], 'openapi-config');
86+
}
87+
88+
$this->loadRoutesFrom(__DIR__.'/../routes/api.php');
89+
}
90+
9091
private function getPathsFromConfig(string $type): array
9192
{
9293
$directories = config('openapi.locations.'.$type, []);

0 commit comments

Comments
 (0)