Class \Prado\IO\TStreamNotificationCallback
This class is used to listen into the connections of fopen(), file_get_contents(), and file_put_contents() by patching into context 'notification' parameter callback.
This class is an invokable callback that is notified as the connection unfolds. Of particular use is listening to the progress of data transfer with TStreamNotificationCallback::onProgress() The TStreamNotificationCallback::filterStreamContext() method can accept a TStreamNotificationCallback or an array of options that includes "notification". The array of options are the options for stream_context_create and can include events as keys and event handlers (or an array of Event Handlers) to patch into the "notification" callback. Within the array of options, "notification" can be a TStreamNotificationCallback or an array of events as keys and event handlers as values.
The following event handlers are available to listen to the file connection and transfer:
- onResolve: Raised when the Notification Code is STREAM_NOTIFY_RESOLVE.
- onConnected: Raised when the Notification Code is STREAM_NOTIFY_CONNECT.
- onAuthRequired: Raised when the Notification Code is STREAM_NOTIFY_AUTH_REQUIRED.
- onAuthResult: Raised when the Notification Code is STREAM_NOTIFY_AUTH_RESULT.
- onRedirected: Raised when the Notification Code is STREAM_NOTIFY_REDIRECTED.
- onMimeType: Raised when the Notification Code is STREAM_NOTIFY_MIME_TYPE_IS. This parses the $message Mime Type and Charset and is retrievable with TStreamNotificationCallback::getMimeType() and TStreamNotificationCallback::getCharset().
- onFileSize: Raised when the Notification Code is STREAM_NOTIFY_FILE_SIZE_IS. This stores the file size and is retrievable with TStreamNotificationCallback::getFileSize().
- onProgress: Raised when the Notification Code is STREAM_NOTIFY_PROGRESS. This stores the bytes Transferred and is retrievable with TStreamNotificationCallback::getBytesTransferred().
- onCompleted: Raised when the Notification Code is STREAM_NOTIFY_COMPLETED. This sets the TStreamNotificationCallback::getIsCompleted() to true (from false).
- onFailure: Raised when the Notification Code is STREAM_NOTIFY_FAILURE. This sets the TStreamNotificationCallback::getIsFailure() to true (from false) and stores the Message Code for retrieval with TStreamNotificationCallback::getMessageCode().
These events pass the TStreamNotificationParameter as the parameter. It contains the arguments of the Stream Notification Callback and is reused in each notification.
Class hierarchy
Author: Brad Anderson <belisoful@icloud.com>Since: 4.3.0
public
|
|
public
|
__invoke(int $notification_code, int $severity, string|null $message, int $message_code, int $bytes_transferred, int $bytes_max) : void
The callback for stream notifications.
|
public
static
|
filterStreamContext(mixed $context) : mixed
This converts the input TStreamNotificationCallback or array into a proper stream
context with options and parameters (notification). If $context is an array
this can use or convert the "notification" into a stream context parameter.
When "notifications" are an array, the keys are events for the TStreamNotificationCallback and values could be a single event handler callback or an array of event handler callbacks.
If Event Handlers for TStreamNotificationCallback are in the array, and the TStreamNotificationCallback notification is not instanced, it will be created. If the "notification" is a callable that is not a TStreamNotificationCallback then the "notification" callable is wrapped in a TStreamNotificationCallback. |
public
|
|
public
|
getCallbacks() : TWeakCallableCollection
This holds any direct notification callbacks so multiple callbacks are supported.
|
public
|
|
public
static
|
getContextNotificationCallback(mixed $context) : mixed
Given a Stream Context, this returns that stream context "notification" callback.
In this context, it is likely a TStreamNotificationCallback. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
onAuthRequired(TStreamNotificationParameter|null $param) : array<string|int, mixed>
Raised when the Notification Code is STREAM_NOTIFY_AUTH_REQUIRED.
|
public
|
onAuthResult(TStreamNotificationParameter|null $param) : array<string|int, mixed>
Raised when the Notification Code is STREAM_NOTIFY_AUTH_RESULT.
|
public
|
onCompleted(TStreamNotificationParameter|null $param) : array<string|int, mixed>
Raised when the Notification Code is STREAM_NOTIFY_COMPLETED.
|
public
|
onConnected(TStreamNotificationParameter|null $param) : array<string|int, mixed>
Raised when the Notification Code is STREAM_NOTIFY_CONNECT.
|
public
|
onFailure(TStreamNotificationParameter|null $param) : array<string|int, mixed>
Raised when the Notification Code is STREAM_NOTIFY_FAILURE.
|
public
|
onFileSize(TStreamNotificationParameter|null $param) : array<string|int, mixed>
Raised when the Notification Code is STREAM_NOTIFY_FILE_SIZE_IS.
|
public
|
onMimeType(TStreamNotificationParameter|null $param) : array<string|int, mixed>
Raised when the Notification Code is STREAM_NOTIFY_MIME_TYPE_IS.
|
public
|
onProgress(TStreamNotificationParameter|null $param) : array<string|int, mixed>
Raised when the Notification Code is STREAM_NOTIFY_PROGRESS.
|
public
|
onRedirected(TStreamNotificationParameter|null $param) : array<string|int, mixed>
Raised when the Notification Code is STREAM_NOTIFY_REDIRECTED.
|
public
|
onResolve(TStreamNotificationParameter|null $param) : array<string|int, mixed>
Raised when the Notification Code is STREAM_NOTIFY_RESOLVE.
|
public
mixed
|
NOTIFICATION
|
'notification'
|
\Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |