Download the PHP package peterdkc/parser without Composer
On this page you can find all versions of the php package peterdkc/parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package parser
Note: This package is a fork and may / may not be maintained independently depending on whether the original maintainer starts maintaining his source as of 4/18/2018. Please use with caution and Watch the source repo for updates.
All the documentation below should still be relevant although items such as build status may not reflect reality for this fork.
Parser
Simple PHP Parser Library for API Development, parse a post http payload into a php array.
Also see the Responder library for handling output.
Installation
Begin by installing this package through Composer. From the Terminal:
composer require peterdkc/parser
Laravel/Lumen Users
Laravel/Lumen Verison | Supported Library Verison |
---|---|
Laravel/Lumen 5+ | > 3.* |
Laravel 4 | 2.* |
Laravel Users (Adding the Service Provider)
If you are a Laravel user, then there is a service provider that you can make use of to automatically prepare the bindings and such.
Include the service provider within app/config/app.php
.
And, for convenience, add a facade alias to this same file at the bottom:
Lumen Users (Adding the Service Provider)
If you are a Lumen user, then there is a service provider that you can make use of to automatically prepare the binding and such.
Lumen users can also add the facade alias.
Using the Facade
All the examples below assume you aren't using Laravel (or Lumen), and therefore don't have access to the facade. As with any other facade, instead of:
just use:
Usage
Parsing Functions
Parse Input/Payload (PUT/POST)
Helper functions
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.
Sample Payload
Applying the Mask
Output
This is the output generated as a result of applying the mask against the sample payload provided above.
Wildcards/Special Keys (*, %, :first, :last, :index[0], :item[0])
Parse JSON
Parse XML
Parse Query String
Parse Serialized Object
Parse YAML
Parse BSON
Parse MSGPack
Custom Parsers/Formatters
You can make your own custom parsers/formatters by implementing FormatInterface, the below example demostrates the use of a custom parser/formatter.
Using the CustomFormatter
Autodetecting the CustomFormatter
Testing
To test the library itself, run the tests:
composer test
Contributing
Please see CONTRIBUTING for details.
Credits
- nathanmac
- All Contributors
License
The MIT License (MIT). Please see License File for more information.