piotrgradzinski / uuid-extra-bundle
用于 Ramsey Uuid 的 Paramconverter、Normalizer 和 Form Type
4.3.0
2023-05-19 16:28 UTC
Requires
- php: ^8.1
- ramsey/uuid: ^4.2.3
- sensio/framework-extra-bundle: ^6.2
- symfony/framework-bundle: ^6.2
Requires (Dev)
- doctrine/coding-standard: ^9.0
- phpunit/phpunit: ^9.6
- psalm/plugin-phpunit: ^0.16.1
- symfony/browser-kit: ^6.2
- symfony/form: ^6.2
- symfony/monolog-bundle: ^3.8
- symfony/serializer: ^6.2
- symfony/validator: ^6.2
- symfony/yaml: ^6.2
- vimeo/psalm: ^4.23
Conflicts
- ramsey/collection: <1.2.0
- symfony/browser-kit: <6.2
- symfony/cache: <6.2
- symfony/config: <6.2
- symfony/console: <6.2
- symfony/dependency-injection: <6.2
- symfony/dom-crawler: <6.2
- symfony/error-handler: <6.2
- symfony/event-dispatcher: <6.2
- symfony/filesystem: <6.2
- symfony/finder: <6.2
- symfony/http-foundation: <6.2
- symfony/http-kernel: <6.2
- symfony/monolog-bridge: <6.2
- symfony/options-resolver: <6.2
- symfony/property-access: <6.2
- symfony/property-info: <6.2
- symfony/routing: <6.2
- symfony/var-dumper: <6.2
- symfony/var-exporter: <6.2
This package is auto-updated.
Last update: 2024-09-19 19:43:04 UTC
README
一个方便的包,用于在项目中使用 ramsey/uuid
免责声明
此存储库是 ekreative/uuid-extra-bundle 的分支,包含一些更新,因为原始项目已有一段时间未更新。
安装
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