I’m currently working on an integration with a third party API for an application, for which I’m using Spatie’s data transfer object library. I’m currently looking to set up validation for some fields, and have run into an issue. I’ve written the following validator attribute, to validate that a string contains an email address: And it’s used in this DTO
Tag: php-attributes
PHP 8 Attributes: Is it possible to validate metadata passed to attributes or force attribute instantiation?
Playing a little bit with the new PHP 8 attributes (annotations) (https://stitcher.io/blog/attributes-in-php-8) I started to create my own ones. Simple example: Hoping that the following code would throw an BadAttributeMetadataException unfortunately it finishes successfully: Is there away to validate the metadata passed for (custom) attributes? Most probably the attributes have to be instantiated automatically somehow. Answer Everything is possible –