PHP code example of guennichi / mapper
1. Go to this page and download the library: Download guennichi/mapper library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
guennichi / mapper example snippets
use Guennichi\Collection\Collection;
final class Person
{
public function __construct(public readonly string $name) {}
}
/**
* @extends Collection<Person>
*/
final class PersonCollection extends Collection
{
public function __construct(Person ...$elements)
{
parent::__construct(...$elements);
}
}
$input = [
['name' => 'Person1'],
['name' => 'Person2'],
['name' => 'Person3'],
];
$mapper = new Guennichi\Mapper\Mapper(/** dependencies */)
$output = $mapper->map($input, PersonCollection::class);
// Result instance of PersonCollection(Person{"name": "Person1"}, Person{"name": "Person2"}, Person{"name": "Person3"})