-
Notifications
You must be signed in to change notification settings - Fork 1
PSR 17: StreamFactory Example
Terry L edited this page Jun 21, 2020
·
3 revisions
Namespace
Shieldon\Psr17\StreamFactory
None
-
param
string
content= ""
String content with which to populate the stream. -
return
StreamInterface
Example:
$streamFactory = new StreamFactory();
$stream = $streamFactory->createStream('Foo Bar');
echo $stream;
// Outputs: Foo Bar
-
param
string
filename*
The filename or stream URI to use as basis of stream. -
param
string
moder
The mode with which to open the underlying filename/stream. -
return
StreamInterface
Example:
$sourceFile = BOOTSTRAP_DIR . '/sample/shieldon_logo.png';
$streamFactory = new StreamFactory();
$stream = $streamFactory->createStreamFromFile($sourceFile);
echo $stream->getSize();
// Outputs: 15166
-
param
string
resource*
The PHP resource to use as the basis for the stream. -
return
StreamInterface
Example:
$streamFactory = new StreamFactory();
$stream = $streamFactory->createStreamResource(
fopen('php://temp', 'r+')
);
composer require shieldon/psr-http
Shieldon PSR HTTP implementation written by Terry L. from Taiwan.