1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace TheCodingMachine\Gotenberg; |
||
6 | |||
7 | use GuzzleHttp\Psr7\LazyOpenStream; |
||
8 | use Psr\Http\Message\StreamInterface; |
||
9 | use function fopen; |
||
10 | use function fwrite; |
||
11 | use function GuzzleHttp\Psr7\stream_for; |
||
12 | |||
13 | final class DocumentFactory |
||
14 | { |
||
15 | public static function makeFromPath(string $fileName, string $filePath): Document |
||
16 | { |
||
17 | return new Document($fileName, new LazyOpenStream($filePath, 'r')); |
||
18 | } |
||
19 | |||
20 | public static function makeFromStream(string $fileName, StreamInterface $fileStream): Document |
||
21 | { |
||
22 | return new Document($fileName, $fileStream); |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * @throws FilesystemException |
||
27 | */ |
||
28 | public static function makeFromString(string $fileName, string $string): Document |
||
29 | { |
||
30 | $fileStream = fopen('php://memory', 'rb+'); |
||
31 | if ($fileStream === false) { |
||
32 | throw FilesystemException::createFromPhpError(); |
||
33 | } |
||
34 | |||
35 | if (fwrite($fileStream, $string) === false) { |
||
36 | throw FilesystemException::createFromPhpError(); |
||
37 | } |
||
38 | |||
39 | return new Document($fileName, stream_for($fileStream)); |
||
0 ignored issues
–
show
|
|||
40 | } |
||
41 | } |
||
42 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.