Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow fetching extra metadata #1324

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/AsyncAwsS3/AsyncAwsS3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,17 @@ public function fileSize(string $path): FileAttributes
return $attributes;
}

public function extraMetadata(string $path): FileAttributes
{
$attributes = $this->fetchFileMetadata($path, FileAttributes::ATTRIBUTE_EXTRA_METADATA);

if (null === $attributes->extraMetadata()) {
throw UnableToRetrieveMetadata::extraMetadata($path);
}

return $attributes;
}

public function listContents(string $path, bool $deep): iterable
{
$prefix = trim($this->prefixer->prefixPath($path), '/');
Expand Down
11 changes: 11 additions & 0 deletions src/AwsS3V3/AwsS3V3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,17 @@ public function fileSize(string $path): FileAttributes
return $attributes;
}

public function extraMetadata(string $path): FileAttributes
{
$attributes = $this->fetchFileMetadata($path, FileAttributes::ATTRIBUTE_EXTRA_METADATA);

if ($attributes->extraMetadata() === null) {
throw UnableToRetrieveMetadata::extraMetadata($path);
}

return $attributes;
}

public function listContents(string $path, bool $deep): iterable
{
$prefix = trim($this->prefixer->prefixPath($path), '/');
Expand Down
5 changes: 5 additions & 0 deletions src/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ public function mimeType(string $path): string
return $this->adapter->mimeType($this->pathNormalizer->normalizePath($path))->mimeType();
}

public function extraMetadata(string $path): array
{
return $this->adapter->extraMetadata($this->pathNormalizer->normalizePath($path))->extraMetadata();
}

public function setVisibility(string $path, string $visibility): void
{
$this->adapter->setVisibility($this->pathNormalizer->normalizePath($path), $visibility);
Expand Down
6 changes: 6 additions & 0 deletions src/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ public function lastModified(string $path): FileAttributes;
*/
public function fileSize(string $path): FileAttributes;

/**
* @throws UnableToRetrieveMetadata
* @throws FilesystemException
*/
public function extraMetadata(string $path): FileAttributes;

/**
* @return iterable<StorageAttributes>
*
Expand Down
6 changes: 6 additions & 0 deletions src/FilesystemReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@ public function mimeType(string $path): string;
* @throws FilesystemException
*/
public function visibility(string $path): string;

/**
* @throws UnableToRetrieveMetadata
* @throws FilesystemException
*/
public function extraMetadata(string $path): array;
}
5 changes: 5 additions & 0 deletions src/Ftp/FtpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ public function visibility(string $path): FileAttributes
return $this->fetchMetadata($path, FileAttributes::ATTRIBUTE_VISIBILITY);
}

public function extraMetadata(string $path): FileAttributes
{
return $this->fetchMetadata($path, FileAttributes::ATTRIBUTE_EXTRA_METADATA);
}

public function fileSize(string $path): FileAttributes
{
$location = $this->prefixer->prefixPath($path);
Expand Down
5 changes: 5 additions & 0 deletions src/GoogleCloudStorage/GoogleCloudStorageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ public function fileSize(string $path): FileAttributes
return $this->fileAttributes($path, 'fileSize');
}

public function extraMetadata(string $path): FileAttributes
{
return $this->fileAttributes($path, 'extraMetadata');
}

private function fileAttributes(string $path, string $type): FileAttributes
{
$exception = null;
Expand Down
15 changes: 15 additions & 0 deletions src/InMemory/InMemoryFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class InMemoryFile
*/
private $visibility;

/**
* @var array[]
*/
private $extraMetadata;

public function updateContents(string $contents): void
{
$this->contents = $contents;
Expand Down Expand Up @@ -75,4 +80,14 @@ public function visibility(): ?string
{
return $this->visibility;
}

public function extraMetadata(): array
{
return $this->extraMetadata;
}

public function setExtraMetadata(array $extraMetadata): void
{
$this->extraMetadata = $extraMetadata;
}
}
11 changes: 11 additions & 0 deletions src/InMemory/InMemoryFilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ public function fileSize(string $path): FileAttributes
return new FileAttributes($path, $this->files[$path]->fileSize());
}

public function extraMetadata(string $path): FileAttributes
{
$path = $this->preparePath($path);

if (array_key_exists($path, $this->files) === false) {
throw UnableToRetrieveMetadata::extraMetadata($path, 'file does not exist');
}

return new FileAttributes($path, null, null, null, null, $this->files[$path]->extraMetadata());
}

public function listContents(string $path, bool $deep): iterable
{
$prefix = rtrim($this->preparePath($path), '/') . '/';
Expand Down
5 changes: 5 additions & 0 deletions src/Local/LocalFilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,11 @@ public function mimeType(string $path): FileAttributes
return new FileAttributes($path, null, null, null, $mimeType);
}

public function extraMetadata(string $path): FileAttributes
{
throw UnableToRetrieveMetadata::extraMetadata($path, 'No extra metadata available for local files');
}

public function lastModified(string $path): FileAttributes
{
$location = $this->prefixer->prefixPath($path);
Expand Down
5 changes: 5 additions & 0 deletions src/PhpseclibV2/SftpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ public function visibility(string $path): FileAttributes
return $this->fetchFileMetadata($path, FileAttributes::ATTRIBUTE_VISIBILITY);
}

public function extraMetadata(string $path): FileAttributes
{
return $this->fetchFileMetadata($path, FileAttributes::ATTRIBUTE_EXTRA_METADATA);
}

public function listContents(string $path, bool $deep): iterable
{
$connection = $this->connectionProvider->provideConnection();
Expand Down
5 changes: 5 additions & 0 deletions src/PhpseclibV3/SftpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ public function visibility(string $path): FileAttributes
return $this->fetchFileMetadata($path, FileAttributes::ATTRIBUTE_VISIBILITY);
}

public function extraMetadata(string $path): FileAttributes
{
return $this->fetchFileMetadata($path, FileAttributes::ATTRIBUTE_EXTRA_METADATA);
}

public function listContents(string $path, bool $deep): iterable
{
$connection = $this->connectionProvider->provideConnection();
Expand Down
5 changes: 5 additions & 0 deletions src/UnableToRetrieveMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public static function mimeType(string $location, string $reason = '', Throwable
return static::create($location, FileAttributes::ATTRIBUTE_MIME_TYPE, $reason, $previous);
}

public static function extraMetadata(string $location, string $reason = '', Throwable $previous = null): self
{
return static::create($location, FileAttributes::ATTRIBUTE_EXTRA_METADATA, $reason, $previous);
}

public static function create(string $location, string $type, string $reason = '', Throwable $previous = null): self
{
$e = new static("Unable to retrieve the $type for file at location: $location. {$reason}", 0, $previous);
Expand Down