| @@ 73-89 (lines=17) @@ | ||
| 70 | * |
|
| 71 | * @throws FileAlreadyExistsException when file is already exists |
|
| 72 | */ |
|
| 73 | public function __invoke(ByHashUploadFileCommand $aCommand) |
|
| 74 | { |
|
| 75 | $id = new FileId($aCommand->id()); |
|
| 76 | $file = $this->repository->fileOfId($id); |
|
| 77 | if (null !== $file) { |
|
| 78 | throw new FileAlreadyExistsException(); |
|
| 79 | } |
|
| 80 | $name = FileName::fromHash($aCommand->name()); |
|
| 81 | if (true === $this->filesystem->has($name)) { |
|
| 82 | throw new FileAlreadyExistsException(); |
|
| 83 | } |
|
| 84 | ||
| 85 | $this->filesystem->write($name, $aCommand->uploadedFile()); |
|
| 86 | $file = $this->factory->build($id, $name, new FileMimeType($aCommand->mimeType())); |
|
| 87 | ||
| 88 | $this->repository->persist($file); |
|
| 89 | } |
|
| 90 | } |
|
| 91 | ||
| @@ 73-89 (lines=17) @@ | ||
| 70 | * |
|
| 71 | * @throws FileAlreadyExistsException when file is already exists |
|
| 72 | */ |
|
| 73 | public function __invoke(UploadFileCommand $aCommand) |
|
| 74 | { |
|
| 75 | $id = new FileId($aCommand->id()); |
|
| 76 | $file = $this->repository->fileOfId($id); |
|
| 77 | if (null !== $file) { |
|
| 78 | throw new FileAlreadyExistsException(); |
|
| 79 | } |
|
| 80 | $name = new FileName($aCommand->name()); |
|
| 81 | if (true === $this->filesystem->has($name)) { |
|
| 82 | throw new FileAlreadyExistsException(); |
|
| 83 | } |
|
| 84 | ||
| 85 | $this->filesystem->write($name, $aCommand->uploadedFile()); |
|
| 86 | $file = $this->factory->build($id, $name, new FileMimeType($aCommand->mimeType())); |
|
| 87 | ||
| 88 | $this->repository->persist($file); |
|
| 89 | } |
|
| 90 | } |
|
| 91 | ||