Issues (25)

src/Providers/ApieLumenServiceProvider.php (1 issue)

Labels
Severity
1
<?php
2
namespace W2w\Laravel\Apie\Providers;
3
4
use Illuminate\Support\ServiceProvider;
5
use Laravel\Lumen\Routing\UrlGenerator;
0 ignored issues
show
The type Laravel\Lumen\Routing\UrlGenerator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Psr\Http\Message\ServerRequestInterface;
7
use W2w\Laravel\Apie\Controllers\SwaggerUiController;
8
use W2w\Laravel\Apie\Services\ApieContext;
9
use W2w\Laravel\Apie\Services\ApieRouteLoader;
10
use W2w\Laravel\Apie\Services\LumenRouteLoader;
11
use W2w\Laravel\Apie\Services\RouteLoaderInterface;
12
13
/**
14
 * Service provider for Apie to link to Laravel (and that do not work in Laravel)
15
 */
16
class ApieLumenServiceProvider extends ServiceProvider
17
{
18
    public function boot()
19
    {
20
        $this->app->bind(RouteLoaderInterface::class, LumenRouteLoader::class);
21
        $this->app->make(ApieRouteLoader::class)->renderRoutes();
22
    }
23
24
    public function register()
25
    {
26
        // fix for PSR requests in Lumen
27
        $this->app->extend(
28
            ServerRequestInterface::class, function (ServerRequestInterface $psrRequest) {
29
                $route = (array) $this->app->make('request')->route();
30
                if (is_array($route[2])) {
31
                    foreach ($route[2] as $key => $value) {
32
                        $psrRequest = $psrRequest->withAttribute($key, $value);
33
                    }
34
                }
35
                return $psrRequest;
36
            }
37
        );
38
39
        $this->app->bind(
40
            SwaggerUiController::class,
41
            function () {
42
                $urlGenerator = new UrlGenerator($this->app);
43
                return new SwaggerUiController(
44
                    $this->app->make(ApieContext::class),
45
                    $urlGenerator,
46
                    __DIR__ . '/../../resources/open-api.html'
47
                );
48
            }
49
        );
50
    }
51
}
52