troytft / mapper
Mapper is a PHP library for mapping data to objects, type of property can be configured by annotation
Installs: 7 790
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.4
- doctrine/annotations: ^1.11
- symfony/polyfill-php81: ^1.22
Requires (Dev)
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^9.5
- slevomat/coding-standard: ^6.4
- squizlabs/php_codesniffer: ^3.5
README
Mapper is a PHP library for mapping data to objects, type of property can be configured by annotation
Features
- Supports scalar types: integer, float, boolean, string
- Supports any nesting level using object and collection types
- Supports work with dates
- Allows write your own types
- Allows define nullability of property
Usage
<?php use Mapper\Annotation as Mapper; use Mapper\ModelInterface; class Movie implements ModelInterface { /** * @var string * * @Mapper\StringType() */ private $name; /** * @var Release[]|null * * @Mapper\CollectionType(type=@Mapper\ObjectType(class="Model\Release"), nullable=true) */ private $releases; ... getters and setters } $model = new Movie(); $data = [ 'name' => 'Taxi 2', 'releases' => [ [ 'country' => 'France', 'date' => '2000-03-25' ], ] ]; $mapper->map($model, $data);
Requirements
- PHP 7.4 or higher
Installation
composer require troytft/mapper
Documentation
Full documentation can be found at docs/main.md