-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoute.php
More file actions
72 lines (65 loc) · 1.43 KB
/
Route.php
File metadata and controls
72 lines (65 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace Neuron\Routing\Attributes;
use Attribute;
/**
* Base route attribute for defining HTTP routes on controller methods.
*
* This attribute allows routes to be defined directly on controller methods,
* providing a modern alternative to YAML-based route configuration.
*
* @package Neuron\Routing\Attributes
*
* @example
* ```php
* #[Route('/users/:id', method: 'GET', name: 'users.show', filters: ['auth'])]
* public function show(int $id) {
* // Implementation
* }
* ```
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class Route
{
/**
* @param string $path The route path (e.g., '/users/:id')
* @param string $method HTTP method (GET, POST, PUT, DELETE)
* @param string|null $name Optional route name for URL generation
* @param array $filters Array of filter names to apply to this route
*/
public function __construct(
public readonly string $path,
public readonly string $method = 'GET',
public readonly ?string $name = null,
public readonly array $filters = []
)
{
}
/**
* Get the route path
*/
public function getPath(): string
{
return $this->path;
}
/**
* Get the HTTP method
*/
public function getMethod(): string
{
return strtoupper( $this->method );
}
/**
* Get the route name
*/
public function getName(): ?string
{
return $this->name;
}
/**
* Get the filters
*/
public function getFilters(): array
{
return $this->filters;
}
}