Created
April 25, 2018 10:57
-
-
Save bmoex/dfc2e50ab75878ec2a2847ac598c776b to your computer and use it in GitHub Desktop.
Extend RealURL to store cHash when not already calculated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['storeInUrlCache']['realurl_cache_hash_generation'] = \Serfhos\RealurlCacheHashGeneration\Cache\StoreInUrlCacheHook::class . '->manipulateUrlCacheEntry'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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