Skip to content

About

[READ ONLY] ✨ TypeLang Mapper bridge for Laravel Framework

Topics

Resources

Code of conduct

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

PHP 8.1+ Latest Stable Version Latest Unstable Version License MIT


Laravel integration of the TypeLang mapper: the service provider registers the mappers in the container and configures them from config/type-lang-mapper.php.

Full documentation is available at typelang.dev.

Installation

Install the package via Composer:

composer require type-lang/mapper-laravel

The service provider is discovered automatically. Publish the config to change the settings:

php artisan vendor:publish --tag=type-lang-mapper-config

Requirements:

  • PHP 8.1+
  • Laravel 10+

Usage

The default mapper is injected by MapperInterface, DenormalizerInterface or NormalizerInterface:

use TypeLang\Mapper\MapperInterface;

final class CreateUserController
{
    public function __invoke(Request $req, MapperInterface $mapper): Response
    {
        $user = $mapper->denormalize($req->all(), UserRequestDTO::class);
        // ...
    }
}

A named mapper takes the settings of the default one and overrides some of them:

// config/type-lang-mapper.php
return [
    'naming' => 'snake_case',
    'types' => [App\Mapper\UuidTypeBuilder::class],
    'mappers' => [
        'api' => [
            'strict' => true,
            'types' => [App\Mapper\MoneyTypeBuilder::class],
        ],
    ],
];
app('type-lang.mapper')->denormalize('42', 'int');
// 42

app('type-lang.mapper.api')->denormalize('42', 'int');
// throws InvalidValueException: $: Value must be of type int, but "42" given

About

[READ ONLY] ✨ TypeLang Mapper bridge for Laravel Framework

Topics

Resources

Code of conduct

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages