aipng / apitte-mapping
Custom type mappers for contributte/apitte
Requires
- php: >=8.4
- aipng/value-objects: ^3.0
- contributte/apitte: ^0.14
Requires (Dev)
- aipng/coding-standard: ^2.1
- nette/tester: ^2.5
- phpstan/phpstan: ^2.0
- phpstan/phpstan-nette: ^2.0
This package is auto-updated.
Last update: 2026-05-16 07:31:58 UTC
README
Custom parameter type mappers for contributte/apitte.
Installation
composer require aipng/apitte-mapping
Registration
Register the mappers manually in your Nette configuration:
api: plugins: Apitte\Core\DI\Plugin\CoreMappingPlugin: types: date: AipNg\ApitteMapping\Parameter\DateTypeMapper email: AipNg\ApitteMapping\Parameter\EmailTypeMapper int_array: AipNg\ApitteMapping\Parameter\IntegerArrayTypeMapper
Mappers
DateTypeMapper
Type name: date
Accepts a date string in Y-m-d format and returns a DateTimeImmutable with time set to 00:00:00.
Invalid input throws Apitte\Core\Exception\Runtime\InvalidArgumentTypeException.
EmailTypeMapper
Type name: email
Accepts an email address string and returns an AipNg\ValueObjects\Web\Email value object. The address is normalized to lowercase.
Invalid input throws Apitte\Core\Exception\Runtime\InvalidArgumentTypeException.
IntegerArrayTypeMapper
Type name: int_array
Accepts a comma-separated string of integers (e.g. 1,2,3) and returns array<int>. Whitespace around items is trimmed. Empty string or comma-only input returns an empty array.
Invalid input (non-string, non-integer values, floats) throws Apitte\Core\Exception\Runtime\InvalidArgumentTypeException.
Usage
use Apitte\Core\Annotation\Controller\Path; use Apitte\Core\Annotation\Controller\RequestParameter; use Apitte\Core\Annotation\Controller\Method; use Apitte\Core\Http\ApiRequest; use Apitte\Core\Http\ApiResponse; use AipNg\ValueObjects\Web\Email; #[Path('/users')] final class UserController implements \Apitte\Core\UI\Controller\IController { #[Path('/search')] #[Method('GET')] public function search( ApiRequest $request, ApiResponse $response, #[RequestParameter(name: 'email', type: 'email')] Email $email, #[RequestParameter(name: 'since', type: 'date')] \DateTimeImmutable $since, #[RequestParameter(name: 'ids', type: 'int_array', required: false)] array $ids = [], ): ApiResponse { // $email is AipNg\ValueObjects\Web\Email // $since is DateTimeImmutable at 00:00:00 // $ids is array<int> ... } }