From 9e20117eaecf2c9a807a3896ed0406f1661da34f Mon Sep 17 00:00:00 2001 From: Shalvah Date: Sat, 18 Jan 2025 23:13:42 +0100 Subject: [PATCH] Drop Lumen --- .github/workflows/run-tests.yml | 2 +- README.md | 2 +- composer.json | 1 - composer.lowest.json | 1 - src/Config/Defaults.php | 1 - .../Strategies/Responses/ResponseCalls.php | 23 ++------ .../UrlParameters/GetFromLaravelAPI.php | 4 -- .../UrlParameters/GetFromLumenAPI.php | 59 ------------------- src/Matching/LumenRouteAdapter.php | 23 -------- src/Matching/RouteMatcher.php | 4 -- src/ScribeServiceProvider.php | 2 +- src/Tools/Utils.php | 33 ----------- 12 files changed, 9 insertions(+), 146 deletions(-) delete mode 100644 src/Extracting/Strategies/UrlParameters/GetFromLumenAPI.php delete mode 100644 src/Matching/LumenRouteAdapter.php diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 69fb501e..5485743d 100644 --- a/.github/workflows/run-tests.yml +++ b/.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' }} diff --git a/README.md b/README.md index 6bb50c1f..6bcb76c6 100644 --- a/README.md +++ b/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: diff --git a/composer.json b/composer.json index 8593a7f8..213bdc3d 100644 --- a/composer.json +++ b/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", diff --git a/composer.lowest.json b/composer.lowest.json index 12ffd85c..e5977290 100644 --- a/composer.lowest.json +++ b/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", diff --git a/src/Config/Defaults.php b/src/Config/Defaults.php index 4483c3d3..d294794f 100644 --- a/src/Config/Defaults.php +++ b/src/Config/Defaults.php @@ -18,7 +18,6 @@ public static function urlParametersStrategies(): StrategyListWrapper { return new StrategyListWrapper([ Strategies\UrlParameters\GetFromLaravelAPI::class, - Strategies\UrlParameters\GetFromLumenAPI::class, Strategies\UrlParameters\GetFromUrlParamAttribute::class, Strategies\UrlParameters\GetFromUrlParamTag::class, ]); diff --git a/src/Extracting/Strategies/Responses/ResponseCalls.php b/src/Extracting/Strategies/Responses/ResponseCalls.php index 39c14a0b..c5ad2bc3 100644 --- a/src/Extracting/Strategies/Responses/ResponseCalls.php +++ b/src/Extracting/Strategies/Responses/ResponseCalls.php @@ -249,26 +249,15 @@ private function addBodyParameters(Request $request, array $body): void */ 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; } diff --git a/src/Extracting/Strategies/UrlParameters/GetFromLaravelAPI.php b/src/Extracting/Strategies/UrlParameters/GetFromLaravelAPI.php index 3e33a4b4..774f5c76 100644 --- a/src/Extracting/Strategies/UrlParameters/GetFromLaravelAPI.php +++ b/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; diff --git a/src/Extracting/Strategies/UrlParameters/GetFromLumenAPI.php b/src/Extracting/Strategies/UrlParameters/GetFromLumenAPI.php deleted file mode 100644 index 5e9b620b..00000000 --- a/src/Extracting/Strategies/UrlParameters/GetFromLumenAPI.php +++ /dev/null @@ -1,59 +0,0 @@ -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; - } -} diff --git a/src/Matching/LumenRouteAdapter.php b/src/Matching/LumenRouteAdapter.php deleted file mode 100644 index 581bf579..00000000 --- a/src/Matching/LumenRouteAdapter.php +++ /dev/null @@ -1,23 +0,0 @@ -shouldExcludeRoute($route, $routeRule)) { continue; } diff --git a/src/ScribeServiceProvider.php b/src/ScribeServiceProvider.php index 0c5fce5f..0a4fd173 100644 --- a/src/ScribeServiceProvider.php +++ b/src/ScribeServiceProvider.php @@ -48,7 +48,7 @@ protected function bootRoutes() 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); } } diff --git a/src/Tools/Utils.php b/src/Tools/Utils.php index 114de014..46aacf39 100644 --- a/src/Tools/Utils.php +++ b/src/Tools/Utils.php @@ -67,25 +67,6 @@ public static function replaceUrlParameterPlaceholdersWithValues(string $uri, ar 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 @@ public static function getModelFactory(string $modelName, array $states = [], ar 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). *