I have a mehtod that returns timestamps. I want to do something like this: However, I don’t think @return array<int, timestamp> is valid. What is the valid format for specifying timestamps in docblocks? Answer You can use int[], there is no valid value for timestamps. You can however create a ValueObject. If you use a value object:
Tag: annotations
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 –
How do I prevent PHP CS Fixer from fixing specific function names?
When using PHP CS Fixer to resolve syntax errors on file save and using the Symfony rule set, any function names that are not camelCase will be corrected (as expected). However when writing PHP Unit based tests, it’s often common practice to make the function names snake_case. This normally means that PHP CS Fixer will resolve the issue automatically, even
Is it possible to load Swagger annotations from a different class or file?
I have the following simple PHP method like the following and I need to include long Swagger documentation into the annotation above the method, so is it possible to write the annotation in a different class ? and call it here with something like The main purpose is to have a clean class without so many lines of documentation and
How to autoload custom annotation classes without using AnnotationRegistry?
I’m using Doctrine Annotations library (not the whole Doctrine, only annotations) and want to make a custom annotation class. composer.json: index.php: entities/MyClass.php annotations/TestAnnotation.php It gives me the following error: The only solution i found on the Internet is to use AnnotationRegistry::registerLoader or something similar, but it is deprecated so i’d like to solve the problem in another way. Answer One
Annotations in Symfony 4
I try to develop with Symfony 4 so I follow the tutorial on symfony.com I’ve got an error when I try to access at : This is the error : [Syntax Error] Expected PlainValue, got ”’ at position 7 in method AppControllerHomeController::home() in /Users//Documents/ProjetSymfo4/my-project/config/routes/../../src/Controller/ (which is being imported from “/Users//Documents/ProjetSymfo4/my-project/config/routes/annotations.yaml”). Make sure annotations are installed and enabled. I already ran
How persist new Entity in Doctrine 2 prePersist method?
I’ve a Entity with @HasLifecycleCallbacks for define prePersist and preUpdate method. My PrePersist method is /** * @ORMOneToMany(targetEntity=”Field”, mappedBy=”service”, cascade={“persist”}, …