-
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.
[ENH] refactoring routing system to be more flexiblea and manageable …
…via application
- Loading branch information
Showing
7 changed files
with
207 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
/* | ||
* Copyright (c) 2024. Wepesi Dev Framework | ||
*/ | ||
|
||
namespace Wepesi\Core\Routing\Providers\Contracts; | ||
|
||
/** | ||
* @template T | ||
*/ | ||
interface RouteContract | ||
{ | ||
public function call(); | ||
} |
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,48 @@ | ||
<?php | ||
/* | ||
* Copyright (c) 2024. Wepesi Dev Framework | ||
*/ | ||
|
||
namespace Wepesi\Core\Routing\Providers\Contracts; | ||
|
||
/** | ||
* @template T | ||
*/ | ||
interface RouterContract | ||
{ | ||
/** | ||
* @param string $path | ||
* @param $callable | ||
* @param $name | ||
* @return RouteContract | ||
*/ | ||
public function get(string $path, $callable, $name = null): RouteContract; | ||
/** | ||
* @param string $path | ||
* @param $callable | ||
* @param $name | ||
* @return RouteContract | ||
*/ | ||
public function post(string $path, $callable, $name = null): RouteContract; | ||
|
||
/** | ||
* @param string $path | ||
* @param $callable | ||
* @param $name | ||
* @return RouteContract | ||
*/ | ||
public function put(string $path, $callable, $name = null): RouteContract; | ||
|
||
/** | ||
* @param string $path | ||
* @param $callable | ||
* @param $name | ||
* @return RouteContract | ||
*/ | ||
public function delete(string $path, $callable, $name = null): RouteContract; | ||
|
||
/** | ||
* | ||
*/ | ||
public function run(); | ||
} |
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,18 @@ | ||
<?php | ||
/* | ||
* Copyright (c) 2024. Wepesi Dev Framework | ||
*/ | ||
|
||
namespace Wepesi\Core\Routing\Providers\Contracts; | ||
|
||
/** | ||
* @template T | ||
*/ | ||
interface RouterProviders | ||
{ | ||
/** | ||
* @param string $routes | ||
* @return void | ||
*/ | ||
public function register(string $routes): void; | ||
} |
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,46 @@ | ||
<?php | ||
/* | ||
* Copyright (c) 2024. Wepesi Dev Framework | ||
*/ | ||
|
||
namespace Wepesi\Core\Routing; | ||
|
||
|
||
use Wepesi\Core\Routing\Providers\Contracts\RouterContract; | ||
use Wepesi\Core\Routing\Providers\Contracts\RouterProviders; | ||
|
||
/** | ||
* @template T | ||
* @template-implements RouterProviders<T> | ||
*/ | ||
final class RouteFileRegistrar implements RouterProviders | ||
{ | ||
/** | ||
* @var RouterContract | ||
*/ | ||
protected RouterContract $router; | ||
|
||
/** | ||
* Create a new route file registrar instance. | ||
* | ||
* @param Router $router | ||
*/ | ||
public function __construct(RouterContract $router) | ||
{ | ||
$this->router = $router; | ||
} | ||
|
||
/** | ||
* Require the given routes file. | ||
* | ||
* @param class-string<T> $routes | ||
* @return void | ||
*/ | ||
public function register(string $routes): void | ||
{ | ||
$router = $this->router; | ||
if (is_file($routes)) { | ||
require $routes; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.