Skip to content

Commit e7cf565

Browse files
change README and add CHANGELOG
1 parent a3da4db commit e7cf565

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog for github.com/a-afsharfarnia/php-data-mapper
2+
3+
All notable changes to this package will be documented in this file.
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/).
6+
7+
## [1.0.0] - 2019-10-21
8+
9+
First release

README.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,37 @@
11
# A Simple Method to Make a Data Mapper in PHP
2-
In most projects, we have to map data to other cases. For example we want to map `1m` to `1 minute` or `3d` to `3 days`.
3-
4-
This package is a data mapper and we can create our mapper based on that very easily.
2+
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.
53

64
## Install
75
```
86
$ composer require a-afsharfarnia/data-mapper
97
```
108

119
### How to use
12-
You can find samples of using this package in `/src/samples`. You can have a look on `TimeMapper` and `LanguageMapper` classes.
10+
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:
11+
12+
- Time Mapper (e.g. map `1m` to `1 minute` and vise versa)
13+
- Language Mapper (e.g. map `en` to `english` and vise versa)
14+
15+
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`.
16+
17+
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.
18+
19+
``` php
20+
public static $mapper = [
21+
"1m" => "1minute",
22+
"30m" => "30minutes",
23+
"1h" => "1hour",
24+
"8h" => "8hours",
25+
"12h" => "12hours",
26+
"1d" => "1day",
27+
"3d" => "3days",
28+
"1w" => "1week",
29+
"1M" => "1month"
30+
];
31+
```
1332

14-
In fact, in your project, for each map data, you must create a class which is extended of `Afsharfarnia\DataMapper\mappers\Mapper` of this package. Then in each class you must define a `$mapper` static property which includes its mapper data.
33+
After creating your mapper classes, you can use them in your projects as following:
34+
```php
35+
echo TimeMapper::mapData("1m"); --> result: 1 minute (to map)
36+
echo TimeMapper::unmapData("12hours"); --> result: 12h (to unmap)
37+
```

0 commit comments

Comments
 (0)