https://github.com/mapado/request-fields-parser
Convert string like "id,firstname,lastname,jobs{startDate,position,company{id,recordNumber}}" to array
https://github.com/mapado/request-fields-parser
Last synced: about 1 year ago
JSON representation
Convert string like "id,firstname,lastname,jobs{startDate,position,company{id,recordNumber}}" to array
- Host: GitHub
- URL: https://github.com/mapado/request-fields-parser
- Owner: mapado
- License: mit
- Created: 2019-02-08T13:15:38.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2023-12-08T13:56:39.000Z (over 2 years ago)
- Last Synced: 2025-04-30T21:52:23.292Z (about 1 year ago)
- Language: PHP
- Size: 59.6 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# request-fields-parser
Convert string like `id,firstname,lastname,jobs{startDate,position,company{id,recordNumber}}` to the following array:
```php
[
'id' => true,
'firstname' => true,
'lastname' => true,
'jobs' => [
'startDate' => true,
'position' => true,
'company' => [
'id' => true,
'recordNumber' => true,
],
]
]
```
You can think of it like an [explode](https://php.net/explode) on steroids.
Also implement a `reverseParse` function for the opposite transformation.
## Installation
```sh
composer require mapado/request-fields-parser
```
## Usage
```php
use Mapado\RequestFieldsParser\Parser;
$parser = new Parser();
$outArray = $parser->parse($string);
$outString = $parser->reverseParse($array);
```
## Extensibility
You can decorate the Parser like this:
```php
use Mapado\RequestFieldsParser\ParserInterface;
class ExtendedParser implements ParserInterface
{
/**
* @var ParserInterface
*/
private $decoratedParser;
public function __construct(ParserInterface $decoratedParser)
{
$this->decoratedParser = $decoratedParser;
}
public function parse(string $string): array
{
// do stuff and return an array
}
}
```
## Contribute
Just run `make test` to launch the test suite