Skip to content

[LazyImage] Usage of file_get_contents for external images #1773

@Kocal

Description

@Kocal

Hi everyone,

This is more of an RFC/question regarding LazyImage and file_get_contents.

I haven't yet attempted to use data_uri_thumbnail('https://...') with an external image (let's say https://symfony.com/doc/6.2fr//the-fast-track/_images/infrastructure.png), but I assume it should work, leveraging file_get_contents.

However, here lies the issue: I'm not particularly fond of usingfile_get_contents for downloading resources over HTTP. Even if we can use it, we're limited in configuring any options (e.g., proxy, authentication, timeout...).

I have two suggestions at the moment:

  1. Add support for PSR-7 and PSR-18. Inject a Psr\Http\Client\ClientInterface instance, and if we detect that $filename starts with https?://, we utilize the client to download the file.
  2. Alternatively, create an abstraction over file_get_contents, with an interface and a default implementation usingfile_get_contents. End-users can then use their own implementation, making it easier for us to implement and maintain on our side.

WDYT? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions