mirror of
https://github.com/silverstripe/silverstripe-versionfeed
synced 2024-06-24 13:39:26 +02:00
If a there exists at some point in the history a class that no longer exists, Versioned will create it as a `DataObject` as opposed to some form of the `SiteTree` superclass. This would break the absolute link funcitonality, so we should make the version at least an instance of SiteTree so we can generate the link accurately (without fatal errors).
67 lines
1.5 KiB
PHP
67 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\VersionFeed\Filters;
|
|
|
|
use SilverStripe\VersionFeed\VersionFeedController;
|
|
use SilverStripe\Core\Config\Configurable;
|
|
use Psr\SimpleCache\CacheInterface;
|
|
use SilverStripe\Core\Injector\Injector;
|
|
|
|
/**
|
|
* Conditionally executes a given callback, attempting to return the desired results
|
|
* of its execution.
|
|
*/
|
|
abstract class ContentFilter
|
|
{
|
|
|
|
use Configurable;
|
|
|
|
/**
|
|
* 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 CacheInterface
|
|
*/
|
|
protected function getCache()
|
|
{
|
|
return Injector::inst()->get(
|
|
CacheInterface::class . '.VersionFeedController'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
}
|
|
}
|