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 from digital-craftsman/self-aware-normalizers are registered automatically and will handle the serialization and deserialization of the Id class, as it implements the StringNormalizable interface.
This can be combined with the CQS bundle to have serialized ids there.
Doctrine types
To use an id in your entities, you just need to make sure that the directory your id is in, is added in the self_aware_normalizers.implementation_directories configuration of self-aware-normalizers.php. They are then automatically registered with the relevant doctrine type and can be used directly with it's class name.
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 from digital-craftsman/self-aware-normalizers are registered automatically and will handle the serialization and deserialization of the IdList class, as it implements the ArrayNormalizable interface.
Doctrine types
Same as with the ids, you just have to make sure that the directory the id list is in, is part of the self_aware_normalizers.implementation_directories configuration of self-aware-normalizers.php.
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
digital-craftsman/self-aware-normalizers Version ^1.3.0
doctrine/dbal Version ^4.4
symfony/framework-bundle Version ^7.4|^8.0
symfony/polyfill-uuid Version ^1.31
symfony/serializer Version ^7.4|^8.0