gamez / ramsey-uuid-normalizer
Symfony Normalizer and Denormalizer for ramsey/uuid
Fund package maintenance!
jeromegamez
Installs: 254 554
Dependents: 2
Suggesters: 2
Security: 0
Stars: 15
Watchers: 3
Forks: 4
Open Issues: 0
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0
- ramsey/uuid: ^4.7.5
- symfony/serializer: ^6.4 || ^7.0.1
Requires (Dev)
- phpstan/extension-installer: ^1.3.1
- phpstan/phpstan: ^1.10.50
- phpstan/phpstan-phpunit: ^1.3.15
- phpunit/phpunit: ^10.5.3
- symfony/property-access: ^6.4 || ^7.0
README
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.