Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 311 and 401] [Versions 400 and 401]

   1  <?php
   2  
   3  namespace MongoDB\GridFS\Exception;
   4  
   5  use MongoDB\Exception\RuntimeException;
   6  
   7  use function MongoDB\BSON\fromPHP;
   8  use function MongoDB\BSON\toJSON;
   9  use function sprintf;
  10  use function stream_get_meta_data;
  11  
  12  class StreamException extends RuntimeException
  13  {
  14      /**
  15       * @param resource $source
  16       * @param resource $destination
  17       */
  18      public static function downloadFromFilenameFailed(string $filename, $source, $destination): self
  19      {
  20          $sourceMetadata = stream_get_meta_data($source);
  21          $destinationMetadata = stream_get_meta_data($destination);
  22  
  23          return new static(sprintf('Downloading file from "%s" to "%s" failed. GridFS filename: "%s"', $sourceMetadata['uri'], $destinationMetadata['uri'], $filename));
  24      }
  25  
  26      /**
  27       * @param mixed    $id
  28       * @param resource $source
  29       * @param resource $destination
  30       */
  31      public static function downloadFromIdFailed($id, $source, $destination): self
  32      {
  33          $idString = toJSON(fromPHP(['_id' => $id]));
  34          $sourceMetadata = stream_get_meta_data($source);
  35          $destinationMetadata = stream_get_meta_data($destination);
  36  
  37          return new static(sprintf('Downloading file from "%s" to "%s" failed. GridFS identifier: "%s"', $sourceMetadata['uri'], $destinationMetadata['uri'], $idString));
  38      }
  39  
  40      /** @param resource $source */
  41      public static function uploadFailed(string $filename, $source, string $destinationUri): self
  42      {
  43          $sourceMetadata = stream_get_meta_data($source);
  44  
  45          return new static(sprintf('Uploading file from "%s" to "%s" failed. GridFS filename: "%s"', $sourceMetadata['uri'], $destinationUri, $filename));
  46      }
  47  }