From 2679b8d562cccf0f94e196655df2e29f0dcbca12 Mon Sep 17 00:00:00 2001 From: Artjoms Nemiro Date: Tue, 3 Oct 2017 21:07:45 +0300 Subject: [PATCH] Add usage info --- README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/README.md b/README.md index 80e3573..02c5215 100644 --- a/README.md +++ b/README.md @@ -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 +```