ILIAS  release_7 Revision v7.30-3-g800a261c036
Streams.php
Go to the documentation of this file.
1<?php
2declare(strict_types=1);
3
5
6use Psr\Http\Message\StreamInterface;
7
16final class Streams
17{
18
25 public static function ofString($string) : FileStream
26 {
27 if (!is_string($string)) {
28 throw new \InvalidArgumentException('The argument $string must be of type string but was "' . gettype($string) . '"');
29 }
30
31 $stream = new Stream(fopen('php://memory', 'rw'));
32 $stream->write($string);
33 return $stream;
34 }
35
43 public static function ofResource($resource) : FileStream
44 {
45 if (!is_resource($resource)) {
46 throw new \InvalidArgumentException('The argument $resource must be of type resource but was "' . gettype($resource) . '"');
47 }
48
49 return new Stream($resource);
50 }
51
58 public static function ofPsr7Stream(StreamInterface $stream) : FileStream
59 {
60 $resource = $stream->detach();
61 return self::ofResource($resource);
62 }
63
64 public function ofZipResource(\ZipArchive $zip, int $index) : FileStream
65 {
66
67 }
68
69}
An exception for terminatinating execution or to throw for unit testing.
Class Streams Stream factory which enables the user to create streams without the knowledge of the co...
Definition: Streams.php:17
static ofPsr7Stream(StreamInterface $stream)
Create a FileStream from a Psr7 compliant stream.
Definition: Streams.php:58
ofZipResource(\ZipArchive $zip, int $index)
Definition: Streams.php:64
static ofResource($resource)
Wraps an already created resource with the stream abstraction.
Definition: Streams.php:43
static ofString($string)
Creates a new stream with an initial value.
Definition: Streams.php:25
Interface FileStream The base interface for all filesystem streams.
Definition: FileStream.php:18
$index
Definition: metadata.php:128