7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
16 * @package Zend_Memory
17 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license http://framework.zend.com/license/new-bsd New BSD License
26 * It's an OO string wrapper.
27 * Used to intercept string updates.
30 * @package Zend_Memory
31 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32 * @license http://framework.zend.com/license/new-bsd New BSD License
33 * @todo also implement Countable for PHP 5.1 but not yet to stay 5.0 compatible
35 class Zend_Memory_Value
implements ArrayAccess
{
46 * @var Zend_Memory_Container_Interface
51 * Boolean flag which signals to trace value modifications
61 * @param string $value
62 * @param Zend_Memory_Container_Movable $container
64 public function __construct($value, Zend_Memory_Container_Movable
$container)
66 $this->_container
= $container;
68 $this->_value
= (string)$value;
71 * Object is marked as just modified by memory manager
72 * So we don't need to trace followed object modifications and
73 * object is processed (and marked as traced) when another
74 * memory object is modified.
76 * It reduces overall numberr of calls necessary to modification trace
78 $this->_trace
= false;
83 * ArrayAccess interface method
84 * returns true if string offset exists
86 * @param integer $offset
89 public function offsetExists($offset)
91 return $offset >= 0 && $offset < strlen($this->_value
);
95 * ArrayAccess interface method
96 * Get character at $offset position
98 * @param integer $offset
101 public function offsetGet($offset)
103 return $this->_value
[$offset];
107 * ArrayAccess interface method
108 * Set character at $offset position
110 * @param integer $offset
111 * @param string $char
113 public function offsetSet($offset, $char)
115 $this->_value
[$offset] = $char;
118 $this->_trace
= false;
119 $this->_container
->processUpdate();
124 * ArrayAccess interface method
125 * Unset character at $offset position
127 * @param integer $offset
129 public function offsetUnset($offset)
131 unset($this->_value
[$offset]);
134 $this->_trace
= false;
135 $this->_container
->processUpdate();
141 * To string conversion
145 public function __toString()
147 return $this->_value
;
152 * Get string value reference
154 * _Must_ be used for value access before PHP v 5.2
155 * or _may_ be used for performance considerations
160 public function &getRef()
162 return $this->_value
;
166 * Start modifications trace
168 * _Must_ be used for value access before PHP v 5.2
169 * or _may_ be used for performance considerations
173 public function startTrace()
175 $this->_trace
= true;