Download the PHP package mcoste/directory-files-stream-wrapper without Composer
On this page you can find all versions of the php package mcoste/directory-files-stream-wrapper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mcoste/directory-files-stream-wrapper
More information about mcoste/directory-files-stream-wrapper
Files in mcoste/directory-files-stream-wrapper
Package directory-files-stream-wrapper
Short Description A stream wrapper for PHP that allow to read from multiple files with one resource.
License MIT
Informations about the package directory-files-stream-wrapper
DirectoryFilesStreamWrapper
Allow to read all files of a directory with a single resource object.
Install
Initialization
Before being able to use this stream wrapper, you have to register it. To do so, you have 2 ways.
The easy way
You can use the PHP stream_wrapper_register() function:
Replace 'protocol' by whatever valid string you want. See the RFC 2396 (section 3.1: Scheme Component) for more details. You can simply use DirectoryFilesStreamWrapper::DEFAULT_PROTOCOL_NAME if you want.
The very easy way
An easier way is to call the static method DirectoryFilesStreamWrapper::register(). And that's it, you're good to go.
This method takes an optional parameter to specify the protocol name you want. By default, it uses DirectoryFilesStreamWrapper::DEFAULT_PROTOCOL_NAME.
Usage
With the registration completed, all you have to do is open a directory like so :
'protocol' must be replaced by the protocol name you have chosen ('directory-files' if you used DirectoryFilesStream::register() without parameters)
You can now use the resource as any other. For exemple :
The files to be read are sorted by their names using the natural order, as defined by the PHP function natsort().
Limitations
Read only
This stream wrapper does not allow any other mode than 'r'. You can pass whatever mode you want to fopen(), 'r' will always be used. This limitation is needed because 'r' is the only mode that makes sense in the context of this wrapper.