Documentation

SUTWithPublicClose extends SUT
in package

Class \Hoa\Stream.

Static register for all streams (files, sockets etc.).

Table of Contents

Constants

CONTEXT  = 3
Context index in the stream bucket.
DEFAULT_BUFFER_SIZE  = 8192
Default buffer size.
HANDLER  = 1
Handler index in the stream bucket.
NAME  = 0
Name index in the stream bucket.
RESOURCE  = 2
Resource index in the stream bucket.

Properties

$_borrowing  : bool
Whether this stream is already opened by another handler.
$_bucket  : array<string|int, mixed>
Current stream bucket.
$_bufferSize  : bool
Buffer size (default is 8Ko).
$_context  : string
Context name.
$_hasBeenDeferred  : bool
Whether the opening has been deferred.
$_listener  : Listener
Listener instance.
$_streamName  : string
Original stream name, given to the stream constructor.
$_register  : array<string|int, mixed>
Static stream register.

Methods

__construct()  : mixed
Set the current stream.
__destruct()  : void
Close the stream when destructing.
__toString()  : string
Transform object to string.
_close()  : bool
Close the current stream.
_Hoa_Stream()  : void
Call the $handler->close() method on each stream in the static stream register.
_notify()  : void
Notification callback.
_setStream()  : resource
Set the current stream. Useful to manage a stack of streams (e.g. socket and select). Notice that it could be unsafe to use this method without taking time to think about it two minutes. Resource of type “Unknown” is considered as valid.
close()  : void
Close the current stream.
disableStreamBuffer()  : bool
Disable stream buffering.
getStream()  : resource
Get the current stream.
getStreamBufferSize()  : int
Get stream buffer size.
getStreamContext()  : Context
Get the current stream context.
getStreamHandler()  : Stream
Get stream handler according to its name.
getStreamMetaData()  : array<string|int, mixed>
Get stream meta data.
getStreamName()  : string
Get the current stream name.
getStreamWrapperName()  : string
Get stream wrapper name.
hasTimedOut()  : bool
Check whether the connection has timed out or not.
isBorrowing()  : bool
Whether this stream is already opened by another handler.
isOpened()  : bool
Check if the stream is opened.
on()  : Listenable
Attach a callable to a listenable component.
open()  : Stream
Open the stream.
setStreamBlocking()  : bool
Set blocking/non-blocking mode.
setStreamBuffer()  : bool
Set stream buffer.
setStreamTimeout()  : bool
Set the timeout period.
_open()  : resource
Open the stream and return the associated resource.
getListener()  : Listener
Get listener.
hasBeenDeferred()  : mixed
Whether the opening of the stream has been deferred
setListener()  : Listener
Set listener.
_getStream()  : array<string|int, mixed>
Get a stream in the register.

Constants

CONTEXT

Context index in the stream bucket.

public mixed CONTEXT = 3
Tags
const

int

DEFAULT_BUFFER_SIZE

Default buffer size.

public mixed DEFAULT_BUFFER_SIZE = 8192
Tags
const

int

HANDLER

Handler index in the stream bucket.

public mixed HANDLER = 1
Tags
const

int

NAME

Name index in the stream bucket.

public mixed NAME = 0
Tags
const

int

RESOURCE

Resource index in the stream bucket.

public mixed RESOURCE = 2
Tags
const

int

Properties

$_borrowing

Whether this stream is already opened by another handler.

protected bool $_borrowing = false

$_bucket

Current stream bucket.

protected array<string|int, mixed> $_bucket = []

$_bufferSize

Buffer size (default is 8Ko).

protected bool $_bufferSize = self::DEFAULT_BUFFER_SIZE

$_context

Context name.

protected string $_context = null

$_hasBeenDeferred

Whether the opening has been deferred.

protected bool $_hasBeenDeferred = false

$_streamName

Original stream name, given to the stream constructor.

protected string $_streamName = null

$_register

Static stream register.

private static array<string|int, mixed> $_register = []

Methods

__construct()

Set the current stream.

public __construct(string $streamName[, string $context = null ][, bool $wait = false ]) : mixed

If not exists in the register, try to call the $this->_open() method. Please, see the self::_getStream() method.

Parameters
$streamName : string

Stream name (e.g. path or URL).

$context : string = null

Context ID (please, see the Hoa\Stream\Context class).

$wait : bool = false

Differ opening or not.

__destruct()

Close the stream when destructing.

public __destruct() : void

__toString()

Transform object to string.

public __toString() : string
Return values
string

_close()

Close the current stream.

public _close() : bool

