Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace App\Shared\DtoFactory;
use App\Shared\Dto\DtoCollection;
use App\Shared\Dto\FileDto;
use App\Shared\Entity\File;
use Doctrine\Common\Collections\Collection;
class FileDtoFactory
{
public function create(File $file): FileDto
{
return new FileDto(
id: $file->getId(),
name: $file->getName(),
description: $file->getDescription(),
size: $file->getSize(),
type: $file->getType(),
url: $file->getUrl(),
);
}
/**
* @param Collection<File> $files
* @return DtoCollection<FileDto>
*/
public function createCollection(Collection $files): DtoCollection
{
$filesDto = $files->map(function(File $file) {
return $this->create($file);
});
return new DtoCollection(
FileDto::class,
$filesDto->toArray()
);
}
}