/protected/components/ezcomponents/Cache/src/options/stack.php

https://github.com/kamarulismail/kamarul-playground · PHP · 149 lines · 63 code · 3 blank · 83 comment · 11 complexity · 9ef269d95a97acca31dea668f306dca2 MD5 · raw file

  1. <?php
  2. /**
  3. * File containing the ezcCacheStackOptions class.
  4. *
  5. * @package Cache
  6. * @version 1.5
  7. * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
  8. * @license http://ez.no/licenses/new_bsd New BSD License
  9. * @filesource
  10. */
  11. /**
  12. * Options class for ezcCacheStack instances.
  13. *
  14. * This options class is used with {@link ezcCacheStack} instances.
  15. *
  16. * The $configurator property is special, since it only takes effect during
  17. * construction of the stack. The idea is, to use this in combination with
  18. * {@link ezcCacheManager}. The method {@link
  19. * ezcCacheStackConfigurator::configure()} will called by the constructor of
  20. * {@link ezcCacheStack}. Inside this method, the configuration of the stack
  21. * can happen as needed. Therefore, the {@link ezcCacheStackableStorage}
  22. * instances for the stack do not need to exist when the stack is configured in
  23. * the {@link ezcCacheManager}.
  24. *
  25. * The rest of the options is used as usual to affect the behavior of the
  26. * {@link ezcCacheStack}. However, it is highly recommended to not change
  27. * $metaStorage and $replacementStrategy once they have been set for a stack.
  28. * If these options are changed, the whole stack needs to be resetted using
  29. * {@link ezcCacheStack::reset()}. Aside of that, the previous $metaStorage
  30. * needs to be resetted.
  31. *
  32. * @property string $configurator
  33. * Name of a class implementing ezcCacheStackConfigurator. This class
  34. * will be used right after construction of the stack, to perform
  35. * initial configuration. After the construction process, this option
  36. * does not have any effect. Null (default) means no configuration.
  37. * @property ezcCacheStackMetaDataStorage $metaStorage
  38. * This storage will be used to store the meta data of the
  39. * replacement strategy used by the stack. If null (default) is
  40. * given, the top most storage will be used.
  41. * @property string $replacementStrategy
  42. * The name of the class given in this property must extend {@link
  43. * ezcCacheReplacementStrategy}. The class will be used as the
  44. * replacement strategy in the stack. ezcCacheLruReplacementStrategy
  45. * is the default.
  46. * @property bool $bubbleUpOnRestore
  47. * This option determines if data that is restored from a storage in
  48. * the stack will be bubbled up to higher caches. The default here is
  49. * false, since it might significantly reduce the {@link
  50. * ezcCacheStack::restore()} performance. In addition, for bubbled up
  51. * items, only the attributes will be used that have been provided
  52. * while restoring the desired item. Also the lifetime of the item
  53. * will practically be reset, since higher storages will start with a
  54. * fresh TTL value.
  55. * @package Cache
  56. * @version 1.5
  57. */
  58. class ezcCacheStackOptions extends ezcBaseOptions
  59. {
  60. /**
  61. * Construct a new options object.
  62. * Options are constructed from an option array by default. The constructor
  63. * automatically passes the given options to the __set() method to set them
  64. * in the class.
  65. *
  66. * @throws ezcBasePropertyNotFoundException
  67. * If trying to access a non existent property.
  68. * @throws ezcBaseValueException
  69. * If the value for a property is out of range.
  70. * @param array(string=>mixed) $options The initial options to set.
  71. */
  72. public function __construct( array $options = array() )
  73. {
  74. $this->properties['configurator'] = null;
  75. $this->properties['metaStorage'] = null;
  76. $this->properties['replacementStrategy'] = 'ezcCacheStackLruReplacementStrategy';
  77. $this->properties['bubbleUpOnRestore'] = false;
  78. parent::__construct( $options );
  79. }
  80. /**
  81. * Sets an option.
  82. * This method is called when an option is set.
  83. *
  84. * @param string $propertyName The name of the option to set.
  85. * @param mixed $propertyValue The option value.
  86. * @ignore
  87. *
  88. * @throws ezcBasePropertyNotFoundException
  89. * if the given property does not exist.
  90. * @throws ezcBaseValueException
  91. * if the value to be assigned to a property is invalid.
  92. * @throws ezcBasePropertyPermissionException
  93. * if the property to be set is a read-only property.
  94. */
  95. public function __set( $propertyName, $propertyValue )
  96. {
  97. switch ( $propertyName )
  98. {
  99. case 'configurator':
  100. if ( $propertyValue !== null && ( !is_string( $propertyValue ) || ( !class_exists( $propertyValue ) )
  101. || !in_array( 'ezcCacheStackConfigurator', class_implements( $propertyValue ) ) ) )
  102. {
  103. throw new ezcBaseValueException(
  104. $propertyName,
  105. $propertyValue,
  106. 'existsing class implementing ezcCacheStackConfigurator or null'
  107. );
  108. }
  109. break;
  110. case 'metaStorage':
  111. if ( $propertyValue !== null && !( $propertyValue instanceof ezcCacheStackMetaDataStorage ) )
  112. {
  113. throw new ezcBaseValueException(
  114. $propertyName,
  115. $propertyValue,
  116. 'ezcCacheStackMetaDataStorage or null'
  117. );
  118. }
  119. break;
  120. case 'replacementStrategy':
  121. if ( !is_string( $propertyValue ) || !class_exists( $propertyValue ) || !in_array( 'ezcCacheStackReplacementStrategy', class_implements( $propertyValue ) ) )
  122. {
  123. throw new ezcBaseValueException(
  124. $propertyName,
  125. $propertyValue,
  126. 'existing class implementing ezcCacheStackReplacementStrategy'
  127. );
  128. }
  129. break;
  130. case 'bubbleUpOnRestore':
  131. if ( !is_bool( $propertyValue ) )
  132. {
  133. throw new ezcBaseValueException(
  134. $propertyName,
  135. $propertyValue,
  136. 'bool'
  137. );
  138. }
  139. break;
  140. default:
  141. throw new ezcBasePropertyNotFoundException( $propertyName );
  142. }
  143. $this->properties[$propertyName] = $propertyValue;
  144. }
  145. }
  146. ?>