flysystem
flysystem copied to clipboard
Allow fetching extra metadata
Fix #1323
Allow fetching of extra metadata so that more customised code can be written that isn't adapter specific
Adding methods to an interface is a BC break. I cannot merge this.
@Nyholm @frankdejonge He also explains that in the issue: https://github.com/thephpleague/flysystem/issues/1323
I would kind of like this feature as well, as after "upgrading" to version 2 I lost the ability of checking the S3 object version metadata amongst other metadata, are there any plans on starting a new branch/work on a new major version so we can overcome the BC break?
We could also go the less pretty route and not update the interface, but add the methods to the adapters for example.
Let's talk about this :smile:
@Nyholm Would you be fine with adding a method to the Filesystem
like so?
public function extraMetadata(string $path): array
{
if (!method_exists($this->adapter, 'extraMetadata')) {
return [];
}
return $this->adapter->extraMetadata($this->pathNormalizer->normalizePath($path))->extraMetadata();
}
With the adapter pattern you're typically only interfacing with the single default implementation, effectively making the adapters a black box. I don't see how your're otherwise able to get the metadata that the StorageAttributes
classes can already hold.
An alternative with less magic would be to add a new interface for adapters supporting an extraMetadata
function and test against this interface in the Filesystem
.
@m-vo make a PR
@m-vo make a PR
Not if there is no intention for it to get merged?
This would have been great for v3
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Ah... Can we perhaps re-work this to support additional meta-data, without having to introduce a breaking change?
A possible solution would be to extract the the extraMetadata()
into its own interface, so that adapters that support it can chose to implement it, e.g.
interface HasMetaData
{
/**
* @throws UnableToRetrieveMetadata
* @throws FilesystemException
*/
public function extraMetadata(string $path): FileAttributes;
}
As for the filesystem implementation, it does not have to beak it's interface, but simply offer a public method:
class Filesystem implements FilesystemOperator
{
// ...previous not shown ....
public function extraMetadata(string $path): array
{
$adapter = $this->adapter;
if ($adapter instanceof HasMetaData) {
return $this->adapter->extraMetadata($this->pathNormalizer->normalizePath($path))->extraMetadata();
}
// Default to empty array
return [];
}
}
Then, perhaps, in a future major version you could choose to merge the "HasMetaData" interface into the appropriate interfaces.