Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Memory / Container / Movable.php
blob24568164f1f9b9a14efc3836401df090c9747d69
1 <?php
2 /**
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
8 */
10 namespace Zend\Memory\Container;
12 use Zend\Memory;
13 use Zend\Memory\Exception;
15 /**
16 * Memory value container
18 * Movable (may be swapped with specified backend and unloaded).
20 class Movable extends AbstractContainer
22 /**
23 * Internal object Id
25 * @var int
27 protected $id;
29 /**
30 * Memory manager reference
32 * @var \Zend\Memory\MemoryManager
34 private $memManager;
36 /**
37 * Value object
39 * @var \Zend\Memory\Value
41 private $value;
43 /** Value states */
44 const LOADED = 1;
45 const SWAPPED = 2;
46 const LOCKED = 4;
48 /**
49 * Value state (LOADED/SWAPPED/LOCKED)
51 * @var int
53 private $state;
55 /**
56 * Object constructor
58 * @param \Zend\Memory\MemoryManager $memoryManager
59 * @param int $id
60 * @param string $value
62 public function __construct(Memory\MemoryManager $memoryManager, $id, $value)
64 $this->memManager = $memoryManager;
65 $this->id = $id;
66 $this->state = self::LOADED;
67 $this->value = new Memory\Value($value, $this);
70 /**
71 * Lock object in memory.
73 public function lock()
75 if (!($this->state & self::LOADED)) {
76 $this->memManager->load($this, $this->id);
77 $this->state |= self::LOADED;
80 $this->state |= self::LOCKED;
82 /**
83 * @todo
84 * It's possible to set "value" container attribute to avoid modification tracing, while it's locked
85 * Check, if it's more effective
89 /**
90 * Unlock object
92 public function unlock()
94 // Clear LOCKED state bit
95 $this->state &= ~self::LOCKED;
98 /**
99 * Return true if object is locked
101 * @return bool
103 public function isLocked()
105 return $this->state & self::LOCKED;
109 * Get handler
111 * Loads object if necessary and moves it to the top of loaded objects list.
112 * Swaps objects from the bottom of loaded objects list, if necessary.
114 * @param string $property
115 * @return string
116 * @throws Exception\InvalidArgumentException
118 public function __get($property)
120 if ($property != 'value') {
121 throw new Exception\InvalidArgumentException('Unknown property: \Zend\Memory\Container\Movable::$' . $property);
124 if (!($this->state & self::LOADED)) {
125 $this->memManager->load($this, $this->id);
126 $this->state |= self::LOADED;
129 return $this->value;
133 * Set handler
135 * @param string $property
136 * @param string $value
137 * @throws Exception\InvalidArgumentException
139 public function __set($property, $value)
141 if ($property != 'value') {
142 throw new Exception\InvalidArgumentException('Unknown property: \Zend\Memory\Container\Movable::$' . $property);
145 $this->state = self::LOADED;
146 $this->value = new Memory\Value($value, $this);
148 $this->memManager->processUpdate($this, $this->id);
153 * Get string value reference
155 * _Must_ be used for value access before PHP v 5.2
156 * or _may_ be used for performance considerations
158 * @return &string
160 public function &getRef()
162 if (!($this->state & self::LOADED)) {
163 $this->memManager->load($this, $this->id);
164 $this->state |= self::LOADED;
167 return $this->value->getRef();
171 * Signal, that value is updated by external code.
173 * Should be used together with getRef()
175 public function touch()
177 $this->memManager->processUpdate($this, $this->id);
181 * Process container value update.
182 * Must be called only by value object
184 * @internal
186 public function processUpdate()
188 // Clear SWAPPED state bit
189 $this->state &= ~self::SWAPPED;
191 $this->memManager->processUpdate($this, $this->id);
195 * Start modifications trace
197 * @internal
199 public function startTrace()
201 if (!($this->state & self::LOADED)) {
202 $this->memManager->load($this, $this->id);
203 $this->state |= self::LOADED;
206 $this->value->startTrace();
210 * Set value (used by memory manager when value is loaded)
212 * @internal
214 public function setValue($value)
216 $this->value = new Memory\Value($value, $this);
220 * Clear value (used by memory manager when value is swapped)
222 * @internal
224 public function unloadValue()
226 // Clear LOADED state bit
227 $this->state &= ~self::LOADED;
229 $this->value = null;
233 * Mark, that object is swapped
235 * @internal
237 public function markAsSwapped()
239 // Clear LOADED state bit
240 $this->state |= self::LOADED;
244 * Check if object is marked as swapped
246 * @internal
247 * @return bool
249 public function isSwapped()
251 return $this->state & self::SWAPPED;
255 * Get object id
257 * @internal
258 * @return int
260 public function getId()
262 return $this->id;
265 * Destroy memory container and remove it from memory manager list
267 * @internal
269 public function destroy()
272 * We don't clean up swap because of performance considerations
273 * Cleaning is performed by Memory Manager destructor
276 $this->memManager->unlink($this, $this->id);