DmitryDulepov\Realurl\Cache\DatabaseCache::getUrlFromCacheBySpeakingUrl PHP Method

getUrlFromCacheBySpeakingUrl() public method

We may not fallback to the default language here!
public getUrlFromCacheBySpeakingUrl ( integer $rootPageId, string $speakingUrl, integer | null $languageId ) : DmitryDulepov\Realurl\Cache\UrlCacheEntry | null
$rootPageId integer
$speakingUrl string
$languageId integer | null
return DmitryDulepov\Realurl\Cache\UrlCacheEntry | null
    public function getUrlFromCacheBySpeakingUrl($rootPageId, $speakingUrl, $languageId)
    {
        $cacheEntry = NULL;
        $rows = $this->databaseConnection->exec_SELECTgetRows('*', 'tx_realurl_urldata', 'rootpage_id=' . (int) $rootPageId . ' AND ' . 'speaking_url=' . $this->databaseConnection->fullQuoteStr($speakingUrl, 'tx_realurl_urldata'), '', 'expire');
        $row = null;
        foreach ($rows as $rowCandidate) {
            $variables = (array) @json_decode($rowCandidate['request_variables'], TRUE);
            if (is_null($languageId)) {
                // No language known, we retrieve only the URL with lowest expiration value
                // See https://github.com/dmitryd/typo3-realurl/issues/250
                $row = $rowCandidate;
                if (isset($variables['cHash'])) {
                    break;
                }
            } else {
                // Should check for language match
                // See https://github.com/dmitryd/typo3-realurl/issues/103
                if (isset($variables['L'])) {
                    if ((int) $variables['L'] === (int) $languageId) {
                        // Found language!
                        $row = $rowCandidate;
                        if (isset($variables['cHash'])) {
                            break;
                        }
                    }
                } elseif ($languageId === 0 && is_null($row)) {
                    // No L in URL parameters of the URL but default language requested. This is a match.
                    $row = $rowCandidate;
                }
            }
        }
        if (is_array($row)) {
            $cacheEntry = GeneralUtility::makeInstance('DmitryDulepov\\Realurl\\Cache\\UrlCacheEntry');
            /** @var \DmitryDulepov\Realurl\Cache\UrlCacheEntry $cacheEntry */
            $cacheEntry->setCacheId($row['uid']);
            $cacheEntry->setExpiration($row['expire']);
            $cacheEntry->setPageId($row['page_id']);
            $cacheEntry->setRootPageId($row['rootpage_id']);
            $cacheEntry->setOriginalUrl($row['original_url']);
            $cacheEntry->setSpeakingUrl($speakingUrl);
            $requestVariables = @json_decode($row['request_variables'], TRUE);
            // TODO Log a problem here because it must be an array always
            $cacheEntry->setRequestVariables(is_array($requestVariables) ? $requestVariables : array());
        }
        return $cacheEntry;
    }