CallbackDependency.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * @link https://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license https://www.yiiframework.com/license/
  6. */
  7. namespace yii\caching;
  8. /**
  9. * CallbackDependency represents a dependency based on the result of a callback function.
  10. *
  11. * Callback function should return a value that serves as the dependency data.
  12. *
  13. * For more details and usage information on Cache, see the [guide article on caching](guide:caching-overview).
  14. *
  15. * @author Vlad Varlamov <vlad@varlamov.dev>
  16. * @since 2.0.50
  17. */
  18. class CallbackDependency extends Dependency
  19. {
  20. /**
  21. * @var callable the PHP callback that will be called to determine if the dependency has been changed.
  22. */
  23. public $callback;
  24. /**
  25. * Generates the data needed to determine if dependency has been changed.
  26. * This method returns the result of the callback function.
  27. * @param CacheInterface $cache the cache component that is currently evaluating this dependency
  28. * @return mixed the data needed to determine if dependency has been changed.
  29. */
  30. protected function generateDependencyData($cache)
  31. {
  32. return ($this->callback)();
  33. }
  34. }