for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Silverback API Component Bundle Project
*
* (c) Daniel West <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Silverback\ApiComponentBundle\Validator\MappingLoader;
use Silverback\ApiComponentBundle\AnnotationReader\UploadableAnnotationReader;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
/**
* @author Vincent Chalamon <[email protected]>
final class UploadableLoader implements LoaderInterface
{
private UploadableAnnotationReader $uploadsHelper;
public function __construct(UploadableAnnotationReader $uploadsHelper)
$this->uploadsHelper = $uploadsHelper;
}
* {@inheritdoc}
public function loadClassMetadata(ClassMetadata $metadata): bool
if (!$this->uploadsHelper->isConfigured($metadata->getClassName())) {
return false;
$fields = $this->uploadsHelper->getConfiguredProperties($metadata->getClassName(), true, false);
foreach ($fields as $fileField) {
$metadata->addPropertyConstraint($fileField, new Assert\NotNull(['groups' => sprintf('%s:create', $metadata->getClassName())]));
return true;