Skip to content

Stream: getMetadata Example

Terry L edited this page Jun 20, 2020 · 2 revisions
Clone this wiki locally

Shieldon\Psr7\Stream

getMetadata($key)

Get stream metadata as an associative array or retrieve a specific key.

  • param string key = null Specific metadata to retrieve.
  • return array|mixed|null

Example:

$resource = fopen(BOOTSTRAP_DIR . '/sample/shieldon_logo.png', 'r+');
$stream = new Stream($resource);
$meta = $stream->getMetadata();

print(print_r($queryParams, true));

/* Outputs:

    Array
    (
        [timed_out] => false
        [blocked] => true
        [eof] => false
        [wrapper_type] => plainfile
        [stream_type] => STDIO
        [mode] => r+
        [unread_bytes] => 0
        [seekable] => true
        [uri] => /home/terrylin/data/psr7/tests/sample/shieldon_logo.png
    )
*/

echo $stream->getMetadata('mode')
// Outputs: r+