Skip to content
This repository has been archived by the owner on Mar 13, 2019. It is now read-only.

Commit

Permalink
Add usage info
Browse files Browse the repository at this point in the history
  • Loading branch information
LinMAD committed Oct 3, 2017
1 parent 6b3f036 commit 2679b8d
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,39 @@ Then if it founds some mismatches it will put error to bucket and after process
In the end, you will receive a boolean and from that you can understand if structure valid as expected mapping.

In other words, it simply walks in your tree and checks needed keys exist and value type are correct.

### Example of usage
For example, for your needs given some data in structure:
```php
$paymentReq = '{
"amount": 10500,
"ccy": "EUR",
"account_id": 42,
"order_description": "facere repellat provident occaecati excepturi optio reprehenderit"
}';
```

And you want to use like "schema", "map" or "structure" to overlay it. For example your map:
```php
$payementReqMap = [
'amount' => 'integer',
'ccy' => 'string',
'account_id' => 'integer'
];
```
So, in your structure map key "order_description" not mandatory and you can accept it or skip.
But others keys are strict and mandatory, so you didn't allow pass invalid data to your system.

```php
// Create instance
$analyzer = new Analyzer();

// Check if structure same as expected in map
$isValid = $analyzer->isValidStructure($paymentReq, $payementReqMap); // return bool, valid or not as expected

if ($isValid) {
// Make some magic
$this->paymentProvider->takeRequest($paymentReq);
}
// Or use other magic
```

0 comments on commit 2679b8d

Please sign in to comment.