Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Movable.php
Go to the documentation of this file.
1 <?php
23 #require_once 'Zend/Memory/Container.php';
24 
26 #require_once 'Zend/Memory/Value.php';
27 
44  protected $_id;
45 
51  private $_memManager;
52 
58  private $_value;
59 
61  const LOADED = 1;
62  const SWAPPED = 2;
63  const LOCKED = 4;
64 
70  private $_state;
71 
79  public function __construct(Zend_Memory_Manager $memoryManager, $id, $value)
80  {
81  $this->_memManager = $memoryManager;
82  $this->_id = $id;
83  $this->_state = self::LOADED;
84  $this->_value = new Zend_Memory_Value($value, $this);
85  }
86 
90  public function lock()
91  {
92  if ( !($this->_state & self::LOADED) ) {
93  $this->_memManager->load($this, $this->_id);
94  $this->_state |= self::LOADED;
95  }
96 
97  $this->_state |= self::LOCKED;
98 
104  }
105 
109  public function unlock()
110  {
111  // Clear LOCKED state bit
112  $this->_state &= ~self::LOCKED;
113  }
114 
120  public function isLocked()
121  {
122  return $this->_state & self::LOCKED;
123  }
124 
135  public function __get($property)
136  {
137  if ($property != 'value') {
138  #require_once 'Zend/Memory/Exception.php';
139  throw new Zend_Memory_Exception('Unknown property: Zend_Memory_container::$' . $property);
140  }
141 
142  if ( !($this->_state & self::LOADED) ) {
143  $this->_memManager->load($this, $this->_id);
144  $this->_state |= self::LOADED;
145  }
146 
147  return $this->_value;
148  }
149 
157  public function __set($property, $value)
158  {
159  if ($property != 'value') {
160  #require_once 'Zend/Memory/Exception.php';
161  throw new Zend_Memory_Exception('Unknown property: Zend_Memory_container::$' . $property);
162  }
163 
164  $this->_state = self::LOADED;
165  $this->_value = new Zend_Memory_Value($value, $this);
166 
167  $this->_memManager->processUpdate($this, $this->_id);
168  }
169 
170 
179  public function &getRef()
180  {
181  if ( !($this->_state & self::LOADED) ) {
182  $this->_memManager->load($this, $this->_id);
183  $this->_state |= self::LOADED;
184  }
185 
186  return $this->_value->getRef();
187  }
188 
194  public function touch()
195  {
196  $this->_memManager->processUpdate($this, $this->_id);
197  }
198 
205  public function processUpdate()
206  {
207  // Clear SWAPPED state bit
208  $this->_state &= ~self::SWAPPED;
209 
210  $this->_memManager->processUpdate($this, $this->_id);
211  }
212 
218  public function startTrace()
219  {
220  if ( !($this->_state & self::LOADED) ) {
221  $this->_memManager->load($this, $this->_id);
222  $this->_state |= self::LOADED;
223  }
224 
225  $this->_value->startTrace();
226  }
227 
233  public function setValue($value)
234  {
235  $this->_value = new Zend_Memory_Value($value, $this);
236  }
237 
243  public function unloadValue()
244  {
245  // Clear LOADED state bit
246  $this->_state &= ~self::LOADED;
247 
248  $this->_value = null;
249  }
250 
256  public function markAsSwapped()
257  {
258  // Clear LOADED state bit
259  $this->_state |= self::LOADED;
260  }
261 
268  public function isSwapped()
269  {
270  return $this->_state & self::SWAPPED;
271  }
272 
279  public function getId()
280  {
281  return $this->_id;
282  }
288  public function destroy()
289  {
295  $this->_memManager->unlink($this, $this->_id);
296  }
297 }
$id
Definition: fieldset.phtml:14
__set($property, $value)
Definition: Movable.php:157
$value
Definition: gender.phtml:16
__construct(Zend_Memory_Manager $memoryManager, $id, $value)
Definition: Movable.php:79