mcfedr/uuid-paramconverter

This package is abandoned and no longer maintained. The author suggests using the mcfedr/uuid-extra-bundle package instead.

Paramconverter, Normalizer and Form Type for Ramsey Uuid

Installs: 56 188

Dependents: 0

Suggesters: 0

Security: 0

Stars: 18

Watchers: 4

Forks: 6

Type:symfony-bundle

4.2.0 2022-01-17 13:28 UTC

This package is auto-updated.

Last update: 2022-02-01 12:47:14 UTC


README

A convenient bundle for using ramsey/uuid in your project

Latest Stable Version License Build Status

Install

Composer

php composer.phar require ekreative/uuid-extra-bundle

AppKernel

Include the bundle in your AppKernel

public function registerBundles()
{
    $bundles = array(
        ...
        new Ekreative\UuidExtraBundle\EkreativeUuidExtraBundle()

Config

No config needed

Param Converter

Use just like any other param converter

/**
 * @ParamConverter("uuid", class="Ramsey\Uuid\UuidInterface")
 * @Route("/simple/{uuid}")
 */
public function simpleAction(UuidInterface $uuid)
{
    return new Response($uuid->toString());
}

Most of the time its going to work automatically, as long as you use type hinting on your action

/**
 * @Route("/automatic/{uuid}")
 */
public function simpleAction(UuidInterface $uuid)
{
    return new Response($uuid->toString());
}

Also works for optional params

/**
 * @Route("/optional/{uuid}")
 */
public function simpleAction(UuidInterface $uuid = null)
{
    return new Response($uuid ? $uuid->toString() : 'no uuid');
}

Serializer

Also like a normalizer should

$this->serializer->serialize($uuid, 'json')

Results in "f13a5b20-9741-4b15-8120-138009d8e0c7"

And the other way around

$this->serializer->denormalize('"f13a5b20-9741-4b15-8120-138009d8e0c7"', UuidInterface::class, 'json')

Results in $uuid

Works in your Objects etc.

Form Type

Does everything you'd expect

->add('uuid', UuidType:class)

And if your model has

/**
 * @Assert\Uuid
 */
private $uuid;

It will automatically use the UuidType