3 * @see https://github.com/zendframework/zend-memory for the canonical source repository
4 * @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5 * @license https://github.com/zendframework/zend-memory/blob/master/LICENSE.md New BSD License
16 * It's an OO string wrapper.
17 * Used to intercept string updates.
19 class Value
implements ArrayAccess
, Countable
31 * @var Container\Movable
36 * Boolean flag which signals to trace value modifications
46 * @param string $value
47 * @param \Zend\Memory\Container\Movable $container
49 public function __construct($value, Container\Movable
$container)
51 $this->container
= $container;
53 $this->value
= (string) $value;
56 * Object is marked as just modified by memory manager
57 * So we don't need to trace followed object modifications and
58 * object is processed (and marked as traced) when another
59 * memory object is modified.
61 * It reduces overall number of calls necessary to modification trace
71 public function count()
73 return strlen($this->value
);
77 * ArrayAccess interface method
78 * returns true if string offset exists
83 public function offsetExists($offset)
85 return $offset >= 0 && $offset < strlen($this->value
);
89 * ArrayAccess interface method
90 * Get character at $offset position
95 public function offsetGet($offset)
97 return $this->value
[$offset];
101 * ArrayAccess interface method
102 * Set character at $offset position
105 * @param string $char
107 public function offsetSet($offset, $char)
109 $this->value
[$offset] = $char;
112 $this->trace
= false;
113 $this->container
->processUpdate();
118 * ArrayAccess interface method
119 * Unset character at $offset position
123 public function offsetUnset($offset)
125 unset($this->value
[$offset]);
128 $this->trace
= false;
129 $this->container
->processUpdate();
134 * To string conversion
138 public function __toString()
144 * Get string value reference
146 * _Must_ be used for value access before PHP v 5.2
147 * or _may_ be used for performance considerations
152 public function &getRef()
158 * Start modifications trace
160 * _Must_ be used for value access before PHP v 5.2
161 * or _may_ be used for performance considerations
165 public function startTrace()