composer package updates
[openemr.git] / vendor / zendframework / zend-memory / src / Value.php
blobe5118fd00c1b32fb6f5ee81c7287e917d35fc5df
1 <?php
2 /**
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
6 */
8 namespace Zend\Memory;
10 use ArrayAccess;
11 use Countable;
13 /**
14 * String value object
16 * It's an OO string wrapper.
17 * Used to intercept string updates.
19 class Value implements ArrayAccess, Countable
21 /**
22 * Value
24 * @var string
26 private $value;
28 /**
29 * Container
31 * @var Container\Movable
33 private $container;
35 /**
36 * Boolean flag which signals to trace value modifications
38 * @var bool
40 private $trace;
43 /**
44 * Object constructor
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;
55 /**
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
63 $this->trace = false;
66 /**
67 * Countable
69 * @return int
71 public function count()
73 return strlen($this->value);
76 /**
77 * ArrayAccess interface method
78 * returns true if string offset exists
80 * @param int $offset
81 * @return bool
83 public function offsetExists($offset)
85 return $offset >= 0 && $offset < strlen($this->value);
88 /**
89 * ArrayAccess interface method
90 * Get character at $offset position
92 * @param int $offset
93 * @return string
95 public function offsetGet($offset)
97 return $this->value[$offset];
101 * ArrayAccess interface method
102 * Set character at $offset position
104 * @param int $offset
105 * @param string $char
107 public function offsetSet($offset, $char)
109 $this->value[$offset] = $char;
111 if ($this->trace) {
112 $this->trace = false;
113 $this->container->processUpdate();
118 * ArrayAccess interface method
119 * Unset character at $offset position
121 * @param int $offset
123 public function offsetUnset($offset)
125 unset($this->value[$offset]);
127 if ($this->trace) {
128 $this->trace = false;
129 $this->container->processUpdate();
134 * To string conversion
136 * @return string
138 public function __toString()
140 return $this->value;
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
149 * @internal
150 * @return string
152 public function &getRef()
154 return $this->value;
158 * Start modifications trace
160 * _Must_ be used for value access before PHP v 5.2
161 * or _may_ be used for performance considerations
163 * @internal
165 public function startTrace()
167 $this->trace = true;