mcfedr/uuid-extra-bundle

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

Paramconverter、Normalizer 和 Form Type 用于 Ramsey Uuid

安装次数 62,031

依赖关系: 0

推荐者: 0

安全: 0

星标: 17

关注者: 4

分支: 8

开放问题: 11

类型:symfony-bundle

4.2.0 2022-01-17 13:28 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