pbergman / stream-wrapper
A stream wrapper for registering and using resources as url argument
Installs: 1 070
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7
This package is auto-updated.
Last update: 2024-10-29 12:56:43 UTC
README
This little library was build to use an resource with XMLWriter and XMLReader but could be used with everything that support an "URL like" path name as argument.
Example
require_once 'vendor/autoload.php';
use PBergman\Stream\StreamWrapper;
// createtmp buffer
$fd = fopen('php://temp', 'w');
// register buffer and wrapper protocol
StreamWrapper::register($fd, 'foo');
// create xml
$writer = new \XMLWriter();
$writer->openUri('wrapper://foo');
$writer->setIndent(true);
$writer->startElement('records');
$writer->startElement('record');
$writer->startElement('title');
$writer->text('Some title...');
$writer->endElement();
$writer->endElement();
$writer->endElement();
$writer->flush();
rewind($fd);
var_dump(stream_get_contents($fd));
// should output something like:
// string(73) "<records>
// <record>
// <title>Some title...</title>
// </record>
// </records>
// "