← Каталог
Современный PHP 8 — enum, readonly и атрибуты — Атрибуты (PHP 8.0)
Фрагмент из «Современный PHP 8 — enum, readonly и атрибуты»: Атрибуты (PHP 8.0).
#[\Attribute(\Attribute::TARGET_METHOD)]
class Route
{
public function __construct(
public string $path,
public array $methods = ['GET'],
) {}
}
class HomeController
{
#[Route('/')]
public function index(): string
{
return 'Главная';
}
#[Route('/about', methods: ['GET'])]
public function about(): string
{
return 'О проекте';
}
} #[\Attribute(\Attribute::TARGET_METHOD)]
class Route
{
public function __construct(
public string $path,
public array $methods = ['GET'],
) {}
}
class HomeController
{
#[Route('/')]
public function index(): string
{
return 'Главная';
}
#[Route('/about', methods: ['GET'])]
public function about(): string
{
return 'О проекте';
}
}