php / php/php-src

autoloader for custom stream wrappers

Aperta
#11,087 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Feature Status: Needs Triage
Lingua principale
C
Stelle
40.4k
Fork
8.1k
Merge medio
2g 13h
PR unite (30g)
96

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia tracciando i protocolli di stream non risolti attraverso file_get_contents(), fopen() e copy(), e verifica come stream_wrapper_register() e stream_get_wrappers() gestiscono attualmente la registrazione. Definisci il comportamento del callback e la sua interazione con le ricerche non riuscite, quindi verifica che un wrapper registrato dal callback consenta il completamento dell’operazione sul file originale.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
c, php
Ambito
backend
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.