1. Go to this page and download the library: Download elaitech/data-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/ */
$transformer = app(ValueTransformer::class);
// Every transformer, in every group
$transformer->getTransformerOptions(); // ['none' => 'None', 'trim' => 'Trim', ...]
// Only the ones in the given groups
$transformer->getTransformerOptions(ValueTransformer::GROUP_CORE, 'export');
// Register a custom transformer (defaults to the "core" group)
$transformer->registerTransformer(new MyCustomTransformer());
$valueTransformer = app(ValueTransformer::class);
// A whole group at once
$valueTransformer->registerGroup('export', [new TransmissionExpandTransformer]);
// One transformer, into one or more groups
$valueTransformer->registerTransformer(new SlugTransformer, 'import', 'export');
// Widen a group with transformers that are already registered
$valueTransformer->addToGroup('export', 'trim', 'upper');
use Medox\DataMapper\Contracts\GroupedTransformerInterface;
final class TransmissionExpandTransformer implements GroupedTransformerInterface
{
public function getGroups(): array
{
return ['export'];
}
// ... getName(), getLabel(), getDescription(), transform(),
// What a UI should offer
$valueTransformer->getTransformerOptions(ValueTransformer::GROUP_CORE); // built-ins only
$valueTransformer->getTransformerOptions(ValueTransformer::GROUP_CORE, 'export'); // built-ins + export
$valueTransformer->getTransformerOptions(); // everything
// Introspection
$valueTransformer->getGroups(); // ['core', 'import', 'export']
$valueTransformer->getGroupsFor('transmission_expand'); // ['export']
$valueTransformer->hasGroup('export'); // true
$valueTransformer->getTransformersInGroups('export'); // array<string, TransformerInterface>
// Lookups can
use Medox\DataMapper\Contracts\TransformerInterface;
final class SlugTransformer implements TransformerInterface
{
public function getName(): string
{
return 'slug';
}
public function getLabel(): string
{
return 'Slugify';
}
public function getDescription(): string
{
return 'Converts text to URL-friendly slug';
}
public function transform($value, ?string $format = null, $defaultValue = null)
{
if ($value === null) {
return $defaultValue;
}
return \Illuminate\Support\Str::slug((string) $value);
}
public function
interface DataMapperInterface
{
public function map(MappingConfigurationData $config): DataMappingResultData;
}
interface TransformerInterface
{
public function getName(): string;
public function getLabel(): string;
public function getDescription(): string;
public function transform($value, ?string $format = null, $defaultValue = null);
public function
interface ColumnMatcherInterface
{
public function matchKey(array $row, string $column): string|int|null;
public function matchIndex(array $headers, string $column): ?int;
}
interface ValueMatcherInterface
{
public function matchValue(mixed $value, array $valueMapping): mixed;
}
interface NormalizerInterface
{
public function normalize(string $value): string;
}
/** @return array<int, string> */
public function getGroups(): array;