a-afsharfarnia / data-mapper
This is a package to make a simple data mapper
Installs: 16
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
Type:helper
pkg:composer/a-afsharfarnia/data-mapper
Requires
- php: 7.2.*
Requires (Dev)
- phpunit/phpunit: >=7.0
This package is not auto-updated.
Last update: 2026-01-07 19:53:30 UTC
README
By this package we can map data from one to another. For example we can create a time mapper for map 1m to 1 minute and vise versa, or map 3d to 3 days. Thereby when we have 1m, we will be able to reach 1 minute and so on.
Install
$ composer require a-afsharfarnia/data-mapper
How to use
After installing the package, the only thing you have to do is creating your mapper classes. Imagine you want to have following mappers in your projects:
- Time Mapper (e.g. map
1mto1 minuteand vise versa) - Language Mapper (e.g. map
entoenglishand vise versa)
So, you must create a class for each mapper. You can have a look on TimeMapper and LanguageMapper classes as a sample in /src/samples.
As you can see in samples, each mapper class is extended of Afsharfarnia\DataMapper\mappers\Mapper. Then in each mapper class you must define a $mapper static property which includes mapper data.
public static $mapper = [ "1m" => "1minute", "30m" => "30minutes", "1h" => "1hour", "8h" => "8hours", "12h" => "12hours", "1d" => "1day", "3d" => "3days", "1w" => "1week", "1M" => "1month" ];
After creating your mapper classes, you can use them in your projects as following:
echo TimeMapper::mapData("1m"); --> result: 1 minute (to map) echo TimeMapper::unmapData("12hours"); --> result: 12h (to unmap)