Skip to content

Commit 3d70ca7

Browse files
authored
[1.x] Adds missing URI on folio:list command (#127)
* Adds missing URI on `folio:list` command * Fix code styling --------- Co-authored-by: nunomaduro <[email protected]>
1 parent 9a959c3 commit 3d70ca7

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

src/Console/ListCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,16 @@ protected function routesFromMountPaths(array $mountPaths): Collection
7676
return collect($mountPaths)->map(function (MountPath $mountPath) {
7777
$views = Finder::create()->in($mountPath->path)->name('*.blade.php')->files()->getIterator();
7878

79+
$baseUri = rtrim($mountPath->baseUri, '/');
7980
$domain = $mountPath->domain;
8081
$mountPath = str_replace(DIRECTORY_SEPARATOR, '/', $mountPath->path);
8182

8283
$path = '/'.ltrim($mountPath, '/');
8384

8485
return collect($views)
85-
->map(function (SplFileInfo $view) use ($domain, $mountPath) {
86+
->map(function (SplFileInfo $view) use ($baseUri, $domain, $mountPath) {
8687
$viewPath = str_replace(DIRECTORY_SEPARATOR, '/', $view->getRealPath());
87-
$uri = str_replace($mountPath, '', $viewPath);
88+
$uri = $baseUri.str_replace($mountPath, '', $viewPath);
8889

8990
if (count($this->laravel->make(FolioManager::class)->mountPaths()) === 1) {
9091
$action = str_replace($mountPath.'/', '', $viewPath);

src/FolioManager.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class FolioManager
4040
*
4141
* @throws \InvalidArgumentException
4242
*/
43-
public function route(string $path = null, ?string $uri = '/', array $middleware = []): PendingRoute
43+
public function route(?string $path = null, ?string $uri = '/', array $middleware = []): PendingRoute
4444
{
4545
return new PendingRoute(
4646
$this,
@@ -117,15 +117,15 @@ public function middlewareFor(string $uri): array
117117
/**
118118
* Get a piece of data from the route / view that was last matched by Folio.
119119
*/
120-
public function data(string $key = null, mixed $default = null): mixed
120+
public function data(?string $key = null, mixed $default = null): mixed
121121
{
122122
return Arr::get($this->lastMatchedView?->data ?: [], $key, $default);
123123
}
124124

125125
/**
126126
* Specify the callback that should be used to render matched views.
127127
*/
128-
public function renderUsing(Closure $callback = null): static
128+
public function renderUsing(?Closure $callback = null): static
129129
{
130130
$this->renderUsing = $callback;
131131

@@ -149,7 +149,7 @@ public function terminate(): void
149149
/**
150150
* Specify the callback that should be used when terminating the application.
151151
*/
152-
public function terminateUsing(Closure $callback = null): static
152+
public function terminateUsing(?Closure $callback = null): static
153153
{
154154
$this->terminateUsing = $callback;
155155

src/Pipeline/PotentiallyBindablePathSegment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function capturesMultipleSegments(): bool
6767
* Resolve the binding or throw a ModelNotFoundException.
6868
*/
6969
public function resolveOrFail(mixed $value,
70-
UrlRoutable $parent = null,
70+
?UrlRoutable $parent = null,
7171
bool $withTrashed = false): UrlRoutable|BackedEnum
7272
{
7373
if (is_null($resolved = $this->resolve($value, $parent, $withTrashed))) {

tests/Feature/Console/ListCommandTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,28 @@
248248

249249
EOF);
250250
});
251+
252+
it('prefixes URIs', function (string $uri) {
253+
$output = new BufferedOutput();
254+
255+
Folio::path(__DIR__.'/../resources/views/more-pages')->uri($uri);
256+
257+
$exitCode = Artisan::call('folio:list', [], $output);
258+
259+
expect($exitCode)->toBe(0)
260+
->and($output->fetch())->toOutput(<<<'EOF'
261+
262+
GET /api ................................................................................................ more-pages.index › index.blade.php
263+
GET /api/{...user} ..................................................................................................... [...User].blade.php
264+
GET /api/{...user}/detail .............................................................. more-pages.user.detail › [...User]/detail.blade.php
265+
266+
Showing [3] routes
267+
268+
269+
EOF);
270+
})->with([
271+
'api',
272+
'/api',
273+
'api/',
274+
'/api/',
275+
]);

0 commit comments

Comments
 (0)