-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ablity to register custom route with action class for reusa…
…bility - Create a class in your Actions folder within your module - Implement \LaraStrict\ContractsCreateCustomRouteActionContract ```php public function execute(CustomRouteEntity $customRoute, RouteRegistrar $routeRegistrar): bool { $routeRegistrar ->prefix('custom-route/' . $customRoute->urlPrefix) ->group($customRoute->path); return true; } ``` - In your service provider within `getCustomRoutes` method add your class: ```php 'custom' => CreateCustomRouteAction::class, ```
- Loading branch information
Showing
10 changed files
with
87 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaraStrict\Contracts; | ||
|
||
use Illuminate\Routing\RouteRegistrar; | ||
use LaraStrict\Entities\CustomRouteEntity; | ||
|
||
interface CreateCustomRouteActionContract | ||
{ | ||
/** | ||
* Registers custom route. Returns false if no registration has been made. | ||
*/ | ||
public function execute(CustomRouteEntity $customRoute, RouteRegistrar $routeRegistrar): bool; | ||
} |
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
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
8 changes: 8 additions & 0 deletions
8
tests/Feature/Providers/WithAll/Http/routes/with_all_custom.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,8 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Support\Facades\Route; | ||
|
||
Route::get('2-custom', static function () { | ||
}); |
21 changes: 21 additions & 0 deletions
21
tests/Feature/Providers/WithCustom/CreateCustomRouteAction.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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\LaraStrict\Feature\Providers\WithCustom; | ||
|
||
use Illuminate\Routing\RouteRegistrar; | ||
use LaraStrict\Contracts\CreateCustomRouteActionContract; | ||
use LaraStrict\Entities\CustomRouteEntity; | ||
|
||
class CreateCustomRouteAction implements CreateCustomRouteActionContract | ||
{ | ||
public function execute(CustomRouteEntity $customRoute, RouteRegistrar $routeRegistrar): bool | ||
{ | ||
$routeRegistrar | ||
->prefix('custom-route/' . $customRoute->urlPrefix) | ||
->group($customRoute->path); | ||
|
||
return true; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/Feature/Providers/WithCustom/Http/routes/with_custom_custom.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,8 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Support\Facades\Route; | ||
|
||
Route::get('1-custom', static function () { | ||
}); |
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