Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   1  <?php
   2  declare(strict_types=1);
   3  
   4  namespace ZipStream\Option;
   5  
   6  final class Archive
   7  {
   8      const DEFAULT_DEFLATE_LEVEL = 6;
   9      /**
  10       * @var string
  11       */
  12      private $comment = '';
  13      /**
  14       * Size, in bytes, of the largest file to try
  15       * and load into memory (used by
  16       * addFileFromPath()).  Large files may also
  17       * be compressed differently; see the
  18       * 'largeFileMethod' option. Default is ~20 Mb.
  19       *
  20       * @var int
  21       */
  22      private $largeFileSize = 20 * 1024 * 1024;
  23      /**
  24       * How to handle large files.  Legal values are
  25       * Method::STORE() (the default), or
  26       * Method::DEFLATE(). STORE sends the file
  27       * raw and is significantly
  28       * faster, while DEFLATE compresses the file
  29       * and is much, much slower. Note that DEFLATE
  30       * must compress the file twice and is extremely slow.
  31       *
  32       * @var Method
  33       */
  34      private $largeFileMethod;
  35      /**
  36       * Boolean indicating whether or not to send
  37       * the HTTP headers for this file.
  38       *
  39       * @var bool
  40       */
  41      private $sendHttpHeaders = false;
  42      /**
  43       * The method called to send headers
  44       *
  45       * @var Callable
  46       */
  47      private $httpHeaderCallback = 'header';
  48      /**
  49       * Enable Zip64 extension, supporting very large
  50       * archives (any size > 4 GB or file count > 64k)
  51       *
  52       * @var bool
  53       */
  54      private $enableZip64 = true;
  55      /**
  56       * Enable streaming files with single read where
  57       * general purpose bit 3 indicates local file header
  58       * contain zero values in crc and size fields,
  59       * these appear only after file contents
  60       * in data descriptor block.
  61       *
  62       * @var bool
  63       */
  64      private $zeroHeader = false;
  65      /**
  66       * Enable reading file stat for determining file size.
  67       * When a 32-bit system reads file size that is
  68       * over 2 GB, invalid value appears in file size
  69       * due to integer overflow. Should be disabled on
  70       * 32-bit systems with method addFileFromPath
  71       * if any file may exceed 2 GB. In this case file
  72       * will be read in blocks and correct size will be
  73       * determined from content.
  74       *
  75       * @var bool
  76       */
  77      private $statFiles = true;
  78      /**
  79       * Enable flush after every write to output stream.
  80       * @var bool
  81       */
  82      private $flushOutput = false;
  83      /**
  84       * HTTP Content-Disposition.  Defaults to
  85       * 'attachment', where
  86       * FILENAME is the specified filename.
  87       *
  88       * Note that this does nothing if you are
  89       * not sending HTTP headers.
  90       *
  91       * @var string
  92       */
  93      private $contentDisposition = 'attachment';
  94      /**
  95       * Note that this does nothing if you are
  96       * not sending HTTP headers.
  97       *
  98       * @var string
  99       */
 100      private $contentType = 'application/x-zip';
 101      /**
 102       * @var int
 103       */
 104      private $deflateLevel = 6;
 105  
 106      /**
 107       * @var resource
 108       */
 109      private $outputStream;
 110  
 111      /**
 112       * Options constructor.
 113       */
 114      public function __construct()
 115      {
 116          $this->largeFileMethod = Method::STORE();
 117          $this->outputStream = fopen('php://output', 'wb');
 118      }
 119  
 120      public function getComment(): string
 121      {
 122          return $this->comment;
 123      }
 124  
 125      public function setComment(string $comment): void
 126      {
 127          $this->comment = $comment;
 128      }
 129  
 130      public function getLargeFileSize(): int
 131      {
 132          return $this->largeFileSize;
 133      }
 134  
 135      public function setLargeFileSize(int $largeFileSize): void
 136      {
 137          $this->largeFileSize = $largeFileSize;
 138      }
 139  
 140      public function getLargeFileMethod(): Method
 141      {
 142          return $this->largeFileMethod;
 143      }
 144  
 145      public function setLargeFileMethod(Method $largeFileMethod): void
 146      {
 147          $this->largeFileMethod = $largeFileMethod;
 148      }
 149  
 150      public function isSendHttpHeaders(): bool
 151      {
 152          return $this->sendHttpHeaders;
 153      }
 154  
 155      public function setSendHttpHeaders(bool $sendHttpHeaders): void
 156      {
 157          $this->sendHttpHeaders = $sendHttpHeaders;
 158      }
 159  
 160      public function getHttpHeaderCallback(): Callable
 161      {
 162          return $this->httpHeaderCallback;
 163      }
 164  
 165      public function setHttpHeaderCallback(Callable $httpHeaderCallback): void
 166      {
 167          $this->httpHeaderCallback = $httpHeaderCallback;
 168      }
 169  
 170      public function isEnableZip64(): bool
 171      {
 172          return $this->enableZip64;
 173      }
 174  
 175      public function setEnableZip64(bool $enableZip64): void
 176      {
 177          $this->enableZip64 = $enableZip64;
 178      }
 179  
 180      public function isZeroHeader(): bool
 181      {
 182          return $this->zeroHeader;
 183      }
 184  
 185      public function setZeroHeader(bool $zeroHeader): void
 186      {
 187          $this->zeroHeader = $zeroHeader;
 188      }
 189  
 190      public function isFlushOutput(): bool
 191      {
 192          return $this->flushOutput;
 193      }
 194  
 195      public function setFlushOutput(bool $flushOutput): void
 196      {
 197          $this->flushOutput = $flushOutput;
 198      }
 199  
 200      public function isStatFiles(): bool
 201      {
 202          return $this->statFiles;
 203      }
 204  
 205      public function setStatFiles(bool $statFiles): void
 206      {
 207          $this->statFiles = $statFiles;
 208      }
 209  
 210      public function getContentDisposition(): string
 211      {
 212          return $this->contentDisposition;
 213      }
 214  
 215      public function setContentDisposition(string $contentDisposition): void
 216      {
 217          $this->contentDisposition = $contentDisposition;
 218      }
 219  
 220      public function getContentType(): string
 221      {
 222          return $this->contentType;
 223      }
 224  
 225      public function setContentType(string $contentType): void
 226      {
 227          $this->contentType = $contentType;
 228      }
 229  
 230      /**
 231       * @return resource
 232       */
 233      public function getOutputStream()
 234      {
 235          return $this->outputStream;
 236      }
 237  
 238      /**
 239       * @param resource $outputStream
 240       */
 241      public function setOutputStream($outputStream): void
 242      {
 243          $this->outputStream = $outputStream;
 244      }
 245  
 246      /**
 247       * @return int
 248       */
 249      public function getDeflateLevel(): int
 250      {
 251          return $this->deflateLevel;
 252      }
 253  
 254      /**
 255       * @param int $deflateLevel
 256       */
 257      public function setDeflateLevel(int $deflateLevel): void
 258      {
 259          $this->deflateLevel = $deflateLevel;
 260      }
 261  }