Skip to content

Commit

Permalink
Add CacheOpenAPI commands
Browse files Browse the repository at this point in the history
Provide Membrane with CachedBuilders
  • Loading branch information
charjr committed Jan 16, 2024
1 parent 3602c85 commit 9df8379
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
21 changes: 21 additions & 0 deletions config/membrane.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,25 @@
'validation_error_response_type' => 'about:blank',
'api_problem_response_types' => [],

/*
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
|
|
|
*/
'routes_file' => base_path() . '/cache/routes.php',

/*
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
|
|
|
*/
'additional_builders' => [],
];
27 changes: 27 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

namespace Membrane\Laravel;

use Membrane\Builder\Builder;
use Membrane\Console\Command\CacheOpenAPIProcessors;
use Membrane\Laravel\Middleware\RequestValidation;
use Membrane\Membrane;
use Membrane\OpenAPIRouter\Console\Commands\CacheOpenAPI;
use Membrane\OpenAPIRouter\Router\Router;
use Membrane\OpenAPIRouter\Router\ValueObject\RouteCollection;

class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
Expand All @@ -15,6 +21,10 @@ public function boot(): void
{
/** @phpstan-ignore-next-line */ // config_path is a laravel framework helper method
$this->publishes([self::CONFIG_PATH => config_path('membrane.php')], [self::CONFIG_NAME]);

if ($this->app->runningInConsole()) {
$this->commands([CacheOpenAPI::class, CacheOpenAPIProcessors::class]);

Check failure on line 26 in src/ServiceProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.1, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Class Membrane\OpenAPIRouter\Console\Commands\CacheOpenAPI not found.

Check failure on line 26 in src/ServiceProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Class Membrane\OpenAPIRouter\Console\Commands\CacheOpenAPI not found.

Check failure on line 26 in src/ServiceProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.3, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Class Membrane\OpenAPIRouter\Console\Commands\CacheOpenAPI not found.

Check failure on line 26 in src/ServiceProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.1, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Class Membrane\OpenAPIRouter\Console\Commands\CacheOpenAPI not found.

Check failure on line 26 in src/ServiceProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Class Membrane\OpenAPIRouter\Console\Commands\CacheOpenAPI not found.

Check failure on line 26 in src/ServiceProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.3, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Class Membrane\OpenAPIRouter\Console\Commands\CacheOpenAPI not found.
}
}

public function register(): void
Expand All @@ -34,5 +44,22 @@ public function register(): void
$this->app->when(ApiProblemBuilder::class)
->needs('$apiProblemTypes')
->giveConfig('membrane.api_problem_response_types');

$this->app->when(Membrane::class)
->needs('$builders')
->give(...$this->instantiateBuilders());

Check failure on line 50 in src/ServiceProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.1, lowest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Parameter #1 $implementation of method Illuminate\Contracts\Container\ContextualBindingBuilder::give() expects array|Closure|string, Membrane\Builder\Builder given.

Check failure on line 50 in src/ServiceProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.1, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Parameter #1 $implementation of method Illuminate\Contracts\Container\ContextualBindingBuilder::give() expects array|Closure|string, Membrane\Builder\Builder given.

Check failure on line 50 in src/ServiceProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.2, lowest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Parameter #1 $implementation of method Illuminate\Contracts\Container\ContextualBindingBuilder::give() expects array|Closure|string, Membrane\Builder\Builder given.

Check failure on line 50 in src/ServiceProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Parameter #1 $implementation of method Illuminate\Contracts\Container\ContextualBindingBuilder::give() expects array|Closure|string, Membrane\Builder\Builder given.

Check failure on line 50 in src/ServiceProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.3, lowest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Parameter #1 $implementation of method Illuminate\Contracts\Container\ContextualBindingBuilder::give() expects array|Closure|string, Membrane\Builder\Builder given.

Check failure on line 50 in src/ServiceProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.3, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Parameter #1 $implementation of method Illuminate\Contracts\Container\ContextualBindingBuilder::give() expects array|Closure|string, Membrane\Builder\Builder given.

Check failure on line 50 in src/ServiceProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.1, lowest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Parameter #1 $implementation of method Illuminate\Contracts\Container\ContextualBindingBuilder::give() expects array|Closure|string, Membrane\Builder\Builder given.

Check failure on line 50 in src/ServiceProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.1, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Parameter #1 $implementation of method Illuminate\Contracts\Container\ContextualBindingBuilder::give() expects array|Closure|string, Membrane\Builder\Builder given.

Check failure on line 50 in src/ServiceProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.2, lowest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Parameter #1 $implementation of method Illuminate\Contracts\Container\ContextualBindingBuilder::give() expects array|Closure|string, Membrane\Builder\Builder given.

Check failure on line 50 in src/ServiceProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Parameter #1 $implementation of method Illuminate\Contracts\Container\ContextualBindingBuilder::give() expects array|Closure|string, Membrane\Builder\Builder given.

Check failure on line 50 in src/ServiceProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.3, lowest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Parameter #1 $implementation of method Illuminate\Contracts\Container\ContextualBindingBuilder::give() expects array|Closure|string, Membrane\Builder\Builder given.

Check failure on line 50 in src/ServiceProvider.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPStan [8.3, latest], ubuntu-latest, laminas/laminas-continuous-integration-action@v1...

Parameter #1 $implementation of method Illuminate\Contracts\Container\ContextualBindingBuilder::give() expects array|Closure|string, Membrane\Builder\Builder given.
}

/** @return Builder[] */
private function instantiateBuilders(): array
{
/** @phpstan-ignore-next-line */ // config is a laravel framework helper method
$routesFile = config('membrane.routes_file');

/** @phpstan-ignore-next-line */ // config is a laravel framework helper method
$router = new Router(new RouteCollection(include config('membrane.routes_file')));

/** @phpstan-ignore-next-line */ // config is a laravel framework helper method
return array_map(fn($className) => new $className($router), config('membrane.additional_builders'));
}
}

0 comments on commit 9df8379

Please sign in to comment.