Skip to content

Commit 371b433

Browse files
authored
Merge pull request mpociot#688 from pthiers/master
Shim URL::formatRoot() on Lumen
2 parents e7cbd3f + c610b25 commit 371b433

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"require-dev": {
3232
"dingo/api": "^2.3.0",
3333
"dms/phpunit-arraysubset-asserts": "^0.1.0",
34+
"laravel/lumen-framework": "^5.7|^6.0|^7.0",
3435
"league/fractal": "^0.17.0",
3536
"mockery/mockery": "^1.2.0",
3637
"orchestra/testbench": "^3.7|^4.0",

src/Writing/PostmanCollectionWriter.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Support\Facades\URL;
77
use Illuminate\Support\Str;
88
use Ramsey\Uuid\Uuid;
9+
use ReflectionMethod;
910

1011
class PostmanCollectionWriter
1112
{
@@ -38,7 +39,7 @@ public function __construct(Collection $routeGroups, $baseUrl)
3839
{
3940
$this->routeGroups = $routeGroups;
4041
$this->protocol = Str::startsWith($baseUrl, 'https') ? 'https' : 'http';
41-
$this->baseUrl = URL::formatRoot('', $baseUrl);
42+
$this->baseUrl = $this->getBaseUrl($baseUrl);
4243
$this->auth = config('apidoc.postman.auth');
4344
}
4445

@@ -181,4 +182,17 @@ protected function getAuthHeader()
181182
return null;
182183
}
183184
}
185+
186+
protected function getBaseUrl($baseUrl)
187+
{
188+
if (Str::contains(app()->version(), 'Lumen')) { //Is Lumen
189+
$reflectionMethod = new ReflectionMethod(\Laravel\Lumen\Routing\UrlGenerator::class, 'getRootUrl');
190+
$reflectionMethod->setAccessible(true);
191+
$url = app('url');
192+
193+
return $reflectionMethod->invokeArgs($url, ['', $baseUrl]);
194+
}
195+
196+
return URL::formatRoot('', $baseUrl);
197+
}
184198
}

0 commit comments

Comments
 (0)