From f4cd475ce4eeece5ad387acd735dff67cbb1b54c Mon Sep 17 00:00:00 2001 From: Nathan Macnamara Date: Mon, 29 Jun 2015 22:18:19 +0100 Subject: [PATCH] Update Docs --- README.md | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/README.md b/README.md index c977df1..32f0845 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ $parser->xml($payload); // XML > Array $parser->yaml($payload); // YAML > Array $parser->querystr($payload); // Query String > Array $parser->serialize($payload); // Serialized Object > Array +$parser->bson($payload); // BSON > Array ``` #### Parse Input/Payload (PUT/POST) @@ -109,6 +110,58 @@ $parser->only('id', 'name', 'email'); // Only return value from the selected k $parser->except('password'); // Don't return values from the selected keys. ``` +#### Mask function +The mask function processes payload data using a configuration mask, thereby returning only a selected subset of the data. +It works just like the `only` method but with the added benefit of allowing you to specify a mask in the form of an array, +this means you can generate masks on-the-fly based on system and/or user defined conditions. + +##### Demo +###### Mask +Defining the mask, masks consist of basic array structure, for this particular example we have some rules for the data +to be returned they include: + - the title of the post + - all the body's for all the comments. + +```php +$mask = [ + 'post' => [ + 'title' => '*', + 'comments' => [ + 'body' => '*' + ] + ] +]; +``` + +###### Sample Payload +```json +{ + "post": { + "title": "Hello World", + "author": "John Smith", + "comments": [ + {"body": "This is a comment", "date": "2015-02-20"}, + {"body": "This is another comment", "date": "2015-05-09"} + ] + } +} +``` + +###### Output +This is the output generated as a result of applying the mask against the sample payload provided above. + +```php +$output = [ + 'post' => [ + 'title' => 'Hello World', + 'comments' => [ + ['body' => 'This is a comment'], + ['body' => 'This is another comment'] + ] + ] +]; +``` + #### Wildcards/Special Keys (*, %, :first, :last, :index[0], :item[0]) ```php $parser = new Parser();