Download the PHP package elaitech/data-mapper without Composer
On this page you can find all versions of the php package elaitech/data-mapper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download elaitech/data-mapper
More information about elaitech/data-mapper
Files in elaitech/data-mapper
Package data-mapper
Short Description Elaitech DataMapper - A reusable data mapping and transformation component for Laravel.
License MIT
Informations about the package data-mapper
๐ฆ Elaitech DataMapper
A reusable data mapping and transformation library for Laravel 12. Maps source fields to target fields with chained value transformers, dot-notation and wildcard field extraction, value mapping lookups, and full support for both associative and indexed (header-based) data rows.
Namespace:
Elaitechx\DataMapper
Requires: PHP 8.4+ ยท Laravel 12 ยทspatie/laravel-data^4.19
๐ Table of Contents
- Installation
- Architecture
- Quick Start
- Core Components
- Built-in Transformers
- Field Extraction
- Value Mapping
- Creating Custom Transformers
- DTOs
- Contracts
- Testing
- License
๐ Installation
As a local Composer package
In your root composer.json, add the package as a path repository:
Then install:
The DataMapperServiceProvider is auto-discovered by Laravel. It registers:
DataMapperInterfaceโDataMapperService(binding)ValueTransformerโ singleton with 10 built-in transformersFieldExtractorโ singleton
๐ Architecture
โก Quick Start
๐งฉ Core Components
DataMapperService
The main service class. Implements DataMapperInterface.
Behaviour:
- Automatically detects whether rows are associative (
['name' => 'John']) or indexed (['John', '[email protected]']) - For indexed rows, uses the
headersarray to resolve field positions - Wraps each row in a try/catch โ failed rows are captured as errors, not exceptions
- Returns
DataMappingResultDatawith mapped data and any per-row errors
FieldExtractor
Extracts values from data using:
| Pattern | Example | Description |
|---|---|---|
| Direct access | name |
Top-level field |
| Dot notation | address.city |
Nested field traversal |
| Wildcard | items.*.name |
Extract from all array elements |
ValueTransformer
The transformer registry and execution engine. Manages all registered transformers and applies transformation chains.
Transformation flow:
- Check if value is empty โ return
defaultValue(unless it's an array transformer) - Apply value mapping if configured (lookup table)
- Apply transformer (type conversion, formatting)
- If result is empty string and
defaultValueis set โ returndefaultValue
๐ง Built-in Transformers
| Name | Label | Description | Requires Format |
|---|---|---|---|
none |
None | Pass-through, no transformation | โ |
trim |
Trim | Remove leading/trailing whitespace | โ |
upper |
Uppercase | Convert to UPPERCASE | โ |
lower |
Lowercase | Convert to lowercase | โ |
int |
Integer | Cast to int (extracts digits from messy strings; falls back to default) |
โ |
float |
Float | Cast to float with precision control |
โ (decimals) |
bool |
Boolean | Cast to bool (handles "true", "1", "yes", etc.) |
โ |
date |
Date | Parse and reformat dates | โ (date format) |
array_first |
Array First | Extract first element from array | โ |
array_join |
Array Join | Join array elements with separator | โ (separator) |
๐บ Field Extraction
Dot Notation
Access nested fields in associative arrays:
Wildcard Notation
Extract values from arrays of objects:
Indexed (Header-Based) Rows
For data without keys (e.g., CSV rows), provide headers:
๐ Value Mapping
Map specific values using a lookup table. Useful for code-to-label conversions:
Value mapping is applied before the transformer, so you can combine both:
๐ Creating Custom Transformers
Implement the TransformerInterface:
Register it:
Or register in a service provider for global availability:
๐ DTOs
MappingConfigurationData
Input to the mapper:
| Property | Type | Description |
|---|---|---|
data |
array |
Array of rows to map |
mappingRules |
DataCollection<MappingRuleData> |
Mapping rules to apply |
headers |
?array |
Column headers for indexed rows |
MappingRuleData
A single field mapping rule:
| Property | Type | Default | Description |
|---|---|---|---|
sourceField |
string |
โ | Source field name (supports dot/wildcard notation) |
targetField |
string |
โ | Target field name in output |
transformation |
string |
'none' |
Transformer name to apply |
isRequired |
bool |
false |
Throw if source field is missing |
defaultValue |
mixed |
null |
Fallback for empty values |
format |
?string |
null |
Format parameter for transformers (e.g., date format) |
valueMapping |
?array |
null |
Value lookup table ([['from' => ..., 'to' => ...]]) |
DataMappingResultData
Output from the mapper:
| Property | Type | Description |
|---|---|---|
data |
array |
Successfully mapped rows |
errors |
array |
Per-row error messages |
๐ Contracts
DataMapperInterface
TransformerInterface
๐งช Testing
๐ฆ Dependencies
| Package | Version | Purpose |
|---|---|---|
illuminate/support |
^12.0 | Laravel framework support |
spatie/laravel-data |
^4.19 | Typed DTOs with auto-mapping |
๐ License
MIT
All versions of data-mapper with dependencies
illuminate/support Version ^12.0|^13.0
spatie/laravel-data Version ^4.19