php / php/php-src

autoloader for custom stream wrappers

Abierto
#11,087 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Feature Status: Needs Triage
Lenguaje dominante
C
Estrellas
40.4k
Forks
8.1k
Merge medio
2 d 13 h
PR fusionados (30 d)
96

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza rastreando los protocolos de stream no resueltos a través de file_get_contents(), fopen() y copy(), y revisa cómo stream_wrapper_register() y stream_get_wrappers() gestionan actualmente el registro. Define el comportamiento del callback y su interacción con las búsquedas fallidas, y luego verifica que un wrapper registrado por el callback permita que la operación de archivo original se complete.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
c, php
Área
backend
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.