ekreative / uuid-extra-bundle
用于 Ramsey Uuid 的 Paramconverter、Normalizer 和 Form Type
4.2.0
2022-01-17 13:28 UTC
Requires
- php: ^7.3 || ~8.0.0 || ~8.1.0
- ramsey/uuid: ^4.2.3
- sensio/framework-extra-bundle: ^5.6.1 || 6.2.6
- symfony/framework-bundle: ^5.4.2 || ^6.0.2
Requires (Dev)
- doctrine/coding-standard: ^9.0
- phpunit/phpunit: ^9.5.11
- psalm/plugin-phpunit: ^0.16.1
- symfony/browser-kit: ^5.4.2 || ^6.0.1
- symfony/form: ^5.4.2 || ^6.0.2
- symfony/monolog-bundle: ^3.7.1
- symfony/serializer: ^5.4.2 || ^6.0.2
- symfony/validator: ^5.4.2 || ^6.0.2
- symfony/yaml: ^5.4.2 || ^6.0.2
- vimeo/psalm: ^4.18.1
Conflicts
- ramsey/collection: <1.2.0
- symfony/browser-kit: <5.3.7
- symfony/cache: <5.3.7
- symfony/config: <5.3.7
- symfony/console: <5.3.7
- symfony/dependency-injection: <5.3.7
- symfony/dom-crawler: <5.3.7
- symfony/error-handler: <5.3.7
- symfony/event-dispatcher: <5.3.7
- symfony/filesystem: <5.3.7
- symfony/finder: <5.3.7
- symfony/http-foundation: <5.3.7
- symfony/http-kernel: <5.3.7
- symfony/monolog-bridge: <5.3.7
- symfony/options-resolver: <5.3.7
- symfony/property-access: <5.3.7
- symfony/property-info: <5.3.7
- symfony/routing: <5.3.7
- symfony/var-dumper: <5.3.7
- symfony/var-exporter: <5.3.7
- dev-master
- 4.2.0
- 4.1.0
- 4.0.0
- 3.2.1
- 3.2.0
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.2
- 3.0.1
- 3.0.0
- 2.3.1
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.1
- 2.0.0
- 1.0.0
- dev-dependabot/composer/symfony/form-5.4.21
- dev-dependabot/composer/symfony/serializer-5.4.21
- dev-dependabot/composer/symfony/string-5.4.21
- dev-dependabot/composer/symfony/framework-bundle-5.4.21
- dev-dependabot/github_actions/ridedott/merge-me-action-2.10.43
- dev-dependabot/composer/slevomat/coding-standard-7.2.1
- dev-rename
- dev-uuid3
This package is auto-updated.
Last update: 2024-09-06 18:32:18 UTC
README
一个方便的bundle,用于在项目中使用 ramsey/uuid
安装
Composer
php composer.phar require ekreative/uuid-extra-bundle
AppKernel
在您的 AppKernel 中包含此 bundle
public function registerBundles() { $bundles = array( ... new Ekreative\UuidExtraBundle\EkreativeUuidExtraBundle()
配置
不需要配置
Param Converter
就像使用任何其他 param converter 一样使用
/** * @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'); }
序列化器
就像一个正常的 normalizer 一样
$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