weblabel / data-transformer
This library provides object-oriented interface for decoding string formats (e.g. JSON) into an array
Installs: 2 010
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.4
- ext-json: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.3
- phpstan/phpstan: ^0.12.99
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-11-09 05:22:24 UTC
README
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Open a command console, enter your project directory and execute:
$ composer require weblabel/data-transformer
Basic Usage
<?php declare(strict_types=1); require 'vendor/autoload.php'; use Weblabel\DataTransformer\Decoder\JsonDecoder; use Weblabel\DataTransformer\Resolver\DecoderResolver; $decoders = [ new JsonDecoder(), ]; $decoderResolver = new DecoderResolver($decoders); $jsonDecoder = $decoderResolver->resolve('json'); $data = $jsonDecoder->decode('{"status":"ok"}'); // will return // [ // 'status' => 'ok', // ]
Testing
To run all unit tests, use the locally installed PHPUnit:
$ ./vendor/bin/phpunit