You are here

class cmisStreamAsString in CMIS API 7

A class to hold a reference to a stream, but that can pretend to be a string.

We use this class so that we can return a reference to a stream for consumers to use, but if they choose to then they can just treat this object as a string and they get the full contents of the stream. However, this will cause the entire stream to be in PHP's memory, which may cause out of memory issues. Where large streams may be returned, you should check to see if the return value is this class, and then use the getStream method to handle it as a stream, avoiding memory issues.

Hierarchy

Expanded class hierarchy of cmisStreamAsString

File

cmis_common/cmis_common.module, line 136

View source
class cmisStreamAsString {
  protected $stream;

  /**
   * Get the stream represented by this object.
   *
   * @return
   *   A handle the stream passed in in constructor.
   */
  public function getStream() {
    return $this->stream;
  }

  /**
   * Create a new wrapper for the given stream.
   */
  function __construct($stream) {
    $this->stream = $stream;
  }

  /**
   * Create a new temporary stream and wrap it in the cmisStreamAsString class.
   */
  static function temporaryStream() {
    $stream = fopen('php://temp', 'r+');
    return new cmisStreamAsString($stream);
  }

  /**
   * Return the entire stream contents as a string.
   *
   * Note that this function will rewind the stream.
   */
  function __toString() {

    // Rewind our stream.
    rewind($this->stream);
    return stream_get_contents($this->stream);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
cmisStreamAsString::$stream protected property
cmisStreamAsString::getStream public function Get the stream represented by this object.
cmisStreamAsString::temporaryStream static function Create a new temporary stream and wrap it in the cmisStreamAsString class.
cmisStreamAsString::__construct function Create a new wrapper for the given stream.
cmisStreamAsString::__toString function Return the entire stream contents as a string.