1. Go to this page and download the library: Download scriptfusion/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/ */
scriptfusion / mapper example snippets
$mappedData = (new Mapper)->map($data, new MyMapping);
$fooData = ['foo' => 123];
class FooToBarMapping extends Mapping
{
protected function createMapping()
{
return ['bar' => new Copy('foo')];
}
}
$barData = (new Mapper)->map($fooData, new FooToBarMapping);
protected function createMapping()
{
return [
'foo' => new FooMapping,
'bar' => new BarMapping,
]
}
protected function createMapping()
{
return new Merge(new FooMapping, new BarMapping);
}
class FooBookAddressToAddresesMapping extends Mapping
{
protected function createMapping()
{
return [
'line1' => new Copy('address->address_line1'),
'line2' => new Copy('address->address_line2'),
'city' => new Copy('address->city'),
'postcode' => new Copy('address->post_code'),
'country' => new Copy('country'),
];
}
}
$address = (new Mapper)->map($fooBookAddress, new FooBookAddressToAddresesMapping);
// Output.
[
'line1' => '3 High Street',
'line2' => 'Hedge End',
'city' => 'SOUTHAMPTON',
'postcode' => 'SO31 4NG',
'country' => 'UK',
]
(new Mapper)->map(
['foo' => 'bar'],
new TryCatch(
new Callback(
function () {
throw new \DomainException;
}
),
function (\Exception $exception, array $data) {
if (!$exception instanceof \DomainException) {
throw $exception;
}
},
new Copy('foo')
)
);
Type(DataType $type, Strategy $strategy)
(new Mapper)->map(['foo' => 123], new Type(DataType::STRING(), new Copy('foo')));
Unique(Strategy|Mapping|array|mixed $collection)
(new Mapper)->map(
['foo' => array_merge(range(1, 3), range(3, 5))],
new Unique(new Copy('foo'))
);
Debug(Strategy|Mapping|array|mixed $expression)
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.