Overview

Packages

  • Support

Classes

  • Horde_Support_Array
  • Horde_Support_Backtrace
  • Horde_Support_CombineStream
  • Horde_Support_ConsistentHash
  • Horde_Support_Guid
  • Horde_Support_Inflector
  • Horde_Support_Memory
  • Horde_Support_Numerizer
  • Horde_Support_Numerizer_Locale_Base
  • Horde_Support_Numerizer_Locale_De
  • Horde_Support_Numerizer_Locale_Pt
  • Horde_Support_Randomid
  • Horde_Support_Stack
  • Horde_Support_StringStream
  • Horde_Support_Stub
  • Horde_Support_Timer
  • Horde_Support_Uuid
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Copyright 2007-2012 Horde LLC (http://www.horde.org/)
  4:  *
  5:  * @author   Chuck Hagenbuch <chuck@horde.org>
  6:  * @category Horde
  7:  * @license  http://www.horde.org/licenses/bsd BSD
  8:  * @package  Support
  9:  */
 10: 
 11: /**
 12:  * @author   Chuck Hagenbuch <chuck@horde.org>
 13:  * @category Horde
 14:  * @license  http://www.horde.org/licenses/bsd BSD
 15:  * @package  Support
 16:  */
 17: class Horde_Support_StringStream implements Horde_Stream_Wrapper_StringStream
 18: {
 19:     /* Wrapper name. */
 20:     const WNAME = 'horde-string';
 21: 
 22:     /**
 23:      * String data.
 24:      *
 25:      * @var string
 26:      */
 27:     protected $_string;
 28: 
 29:     /**
 30:      * Constructor
 31:      *
 32:      * @param string &$string  Reference to the string to wrap as a stream
 33:      */
 34:     public function __construct(&$string)
 35:     {
 36:         $this->installWrapper();
 37:         $this->_string =& $string;
 38:     }
 39: 
 40:     /**
 41:      * Return a stream handle to this string stream.
 42:      *
 43:      * @return resource
 44:      */
 45:     public function fopen()
 46:     {
 47:         return fopen(
 48:             self::WNAME . '://' . spl_object_hash($this),
 49:             'rb',
 50:             false,
 51:             stream_context_create(array(
 52:                 self::WNAME => array(
 53:                     'string' => $this
 54:                 )
 55:             ))
 56:         );
 57:     }
 58: 
 59:     /**
 60:      * Return an SplFileObject representing this string stream
 61:      *
 62:      * @return SplFileObject
 63:      */
 64:     public function getFileObject()
 65:     {
 66:         return new SplFileObject(
 67:             self::WNAME . '://' . spl_object_hash($this),
 68:             'rb',
 69:             false,
 70:             stream_context_create(array(
 71:                 self::WNAME => array(
 72:                     'string' => $this
 73:                 )
 74:             ))
 75:         );
 76:     }
 77: 
 78:     /**
 79:      * Install the stream wrapper if it isn't already registered.
 80:      */
 81:     public function installWrapper()
 82:     {
 83:         if (!in_array(self::WNAME, stream_get_wrappers()) &&
 84:             !stream_wrapper_register(self::WNAME, 'Horde_Stream_Wrapper_String')) {
 85:             throw new Exception('Unable to register stream wrapper.');
 86:         }
 87:     }
 88: 
 89:     /**
 90:      * Return a reference to the wrapped string.
 91:      *
 92:      * @return string
 93:      */
 94:     public function &getString()
 95:     {
 96:         return $this->_string;
 97:     }
 98: 
 99: }
100: 
API documentation generated by ApiGen