Download the PHP package xdimedrolx/hoa-stream without Composer

On this page you can find all versions of the php package xdimedrolx/hoa-stream. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package hoa-stream

Reasons to fork

The Hoa project was archived, and no upgrades or patches are neither provided nor accepted by merge requests.

HOA Packages include some code that is Deprecated for PHP 8.0 and PHP 8.1, but we needed these packages to run on modern PHP versions.

What's changed in from?

The changes mainly affected the return data type hinting in methods declaration, access to uninitialized properties.

How to use

We've currently forked the following packages, primarily to make hoa/stream work with PHP 8.1:

Original packageForked package
hoa/rulerhiqdev/hoa-ruler
hoa/compilerhiqdev/hoa-compiler
hoa/protocolhiqdev/hoa-protocol
hoa/iteratorhiqdev/hoa-iterator
hoa/iteratorhiqdev/hoa-stream

You can simply replace requirements in composer.json from hoa packages to the corresponding forked packages: there is no need to change something in the codebase.

If you use someone's package, that requires hoa – simply add forks to your project root composer.json: we have marked forks as a replacement, so composer will install them instead of the original packages.

Versions

We've forked from the latest hoa package versions and bump own versions starting from 1.0.

Testing

Before running the test suites, the development dependencies must be installed:

Then, to run all the test suites:

For more information, please read the contributor guide.

Quick usage

As a quick overview, we propose to discover what Hoa\Stream provides in term of interfaces, i.e. stream capabilities. This is almost the most important part of this library. Then, how to define a stream, followed by how to use stream contexts. Events, listeners and notifications will be detailed in the next section. Finally, wrappers and filters are detailed in the last sections.

Interfaces, aka stream capabilities

This library defines several interfaces representing important stream capabilities. This is very useful when designing a function, or a library, working with streams. It ensures the stream is typed and offers certain capabilities. The interfaces are declared in the Hoa\Stream\IStream namespace:

Thus, if one only need to read from a stream, it will type the stream with Hoa\Stream\IStream\In. It also allows an implementer to choose what capabilities its stream will provide or not.

Finally, the highest interface is Stream, defining the getStream method, that's all. That's the most undefined stream. All capabilities must extend this interface.

Define a concrete stream

The main Hoa\Stream\Stream class is abstract. Two method implementations are left to the user: _open and : _close, respectively to open a particular stream, and to close this particular stream, for instance:

Then, the most common usage will be:

That's all. This stream has no capability yet. Let's implement the In capability:

Other methods are left as an exercise to the reader. Thus, we are now able to:

The Stream capability is already implemented by the Hoa\Stream\Stream class.

Contextual streams

A context is represented by the Hoa\Stream\Context class. It represents a set of options and parameters for the stream. See the options and parameters for the http:// stream wrapper as an example of possible ones. Thanks to context, this is possible to add HTTP headers for instance, or to specify the proxy, the maximum number of redirections etc. All these information are options/parameters of the stream.

To use them, first let's define the context:

And thus, we can ask a stream to use this context based on the chosen context ID, like this:

For the stream implementer, the getOptions and getParameters methods on the Hoa\Stream\Context class will be useful to respectively retrieve the options and the parameters, and acts according to them.

The concept of options and parameters are defined by PHP itself.

Events, listeners, and notifications

A stream has some events, and several listeners. So far, listeners mostly represent “stream notifications”.

2 events are registered: hoa://Event/Stream/<streamName> and hoa://Event/Stream/<streamName>:close-before. Thus, for instance, to execute a function before the /path/to/file stream closes, one will write:

Remember that a stream is not necessarily a file. It can be a socket, a WebSocket, a stringbuffer, any stream you have defined… Consequently, this event can be used in very different manner for various scenario, like logging things, closing related resources, firing another event… There is no rule. The observed stream is still opened, and can theoritically still be used.

This event is fired when calling the Hoa\Stream\Stream::close method.

Now let's move on to listeners. To register a listener, we must create an instance of our stream without opening it. This action is called “deferred opening”. We can control the opening time with the third argument of the default Hoa\Stream\Stream constructor; true to defer the opening, like:

Passing null as a second argument means: No context. Note that we must manually call the open method to open the stream then. Between the stream instanciation and the stream opening, we can attach new listeners.

Depending of the stream implementation, different listeners will be fired. The term “listener” is the one used everywhere in Hoa, but PHP —in the context of stream— refers to them as notifications. Let's take an example with an HTTP stream:

You might see something like this:

The exhaustive list of listeners is the following:

All listener bucket data is an array containing the following pairs:

This is possible for the stream implementer to add more listeners. Please, take a look at the Hoa\Event library. Not all listeners will be fired by all kind of streams.

Wrappers

A stream wrapper allows to declare schemes, like hoa:// or fortune://. You can imagine adding your favorite online storage too, cloud://. Any stream wrapper can be used with native standard PHP functions, like fopen, file_get_contents, mkdir, touch etc. It will be transparent for the user.

The Hoa\Stream\Wrapper\Wrapper class holds all methods to register, unregister, and restore wrappers. The isRegistered and getRegistered methods are also helpful. A wrapper is represented by a class:

A wrapper must implement the Hoa\Stream\Wrapper\IWrapper\IWrapper interface. It is a combination of two other interfaces in the same namespace: Stream and File.

The Stream interface requires to implement several methods related to a stream, such as:

The API provides all required information.

The File interface requires to implement other methods related to stream acting as a file, such as:

An example of an implementation is the hoa:// scheme in the Hoa\Protocol library. It does not depend on this library to avoid dependencies, but the code can be helpful.

Filters

A stream is like a pipe, with an input, and an output. This is possible to cut this pipe in two pieces, and insert a small part: A filter. There are three types of filter, identified by constants on the Hoa\Stream\Filter\Filter class:

  1. Filter::READ when the filter applies for reading operations,
  2. Filter::WRITE when the filter applies for writing operations,
  3. Filter::READ_AND_WRITE when both.

This class allows to register or remove filters. A filter takes the form of a class extending the Hoa\Stream\Filter\Basic filter, and an associated name. This is not mandatory but highly encouraged.

Once a filter is registered, we can apply it on a stream by using its name, with the append or prepend methods. You might guess that several filters can be applied on a stream, in a specific order, like “decrypt”, “unzip”, “transform to…”. In such a scenario, the order matters.

Finally, we use the stream as usual. A stream is not necessarily an instance of Hoa\Stream, it can be any PHP stream resources. Passing an Hoa\Stream instance will obviously unwraps to its underlying PHP stream resource.

Let's implement a filter that changes the content of the stream into uppercase. We start by defining out filter:

Great. Now let's register our filter under a specific name:

Then, we must apply the filter on a specific stream, so let's open a stream, and append the filter:

This filter has been applied for reading operations only. So we will see its effect when reading on our stream, let's do it:

You will see everything in ASCII uppercase.

A filter is a low-level stream API. It integrates with all kind of streams. And this is a very powerful tool. We mentionned some usages like decrypt, transform to, unzip… Actually, PHP comes with certain standard filters, like: string.toupper, string.tolower, dechunk, zlib.*, bzip2.*, convert.iconv.* etc. The Hoa\Stream\Filter\Filter::getRegistered method will provide the list of all registered filters.

The Hoa\Stream\Filter\LateComputed class is a special filter. It calls its public compute method when the stream reaches its end. So by extending this filter, you can override the compute method and works on the _buffer attribute. This buffer contains the whole content of the stream. This is really a buffer. Why would it be useful? For instance if you are reading a PHP file, you can transform the source code on-the-fly by using a parser —for instance— and rewrite parts of the file. This technique is particularily useful to instrument codes (adding some probes).

This is also possible to auto-apply a filter with… a wrapper! For example the instrument:// wrapper can prepend a filter to the stream being opened with the stream_open method (from the Hoa\Stream\Wrapper\IWrapper\Stream interface).

Possibilities are numerous.

Other operations

There are more to cover. Hoa\Stream supports composite streams (with the Hoa\Stream\Composite abstract class), i.e. streams embedding other streams, like the Hoa\Xml library. An XML stream reads and writes from another inner stream (a file, a socket, or anything else). The Hoa\Stringbuffer library allows a string to be manipulated with a stream API, so the stream content is written on the disk. Stream capabiilities are not the same than Hoa\File as you might guess.

Documentation

The hack book of Hoa\Stream contains detailed information about how to use this library and how it works.

To generate the documentation locally, execute the following commands:

More documentation can be found on the project's website: hoa-project.net.

Getting help

There are mainly two ways to get help:

Contribution

Do you want to contribute? Thanks! A detailed contributor guide explains everything you need to know.

License

Hoa is under the New BSD License (BSD-3-Clause). Please, see LICENSE for details.

Related projects

The following projects are using this library:


All versions of hoa-stream with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
hoa/consistency Version ~1.0
hoa/event Version ~1.0
hoa/exception Version ~1.0
xdimedrolx/hoa-protocol Version ~1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package xdimedrolx/hoa-stream contains the following files

Loading the files please wait ....