StreamWrapperInterface doesn't have to implement PhpStreamWrapperInterface

Created on 6 June 2015, over 9 years ago
Updated 19 April 2024, 7 months ago

Problem/Motivation

PHP Stream wrappers don't have to implement an interface. There's a reason for this. PHP determines what features a stream wrapper supports by what methods it implements:

http://php.net/manual/en/streamwrapper.mkdir.php
http://php.net/manual/en/streamwrapper.rename.php
http://php.net/manual/en/streamwrapper.rmdir.php

Drupal has an extended Drupal\Core\StreamWrapper\StreamWrapperInterface which implements some extra methods for doing Drupally things. This is odd, but fine. The problem is that StreamWrapperInterface extends PhpStreamWrapperInterface making it painful to register stream wrappers with Drupal that only support a subset of functionality.

I should be able to register a stream wrapper that only allows iterating directories, dir_closedir(), dir_opendir(), dir_readdir(), dir_rewinddir(), and register it with Drupal. Granted, this will be mostly useless, but the only thing stopping me is that I have to implement a bunch of other methods that return FALSE. That will work, but as the links above show, is incorrect.

This also makes things easier in the future when new stream wrapper methods get added for newer versions of PHP. See #2107287: PHP 5.4 calls a new stream_metadata() method on stream wrappers not implemented by Drupal β†’
We should be able to just add support for the newer features and not have to create a sub-interface for them.

Proposed resolution

  • Remove PhpStreamWrapperInterface.
  • If we really decide that we need an interface, create a LocalStreamWrapperInterface that requires the functionality necessary to implement local stream wrappers.

Remaining tasks

Write patch if agreed.

User interface changes

None.

API changes

API is less restricted. All existing code works fine, unless a Drupal module directly implements PhpStreamWrapperInterface. (Not likely)

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component
File systemΒ  β†’

Last updated about 12 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States twistor

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States lhridley

    @catch The use case would be to open up the use of the StreamWrapperManager for managing stream wrappers that may not necessarily need to be 100% compliant with PhpStreamWrapperInterface.

    Right now StreamWrapperManagerInterface defines certain parameters for methods that explicitely expect entities that comply with StreamWrapperInterface. By removing PhpStreamWrapperInterface from the dependency string this opens up the ability to do so.

    There are multiple places in Drupal Core where multiple interfaces are implemented. The current entities that implement StreamWrapperInterface as it is defined today would simply need to be modified to also implement PhpStreamWrapperInterface.

    All of the methods on StreamWrapperInterface except for two (which IMO should not be there, see the discussion on the related issue) are designed explicitely for registering a StreamWrapper entity with a StreamWrapperManager implementing StreamWrapperManagerInterface. By decoupling StreamWrapperInterface from PhpStreamWrapperInterface you make the StreamWrapper Management component in Drupal Core much more flexible, and would allow for implementing alternative File systems (Like a NoSQL implementation) for Drupal while still taking advantage of the Stream Wrapper Management component.

    It's all about decoupling.

Production build 0.71.5 2024