Je suis le tutoriel pour la gestion des images.

J'ai mon entité product avec un champ image. Ce champ correspond à l'image de mon produit.
J'ai un problème sur la fonction getUploadablefiled.
https://youtu.be/xEBWsTKCnKA?t=1631

J'ai comme message d'erreur, [Semantical Error] The annotation "@Sport\AdminBundle\Annotation\UploadableField" in property Sport\UsersBundle\Entity\Product::$file does not exist, or could not be auto-loaded.

Mon fichier entity product

?php

namespace Sport\UsersBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Sport\AdminBundle\Annotation\Uploadable;
use Sport\AdminBundle\Annotation\UploadableField;
use Sport\AdminBundle\Annotation\UploadableAnnotationReader;
use Symfony\Component\HttpFoundation\File\File;
use Doctrine\Common\Annotations\AnnotationReader;
/**
 * Product
 * @Uploadable()
  */
class Product
{
  /**
   * @var string
   */
    private $image;

    /**
     * @UploadableField(image="image", path="uploads")
     */
      private $file;

      /**
       * @return File/null
       */
       public function getFile()
       {
         return $this->file;
       }

       /**
        * @param File $file/null
        */
       public function setFile(File $file)
       {
         return $this->file;
       }

et mon fichier Annotation UploadableAnnotationReader

<?php

namespace Sport\AdminBundle\Annotation;

use Doctrine\Common\Annotations\Annotation\Target;
use Doctrine\Common\Annotations\AnnotationReader;
use Sport\AdminBundle\Annotation\UploadableField;

class UploadableAnnotationReader {

  /**
   * @var AnnotationReader
   */
   private $reader;

  public function __construct(AnnotationReader $reader)
  {
      $this->reader = $reader;
  }

public function isUploadable($entity): bool{
 $reflection =new \ReflectionClass(get_class($entity));
return $this->reader->getClassAnnotation($reflection, Uploadable::class) !==null;

}

public function getUploadableFields($entity): array {
        $reflection = new \ReflectionClass(get_class($entity));
        if (!$this->isUploadable($entity)){
          return[];
        }

        $properties = [];
        foreach($reflection->getProperties() as $property) {
            $annotation = $this->reader->getPropertyAnnotation($property,  UploadableField::class);
            if ($annotation !== null) {
                $properties[$property->getName()] = $annotation;
            }
        }
        return $properties;
    }

}

Aucune réponse