aipng/apitte-mapping

Custom type mappers for contributte/apitte

Maintainers

Package info

github.com/aipng/apitte-mapping

pkg:composer/aipng/apitte-mapping

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.1 2026-05-16 07:28 UTC

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>
        ...
    }

}