kherge / uuid-bundle
2.0.0
2017-01-19 22:16 UTC
Requires
- php: >=5.6
- ramsey/uuid: ^3.5
- symfony/config: ^2.8|^3.0
- symfony/dependency-injection: ^2.8|^3.0
- symfony/http-kernel: ^2.8|^3.0
Requires (Dev)
- doctrine/dbal: ^2.5
- doctrine/orm: ^2.4
- ircmaxell/random-lib: ^1.1
- jms/serializer-bundle: ^1.1
- moontoast/math: ^1.1
- paragonie/random_compat: ^1.2
- ramsey/uuid-doctrine: ^1.1
- sensio/framework-extra-bundle: ^3.0.2
Suggests
- ext-libsodium: For use as a CSPRNG.
- ext-uuid: For generating time-based UUIDs.
- jms/serializer-bundle: For better serialization/deserialization of UUIDs.
- moontoast/math: For using UUID v2 and greater.
- ramsey/uuid-doctrine: For registering a uuid type with Doctrine.
- sensio/framework-extra-bundle: For converting request parameters to Uuid instances.
This package is auto-updated.
Last update: 2020-02-01 03:17:52 UTC
README
UUID Bundle
此扩展包将 ramsey/uuid
集成到 Symfony 2 作为服务。
使用方法
use Ramsey\Uuid\Uuid; // The UUID factory is available as a service. $factory = $this->container->get('kherge_uuid.uuid_factory'); // And you can use it how you normally would. $v1 = $factory->uuid1(); $v3 = $factory->uuid3(Uuid::NAMESPACE_DNS, 'example.com'); $v4 = $factory->uuid4(); $v5 = $factory->uuid5(Uuid::NAMESPACE_DNS, 'example.com');
安装
composer require kherge/uuid-bundle
一旦 Composer 下载了扩展包及其依赖项,请将以下行添加到 AppKernel
类(或您应用程序的等效类)中合适的位置。
new KHerGe\Bundle\UuidBundle\KHerGeUuidBundle(),
配置
虽然不需要配置,但您可能想查看 app/console config:dump-reference kherge_uuid
的输出,以了解所有可用设置的分解。每个设置都有文档说明,以便选择正确的设置变得简单一些。您需要了解如何使用 ramsey/uuid
包,以便了解扩展包的设置如何与其类一起工作。
推荐设置
这将允许您生成安全的 UUID,但要求您已安装 moontoast/math
包和 libsodium
扩展。
kherge_uuid: builder: default: number_converter: kherge_uuid.number_converter.big_number generator: default_time: time_converter: kherge_uuid.time_converter.big_number uuid_factory: number_converter: kherge_uuid.number_converter.big_number random_generator: kherge_uuid.generator.sodium time_generator: kherge_uuid.generator.default_time
您可能想更改随机生成器。
Doctrine
您可以要求 Doctrine 为您的新实体自动生成新的 UUID。支持仅限于 v1 和 v4 UUID。要使用自定义生成器,您需要在实体中的 ID 字段使用以下注解
use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity() * @ORM\Table() */ class Entity { /** * @ORM\Column(type="uuid") * @ORM\CustomIdGenerator("KHerGe\Bundle\UuidBundle\Doctrine\Id\Uuid4Generator") * @ORM\GeneratedValue(strategy="CUSTOM") * @ORM\Id() */ private $id; }
将类名替换为您想要的生成器。
强烈建议您启用全局工厂的使用。如果不这样做,UUID 库将创建和使用其自己的 UUID 工厂,而不依赖于为 Symfony 配置的工厂服务。
kherge_uuid: uuid_factory: global: true
参数转换
此扩展包提供对请求参数中 UUID 转换的支持。要使用此功能,您必须安装 sensio/framework-extra-bundle
以支持参数转换。
use Ramsey\Uuid\Uuid; /** * @Route("/entity/{id}") * @ParamConverter("id") */ public function getAction(Uuid $id) { // ... use the uuid ... }