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; namespace Index\Http\Routing;
use Attribute;
use ReflectionAttribute; use ReflectionAttribute;
use ReflectionObject; 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)] abstract class HandlerAttribute {
class HandlerAttribute {
public function __construct(private string $path) {} public function __construct(private string $path) {}
/** /**

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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