Abstraction of streaming behavior for PHP. PhpStreams are opened by StreamWrappers on a call to fopen().

PhpStream is a descendant of PhpResource, it contains a StreamContext (may be empty) and two ordered lists of StreamFilters (input and output filters). PhpStream may be cast to a .NET stream (using its RawStream property).

Various stream types are defined by overriding the Raw* methods that provide direct access to the underlying physical stream. Corresponding public methods encapsulate these accessors with buffering and filtering. Raw stream access is performed at the byte[] level. ClassLibrary functions may use either the Read/WriteBytes or Read/WriteString depending on the nature of the PHP function. Data are converted using the ApplicationConfiguration.GlobalizationSection.PageEncoding as necessary.

When reading from a stream, the stream data is read in binary format in chunks of predefined size (8kB). Stream filters (if any) are then applied in a cascade to the whole block. Filtered blocks are stored in a Queue of either strings or PhpBytes depending on the last filter output (note that after filtering not all blocks have necessarily the original chunk size; when appending a filter to the filter-chain all the buffered data is passed through this one too). The input queue is being filled until the required data length is available. The readPosition property holds the index into the first chunk of data. When this chunk is entirely consumed it is dequeued.

Writing to a stream is buffered too (unless it is disabled using stream_set_write_buffer). When the data passes through the filter-chain it is appended to the write buffer (using the writePosition property). When the write buffer is full it is flushed to the underlying stream.

Inheritance: Pchp.Core.PhpResource
Esempio n. 1
0
        // int (*stream_closer)(php_stream_wrapper *wrapper, php_stream *stream TSRMLS_DC);

        /// <summary>
        /// Wrapper may override the <c>stat()</c>ing of a stream using this method.
        /// </summary>
        /// <param name="stream">The Wrapper-opened stream to be <c>stat()</c>ed.</param>
        /// <returns></returns>
        public virtual PhpArray OnStat(PhpStream stream) { return null; }
Esempio n. 2
0
 /// <summary>
 /// Wrapper may be notified of closing a stream using this method.
 /// </summary>
 public virtual void OnClose(PhpStream stream) { }