weblabel/data-transformer

This library provides object-oriented interface for decoding string formats (e.g. JSON) into an array

v1.0.3 2021-12-08 21:29 UTC

This package is auto-updated.

Last update: 2024-11-09 05:22:24 UTC


README

Github CI

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