ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Filesystem\Provider\FlySystem\FlySystemFileStreamAccess Class Reference
+ Inheritance diagram for ILIAS\Filesystem\Provider\FlySystem\FlySystemFileStreamAccess:
+ Collaboration diagram for ILIAS\Filesystem\Provider\FlySystem\FlySystemFileStreamAccess:

Public Member Functions

 __construct (private FilesystemOperator $flysystem_operator)
 
 readStream (string $path)
 Opens a readable stream of the file. More...
 
 writeStream (string $path, FileStream $stream)
 Writes the stream to a new file. More...
 
 putStream (string $path, FileStream $stream)
 Creates a new file or updates an existing one. More...
 
 updateStream (string $path, FileStream $stream)
 Updates an existing file. More...
 
 readStream (string $path)
 Opens a readable stream of the file. More...
 
 writeStream (string $path, FileStream $stream)
 Writes the stream to a new file. More...
 
 putStream (string $path, FileStream $stream)
 Creates a new file or updates an existing one. More...
 
 updateStream (string $path, FileStream $stream)
 Updates an existing file. More...
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Filesystem\Provider\FlySystem\FlySystemFileStreamAccess::__construct ( private FilesystemOperator  $flysystem_operator)

Definition at line 40 of file FlySystemFileStreamAccess.php.

42 {
43 }

Member Function Documentation

◆ putStream()

ILIAS\Filesystem\Provider\FlySystem\FlySystemFileStreamAccess::putStream ( string  $path,
FileStream  $stream 
)

Creates a new file or updates an existing one.

If the file is updated its content will be truncated before writing the stream.

See also
FileStream::detach()

Implements ILIAS\Filesystem\Provider\FileStreamWriteAccess.

Definition at line 96 of file FlySystemFileStreamAccess.php.

96 : void
97 {
98 $resource = $stream->detach();
99 try {
100 if (!is_resource($resource)) {
101 throw new \InvalidArgumentException('The given stream must not be detached.');
102 }
103
104 $result = $this->flysystem_operator->putStream($path, $resource);
105
106 if ($result === false) {
107 throw new IOException("Could not put stream content into \"$path\"");
108 }
109 } finally {
110 if (is_resource($resource)) {
111 fclose($resource);
112 }
113 }
114 }
$path
Definition: ltiservices.php:30

References $path.

◆ readStream()

ILIAS\Filesystem\Provider\FlySystem\FlySystemFileStreamAccess::readStream ( string  $path)

Opens a readable stream of the file.

Please make sure to close the stream after the work is done with Stream::close()

See also
FileStream::close()

Implements ILIAS\Filesystem\Provider\FileStreamReadAccess.

Definition at line 50 of file FlySystemFileStreamAccess.php.

51 {
52 try {
53 $resource = $this->flysystem_operator->readStream($path);
54 if ($resource === false) {
55 throw new IOException("Could not open stream for file \"$path\"");
56 }
57 return Streams::ofResource($resource);
58 } catch (UnableToRetrieveMetadata|UnableToReadFile $ex) {
59 throw new FileNotFoundException("File \"$path\" not found.", 0, $ex);
60 }
61 }
static ofResource($resource)
Wraps an already created resource with the stream abstraction.
Definition: Streams.php:64
The base interface for all filesystem streams.
Definition: FileStream.php:32

References $path, and ILIAS\Filesystem\Stream\Streams\ofResource().

+ Here is the call graph for this function:

◆ updateStream()

ILIAS\Filesystem\Provider\FlySystem\FlySystemFileStreamAccess::updateStream ( string  $path,
FileStream  $stream 
)

Updates an existing file.

The file content will be truncated to 0.

The stream will be closed after the write operation is done. Please note that the resource must be detached from the stream in order to write to the file.

Implements ILIAS\Filesystem\Provider\FileStreamWriteAccess.

Definition at line 123 of file FlySystemFileStreamAccess.php.

123 : void
124 {
125 $resource = $stream->detach();
126 try {
127 if (!is_resource($resource)) {
128 throw new \InvalidArgumentException('The given stream must not be detached.');
129 }
130 // FlySystem 3 has no updateStream method, so we have to use writeStream instead.
131 $this->flysystem_operator->writeStream($path, $resource);
132 } catch (UnableToWriteFile $ex) {
133 throw new FileNotFoundException("Unable to update Stream in \"$path\".", 0, $ex);
134 } finally {
135 if (is_resource($resource)) {
136 fclose($resource);
137 }
138 }
139 }

References $path.

◆ writeStream()

ILIAS\Filesystem\Provider\FlySystem\FlySystemFileStreamAccess::writeStream ( string  $path,
FileStream  $stream 
)

Writes the stream to a new file.

The directory path to the file will be created.

The stream will be closed after the write operation is done. Please note that the resource must be detached from the stream in order to write to the file.

See also
FileStream::detach()

Implements ILIAS\Filesystem\Provider\FileStreamWriteAccess.

Definition at line 71 of file FlySystemFileStreamAccess.php.

71 : void
72 {
73 $resource = $stream->detach();
74 if (!is_resource($resource)) {
75 throw new \InvalidArgumentException('The given stream must not be detached.');
76 }
77 if ($this->flysystem_operator->fileExists($path)) {
78 throw new FileAlreadyExistsException("File \"$path\" already exists.");
79 }
80 try {
81 $this->flysystem_operator->writeStream($path, $resource);
82 } catch (UnableToWriteFile $ex) {
83 throw new IOException("Could not write stream to file \"$path\"", 0, $ex);
84 } finally {
85 if (is_resource($resource)) {
86 fclose($resource);
87 }
88 }
89 }

References $path.


The documentation for this class was generated from the following file: