[ZF-10089] Zend_Log
[zend/radio.git] / library / Zend / Memory / Value.php
blob96dfec978e77ac28a08049122a256f2399d41e61
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
15 * @category Zend
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
19 * @version $Id$
23 /**
24 * String value object
26 * It's an OO string wrapper.
27 * Used to intercept string updates.
29 * @category Zend
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 {
36 /**
37 * Value
39 * @var string
41 private $_value;
43 /**
44 * Container
46 * @var Zend_Memory_Container_Interface
48 private $_container;
50 /**
51 * Boolean flag which signals to trace value modifications
53 * @var boolean
55 private $_trace;
58 /**
59 * Object constructor
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;
70 /**
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;
82 /**
83 * ArrayAccess interface method
84 * returns true if string offset exists
86 * @param integer $offset
87 * @return boolean
89 public function offsetExists($offset)
91 return $offset >= 0 && $offset < strlen($this->_value);
94 /**
95 * ArrayAccess interface method
96 * Get character at $offset position
98 * @param integer $offset
99 * @return string
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;
117 if ($this->_trace) {
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]);
133 if ($this->_trace) {
134 $this->_trace = false;
135 $this->_container->processUpdate();
141 * To string conversion
143 * @return string
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
157 * @internal
158 * @return string
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
171 * @internal
173 public function startTrace()
175 $this->_trace = true;