Download the PHP package digital-craftsman/ids without Composer
On this page you can find all versions of the php package digital-craftsman/ids. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download digital-craftsman/ids
More information about digital-craftsman/ids
Files in digital-craftsman/ids
Package ids
Short Description Working with value objects for ids in Symfony
License MIT
Informations about the package ids
Id handling with value objects in Symfony
A Symfony bundle to work with id and id list value objects in Symfony. It includes Symfony normalizers for automatic normalization and denormalization and Doctrine types to store the ids and id lists directly in the database.
As it's a central part of an application, it's tested thoroughly (including mutation testing).
Installation and configuration
Install package through composer:
It's recommended that you install the uuid
PHP extension for better performance of id creation and validation. symfony/polyfill-uuid
is used as a fallback. You can prevent installing the polyfill when you've installed the PHP extension.
Working with ids
Creating a new id
The bulk of the logic is in the Id
class. Creating a new id is as simple as creating a new final readonly class
and extending from it like the following:
Now you're already able to use it in your code like this:
Guard against invalid usages:
Or with a custom exception:
Symfony serializer
If you're injecting the SerializerInterface
directly, there is nothing to do. The normalizer for the id is automatically registered.
This can be combined with the CQRS bundle to have serialized ids there.
Doctrine types
To use an id in your entities, you just need to register a new type for the id. Create a new class for the new id like the following:
Then register the new type in your config/packages/doctrine.yaml
file:
Alternatively you can also add a compiler pass to register the types automatically.
Then you're already able to add it into your entity like this:
Working with id lists
Id lists are wrapper for an array of ids. They contain a few utility functions and improved type safety.
The IdList
is immutable. Therefore, the mutation methods (like add
, remove
, ...) always return a new instance of the list.
Creating a new id list
The bulk of the logic is in the IdList
class. Creating a new id list is as simple as creating a new final readonly class
and extending from it like the following:
Now you're already able to use it in your code like this:
Guard against invalid usages:
Or with custom exception:
Symfony serializer
If you're injecting the SerializerInterface
directly, there is nothing to do. The normalizer for the id list is automatically registered.
Doctrine types
To use an id list in your entities, you just need to register a new type for the id list. Create a new class for the new id list like the following:
Then register the new type in your config/packages/doctrine.yaml
file:
Then you're already able to add it into your entity like this:
Additional documentation
- Prevent polyfill usage
- Use other UUID versions
- Changelog
- Upgrade guide
All versions of ids with dependencies
symfony/framework-bundle Version ^6.3|^7.0
symfony/serializer Version ^6.3|^7.0
doctrine/dbal Version ^2.13.8|^3.3.6
symfony/polyfill-uuid Version ^1.26