Skip to content

Commit

Permalink
[CS] Refactored IOBinaryFile building
Browse files Browse the repository at this point in the history
Co-Authored-By: Mikolaj Adamczyk <mikadamczyk@users.noreply.github.com>
  • Loading branch information
alongosz and mikadamczyk committed Dec 20, 2022
1 parent 92c7f26 commit 751ed4f
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/lib/IO/IOMetadataHandler/Flysystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Ibexa\Core\IO\IOMetadataHandler;

use DateTime;
use Ibexa\Contracts\Core\IO\BinaryFile as SPIBinaryFile;
use Ibexa\Contracts\Core\IO\BinaryFile as IOBinaryFile;
use Ibexa\Contracts\Core\IO\BinaryFileCreateStruct as SPIBinaryFileCreateStruct;
use Ibexa\Core\IO\Exception\BinaryFileNotFoundException;
use Ibexa\Core\IO\Exception\IOException;
Expand All @@ -29,7 +29,7 @@ public function __construct(FilesystemOperator $filesystem)
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
*/
public function create(SPIBinaryFileCreateStruct $spiBinaryFileCreateStruct): SPIBinaryFile
public function create(SPIBinaryFileCreateStruct $spiBinaryFileCreateStruct): IOBinaryFile
{
return $this->load($spiBinaryFileCreateStruct->id);
}
Expand All @@ -43,17 +43,10 @@ public function delete($spiBinaryFileId)
{
}

public function load($spiBinaryFileId): SPIBinaryFile
public function load($spiBinaryFileId): IOBinaryFile
{
try {
$spiBinaryFile = new SPIBinaryFile();
$spiBinaryFile->id = $spiBinaryFileId;
$spiBinaryFile->size = $this->filesystem->fileSize($spiBinaryFileId);
$spiBinaryFile->mtime = new DateTime(
'@' . $this->filesystem->lastModified($spiBinaryFileId)
);

return $spiBinaryFile;
return $this->getIOBinaryFile($spiBinaryFileId);
} catch (FilesystemException $e) {
throw new BinaryFileNotFoundException($spiBinaryFileId);
}
Expand Down Expand Up @@ -89,6 +82,21 @@ public function getMimeType($spiBinaryFileId): string
public function deleteDirectory($spiPath)
{
}

/**
* @throws \League\Flysystem\FilesystemException
*/
private function getIOBinaryFile(string $spiBinaryFileId): IOBinaryFile
{
$spiBinaryFile = new IOBinaryFile();
$spiBinaryFile->id = $spiBinaryFileId;
$spiBinaryFile->size = $this->filesystem->fileSize($spiBinaryFileId);
$spiBinaryFile->mtime = new DateTime(
'@' . $this->filesystem->lastModified($spiBinaryFileId)
);

return $spiBinaryFile;
}
}

class_alias(Flysystem::class, 'eZ\Publish\Core\IO\IOMetadataHandler\Flysystem');

0 comments on commit 751ed4f

Please sign in to comment.