ILIAS  trunk Revision v5.2.0beta1-34115-g3a2438be29
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...
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 42 of file FlySystemFileStreamAccess.php.

44  {
45  }

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 98 of file FlySystemFileStreamAccess.php.

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

◆ 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 52 of file FlySystemFileStreamAccess.php.

References ILIAS\Filesystem\Stream\Streams\ofResource().

52  : FileStream
53  {
54  try {
55  $resource = $this->flysystem_operator->readStream($path);
56  if ($resource === false) {
57  throw new IOException("Could not open stream for file \"$path\"");
58  }
59  return Streams::ofResource($resource);
60  } catch (UnableToRetrieveMetadata|UnableToReadFile $ex) {
61  throw new FileNotFoundException("File \"$path\" not found.", 0, $ex);
62  }
63  }
static ofResource($resource, bool $inside_zip=false)
Wraps an already created resource with the stream abstraction.
Definition: Streams.php:64
$path
Definition: ltiservices.php:30
+ 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 125 of file FlySystemFileStreamAccess.php.

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

◆ 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 73 of file FlySystemFileStreamAccess.php.

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

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