diff --git a/packages/file-association-entity/src/EmbeddedMetadata.php b/packages/file-association-entity/src/EmbeddedMetadata.php index 86dec0c..f4b3fe1 100644 --- a/packages/file-association-entity/src/EmbeddedMetadata.php +++ b/packages/file-association-entity/src/EmbeddedMetadata.php @@ -25,10 +25,15 @@ class EmbeddedMetadata implements RawMetadataInterface, \IteratorAggregate { private ?string $name = null; + private ?int $size = null; + private ?string $type = null; + private ?\DateTimeInterface $modificationTime = null; + private ?int $width = null; + private ?int $height = null; /** diff --git a/packages/file-association-entity/src/FileCollection.php b/packages/file-association-entity/src/FileCollection.php index 4236315..7c799ec 100644 --- a/packages/file-association-entity/src/FileCollection.php +++ b/packages/file-association-entity/src/FileCollection.php @@ -49,6 +49,7 @@ public function getName(): FileNameInterface if ($this->name instanceof TranslatableInterface) { return new TranslatableFileName($this->name); } + return new FileName($this->name); } diff --git a/packages/file-association-entity/src/FileDecorator.php b/packages/file-association-entity/src/FileDecorator.php index 65b3aed..8fbddbd 100644 --- a/packages/file-association-entity/src/FileDecorator.php +++ b/packages/file-association-entity/src/FileDecorator.php @@ -50,6 +50,7 @@ public static function getFile( // any chance the caller calls `flush()`, the metadata will be // persisted. } + $metadata->clear(); $metadata->merge($file->get(RawMetadataInterface::class) ?? []); diff --git a/packages/file-association-entity/src/ReadableFileCollection.php b/packages/file-association-entity/src/ReadableFileCollection.php index c5e62d5..256def2 100644 --- a/packages/file-association-entity/src/ReadableFileCollection.php +++ b/packages/file-association-entity/src/ReadableFileCollection.php @@ -49,6 +49,7 @@ public function getName(): FileNameInterface if ($this->name instanceof TranslatableInterface) { return new TranslatableFileName($this->name); } + return new FileName($this->name); } diff --git a/packages/file-contracts/src/FileProxy.php b/packages/file-contracts/src/FileProxy.php index f73e4e8..b24d55b 100644 --- a/packages/file-contracts/src/FileProxy.php +++ b/packages/file-contracts/src/FileProxy.php @@ -48,6 +48,7 @@ public static function getFile( // private bool $isFileMissing = false; + private ?FileInterface $wrapped = null; // diff --git a/packages/file-contracts/src/FileRepositoryInterface.php b/packages/file-contracts/src/FileRepositoryInterface.php index 8fbbdb5..5f1cc98 100644 --- a/packages/file-contracts/src/FileRepositoryInterface.php +++ b/packages/file-contracts/src/FileRepositoryInterface.php @@ -38,6 +38,7 @@ public function tryGet(FilePointerInterface $filePointer): ?FileInterface; * Gets a lazy-loading proxy to the file specified by the pointer. */ public function getReference(FilePointerInterface $filePointer): FileInterface; + /** * Clears the repository's cache */ diff --git a/packages/file-contracts/src/Trait/EqualityTrait.php b/packages/file-contracts/src/Trait/EqualityTrait.php index d51b3bf..7e76f41 100644 --- a/packages/file-contracts/src/Trait/EqualityTrait.php +++ b/packages/file-contracts/src/Trait/EqualityTrait.php @@ -21,6 +21,7 @@ trait EqualityTrait { abstract public function getFilesystemIdentifier(): ?string; + abstract public function getKey(): string; public function isEqualTo(FilePointerInterface|FileInterface $other): bool diff --git a/packages/file-derivation/src/Filter/AbstractFileFilter.php b/packages/file-derivation/src/Filter/AbstractFileFilter.php index 863f5d0..a844a85 100644 --- a/packages/file-derivation/src/Filter/AbstractFileFilter.php +++ b/packages/file-derivation/src/Filter/AbstractFileFilter.php @@ -21,6 +21,7 @@ abstract class AbstractFileFilter implements FileFilterInterface { private FileRepositoryInterface $fileRepository; + private FileInterface $sourceFile; /** @@ -117,6 +118,7 @@ public function getResult(): FileInterface if ($result->isEqualTo($derivationFilePointer)) { return $result; } + return $this->fileRepository->copy($result, $derivationFilePointer); } diff --git a/packages/file-filepond/src/FilePondType.php b/packages/file-filepond/src/FilePondType.php index d6eaf83..7cf897b 100644 --- a/packages/file-filepond/src/FilePondType.php +++ b/packages/file-filepond/src/FilePondType.php @@ -76,6 +76,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void if (!$options['allow_delete']) { $event->setData($event->getForm()->getData()); } + return; } diff --git a/packages/file-image/src/ImageResizer.php b/packages/file-image/src/ImageResizer.php index ca55207..5fd9004 100644 --- a/packages/file-image/src/ImageResizer.php +++ b/packages/file-image/src/ImageResizer.php @@ -25,6 +25,7 @@ class ImageResizer extends AbstractFileFilter // final public const ASPECTRATIO_ORIGINAL = 'original'; + final public const ASPECTRATIO_SQUARE = 'square'; // @@ -32,6 +33,7 @@ class ImageResizer extends AbstractFileFilter // private int $maxWidthOrHeight = 512; + private string $aspect = self::ASPECTRATIO_ORIGINAL; // diff --git a/packages/file-metadata/src/Constants.php b/packages/file-metadata/src/Constants.php index 86e9421..9e3360e 100644 --- a/packages/file-metadata/src/Constants.php +++ b/packages/file-metadata/src/Constants.php @@ -21,12 +21,20 @@ class Constants { public const HTTP_CACHE_CONTROL = 'http.cacheControl'; + public const HTTP_DISPOSITION = 'http._disposition'; + public const HTTP_ETAG = 'http.eTag'; + public const FILE_NAME = 'file.name'; + public const FILE_SIZE = 'file.size'; + public const FILE_TYPE = 'file.type'; + public const FILE_MODIFICATION_TIME = 'file.modificationTime'; + public const MEDIA_WIDTH = 'media.width'; + public const MEDIA_HEIGHT = 'media.height'; } diff --git a/packages/file-metadata/src/Metadata/FileMetadata.php b/packages/file-metadata/src/Metadata/FileMetadata.php index bcce342..80c132d 100644 --- a/packages/file-metadata/src/Metadata/FileMetadata.php +++ b/packages/file-metadata/src/Metadata/FileMetadata.php @@ -41,6 +41,7 @@ public function getName(): FileNameInterface if ($result === null) { return new FileName(null, $this->getType()->getExtension()); } + return new FileName((string) $result); } diff --git a/packages/file-metadata/src/Model/FileName.php b/packages/file-metadata/src/Model/FileName.php index 945d2d0..8bcd151 100644 --- a/packages/file-metadata/src/Model/FileName.php +++ b/packages/file-metadata/src/Model/FileName.php @@ -20,6 +20,7 @@ final class FileName implements FileNameInterface { private ?string $name = null; + private ?string $extension = null; public function __construct( @@ -49,6 +50,7 @@ public function __toString(): string if ($this->extension !== null && $this->extension !== '') { return 'Untitled.' . $this->extension; } + return 'Untitled'; } @@ -80,6 +82,7 @@ public function getFull(): \Stringable&TranslatableInterface ] ); } + return new TranslatableMessage('Untitled', 'Untitled'); } @@ -94,6 +97,7 @@ public function getFull(): \Stringable&TranslatableInterface ] ); } + return new TranslatableMessage( $this->name, '{name}', @@ -114,6 +118,7 @@ public function getBase(): \Stringable&TranslatableInterface if ($this->name === null) { return new TranslatableMessage('Untitled', 'Untitled'); } + return new TranslatableMessage( $this->name, '{name}', diff --git a/packages/file-metadata/src/Model/MimeMapFileTypeAdapter.php b/packages/file-metadata/src/Model/MimeMapFileTypeAdapter.php index 50de086..359a3e4 100644 --- a/packages/file-metadata/src/Model/MimeMapFileTypeAdapter.php +++ b/packages/file-metadata/src/Model/MimeMapFileTypeAdapter.php @@ -22,6 +22,7 @@ final class MimeMapFileTypeAdapter implements FileTypeInterface { private readonly string $type; + private ?Type $parsedType = null; public function __construct(string $type) diff --git a/packages/file-metadata/src/Model/TranslatableFileName.php b/packages/file-metadata/src/Model/TranslatableFileName.php index 022f49c..2413e6f 100644 --- a/packages/file-metadata/src/Model/TranslatableFileName.php +++ b/packages/file-metadata/src/Model/TranslatableFileName.php @@ -50,6 +50,7 @@ public function getFull(): \Stringable&TranslatableInterface ] ); } + return new TranslatableMessage( (string) $this->base, '{name}', diff --git a/packages/file-null/src/NullFileTrait.php b/packages/file-null/src/NullFileTrait.php index 1cb54ea..db0526c 100644 --- a/packages/file-null/src/NullFileTrait.php +++ b/packages/file-null/src/NullFileTrait.php @@ -28,6 +28,7 @@ private function throwException(string $message): never if ($this instanceof \Throwable) { throw new NullFileOperationException($message, 0, $this); } + throw new NullFileOperationException($message); } diff --git a/packages/file-zip/src/ZipDirectory.php b/packages/file-zip/src/ZipDirectory.php index de6284a..e3f797f 100644 --- a/packages/file-zip/src/ZipDirectory.php +++ b/packages/file-zip/src/ZipDirectory.php @@ -38,8 +38,11 @@ final class ZipDirectory * @var DirectoryInterface */ private DirectoryInterface $directory; + private string $directoryName = ''; + private ?self $parent = null; + private ?string $directoryPathCache = null; public function __construct( @@ -76,6 +79,7 @@ public function process(): void if ($file === null) { continue; } + $this->processFile($file); } elseif ($node instanceof FileInterface) { $this->processFile($node); @@ -160,6 +164,7 @@ private function translate(TranslatableInterface&\Stringable $message): string if ($this->translator !== null) { return $message->trans($this->translator, $this->translator->getLocale()); } + return (string) $message; } diff --git a/packages/file/src/File.php b/packages/file/src/File.php index fb31444..0762144 100644 --- a/packages/file/src/File.php +++ b/packages/file/src/File.php @@ -36,8 +36,11 @@ class File implements FileInterface use MetadataTrait; private ?RawMetadata $metadataCache = null; + private FilesystemOperator $filesystem; + private bool $isAdHocFilesystem = false; + private bool $isLocalFilesystem; /** diff --git a/packages/file/src/Filesystem/RemoteFilesystemDecorator.php b/packages/file/src/Filesystem/RemoteFilesystemDecorator.php index 349dfe1..31dac6a 100644 --- a/packages/file/src/Filesystem/RemoteFilesystemDecorator.php +++ b/packages/file/src/Filesystem/RemoteFilesystemDecorator.php @@ -224,6 +224,7 @@ public function writeStream( $this->metadataGenerator ->generateMetadataFromStream($rawMetadata, $contents); } + fseek($contents, 0); $this->getWrapped()->writeStream($location, $contents, $config); } else { diff --git a/packages/file/src/MetadataSerializer/MetadataSerializer.php b/packages/file/src/MetadataSerializer/MetadataSerializer.php index f49e476..62c13e9 100644 --- a/packages/file/src/MetadataSerializer/MetadataSerializer.php +++ b/packages/file/src/MetadataSerializer/MetadataSerializer.php @@ -76,6 +76,7 @@ private function convertLegacyData(array $inputArray): array if (!is_string($file) && !is_null($file)) { $file = null; } + $newArray[Constants::FILE_NAME] = $file; break; @@ -83,6 +84,7 @@ private function convertLegacyData(array $inputArray): array if (!is_int($value)) { continue 2; } + $newArray[Constants::FILE_SIZE] = $value; break; @@ -94,6 +96,7 @@ private function convertLegacyData(array $inputArray): array if (!is_string($value)) { continue 2; } + $datetime = new \DateTimeImmutable($value); $newArray[Constants::FILE_MODIFICATION_TIME] = (int) $datetime->format('U'); @@ -102,6 +105,7 @@ private function convertLegacyData(array $inputArray): array if (!is_int($value)) { continue 2; } + $newArray[Constants::MEDIA_WIDTH] = $value; break; @@ -109,6 +113,7 @@ private function convertLegacyData(array $inputArray): array if (!is_int($value)) { continue 2; } + $newArray[Constants::MEDIA_HEIGHT] = $value; break; } diff --git a/packages/file/src/MetadataSerializer/MetadataSerializerInterface.php b/packages/file/src/MetadataSerializer/MetadataSerializerInterface.php index 110fc3d..9805df2 100644 --- a/packages/file/src/MetadataSerializer/MetadataSerializerInterface.php +++ b/packages/file/src/MetadataSerializer/MetadataSerializerInterface.php @@ -21,5 +21,6 @@ interface MetadataSerializerInterface { public function serialize(RawMetadataInterface $metadata): string; + public function deserialize(string $serialized): RawMetadataInterface; } diff --git a/packages/file/src/Repository/FileRepository.php b/packages/file/src/Repository/FileRepository.php index a8477b5..ce15e6a 100644 --- a/packages/file/src/Repository/FileRepository.php +++ b/packages/file/src/Repository/FileRepository.php @@ -62,6 +62,7 @@ private function getFilesystemFromPointerOrFile( if ($file instanceof FileInterface) { throw new AdHocFilesystemException($file, $e); } + throw $e; } } @@ -144,6 +145,7 @@ public function get(FilePointerInterface $filePointer): FileInterface $filePointer->getKey(), ); } + return $this->fileCache[$hash] = new File( $filePointer->getKey(), $this->getFilesystemFromPointerOrFile($filePointer), diff --git a/rector.php b/rector.php index bb21699..0194091 100644 --- a/rector.php +++ b/rector.php @@ -6,6 +6,7 @@ use Rector\CodeQuality\Rector\If_\CombineIfRector; use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector; use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector; +use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector; use Rector\CodingStyle\Rector\Use_\SeparateMultiUseImportsRector; use Rector\Config\RectorConfig; use Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector; @@ -43,6 +44,7 @@ ) ->withPhpSets(php81: true) ->withRules([ + NewlineAfterStatementRector::class, // AddOverrideAttributeToOverriddenMethodsRector::class, ]) ->withSkip([ diff --git a/tests/FileAssociation/FileAssociationManagerTest.php b/tests/FileAssociation/FileAssociationManagerTest.php index 6fdbb80..71022bc 100644 --- a/tests/FileAssociation/FileAssociationManagerTest.php +++ b/tests/FileAssociation/FileAssociationManagerTest.php @@ -32,6 +32,7 @@ class FileAssociationManagerTest extends TestCase use FileTestTrait; private ?FileAssociationManager $fileAssociationManager = null; + private ?FileRepositoryInterface $fileRepository = null; public function setUp(): void diff --git a/tests/FileZip/ZipTest.php b/tests/FileZip/ZipTest.php index 76b49dd..c99dd96 100644 --- a/tests/FileZip/ZipTest.php +++ b/tests/FileZip/ZipTest.php @@ -24,6 +24,7 @@ class ZipTest extends TestCase { private ?FileRepositoryInterface $fileRepository = null; + private ?FileZip $fileZip = null; public function setUp(): void