Skip to content

Commit

Permalink
Rename RouteInterface to Route
Browse files Browse the repository at this point in the history
  • Loading branch information
blackshadev committed Dec 5, 2024
1 parent 5e55e67 commit f6285a9
Show file tree
Hide file tree
Showing 16 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Tempest/Router/src/Connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Tempest\Http\Method;

#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
final class Connect implements RouteInterface
final class Connect implements Route
{
use IsRoute;

Expand Down
2 changes: 1 addition & 1 deletion src/Tempest/Router/src/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Tempest\Http\Method;

#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
final class Delete implements RouteInterface
final class Delete implements Route
{
use IsRoute;

Expand Down
4 changes: 2 additions & 2 deletions src/Tempest/Router/src/GenericRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public function toUri(array|string $action, ...$params): string
$controllerMethod = $reflection->getMethod('__invoke');
}

/** @var RouteInterface|null $routeAttribute */
$routeAttribute = $controllerMethod->getAttribute(RouteInterface::class);
/** @var Route|null $routeAttribute */
$routeAttribute = $controllerMethod->getAttribute(Route::class);

$uri = $routeAttribute->uri();
} catch (ReflectionException) {
Expand Down
2 changes: 1 addition & 1 deletion src/Tempest/Router/src/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Tempest\Http\Method;

#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
final class Get implements RouteInterface
final class Get implements Route
{
use IsRoute;

Expand Down
2 changes: 1 addition & 1 deletion src/Tempest/Router/src/Head.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Tempest\Http\Method;

#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
final class Head implements RouteInterface
final class Head implements Route
{
use IsRoute;

Expand Down
2 changes: 1 addition & 1 deletion src/Tempest/Router/src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Tempest\Http\Method;

#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
final class Options implements RouteInterface
final class Options implements Route
{
use IsRoute;

Expand Down
2 changes: 1 addition & 1 deletion src/Tempest/Router/src/Patch.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Tempest\Http\Method;

#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
final class Patch implements RouteInterface
final class Patch implements Route
{
use IsRoute;

Expand Down
2 changes: 1 addition & 1 deletion src/Tempest/Router/src/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Tempest\Http\Method;

#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
final class Post implements RouteInterface
final class Post implements Route
{
use IsRoute;

Expand Down
2 changes: 1 addition & 1 deletion src/Tempest/Router/src/Put.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Tempest\Http\Method;

#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
final class Put implements RouteInterface
final class Put implements Route
{
use IsRoute;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Tempest\Http\Method;

interface RouteInterface
interface Route
{
public function method(): Method;

Expand Down
2 changes: 1 addition & 1 deletion src/Tempest/Router/src/RouteDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
public function discover(DiscoveryLocation $location, ClassReflector $class): void
{
foreach ($class->getPublicMethods() as $method) {
$routeAttributes = $method->getAttributes(RouteInterface::class);
$routeAttributes = $method->getAttributes(Route::class);

foreach ($routeAttributes as $routeAttribute) {
$this->discoveryItems->add($location, [$method, $routeAttribute]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

use Tempest\Http\Method;
use Tempest\Reflection\MethodReflector;
use Tempest\Router\RouteInterface;
use Tempest\Router\Route;

final class DiscoveredRoute implements RouteInterface
final class DiscoveredRoute implements Route
{
public const string DEFAULT_MATCHING_GROUP = '[^/]++';

public const string ROUTE_PARAM_NAME_REGEX = '(\w*)';

public const string ROUTE_PARAM_CUSTOM_REGEX = '(?::([^{}]*(?:\{(?-1)\}[^{}]*)*))?';

public static function fromRoute(RouteInterface $route, MethodReflector $methodReflector): self
public static function fromRoute(Route $route, MethodReflector $methodReflector): self
{
return new self(
$route->uri(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace Tempest\Router\Routing\Construction;

use InvalidArgumentException;
use Tempest\Router\RouteInterface;
use Tempest\Router\Route;

final class DuplicateRouteException extends InvalidArgumentException
{
public function __construct(RouteInterface $route)
public function __construct(Route $route)
{
parent::__construct("Route '{$route->uri()}' already exists.");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tempest/Router/src/Trace.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Tempest\Http\Method;

#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
final class Trace implements RouteInterface
final class Trace implements Route
{
use IsRoute;

Expand Down
4 changes: 2 additions & 2 deletions src/Tempest/Router/tests/FakeRouteBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use Tempest\Router\Routing\Construction\DiscoveredRoute;
use Tempest\Router\Routing\Construction\MarkedRoute;
use Tempest\Reflection\MethodReflector;
use Tempest\Router\RouteInterface;
use Tempest\Router\Route;

final readonly class FakeRouteBuilder implements RouteInterface
final readonly class FakeRouteBuilder implements Route
{
private MethodReflector $handler;

Expand Down
2 changes: 0 additions & 2 deletions tests/Benchmark/Http/RouteConfigBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use PhpBench\Attributes\Revs;
use PhpBench\Attributes\Warmup;
use Tempest\Http\Method;
use Tempest\Router\Route;
use Tempest\Router\RouteConfig;
use Tempest\Router\Routing\Construction\RouteConfigurator;
use Tempest\Router\Tests\FakeRouteBuilder;
Expand Down

0 comments on commit f6285a9

Please sign in to comment.