Problem/Motivation
StreamWrapper's currently deal with static strings for URLs which means they're not opted in to any cacheability information system, even though URLs can have cacheability information as outlined in #3358113: Allow StreamWrapper's to provide cacheability metadata.
Additionally most StreamWrappers internally already work with a Url which is then converted to a string, so we have the information but are throwing it away.
This issue probably also partially fixes #2867355: file_create_url() causes LogicException when used with certain stream wrappers or at least has a conflicting solution: the referenced issue implements getUrl
as a protected method.
Steps to reproduce
Proposed resolution
Introduce getUrl
to StreamWrapper
so that it provides normal URL objects which contain routing information that can be provided with cacheability information. Additionally this benefits from improvements when URL objects themselves get cacheability information (e.g. because they're an external time-restricted link).
We specifically do not use GeneratedUrl
because it contains less information than a Url
object, specifically we make assumptions about how a URL should be consumed (absolute/relative) which other systems can better judge. We can see this in action by the FileUrlGenerator
breaking apart output of the stream wrapper and converting it to a Url
itself.
Remaining tasks
In a follow-up that will land in a next major version:
- Deprecate
StreamWrapperGetUrlInterface
- Implement
getUrl
and extendStreamWrapperGetUrlInterface
inStreamWrapperInterface
In a follow-up that will land in a next major version + 1:
- Remove
StreamWrapperGetUrlInterface
User interface changes
API changes
- Introduce
StreamWrapperGetUrlInterface
which contains thegetUrl
method. - All concrete StreamWrappers in Drupal core implement
StreamWrapperGetUrlInterface
- Deprecate
StreamWrapperInterface::getExternalUrl
FileUrlGenerator
throws a deprecation error in caseStreamWrapperGetUrlInterface
is not implemented for aStreamWrapperInterface
implementation