mirror of
https://github.com/silverstripe/silverstripe-versionfeed
synced 2024-10-22 11:05:31 +02:00
4d278f1695
BUG Fix issue in test caching Tests for 3.2 and php 5.6
60 lines
1.3 KiB
PHP
60 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace VersionFeed\Filters;
|
|
|
|
/**
|
|
* Conditionally executes a given callback, attempting to return the desired results
|
|
* of its execution.
|
|
*/
|
|
abstract class ContentFilter {
|
|
|
|
/**
|
|
* Nested content filter
|
|
*
|
|
* @var ContentFilter
|
|
*/
|
|
protected $nestedContentFilter;
|
|
|
|
/**
|
|
* Cache lifetime
|
|
*
|
|
* @config
|
|
* @var int
|
|
*/
|
|
private static $cache_lifetime = 300;
|
|
|
|
public function __construct($nestedContentFilter = null) {
|
|
$this->nestedContentFilter = $nestedContentFilter;
|
|
}
|
|
|
|
/**
|
|
* Gets the cache to use
|
|
*
|
|
* @return Zend_Cache_Frontend
|
|
*/
|
|
protected function getCache() {
|
|
$cache = \SS_Cache::factory('VersionFeed_Controller');
|
|
$cache->setOption('automatic_serialization', true);
|
|
|
|
// Map 0 to null for unlimited lifetime
|
|
$lifetime = \Config::inst()->get(get_class($this), 'cache_lifetime') ?: null;
|
|
$cache->setLifetime($lifetime);
|
|
return $cache;
|
|
}
|
|
|
|
/**
|
|
* Evaluates the result of the given callback
|
|
*
|
|
* @param string $key Unique key for this
|
|
* @param callable $callback Callback for evaluating the content
|
|
* @return mixed Result of $callback()
|
|
*/
|
|
public function getContent($key, $callback) {
|
|
if($this->nestedContentFilter) {
|
|
return $this->nestedContentFilter->getContent($key, $callback);
|
|
} else {
|
|
return call_user_func($callback);
|
|
}
|
|
}
|
|
}
|