AccessController.php 3.6 KB

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