*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Memory / Value.php
blob2d3e9bed3a52eee175ecaaf08da301eae13916dd
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-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 $
23 /**
24 * String value object
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 {
35 /**
36 * Value
38 * @var string
40 private $_value;
42 /**
43 * Container
45 * @var Zend_Memory_Container_Interface
47 private $_container;
49 /**
50 * Boolean flag which signals to trace value modifications
52 * @var boolean
54 private $_trace;
57 /**
58 * Object constructor
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;
69 /**
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;
81 /**
82 * ArrayAccess interface method
83 * returns true if string offset exists
85 * @param integer $offset
86 * @return boolean
88 public function offsetExists($offset)
90 return $offset >= 0 && $offset < strlen($this->_value);
93 /**
94 * ArrayAccess interface method
95 * Get character at $offset position
97 * @param integer $offset
98 * @return string
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;
116 if ($this->_trace) {
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]);
132 if ($this->_trace) {
133 $this->_trace = false;
134 $this->_container->processUpdate();
140 * To string conversion
142 * @return string
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
156 * @internal
157 * @return string
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
170 * @internal
172 public function startTrace()
174 $this->_trace = true;