mcfedr/uuid-paramconverter

此包已被废弃,不再维护。作者建议使用mcfedr/uuid-extra-bundle包。

用于 Ramsey Uuid 的参数转换器、标准化器和表单类型

安装量: 56,136

依赖项: 0

建议者: 0

安全: 0

星级: 18

关注者: 4

分支: 6

类型: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

一个方便的捆绑包,用于在您的项目中使用 ramsey/uuid

Latest Stable Version License Build Status

安装

Composer

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

AppKernel

将捆绑包包含在您的 AppKernel 中

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

配置

不需要配置

参数转换器

就像使用其他任何参数转换器一样使用

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

大多数情况下,只要你在操作上使用类型提示,它就会自动工作

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

也适用于可选参数

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

序列化器

也应该像正常化器一样工作

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

结果为 "f13a5b20-9741-4b15-8120-138009d8e0c7"

反过来也是如此

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

结果为 $uuid

在您的对象等中工作

表单类型

执行您期望的所有操作

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

如果您的模型有

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

它将自动使用 UuidType