Browse Source

Drop Lumen

Shalvah 3 months ago
parent
commit
9e20117eae

+ 1 - 1
.github/workflows/run-tests.yml

@@ -40,7 +40,7 @@ jobs:
         run: COMPOSER=composer.lowest.json composer update --prefer-stable
 
 
-      - name: Execute tests (Laravel/Lumen)
+      - name: Execute tests (Laravel)
         run: composer test-ci
         if: ${{ matrix.deps == 'highest' }}
 

+ 1 - 1
README.md

@@ -9,7 +9,7 @@
 
 > [v4 is out now](https://scribe.knuckles.wtf/blog/laravel-v4)! Featuring subgroups, easier sorting, and an automated upgrade command.
 
-Scribe helps you generate API documentation for humans from your Laravel/Lumen codebase. See a live example at [demo.scribe.knuckles.wtf](https://demo.scribe.knuckles.wtf).
+Scribe helps you generate API documentation for humans from your Laravel codebase. See a live example at [demo.scribe.knuckles.wtf](https://demo.scribe.knuckles.wtf).
 
 ## Features
 - Useful output:

+ 0 - 1
composer.json

@@ -38,7 +38,6 @@
         "brianium/paratest": "^6.0",
         "dms/phpunit-arraysubset-asserts": "^0.4",
         "laravel/legacy-factories": "^1.3.0",
-        "laravel/lumen-framework": "^8.0|^9.0|^10.0",
         "league/fractal": "^0.20",
         "nikic/fast-route": "^1.3",
         "orchestra/testbench": "^6.0|^7.0|^8.0",

+ 0 - 1
composer.lowest.json

@@ -39,7 +39,6 @@
         "brianium/paratest": "^6.0",
         "dms/phpunit-arraysubset-asserts": "^0.2.0",
         "laravel/legacy-factories": "^1.3.0",
-        "laravel/lumen-framework": "^8.0",
         "league/fractal": "^0.19.0",
         "nikic/fast-route": "^1.3",
         "orchestra/testbench": "^6.0|^7.0",

+ 0 - 1
src/Config/Defaults.php

@@ -18,7 +18,6 @@ class Defaults
     {
         return new StrategyListWrapper([
             Strategies\UrlParameters\GetFromLaravelAPI::class,
-            Strategies\UrlParameters\GetFromLumenAPI::class,
             Strategies\UrlParameters\GetFromUrlParamAttribute::class,
             Strategies\UrlParameters\GetFromUrlParamTag::class,
         ]);

+ 6 - 17
src/Extracting/Strategies/Responses/ResponseCalls.php

@@ -249,26 +249,15 @@ class ResponseCalls extends Strategy
      */
     protected function makeApiCall(Request $request, Route $route)
     {
-        return $this->callLaravelOrLumenRoute($request);
+        return $this->callLaravelRoute($request);
     }
 
-    protected function callLaravelOrLumenRoute(Request $request): \Symfony\Component\HttpFoundation\Response
+    protected function callLaravelRoute(Request $request): \Symfony\Component\HttpFoundation\Response
     {
-        // Confirm we're running in Laravel, not Lumen
-        if (app()->bound(Kernel::class)) {
-            /** @var \Illuminate\Foundation\Http\Kernel $kernel */
-            $kernel = app(Kernel::class);
-            $response = $kernel->handle($request);
-            $kernel->terminate($request, $response);
-        } else {
-            // Handle the request using the Lumen application.
-            /** @var \Laravel\Lumen\Application $app */
-            $app = app();
-            $app->bind('request', function () use ($request) {
-                return $request;
-            });
-            $response = $app->handle($request);
-        }
+        /** @var \Illuminate\Foundation\Http\Kernel $kernel */
+        $kernel = app(Kernel::class);
+        $response = $kernel->handle($request);
+        $kernel->terminate($request, $response);
 
         return $response;
     }

+ 0 - 4
src/Extracting/Strategies/UrlParameters/GetFromLaravelAPI.php

@@ -17,10 +17,6 @@ class GetFromLaravelAPI extends Strategy
 
     public function __invoke(ExtractedEndpointData $endpointData, array $routeRules = []): ?array
     {
-        if (Utils::isLumen()) {
-            return (new GetFromLumenAPI($this->config))($endpointData, $routeRules);
-        };
-
         $parameters = [];
 
         $path = $endpointData->uri;

+ 0 - 59
src/Extracting/Strategies/UrlParameters/GetFromLumenAPI.php

@@ -1,59 +0,0 @@
-<?php
-
-namespace Knuckles\Scribe\Extracting\Strategies\UrlParameters;
-
-use Knuckles\Camel\Extraction\ExtractedEndpointData;
-use FastRoute\RouteParser\Std;
-use Illuminate\Support\Arr;
-use Knuckles\Scribe\Extracting\ParamHelpers;
-use Knuckles\Scribe\Extracting\Strategies\Strategy;
-use Knuckles\Scribe\Tools\Utils;
-
-class GetFromLumenAPI extends Strategy
-{
-    use ParamHelpers;
-
-    public function __invoke(ExtractedEndpointData $endpointData, array $routeRules = []): ?array
-    {
-        if (!Utils::isLumen()) {
-            return null;
-        }
-
-        $path = $endpointData->uri;
-
-        $parameters = [];
-        $possibilities = (new Std)->parse($path);
-        // See https://github.com/nikic/FastRoute#overriding-the-route-parser-and-dispatcher
-        $possibilityWithAllSegmentsPresent = end($possibilities);
-
-        foreach ($possibilityWithAllSegmentsPresent as $part) {
-            if (!is_array($part)) {
-                // It's just a path segment, not a URL parameter'
-                continue;
-            }
-
-            $name = $part[0];
-            $isThisParameterOptional = Arr::first($possibilities, function ($possibility) use ($name) {
-                // This function checks if this parameter is present in the current possibility
-                return (function () use ($possibility, $name) {
-                        foreach ($possibility as $part) {
-                            if (is_array($part) && $part[0] === $name) {
-                                return true;
-                            }
-                        }
-                        return false;
-                    })() === false;
-            }, false);
-            $type = 'string';
-            $parameters[$name] = [
-                'name' => $name,
-                'description' => '',
-                'required' => !boolval($isThisParameterOptional),
-                'example' => $this->generateDummyValue($type, hints: ['name' => $name]),
-                'type' => $type,
-            ];
-        }
-
-        return $parameters;
-    }
-}

+ 0 - 23
src/Matching/LumenRouteAdapter.php

@@ -1,23 +0,0 @@
-<?php
-
-namespace Knuckles\Scribe\Matching;
-
-use Illuminate\Routing\Route;
-
-/**
- * Class LumenRouteAdapter.
- * Lumen routes don't extend from Laravel routes,
- * so we need this class to convert a Lumen route to a Laravel one.
- */
-class LumenRouteAdapter extends Route
-{
-    /**
-     * LumenRouteAdapter constructor.
-     *
-     * @param array $lumenRoute
-     */
-    public function __construct(array $lumenRoute)
-    {
-        parent::__construct($lumenRoute['method'], $lumenRoute['uri'], $lumenRoute['action']);
-    }
-}

+ 0 - 4
src/Matching/RouteMatcher.php

@@ -24,10 +24,6 @@ class RouteMatcher implements RouteMatcherInterface
             $includes = $routeRule['include'] ?? [];
 
             foreach ($allRoutes as $route) {
-                if (is_array($route)) {
-                    $route = new LumenRouteAdapter($route);
-                }
-
                 if ($this->shouldExcludeRoute($route, $routeRule)) {
                     continue;
                 }

+ 1 - 1
src/ScribeServiceProvider.php

@@ -48,7 +48,7 @@ class ScribeServiceProvider extends ServiceProvider
             Str::endsWith(config('scribe.type', 'static'), 'laravel') &&
             config('scribe.laravel.add_routes', false)
         ) {
-            $routesPath = Utils::isLumen() ? __DIR__ . '/../routes/lumen.php' : __DIR__ . '/../routes/laravel.php';
+            $routesPath = __DIR__ . '/../routes/laravel.php';
             $this->loadRoutesFrom($routesPath);
         }
     }

+ 0 - 33
src/Tools/Utils.php

@@ -67,25 +67,6 @@ class Utils
             return $uri;
         }
 
-        if (self::isLumen()) {
-            $boundUri = '';
-            $possibilities = (new Std)->parse($uri);
-            // See https://github.com/nikic/FastRoute#overriding-the-route-parser-and-dispatcher
-            $possibilityWithAllSegmentsPresent = end($possibilities);
-            foreach ($possibilityWithAllSegmentsPresent as $part) {
-                if (!is_array($part)) {
-                    // It's just a path segment, not a URL parameter'
-                    $boundUri .= $part;
-                    continue;
-                }
-
-                $name = $part[0];
-                $boundUri .= $urlParameters[$name];
-            }
-
-            return $boundUri;
-        }
-
         foreach ($urlParameters as $parameterName => $example) {
             $uri = preg_replace('#\{' . $parameterName . '\??}#', $example, $uri);
         }
@@ -330,20 +311,6 @@ class Utils
         return $factory;
     }
 
-    public static function isLumen(): bool
-    {
-        // See https://github.com/laravel/lumen-framework/blob/99330e6ca2198e228f5894cf84d843c2a539a250/src/Application.php#L163
-        $app = app();
-        if ($app
-            && is_callable([$app, 'version'])
-            && Str::startsWith($app->version(), 'Lumen')
-        ) {
-            return true;
-        }
-
-        return false;
-    }
-
     /**
      * Filter a list of docblock tags to those matching the specified ones (case-insensitive).
      *