flysystem icon indicating copy to clipboard operation
flysystem copied to clipboard

Allow fetching extra metadata

Open timwsuqld opened this issue 3 years ago • 8 comments

Fix #1323

Allow fetching of extra metadata so that more customised code can be written that isn't adapter specific

timwsuqld avatar Jun 22 '21 05:06 timwsuqld

Adding methods to an interface is a BC break. I cannot merge this.

Nyholm avatar Jul 18 '21 17:07 Nyholm

@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:

4c0n avatar Nov 11 '21 14:11 4c0n

@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 avatar Dec 01 '21 22:12 m-vo

@m-vo make a PR

PaolaRuby avatar Dec 27 '21 22:12 PaolaRuby

@m-vo make a PR

Not if there is no intention for it to get merged?

m-vo avatar Dec 27 '21 22:12 m-vo

This would have been great for v3

fredsal avatar Jan 31 '22 14:01 fredsal

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.

stale[bot] avatar Apr 16 '22 10:04 stale[bot]

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.

aedart avatar May 09 '22 11:05 aedart