piotrgradzinski / uuid-extra-bundle
Paramconverter, Normalizer and Form Type for Ramsey Uuid
Installs: 22 941
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 12
Type:symfony-bundle
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-12-19 20:18:32 UTC
README
A convenient bundle for using ramsey/uuid in your project
Disclaimer
This repository is a fork of ekreative/uuid-extra-bundle with some updates as the original project is not updated for some time now.
Install
Composer
php composer.phar require ekreative/uuid-extra-bundle
AppKernel
Include the bundle in your AppKernel
public function registerBundles() { $bundles = array( ... new Ekreative\UuidExtraBundle\EkreativeUuidExtraBundle()
Config
No config needed
Param Converter
Use just like any other param converter
/** * @ParamConverter("uuid", class="Ramsey\Uuid\UuidInterface") * @Route("/simple/{uuid}") */ public function simpleAction(UuidInterface $uuid) { return new Response($uuid->toString()); }
Most of the time its going to work automatically, as long as you use type hinting on your action
/** * @Route("/automatic/{uuid}") */ public function simpleAction(UuidInterface $uuid) { return new Response($uuid->toString()); }
Also works for optional params
/** * @Route("/optional/{uuid}") */ public function simpleAction(UuidInterface $uuid = null) { return new Response($uuid ? $uuid->toString() : 'no uuid'); }
Serializer
Also like a normalizer should
$this->serializer->serialize($uuid, 'json')
Results in "f13a5b20-9741-4b15-8120-138009d8e0c7"
And the other way around
$this->serializer->denormalize('"f13a5b20-9741-4b15-8120-138009d8e0c7"', UuidInterface::class, 'json')
Results in $uuid
Works in your Objects etc.
Form Type
Does everything you'd expect
->add('uuid', UuidType:class)
And if your model has
/** * @Assert\Uuid */ private $uuid;
It will automatically use the UuidType