exsyst / io
Object-oriented I/O facility
Installs: 6 392
Dependents: 2
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.5
Requires (Dev)
- phpunit/phpunit: ~4.8
This package is auto-updated.
Last update: 2020-02-09 03:41:22 UTC
README
EXSyst I/O Component
Object-oriented I/O facility
Source
s
The Source
objects (objects implementing SourceInterface
) can be used to read raw chunks of data from several sources :
StringSource
s can be used to read data from a string ;StreamSource
s can be used to read data from a PHP stream resource, without protection from most flaws in the implementation of the wrapped PHP stream ; they can also be used asSink
s (read more in the next section) if the stream is writable or bidirectional ;BufferedSource
s can be used to wrap other sources, in order to fix several flaws which their implementation may have, and add missing features (for example, haven't you already needed, if only once, to seek backwards on a socket ?) ;OuterSource
s are abstract : you may extend them to provide additional services on existingSource
s (for example,BufferedSource
s andReader
s areOuterSource
s).
You may create Source
s directly from the classes' constructors, or using static methods from the Source
class, which may provide additional services (for example, fromStream
and fromFile
automatically wrap the StreamSource
s in BufferedSource
s by default).
The Source
class also provides static utility methods.
Sink
s
The Sink
objects (objects implementing SinkInterface
) can be used to write raw chunks of data to several sinks :
StringSink
s can be used to build strings (but may be slower than plain concatenation : beware of call overhead !) ;- The
SystemSink
is a simple wrapper forecho
; it is a singleton ; RecordFunctionSink
s can be used to aggregate data into records (of fixed size, or delimited by a separator, with an optional size limit) and pass them to a custom function ;StreamSource
s (see the previous section) which wrap a writable or bidirectional stream can be used to write data to a PHP stream resource ;TeeSink
s can be used to duplicate data into multipleSink
s.
Like the Source
class, the Sink
class provides static methods which can be used to easily create Sink
s, and static utility methods.
State
s
The State
objects (objects implementing StateInterface
) can be obtained by calling captureState
on a Source
which supports it.
They can be used to rewind the Source
to a previous position using the restore
method.
You can wrap your Source
in a BufferedSource
if you need to rewind it and if it doesn't support it.
Reader
s
The Reader
objects (which do not implement any specific interface, as they provide much different services) can be used to read structured data from Source
s :
CDataReader
s can be used to ease the writing of lexers : they supporteat
ing fixed strings, strings including or excluding only given character classes, and white space ;StringCDataReader
s areCDataReader
s optimized forStringSource
s, which additionally suppporteat
ing strings matching a regular expression (usingpreg_match
) ;SerializedReader
s can be used to separate concatenatedserialize
d values (as inserialize($foo).serialize($bar)
), regardless of whether they come from a localSource
(such as a string or a file stream) or a remote one (such as a pipe or network stream) ; they are explicitly designed to work efficiently with remoteSource
s ;JsonReader
s can be used to separate concatenated JSON (as specified by RFC 7159) values, in the same conditions asSerializedReader
.
It is recommended to create CDataReader
s using the fromSource
static method : it will automatically prefer an optimized implementation (such as StringCDataReader
) when applicable.
Channel
s
The Channel
objects (objects implementing ChannelInterface
) can be used to communicate with remote tasks using messages, which will be serialized if necessary :
SerializedChannel
s serialize the messages using the native PHP format (withserialize
) ;JsonChannel
s serialize the messages using JSON (as specified by RFC 7159).
The ChannelFactory
objects (objects implementing ChannelFactoryInterface
) can be used by an application or a library to specify an encoder/decoder couple, along with their parameters, to another library.
Selectable
s
The Selectable
objects (objects implementing SelectableInterface
) are objects which wrap PHP streams. They can be passed to the static methods of the Selectable
class, which are object-oriented wrappers to stream_select
. These methods can look for Selectable
s wrapped in arbitrarily many OuterSource
s, and will let the originally passed objects (not the inner Selectable
s) in the sets on return.
Many objects are Selectable
: StreamSource
s, all Channel
s, and objects of the Selectable
class itself : in addition to its static utility methods, it provides a bare-bones implementation of the interface (which you can use to, for example, add a server socket to your set).