symfony 从实体文件约束中获取 mimeTypes
symfony get mimeTypes from Entity File Constraint
在我的 API 控制器中,我需要从文件约束(断言)中获取允许的 mimeTypes
use Symfony\Component\Validator\Constraints as Assert;
...
/**
* @Assert\File(
* maxSize="3M",
* mimeTypes={"image/png", "image/jpeg", "image/pjpeg"}
* )
* @Vich\UploadableField(mapping="live_thumbnail_image", fileNameProperty="ThumbURI")
*
* @var File $Picture
*/
protected $Picture;
我试过了
$validator = $this->get('validator');
/** @var ClassMetadata $meta */
$meta = $validator->getMetadataFor(ChannelMetadata::class);
$constraints = $meta->getPropertyMetadata('Picture');
然后我有一组 PropertyMetadataInterface 等等。
是否有更简单的方法来获取此信息?
我用它来获取注释值。
$annotation = $reader->getPropertyAnnotation('Picture', \Symfony\Component\Validator\Constraints\File::class);
$reader是这个服务@annotation_reader
在我的 API 控制器中,我需要从文件约束(断言)中获取允许的 mimeTypes
use Symfony\Component\Validator\Constraints as Assert;
...
/**
* @Assert\File(
* maxSize="3M",
* mimeTypes={"image/png", "image/jpeg", "image/pjpeg"}
* )
* @Vich\UploadableField(mapping="live_thumbnail_image", fileNameProperty="ThumbURI")
*
* @var File $Picture
*/
protected $Picture;
我试过了
$validator = $this->get('validator');
/** @var ClassMetadata $meta */
$meta = $validator->getMetadataFor(ChannelMetadata::class);
$constraints = $meta->getPropertyMetadata('Picture');
然后我有一组 PropertyMetadataInterface 等等。
是否有更简单的方法来获取此信息?
我用它来获取注释值。
$annotation = $reader->getPropertyAnnotation('Picture', \Symfony\Component\Validator\Constraints\File::class);
$reader是这个服务@annotation_reader