forked from spatie/laravel-route-discovery
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b352b21
commit edc7a90
Showing
7 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/PendingRouteTransformers/MoveRoutesStartingWithParametersLast.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Spatie\RouteDiscovery\PendingRouteTransformers; | ||
|
||
use Illuminate\Support\Collection; | ||
use Spatie\RouteDiscovery\PendingRoutes\PendingRoute; | ||
use Spatie\RouteDiscovery\PendingRoutes\PendingRouteAction; | ||
|
||
class MoveRoutesStartingWithParametersLast implements PendingRouteTransformer | ||
{ | ||
/** | ||
* @param Collection<PendingRoute> $pendingRoutes | ||
* | ||
* @return Collection<PendingRoute> | ||
*/ | ||
public function transform(Collection $pendingRoutes): Collection | ||
{ | ||
return $pendingRoutes->sortBy(function(PendingRoute $pendingRoute) { | ||
$containsRouteStartingWithUri = $pendingRoute->actions->contains(function(PendingRouteAction $action) { | ||
return str_starts_with($action->uri, '{'); | ||
}); | ||
|
||
if (! $containsRouteStartingWithUri) { | ||
return 0; | ||
} | ||
|
||
return $pendingRoute->actions->max(function(PendingRouteAction $action) { | ||
if (! str_starts_with($action->uri, '{')) { | ||
return PHP_INT_MAX; | ||
} | ||
|
||
return PHP_INT_MAX - count(explode('/', $action->uri)); | ||
}); | ||
}) | ||
->values(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/Support/TestClasses/Controllers/RouteOrder/AAAController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Spatie\RouteDiscovery\Tests\Support\TestClasses\Controllers\RouteOrder; | ||
|
||
use Spatie\RouteDiscovery\Attributes\Route; | ||
|
||
class AAAController | ||
{ | ||
#[Route(fullUri: '{parameter}')] | ||
public function invoke() | ||
{ | ||
|
||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/Support/TestClasses/Controllers/RouteOrder/MiddleController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Spatie\RouteDiscovery\Tests\Support\TestClasses\Controllers\RouteOrder; | ||
|
||
use Spatie\RouteDiscovery\Attributes\Route; | ||
|
||
class MiddleController | ||
{ | ||
#[Route(fullUri: '{parameter}/extra')] | ||
public function invoke() | ||
{ | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/Support/TestClasses/Controllers/RouteOrder/ZZZController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Spatie\RouteDiscovery\Tests\Support\TestClasses\Controllers\RouteOrder; | ||
|
||
class ZZZController | ||
{ | ||
public function __invoke() | ||
{ | ||
|
||
} | ||
} |