Skip to content

Instantly share code, notes, and snippets.

@bmoex
Created April 25, 2018 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmoex/dfc2e50ab75878ec2a2847ac598c776b to your computer and use it in GitHub Desktop.
Save bmoex/dfc2e50ab75878ec2a2847ac598c776b to your computer and use it in GitHub Desktop.
Extend RealURL to store cHash when not already calculated
<?php
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['storeInUrlCache']['realurl_cache_hash_generation'] = \Serfhos\RealurlCacheHashGeneration\Cache\StoreInUrlCacheHook::class . '->manipulateUrlCacheEntry';
<?php
namespace Serfhos\RealurlCacheHashGeneration\Cache;
use DmitryDulepov\Realurl\Cache\UrlCacheEntry;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Page\CacheHashCalculator;
/**
* RealURL Hook: StoreInUrlCache
* @package Serfhos\Realurl\CacheHashGeneration\Cache
*/
class StoreInUrlCacheHook
{
/**
* Store cHash when url not already generated based on incoming input..
*
* @param array $parameter
*/
public function manipulateUrlCacheEntry($parameter)
{
$cacheEntry = $parameter['cacheEntry'];
if ($cacheEntry instanceof UrlCacheEntry && !array_key_exists('cHash', $cacheEntry->getRequestVariables())) {
$cacheHashParameters = $this->getCacheHashCalculator()->getRelevantParameters($cacheEntry->getOriginalUrl());
if (!empty($cacheHashParameters)) {
$calculatedCacheHash = $this->getCacheHashCalculator()->calculateCacheHash($cacheHashParameters);
// Append cHash to current UrlCacheEntry
$cacheEntry->setRequestVariables($cacheEntry->getRequestVariables() + ['cHash' => $calculatedCacheHash]);
}
}
}
/**
* @return CacheHashCalculator
*/
protected function getCacheHashCalculator()
{
return GeneralUtility::makeInstance(CacheHashCalculator::class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment