This repository has been archived on 2025-02-21. You can view files and clone it, but cannot push or open issues or pull requests.

39 lines
1.0 KiB
PHP

<?php
namespace Notes\Route\Attribute\Method;
#[\Attribute]
class Route implements \Notes\Attribute {
public function __construct(
public string $name,
public string $route,
public string|array $method = [ "GET", "POST" ],
public string $base = "",
public ? string $class = null,
public ? string $classMethod = null,
public bool $currentRoute = false,
) {}
public function getRoute() : string
{
return rtrim("/" . trim(isset($this->base) ?
"/" . trim($this->base, "/") . "/" . ltrim($this->route, "/")
:
"/" . ltrim($this->route, "/"), "/"), '/');
}
public function matchRouteName(string $name) : bool
{
return strtolower($this->name) === strtolower($name);
}
public function isRoute(string $name) {
return $this->name === $name;
}
public function currentRoute(bool|null $value = null ) {
return is_null($value) ? $value : $this->currentRoute = $value;
}
}