Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ExpressionDependency.php 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\caching;
  8. /**
  9. * ExpressionDependency represents a dependency based on the result of a PHP expression.
  10. *
  11. * ExpressionDependency will use `eval()` to evaluate the PHP expression.
  12. * The dependency is reported as unchanged if and only if the result of the expression is
  13. * the same as the one evaluated when storing the data to cache.
  14. *
  15. * A PHP expression can be any PHP code that has a value. To learn more about what an expression is,
  16. * please refer to the [php manual](http://www.php.net/manual/en/language.expressions.php).
  17. *
  18. * @author Qiang Xue <qiang.xue@gmail.com>
  19. * @since 2.0
  20. */
  21. class ExpressionDependency extends Dependency
  22. {
  23. /**
  24. * @var string the string representation of a PHP expression whose result is used to determine the dependency.
  25. * A PHP expression can be any PHP code that evaluates to a value. To learn more about what an expression is,
  26. * please refer to the [php manual](http://www.php.net/manual/en/language.expressions.php).
  27. */
  28. public $expression = 'true';
  29. /**
  30. * @var mixed custom parameters associated with this dependency. You may get the value
  31. * of this property in [[expression]] using `$this->params`.
  32. */
  33. public $params;
  34. /**
  35. * Generates the data needed to determine if dependency has been changed.
  36. * This method returns the result of the PHP expression.
  37. * @param Cache $cache the cache component that is currently evaluating this dependency
  38. * @return mixed the data needed to determine if dependency has been changed.
  39. */
  40. protected function generateDependencyData($cache)
  41. {
  42. return eval("return {$this->expression};");
  43. }
  44. }