mcfedr / uuid-paramconverter
Paramconverter, Normalizer and Form Type for Ramsey Uuid
Installs: 56 216
Dependents: 0
Suggesters: 0
Security: 0
Stars: 18
Watchers: 4
Forks: 6
Type:symfony-bundle
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
README
A convenient bundle for using ramsey/uuid in your project
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