SCHEMES
SCHEMES = ['http', 'https']
The two schemes this wrapper answers for.
An http:// and https:// stream wrapper backed by an injected fetch callable.
WHY THIS EXISTS AT ALL. In a PHP-in-wasm runtime there are no sockets, so overriding an HTTP client's own handler stack fixes that one client and nothing else. Any vendor or contrib code calling file_get_contents('https://...') either fails with "Unable to find the wrapper" or -- on a build whose glue still references a suspension helper the link removed -- dies with a JS ReferenceError that PHP cannot catch. Both failures are per-call and late, which is the worst shape for diagnosis. Shadowing both schemes with this class makes the outcome a documented refusal instead.
WHAT IT DELIBERATELY DOES NOT DO. It does not stream. The whole body is fetched on open and served from memory, because PHP's stream_read() is synchronous and a real streaming read would have to suspend the interpreter mid-call. A build without suspension can only fetch-then-read.
THE FETCH IS INJECTED, never reached for. This package has no host, no service container and no framework; register() takes the callable and the wrapper calls nothing else. See README for the request and reply shape.
REGISTER FROM THE HOST, BEFORE THE FRAMEWORK BOOTS. A stream wrapper has to exist before any code that uses one runs, and a service container is built too late for that.
__construct(callable|null $fetch = null) : mixed
Constructs a wrapper, optionally with its own fetch.
| callable|null | $fetch | A fetch for this instance only. PHP constructs a registered wrapper with no arguments, so the parameter is optional by necessity -- it exists for direct construction in a test or a caller that wants one URL fetched through its own transport. |
register(callable $fetch, array $schemes = \self::SCHEMES) : array
Registers this wrapper for http and https, replacing anything present.
| callable | $fetch | Receives the request array and returns the reply array; see README for both shapes. |
| array | $schemes | Which schemes to take over. Defaults to both. |
The schemes actually registered, in the order given.
stream_open(string $path, string $mode, int $options, string|null $opened_path) : bool
Opens a URL by fetching it whole.
| string | $path | The URL, exactly as the caller wrote it. |
| string | $mode | The fopen() mode; anything that is not a read is refused. |
| int | $options | Stream flags; STREAM_REPORT_ERRORS asks for a warning. |
| string|null | $opened_path | Set to the URL when PHP asked for it. |
TRUE once the body is in memory.
stream_read(int $count) : string
Serves bytes from the response already held in memory.
There is no incremental read: stream_open() fetched the whole body, because a fetch returns a complete response rather than a socket.
| int | $count | How many bytes PHP is asking for. |
Up to $count bytes, or the empty string at EOF.
stream_seek(int $offset, int $whence = \Drupflare\StreamHttp\SEEK_SET) : bool
Moves the read position, refusing to land outside the body.
| int | $offset | Offset to seek to, interpreted according to $whence. |
| int | $whence | One of SEEK_SET, SEEK_CUR or SEEK_END. |
TRUE on success, FALSE if the target is out of range.
url_stat(string $path, int $flags) : array|false
Describes a URL without opening it, for file_exists() and friends.
| string | $path | The URL being stat'd. |
| int | $flags | Stat flags from PHP; not used, since no request is made. |
A stat array claiming the resource exists with an unknown size.
responseMeta() : array
The status and headers of the response this instance is serving.
Reachable from a file handle as
stream_get_meta_data($fh)['wrapper_data']->responseMeta(), because PHP puts the wrapper
instance itself in wrapper_data for a userland wrapper. $http_response_header is
populated only by PHP's own http wrapper and cannot be set from here.
NOT called stream_metadata: that name belongs to the streamWrapper prototype, where it is
stream_metadata(string $path, int $option, mixed $value): bool and PHP invokes it for
touch(), chmod() and chown() on the URL. A 0-argument method under that name is an
ArgumentCountError waiting for the first caller who touches an http:// path.
status and headers.