Declarable HTTP resources #10

Merged
c.fahner merged 15 commits from issues/3 into main 2026-06-16 07:59:25 +02:00
Owner

Resolves #3.

Resolves #3.
c.fahner added this to the v0.1 milestone 2026-05-09 09:34:19 +02:00
c.fahner changed title from Declarable HTTP resources to WIP: Declarable HTTP resources 2026-05-09 09:34:27 +02:00
@ -0,0 +20,4 @@
* @copyright Slendium 2026
*/
#[Attribute(Attribute::TARGET_PARAMETER)]
class NonEmpty implements ArgumentValidator {
Author
Owner

Add tests

Add tests
c.fahner marked this conversation as resolved
@ -0,0 +9,4 @@
* @author C. Fahner
* @copyright Slendium 2026
*/
final class ArgumentCasts {
Author
Owner

Add tests

Add tests
c.fahner marked this conversation as resolved
c.fahner canceled time tracking 2026-05-17 08:21:43 +02:00
c.fahner canceled time tracking 2026-05-17 08:21:54 +02:00
c.fahner added spent time 2026-05-17 08:22:00 +02:00
1 hour
@ -0,0 +136,4 @@
'float' => ArgumentCasts::toFloat($arg->value),
'string' => ArgumentCasts::toString($arg->value),
Field::class => ArgumentCasts::toField($arg->value),
default => ResourceException::forUnsupportedType($param->name, $type)
Author
Owner

ResourceException should not be part of the return type, they should not happen during normal operation. Just throw.

`ResourceException` should not be part of the return type, they should not happen during normal operation. Just throw.
c.fahner marked this conversation as resolved
@ -0,0 +113,4 @@
$type === null => ResourceException::forMissingType($param->name),
$type instanceof ReflectionNamedType => self::castArgumentTyped($param, $arg, $type->getName()),
$type instanceof ReflectionUnionType => self::castArgumentUnion($param, $type, $arg),
$type instanceof ReflectionIntersectionType => ResourceException::forUnsupportedType($param->name, $type),
Author
Owner

Throw and remove from return type.

Throw and remove from return type.
c.fahner marked this conversation as resolved
c.fahner added spent time 2026-05-17 08:31:44 +02:00
15 minutes
src/Resource.php Outdated
@ -0,0 +18,4 @@
*
* To define an HTTP-method for the resource, simply add a class-method with the same name as the
* HTTP-method. The class-method must be `public` and must declare a return type that is covariant
* with `?Method`. To ensure the method's possible responses can be properly documented (eg. for OpenAPI),
Author
Owner

Return type can also be Response

Return type can also be `Response`
c.fahner marked this conversation as resolved
@ -0,0 +4,4 @@
use Exception;
/**
Author
Owner

Add an explanation that this exception should be returned instead of thrown.

Add an explanation that this exception should be returned instead of thrown.
c.fahner marked this conversation as resolved
@ -0,0 +6,4 @@
/**
* Indicates a problem with the way the resource has been declared.
*
Author
Owner

Add explanation that this indicates a developer error and that this exception is thrown.

Add explanation that this indicates a developer error and that this exception is thrown.
c.fahner marked this conversation as resolved
@ -0,0 +5,4 @@
use Slendium\Framework\Builders\ResponseBuilder;
/**
* Modifies a resource method's response before it is sent back.
Author
Owner

"HTTP response modifier for a declared resource method."

"HTTP response modifier for a declared resource method."
c.fahner marked this conversation as resolved
@ -0,0 +22,4 @@
$this->assertSame(2, $result);
}
public function test_parameters_shouldHaveExpectedCount_whenEvaluatingImpliedHeadMethod(): void {
Author
Owner

"whenEvaluatingHeadMethod" (since the head method is a forced wrapper, not really implied)

"whenEvaluatingHeadMethod" (since the head method is a forced wrapper, not really implied)
c.fahner marked this conversation as resolved
c.fahner stopped working 2026-06-15 12:59:22 +02:00
45 minutes 48 seconds
c.fahner changed title from WIP: Declarable HTTP resources to Declarable HTTP resources 2026-06-15 13:00:22 +02:00
c.fahner deleted branch issues/3 2026-06-16 07:59:25 +02:00
c.fahner referenced this pull request from a commit 2026-06-16 07:59:26 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Total time spent: 2 hours
c.fahner
2 hours
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
slendium/framework!10
No description provided.