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-2009 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license http://framework.zend.com/license/new-bsd New BSD License
19 * @version $Id: Value.php 16971 2009-07-22 18:05:45Z mikaelkael $
26 * It's an OO string wrapper.
27 * Used to intercept string updates.
29 * @package Zend_Memory
30 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
31 * @license http://framework.zend.com/license/new-bsd New BSD License
32 * @todo also implement Countable for PHP 5.1 but not yet to stay 5.0 compatible
34 class Zend_Memory_Value
implements ArrayAccess
{
45 * @var Zend_Memory_Container_Interface
50 * Boolean flag which signals to trace value modifications
60 * @param string $value
61 * @param Zend_Memory_Container_Movable $container
63 public function __construct($value, Zend_Memory_Container_Movable
$container)
65 $this->_container
= $container;
67 $this->_value
= (string)$value;
70 * Object is marked as just modified by memory manager
71 * So we don't need to trace followed object modifications and
72 * object is processed (and marked as traced) when another
73 * memory object is modified.
75 * It reduces overall numberr of calls necessary to modification trace
77 $this->_trace
= false;
82 * ArrayAccess interface method
83 * returns true if string offset exists
85 * @param integer $offset
88 public function offsetExists($offset)
90 return $offset >= 0 && $offset < strlen($this->_value
);
94 * ArrayAccess interface method
95 * Get character at $offset position
97 * @param integer $offset
100 public function offsetGet($offset)
102 return $this->_value
[$offset];
106 * ArrayAccess interface method
107 * Set character at $offset position
109 * @param integer $offset
110 * @param string $char
112 public function offsetSet($offset, $char)
114 $this->_value
[$offset] = $char;
117 $this->_trace
= false;
118 $this->_container
->processUpdate();
123 * ArrayAccess interface method
124 * Unset character at $offset position
126 * @param integer $offset
128 public function offsetUnset($offset)
130 unset($this->_value
[$offset]);
133 $this->_trace
= false;
134 $this->_container
->processUpdate();
140 * To string conversion
144 public function __toString()
146 return $this->_value
;
151 * Get string value reference
153 * _Must_ be used for value access before PHP v 5.2
154 * or _may_ be used for performance considerations
159 public function &getRef()
161 return $this->_value
;
165 * Start modifications trace
167 * _Must_ be used for value access before PHP v 5.2
168 * or _may_ be used for performance considerations
172 public function startTrace()
174 $this->_trace
= true;