Semantical Error The Annotation "@Symfony Component Validator Constraints Notblank " in Property was Never Imported

Asked

Viewed 61 times

1

I am developing a simple API with Microframework Slim using Doctrine, I decided to implement some validations, so I installed the library symfony/validator:^5.2.

In my entities, I have some Doctrine Annotations, and I decided to add some of the symfony, so I made the import
use Symfony\Component\Validator\Constraints;
then in the attributes of the class, I added the Annotation
* @Constraints\NotBlank()

But I get the following Exception: [Semantical Error] The annotation "@Symfony\Component\Validator\Constraints\NotBlank" in property App\Entity\UserType::$description was never imported. Did you maybe forget to add a "use" statement for this annotation?

Follows image of how it was implemented:
Código da entidade, arquivo composer.json e exception no postman

Additional information

  • PHP: 8
  • I already uninstalled the library and installed again: Obs: the error continues even after removing lib symfony/validator as if the error were from another lib ex: Doctrine.;
  • Doctrine is reading the Annotations correctly and generating the database tables
  • I already gave the dump-autoload
  • Try calling 'Notblank' without being a function (removes () from the annotation). Also, according to the symfony documentation (https://symfony.com/doc/current/reference/constraints/NotBlank.html#basic-Usage), try to change your import using an alias and see if it makes a difference.

  • Thanks for the suggestion Renan! I just did this, I did the import by adding an alias: use Symfony Component Validator Constraints as Assert; and called it as follows in the attribute: * @Assert Notblank But not yet successful!

  • In this case, try to import the Notblank class directly: use Symfony\Component\Validator\Constraints\NotBlank;

  • I imported it as well, and Exception continued, a colleague suggested that I do this Annotationregistry::registerLoader([require DIR .'/../../vendor/autoload.php', 'loadClass']); Apparently solved the Exception however, not validating, is inserting the empty field even in the bd, I don’t know if I have to do something else, any suggestions ?

  • Autoload.php should be called at the entry point of your application, in which case I imagine there should be an index.php inside your public directory. See if inside the index you are calling this autoload. I suggest you take a look at the Slim version (https://github.com/slimphp/Slim), there is an implementation of index.php there that can help you.

  • All right thanks, I’ll take a look.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.