Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
   1  <?php
   2  /**
   3   * Copyright 2009-2017 Horde LLC (http://www.horde.org/)
   4   *
   5   * @author   Michael Slusarz <slusarz@horde.org>
   6   * @license  http://www.horde.org/licenses/bsd BSD
   7   * @category Horde
   8   * @package  Support
   9   */
  10  
  11  /**
  12   * Provides access to the Combine stream wrapper.
  13   *
  14   * @author     Michael Slusarz <slusarz@horde.org>
  15   * @license    http://www.horde.org/licenses/bsd BSD
  16   * @category   Horde
  17   * @deprecated Use Horde_Stream_Wrapper_Combine::getStream()
  18   * @package    Support
  19   */
  20  class Horde_Support_CombineStream implements Horde_Stream_Wrapper_CombineStream
  21  {
  22      /**
  23       * Data.
  24       *
  25       * @var array
  26       */
  27      protected $_data;
  28  
  29      /**
  30       * Constructor
  31       *
  32       * @param array $data  An array of strings and/or streams to combine into
  33       *                     a single stream.
  34       */
  35      public function __construct($data)
  36      {
  37          $this->installWrapper();
  38          $this->_data = $data;
  39      }
  40  
  41      /**
  42       * Return a stream handle to this stream.
  43       *
  44       * @return resource
  45       */
  46      public function fopen()
  47      {
  48          $context = stream_context_create(array('horde-combine' => array('data' => $this)));
  49          return fopen('horde-combine://' . spl_object_hash($this), 'rb', false, $context);
  50      }
  51  
  52      /**
  53       * Return an SplFileObject representing this stream
  54       *
  55       * @return SplFileObject
  56       */
  57      public function getFileObject()
  58      {
  59          $context = stream_context_create(array('horde-combine' => array('data' => $this)));
  60          return new SplFileObject('horde-combine://' . spl_object_hash($this), 'rb', false, $context);
  61      }
  62  
  63      /**
  64       * Install the horde-combine stream wrapper if it isn't already
  65       * registered.
  66       *
  67       * @throws Exception
  68       */
  69      public function installWrapper()
  70      {
  71          if (!in_array('horde-combine', stream_get_wrappers()) &&
  72              !stream_wrapper_register('horde-combine', 'Horde_Stream_Wrapper_Combine')) {
  73              throw new Exception('Unable to register horde-combine stream wrapper.');
  74          }
  75      }
  76  
  77      /**
  78       * Return a reference to the data.
  79       *
  80       * @return array
  81       */
  82      public function getData()
  83      {
  84          return $this->_data;
  85      }
  86  
  87  }