2
0

AccessController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  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.
  14. *
  15. * @package Zend_Memory
  16. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  17. * @license http://framework.zend.com/license/new-bsd New BSD License
  18. */
  19. /**
  20. * Zend_Memory_Container_Interface
  21. */
  22. require_once 'Zend/Memory/Container/Interface.php';
  23. /**
  24. * Memory object container access controller.
  25. *
  26. * Memory manager stores a list of generated objects to control them.
  27. * So container objects always have at least one reference and can't be automatically destroyed.
  28. *
  29. * This class is intended to be an userland proxy to memory container object.
  30. * It's not referenced by memory manager and class destructor is invoked immidiately after gouing
  31. * out of scope or unset operation.
  32. *
  33. * Class also provides Zend_Memory_Container_Interface interface and works as proxy for such cases.
  34. *
  35. * @category Zend
  36. * @package Zend_Memory
  37. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. */
  40. class Zend_Memory_AccessController implements Zend_Memory_Container_Interface
  41. {
  42. /**
  43. * Memory container object
  44. *
  45. * @var Zend_Memory_Container
  46. */
  47. private $_memContainer;
  48. /**
  49. * Object constructor
  50. *
  51. * @param Zend_Memory_Container_Movable $memoryManager
  52. */
  53. public function __construct(Zend_Memory_Container_Movable $memContainer)
  54. {
  55. $this->_memContainer = $memContainer;
  56. }
  57. /**
  58. * Object destructor
  59. */
  60. public function __destruct()
  61. {
  62. $this->_memContainer->destroy();
  63. }
  64. /**
  65. * Get string value reference
  66. *
  67. * _Must_ be used for value access before PHP v 5.2
  68. * or _may_ be used for performance considerations
  69. *
  70. * @return &string
  71. */
  72. public function &getRef()
  73. {
  74. return $this->_memContainer->getRef();
  75. }
  76. /**
  77. * Signal, that value is updated by external code.
  78. *
  79. * Should be used together with getRef()
  80. */
  81. public function touch()
  82. {
  83. $this->_memContainer->touch();
  84. }
  85. /**
  86. * Lock object in memory.
  87. */
  88. public function lock()
  89. {
  90. $this->_memContainer->lock();
  91. }
  92. /**
  93. * Unlock object
  94. */
  95. public function unlock()
  96. {
  97. $this->_memContainer->unlock();
  98. }
  99. /**
  100. * Return true if object is locked
  101. *
  102. * @return boolean
  103. */
  104. public function isLocked()
  105. {
  106. return $this->_memContainer->isLocked();
  107. }
  108. /**
  109. * Get handler
  110. *
  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.
  113. *
  114. * @param string $property
  115. * @return string
  116. * @throws Zend_Memory_Exception
  117. */
  118. public function __get($property)
  119. {
  120. return $this->_memContainer->$property;
  121. }
  122. /**
  123. * Set handler
  124. *
  125. * @param string $property
  126. * @param string $value
  127. * @throws Zend_Exception
  128. */
  129. public function __set($property, $value)
  130. {
  131. $this->_memContainer->$property = $value;
  132. }
  133. }