php / php/php-src

autoloader for custom stream wrappers

Ouverte
#11,087 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Feature Status: Needs Triage
Langage dominant
C
Étoiles
40.4k
Forks
8.1k
Merge moyen
2 j 13 h
PR mergées (30 j)
96

Description

Description

Would it be possible to add an autoloader/callback function if a call is made to a function using a stream wrapper protocol that is not yet defined?

Currently, if you access a stream protocol not registered, a warning is logged 'Unable to find the wrapper "abc" - did you forget to enable it when you configured PHP?'.

In the below example, since abc hasn't yet been registered with stream_wrapper_register(), the new function stream_wrapper_autoload() would be called where abc would be registered and allow the file_get_contents() call to complete.

<?php
stream_wrapper_autoload(function($protocol)
{
	switch ($protocol)
	{
		case 'abc':
			stream_wrapper_register('abc', 'abc');
			break;
	}
});

$a = file_get_contents('abc://file.txt');
?>

I am using the AWS S3 stream wrapper (https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/s3-stream-wrapper.html). Using this custom stream wrapper currently requires me either to:

  • register the stream wrapper on every request even if it won't be used on the given request
  • or register it before any call that would use it (file_get_contents, fopen, copy, etc).
  • or add a wrapper function around file_get_contents and the other file functions to check first if the stream wrapper is registered by calling stream_get_wrappers().

Having an autoload function would allow me to register the stream wrapper only when it's needed.

Thank you for your help.

Ryan

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par suivre les protocoles de flux non résolus via file_get_contents(), fopen() et copy(), et examinez comment stream_wrapper_register() et stream_get_wrappers() gèrent actuellement l’enregistrement. Définissez le comportement du callback et son interaction avec les recherches infructueuses, puis vérifiez qu’un wrapper enregistré par le callback permet à l’opération de fichier d’origine de s’achever.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
c, php
Domaine
backend
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
30/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.