mapado / request-fields-parser
Convert string like `id,firstname,lastname,jobs{startDate,position,company{id,recordNumber}}` to the array
Installs: 8 268
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 4
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- doctrine/lexer: ^2.0 || ^3.0
Requires (Dev)
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.10
- phpstan/phpstan-phpunit: ^1.3
- phpunit/phpunit: ^10.3
README
Convert string like id,firstname,lastname,jobs{startDate,position,company{id,recordNumber}}
to the following array:
[ 'id' => true, 'firstname' => true, 'lastname' => true, 'jobs' => [ 'startDate' => true, 'position' => true, 'company' => [ 'id' => true, 'recordNumber' => true, ], ] ]
You can think of it like an explode on steroids.
Also implement a reverseParse
function for the opposite transformation.
Installation
composer require mapado/request-fields-parser
Usage
use Mapado\RequestFieldsParser\Parser; $parser = new Parser(); $outArray = $parser->parse($string); $outString = $parser->reverseParse($array);
Extensibility
You can decorate the Parser like this:
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