Today I learned: attribute declaration does not inherit.

This commit is contained in:
Pachira 2024-03-28 20:23:09 +00:00
parent bcc7e8066a
commit a5cfba6b96
10 changed files with 27 additions and 5 deletions

View file

@ -1 +1 @@
0.2403.282019
0.2403.282022

View file

@ -5,15 +5,13 @@
namespace Index\Http\Routing;
use Attribute;
use ReflectionAttribute;
use ReflectionObject;
/**
* Provides an attribute for marking methods in a class as handlers.
* Provides base for attributes that mark methods in a class as handlers.
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class HandlerAttribute {
abstract class HandlerAttribute {
public function __construct(private string $path) {}
/**

View file

@ -5,9 +5,12 @@
namespace Index\Http\Routing;
use Attribute;
/**
* Provides an attribute for marking methods in a class as a DELETE route.
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class HttpDelete extends HttpRoute {
public function __construct(string $path) {
parent::__construct('DELETE', $path);

View file

@ -5,9 +5,12 @@
namespace Index\Http\Routing;
use Attribute;
/**
* Provides an attribute for marking methods in a class as a GET route.
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class HttpGet extends HttpRoute {
public function __construct(string $path) {
parent::__construct('GET', $path);

View file

@ -5,7 +5,10 @@
namespace Index\Http\Routing;
use Attribute;
/**
* Provides an attribute for marking methods in a class as middleware.
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class HttpMiddleware extends HandlerAttribute {}

View file

@ -5,9 +5,12 @@
namespace Index\Http\Routing;
use Attribute;
/**
* Provides an attribute for marking methods in a class as a OPTIONS route.
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class HttpOptions extends HttpRoute {
public function __construct(string $path) {
parent::__construct('OPTIONS', $path);

View file

@ -5,9 +5,12 @@
namespace Index\Http\Routing;
use Attribute;
/**
* Provides an attribute for marking methods in a class as a POST route.
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class HttpPatch extends HttpRoute {
public function __construct(string $path) {
parent::__construct('PATCH', $path);

View file

@ -5,9 +5,12 @@
namespace Index\Http\Routing;
use Attribute;
/**
* Provides an attribute for marking methods in a class as a POST route.
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class HttpPost extends HttpRoute {
public function __construct(string $path) {
parent::__construct('POST', $path);

View file

@ -5,9 +5,12 @@
namespace Index\Http\Routing;
use Attribute;
/**
* Provides an attribute for marking methods in a class as a PUT route.
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class HttpPut extends HttpRoute {
public function __construct(string $path) {
parent::__construct('PUT', $path);

View file

@ -5,9 +5,12 @@
namespace Index\Http\Routing;
use Attribute;
/**
* Provides an attribute for marking methods in a class as a route.
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class HttpRoute extends HandlerAttribute {
private string $method;