public function replaceTemporaryFile(GetResponseForControllerResultEvent $event)
{
$data = $event->getControllerResult();
if (!is_object($data)) {
return;
}
$classReflection = new \ReflectionClass($data);
foreach ($classReflection->getProperties() as $property) {
$propertyAnnotationCollection = $this->reader->getPropertyAnnotation($property, 'PartKeepr\\UploadedFileBundle\\Annotation\\UploadedFileCollection');
$propertyAnnotation = $this->reader->getPropertyAnnotation($property, 'PartKeepr\\UploadedFileBundle\\Annotation\\UploadedFile');
$manyToOneAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToMany');
$oneToOneAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToOne');
if ($propertyAnnotationCollection !== null || $propertyAnnotation !== null) {
if ($manyToOneAnnotation !== null) {
$collection = $this->propertyAccessor->getValue($data, $property->getName());
foreach ($collection as $key => $item) {
if ($item instanceof TempUploadedFile || $item instanceof TempImage) {
$targetEntity = $manyToOneAnnotation->targetEntity;
$newFile = $this->setReplacementFile($targetEntity, $item, $data);
$collection[$key] = $newFile;
}
}
$this->propertyAccessor->setValue($data, $property->getName(), $collection);
}
if ($oneToOneAnnotation !== null) {
$item = $this->propertyAccessor->getValue($data, $property->getName());
if ($item instanceof TempUploadedFile || $item instanceof TempImage) {
$targetEntity = $oneToOneAnnotation->targetEntity;
$newFile = $this->setReplacementFile($targetEntity, $item, $data);
$this->propertyAccessor->setValue($data, $property->getName(), $newFile);
} else {
$item = $this->propertyAccessor->getValue($data, $property->getName());
if ($item !== null && $item->getReplacement() !== null) {
/**
* @var UploadedFile
*/
$tempImage = $this->iriConverter->getItemFromIri($item->getReplacement());
$this->replaceFile($item, $tempImage);
}
}
}
}
}
$event->setControllerResult($data);
}