php / php/php-src

autoloader for custom stream wrappers

Đang mở
#11,087 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Feature Status: Needs Triage
Ngôn ngữ chính
C
Star
40.4k
Fork
8.2k
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
96

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách theo dõi các giao thức stream chưa được phân giải thông qua file_get_contents(), fopen() và copy(), đồng thời xem xét cách stream_wrapper_register() và stream_get_wrappers() hiện xử lý việc đăng ký. Xác định hành vi của callback và sự tương tác của nó với các lần tra cứu thất bại, sau đó xác minh rằng một wrapper được callback đăng ký cho phép thao tác tệp ban đầu hoàn tất.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
c, php
Lĩnh vực
backend
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
30/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.