Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 401]

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