Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.
   1  <?php
   2  /**
   3   * Copyright 2012-2017 Horde LLC (http://www.horde.org/)
   4   *
   5   * See the enclosed file LICENSE for license information (LGPL). If you
   6   * did not receive this file, see http://www.horde.org/licenses/lgpl21.
   7   *
   8   * @category  Horde
   9   * @copyright 2012-2017 Horde LLC
  10   * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
  11   * @package   Stream
  12   */
  13  
  14  /**
  15   * Implementation of Horde_Stream for a PHP temporary stream.
  16   *
  17   * @author    Michael Slusarz <slusarz@horde.org>
  18   * @category  Horde
  19   * @copyright 2012-2017 Horde LLC
  20   * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
  21   * @package   Stream
  22   */
  23  class Horde_Stream_Temp extends Horde_Stream
  24  {
  25      /**
  26       * Constructor.
  27       *
  28       * @param array $opts  Additional configuration options:
  29       * <pre>
  30       *   - max_memory: (integer) The maximum amount of memory to allocate to
  31       *                 the PHP temporary stream.
  32       * </pre>
  33       *
  34       * @throws Horde_Stream_Exception
  35       */
  36      public function __construct(array $opts = array())
  37      {
  38          parent::__construct($opts);
  39      }
  40  
  41      /**
  42       * @throws Horde_Stream_Exception
  43       */
  44      protected function _init()
  45      {
  46          $cmd = 'php://temp';
  47          if (isset($this->_params['max_memory'])) {
  48              $cmd .= '/maxmemory:' . intval($this->_params['max_memory']);
  49          }
  50  
  51          if (($this->stream = @fopen($cmd, 'r+')) === false) {
  52              throw new Horde_Stream_Exception('Failed to open temporary memory stream.');
  53          }
  54      }
  55  
  56  }