Skip to content

Commit

Permalink
Merge pull request #688 from pthiers/master
Browse files Browse the repository at this point in the history
Shim URL::formatRoot() on Lumen
  • Loading branch information
shalvah authored Feb 6, 2020
2 parents e7cbd3f + c610b25 commit 371b433
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"require-dev": {
"dingo/api": "^2.3.0",
"dms/phpunit-arraysubset-asserts": "^0.1.0",
"laravel/lumen-framework": "^5.7|^6.0|^7.0",
"league/fractal": "^0.17.0",
"mockery/mockery": "^1.2.0",
"orchestra/testbench": "^3.7|^4.0",
Expand Down
16 changes: 15 additions & 1 deletion src/Writing/PostmanCollectionWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Str;
use Ramsey\Uuid\Uuid;
use ReflectionMethod;

class PostmanCollectionWriter
{
Expand Down Expand Up @@ -38,7 +39,7 @@ public function __construct(Collection $routeGroups, $baseUrl)
{
$this->routeGroups = $routeGroups;
$this->protocol = Str::startsWith($baseUrl, 'https') ? 'https' : 'http';
$this->baseUrl = URL::formatRoot('', $baseUrl);
$this->baseUrl = $this->getBaseUrl($baseUrl);
$this->auth = config('apidoc.postman.auth');
}

Expand Down Expand Up @@ -181,4 +182,17 @@ protected function getAuthHeader()
return null;
}
}

protected function getBaseUrl($baseUrl)
{
if (Str::contains(app()->version(), 'Lumen')) { //Is Lumen
$reflectionMethod = new ReflectionMethod(\Laravel\Lumen\Routing\UrlGenerator::class, 'getRootUrl');
$reflectionMethod->setAccessible(true);
$url = app('url');

return $reflectionMethod->invokeArgs($url, ['', $baseUrl]);
}

return URL::formatRoot('', $baseUrl);
}
}

0 comments on commit 371b433

Please sign in to comment.