Coder Social home page Coder Social logo

ramsey-uuid-normalizer's Introduction

Symfony Normalizer and Denormalizer for ramsey/uuid

Current version Supported PHP version Monthly Downloads Total Downloads Tests Sponsor

Installation

The utility can be installed with Composer:

$ composer require gamez/ramsey-uuid-normalizer

Usage

Symfony Serializer Component

The usage example requires the PropertyAccess Component component, which can also be installed with Composer:

$ composer require symfony/property-access
use Gamez\Symfony\Component\Serializer\Normalizer\UuidNormalizer;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;

class Person
{
    public $id;
    public $name;
}

$person = new Person();
$person->id = Uuid::uuid4();
$person->name = 'Jérôme Gamez';

$encoders = [new JsonEncoder()];
$normalizers = [new UuidNormalizer(), new ObjectNormalizer()];
$serializer = new Serializer($normalizers, $encoders);

$json = $serializer->serialize($person, 'json');
echo $json.PHP_EOL;
// {"id":"3d79048c-29e7-482f-979a-5b9a708b2ede","name":"J\u00e9r\u00f4me Gamez"}

$person = $serializer->deserialize($json, Person::class, 'json');
var_dump($person);
/*
class Person#27 (2) {
  public $id =>
  string(36) "3d79048c-29e7-482f-979a-5b9a708b2ede"
  public $name =>
  string(14) "Jérôme Gamez"
}
*/

For further information on how to use the Symfony Serializer Component, please see The Serializer Component in the official documentation.

ramsey-uuid-normalizer's People

Contributors

jeromegamez avatar snapshotpl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ramsey-uuid-normalizer's Issues

Fix deprecation from Symfony 6.3

Since symfony/serializer 6.3: "Gamez\Symfony\Component\Serializer\Normalizer\UuidNormalizer" should implement "DenormalizerInterface::getSupportedTypes(?string $format): array".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.