ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Streams.php
Go to the documentation of this file.
1<?php
2
4
6
19{
20
29 public static function ofString($string)
30 {
31 if (!is_string($string)) {
32 throw new \InvalidArgumentException('The argument $string must be of type string but was "' . gettype($string) . '"');
33 }
34
35 $stream = new Stream(fopen('php://memory', 'rw'));
36 $stream->write($string);
37 return $stream;
38 }
39
40
51 public static function ofResource($resource)
52 {
53 if (!is_resource($resource)) {
54 throw new \InvalidArgumentException('The argument $resource must be of type resource but was "' . gettype($resource) . '"');
55 }
56
57 return new Stream($resource);
58 }
59
60
68 public static function ofPsr7Stream(StreamInterface $stream)
69 {
70 $resource = $stream->detach();
71 return self::ofResource($resource);
72 }
73}
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:68
static ofResource($resource)
Wraps an already created resource with the stream abstraction.
Definition: Streams.php:51
static ofString($string)
Creates a new stream with an initial value.
Definition: Streams.php:29
Describes a data stream.
$stream
PHP stream implementation.