Note: this method is protected, but do not forget that it could be overloaded into a public context.

Return values
bool

_Hoa_Stream()

Call the $handler->close() method on each stream in the static stream register.

public final static _Hoa_Stream() : void

This method does not check the return value of $handler->close(). Thus, if a stream is persistent, the $handler->close() should do anything. It is a very generic method.

_notify()

Notification callback.

public _notify(int $ncode, int $severity, string $message, int $code, int $transferred, int $max) : void
Parameters
$ncode : int

Notification code. Please, see STREAM_NOTIFY_* constants.

$severity : int

Severity. Please, see STREAM_NOTIFY_SEVERITY_* constants.

$message : string

Message.

$code : int

Message code.

$transferred : int

If applicable, the number of transferred bytes.

$max : int

If applicable, the number of max bytes.

_setStream()

Set the current stream. Useful to manage a stack of streams (e.g. socket and select). Notice that it could be unsafe to use this method without taking time to think about it two minutes. Resource of type “Unknown” is considered as valid.

public _setStream(mixed $stream) : resource
Parameters
$stream : mixed
Tags
throws
Exception
Return values
resource

close()

Close the current stream.

public final close() : void

disableStreamBuffer()

Disable stream buffering.

public disableStreamBuffer() : bool

Alias of $this->setBuffer(0).

Return values
bool

getStream()

Get the current stream.

public getStream() : resource
Return values
resource

getStreamBufferSize()

Get stream buffer size.

public getStreamBufferSize() : int
Return values
int

getStreamContext()

Get the current stream context.

public getStreamContext() : Context
Return values
Context

getStreamHandler()

Get stream handler according to its name.

public static getStreamHandler(string $streamName) : Stream
Parameters
$streamName : string

Stream name.

Return values
Stream

getStreamMetaData()

Get stream meta data.

public getStreamMetaData() : array<string|int, mixed>
Return values
array<string|int, mixed>

getStreamName()

Get the current stream name.

public getStreamName() : string
Return values
string

getStreamWrapperName()

Get stream wrapper name.

public getStreamWrapperName() : string
Return values
string

hasTimedOut()

Check whether the connection has timed out or not.

public hasTimedOut() : bool

This is basically a shortcut of getStreamMetaData + the timed_out index, but the resulting code is more readable.

Return values
bool

isBorrowing()

Whether this stream is already opened by another handler.

public isBorrowing() : bool
Return values
bool

isOpened()

Check if the stream is opened.

public isOpened() : bool
Return values
bool

on()

Attach a callable to a listenable component.

public on(string $listenerId, mixed $callable) : Listenable
Parameters
$listenerId : string

Listener ID.

$callable : mixed

Callable.

Return values
Listenable

open()

Open the stream.

public final open() : Stream
Tags
throws
Exception
Return values
Stream

setStreamBlocking()

Set blocking/non-blocking mode.

public setStreamBlocking(bool $mode) : bool
Parameters
$mode : bool

Blocking mode.

Return values
bool

setStreamBuffer()

Set stream buffer.

public setStreamBuffer(int $buffer) : bool

Output using fwrite() (or similar function) is normally buffered at 8 Ko. This means that if there are two processes wanting to write to the same output stream, each is paused after 8 Ko of data to allow the other to write.

Parameters
$buffer : int

Number of bytes to buffer. If zero, write operations are unbuffered. This ensures that all writes are completed before other processes are allowed to write to that output stream.

Return values
bool

setStreamTimeout()

Set the timeout period.

public setStreamTimeout(int $seconds[, int $microseconds = 0 ]) : bool
Parameters
$seconds : int

Timeout period in seconds.

$microseconds : int = 0

Timeout period in microseconds.

Return values
bool

_open()

Open the stream and return the associated resource.

protected & _open(mixed $streamName[, Context $context = null ]) : resource

Note: This method is protected, but do not forget that it could be overloaded into a public context.

Parameters
$streamName : mixed

Stream name (e.g. path or URL).

$context : Context = null

Context.

Return values
resource

hasBeenDeferred()

Whether the opening of the stream has been deferred

protected hasBeenDeferred() : mixed

_getStream()

Get a stream in the register.

private final static & _getStream(string $streamName, Stream $handler[, string $context = null ]) : array<string|int, mixed>

If the stream does not exist, try to open it by calling the $handler->_open() method.

Parameters
$streamName : string

Stream name.

$handler : Stream

Stream handler.

$context : string = null

Context ID (please, see the \Hoa\Stream\Context class).

Tags
throws
Exception
Return values
array<string|int, mixed>

        
On this page

Search results