sbooker/litgroup-enumerable-normalizer

LitGroup Enumerable normalizer

2.0.0 2021-12-05 12:02 UTC

This package is auto-updated.

Last update: 2022-01-05 12:32:33 UTC


README

Latest Version Software License PHP Version Total Downloads

The sbooker/litgroup-enumerable-normalizer package provides the ability to normalize/denormalize litgroup/enumerable with Symfony serializer.

Installation

The preferred method of installation is via Packagist and Composer. Run the following command to install the package and add it as a requirement to your project's composer.json:

composer require sbooker/litgroup-enumerable-normalizer

Examples

// Declare Enum 

use LitGroup\Enumerable\Enumerable;

final class ColorEnum extends Enumerable
{
    /**
     * @return self
     */
    public static function red()
    {
        return self::createEnum('red');
    }

    /**
     * @return self
     */
    public static function green()
    {
        return self::createEnum('green');
    }

    /**
     * @return self
     */
    public static function blue()
    {
        return self::createEnum('blue');
    }
}

// Configure Symfony serializer
$serializer = new Symfony\Component\Serializer\Serializer([
    new \Sbooker\LitGroupEnumerable\Normalizer\EnumerableNormalizer(),
]);

// Normalize enum
$normalized = $serializer->normalize(ColorEnum::red()); // $normalized === 'red'

License

See LICENSE file.