sbooker/litgroup-enumerable-normalizer

LitGroup Enumerable normalizer

2.1.0 2024-01-13 14:09 UTC

This package is auto-updated.

Last update: 2024-11-13 16:24:10 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.