Skip to content

Commit

Permalink
Add documentation for array condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Valouleloup committed Jun 19, 2018
1 parent 413cb74 commit eeb59e1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [0.2.1] - 2018-06-19
### Added
- Add array condition
- Add documentation

## [0.2] - 2018-06-12
### Added
- Add an `OptimusException` class
Expand Down
38 changes: 30 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class MyTransformer extends AbstractMappingTransformer
```
The ` $result ` variable now contains the new array.

### The input data
### Configuration

Assuming you got the PHP array `$inputArray`
Assuming you got the PHP array `$inputArray` (input data)
```php
$inputArray = [
'user' => [
Expand All @@ -69,9 +69,7 @@ $inputArray = [
];
```

### YAML Mapping

Consider you want to transform it to the following array
And considering you want to transform it to the following array (expected output)
```php
$outputArray = [
'title' => 'A title',
Expand Down Expand Up @@ -102,7 +100,7 @@ transformer:
```
## Available mapping
## Available mapping options
You can declare your node
* `from` : string, the key path of the `input` array
Expand Down Expand Up @@ -153,8 +151,8 @@ required: true # Default to false
```

#### Use a default value
Actually, if `from` value don't exist in your input array, the `to` field don't appear in the output array.
If you want this field to got a default value, you can add `default` key.
Actually, if `from` value doesn't exist in your input array, the `to` field doesn't appear in the output array.
If you want this field to get a default value, you can add `default` key.
```yaml
from: a
to: b
Expand All @@ -168,3 +166,27 @@ default:
function:
name: getB # You can also use a function to define default value
```

#### Add a condition

If you want to transform a field A only if a field B exists.

```yaml
from: a
to: foo
condition:
exists: b
```

You can put multiple fields in your condition :

```yaml
from: a
to: foo
condition:
exists:
- b
- c
```


0 comments on commit eeb59e1

Please sign in to comment.