3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Memory
;
18 * It's an OO string wrapper.
19 * Used to intercept string updates.
21 class Value
implements ArrayAccess
, Countable
33 * @var Container\Movable
38 * Boolean flag which signals to trace value modifications
48 * @param string $value
49 * @param \Zend\Memory\Container\Movable $container
51 public function __construct($value, Container\Movable
$container)
53 $this->container
= $container;
55 $this->value
= (string) $value;
58 * Object is marked as just modified by memory manager
59 * So we don't need to trace followed object modifications and
60 * object is processed (and marked as traced) when another
61 * memory object is modified.
63 * It reduces overall number of calls necessary to modification trace
73 public function count()
75 return strlen($this->value
);
79 * ArrayAccess interface method
80 * returns true if string offset exists
85 public function offsetExists($offset)
87 return $offset >= 0 && $offset < strlen($this->value
);
91 * ArrayAccess interface method
92 * Get character at $offset position
97 public function offsetGet($offset)
99 return $this->value
[$offset];
103 * ArrayAccess interface method
104 * Set character at $offset position
107 * @param string $char
109 public function offsetSet($offset, $char)
111 $this->value
[$offset] = $char;
114 $this->trace
= false;
115 $this->container
->processUpdate();
120 * ArrayAccess interface method
121 * Unset character at $offset position
125 public function offsetUnset($offset)
127 unset($this->value
[$offset]);
130 $this->trace
= false;
131 $this->container
->processUpdate();
137 * To string conversion
141 public function __toString()
148 * Get string value reference
150 * _Must_ be used for value access before PHP v 5.2
151 * or _may_ be used for performance considerations
156 public function &getRef()
162 * Start modifications trace
164 * _Must_ be used for value access before PHP v 5.2
165 * or _may_ be used for performance considerations
169 public function startTrace()