ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
Streams.php
Go to the documentation of this file.
1<?php
2declare(strict_types=1);
3
5
6use Psr\Http\Message\StreamInterface;
7
19final class Streams
20{
21
30 public static function ofString($string) : FileStream
31 {
32 if (!is_string($string)) {
33 throw new \InvalidArgumentException('The argument $string must be of type string but was "' . gettype($string) . '"');
34 }
35
36 $stream = new Stream(fopen('php://memory', 'rw'));
37 $stream->write($string);
38 return $stream;
39 }
40
41
52 public static function ofResource($resource) : FileStream
53 {
54 if (!is_resource($resource)) {
55 throw new \InvalidArgumentException('The argument $resource must be of type resource but was "' . gettype($resource) . '"');
56 }
57
58 return new Stream($resource);
59 }
60
61
69 public static function ofPsr7Stream(StreamInterface $stream) : FileStream
70 {
71 $resource = $stream->detach();
72 return self::ofResource($resource);
73 }
74}
An exception for terminatinating execution or to throw for unit testing.
static ofPsr7Stream(StreamInterface $stream)
Create a FileStream from a Psr7 compliant stream.
Definition: Streams.php:69
static ofResource($resource)
Wraps an already created resource with the stream abstraction.
Definition: Streams.php:52
static ofString($string)
Creates a new stream with an initial value.
Definition: Streams.php:30