PHP Class DmitryDulepov\Realurl\Decoder\UrlDecoder

Author: Dmitry Dulepov ([email protected])
Inheritance: extends DmitryDulepov\Realurl\EncodeDecoderBase
Show file Open project: dmitryd/typo3-realurl

Protected Properties

Property Type Description
$appendedSlash boolean
$caller TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
$detectedLanguageId integer | null Finally preVar handling code will check for L after decoding and set this attribute either to the decoded value or to zero. This value can be null until preVars are decoded. After that it is either zero or the decoded language uid.
$disallowedDoktypes string
$expiredPath string Holds information about expired path for the SEO redirect.
$isExpiredPath boolean Indicates that the path is expired but we could not redirect because non-expired path is missing from the path cache. In such case we do not cache the entry in the URL cache to force resolving of the path when the current URL is fetched.
$mimeType string
$mountPointStartPid integer Contains a mount point starting pid for the current branch. Zero means "no mount point in the path". This variable will direct the decoder to continue page look up from this branch of tree.
$mountPointVariable string Contains a generated $_GET['MP'] for the currently decoded branch.
$originalPath string This variable is set to the speaking path only if he decoding has to run.
$savedErrorHandler string
$siteScript string
$speakingUri string

Public Methods

Method Description
__construct ( ) Initializes the class.
decodeUrl ( array $params ) : void Decodes the URL. This function is called from \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::checkAlternativeIdMethods()

Protected Methods

Method Description
callPreDecodeHooks ( array $params ) Calls user-defined hooks.
canDecoderExecute ( ) : boolean Checks if the decoder can execute.
checkExpiration ( DmitryDulepov\Realurl\Cache\UrlCacheEntry $cacheEntry ) Checks if the entry is expired and redirects to a non-expired entry.
checkMissingSlash ( ) : void Checks if the missing slash should be corrected.
convertAliasToId ( array $configuration, string $value ) : integer | string Converts alias to id.
createPathCacheEntry ( string $segment, array $pages, array &$shortcutPages ) : DmitryDulepov\Realurl\Cache\PathCacheEntry Find a page entry for the current segment and returns a PathCacheEntry for it.
createQueryStringParameter ( array $parameters, string $prependString = '' ) : array Generates a parameter string from an array recursively
decodeFixedPostVars ( integer $pageId, array &$pathSegments ) : array Decodes fixedPostVars into request variables.
decodePath ( array &$pathSegments ) : integer Decodes the path.
decodePathByOverride ( array &$pathSegments ) : DmitryDulepov\Realurl\Cache\PathCacheEntry Tries to decode the path by path override when the whole path is overriden.
decodePostVarSets ( integer $pageId, array &$pathSegments ) : array Decodes postVarSets into request variables.
decodePreVars ( array &$pathSegments ) : array Decodes preVars into request variables.
decodeSingleVariable ( array $varConfiguration, array &$pathSegments, array &$requestVariables, &$previousValue ) : void Decodes a single variable and adds it to the list of request variables.
decodeUrlParameterBlockUseAsIs ( array $configuration, $getVarValue, array &$requestVariables ) : boolean Sets segment value as is to the request variables
decodeUrlParameterBlockUsingLookupTable ( array $configuration, $getVarValue, array &$requestVariables ) : boolean Sets segment value as is to the request variables
decodeUrlParameterBlockUsingNoMatch ( array $configuration, $getVarValue, array &$requestVariables, array &$pathSegments, boolean $isFakeValue ) : boolean Sets segment value as is to the request variables
decodeUrlParameterBlockUsingUserFunc ( array $configuration, $getVarValue, array &$requestVariables, array &$pathSegments, boolean $isFakeValue ) : boolean Sets segment value as is to the request variables
decodeUrlParameterBlockUsingValueDefault ( array $configuration, $getVarValue, array &$requestVariables ) : boolean Sets segment value as is to the request variables
decodeUrlParameterBlockUsingValueMap ( array $configuration, $getVarValue, array &$requestVariables ) : boolean Sets segment value as is to the request variables
doDecoding ( string $path ) : DmitryDulepov\Realurl\Cache\UrlCacheEntry Decodes the URL. This function is called only if the URL is not in the URL cache.
fixBracketsAfterParseStr ( array &$array ) : void Fixes a problem with parse_str that returns a[b[c] instead of a[b[c]] when parsing a%5Bb%5Bc%5D%5D
getFromUrlCache ( string $speakingUrl ) : DmitryDulepov\Realurl\Cache\UrlCacheEntry | null Gets the entry from cache.
getPathCacheEntryAfterExcludedPages ( string $segment, array $pages, string $pagesEnableFields, array &$shortcutPages ) : DmitryDulepov\Realurl\Cache\PathCacheEntry Searches a page below excluded pages and returns the PathCacheEntry if something was found.
getRootPageIdForPage ( integer $pageUid ) : integer Obtains a root page id for the given page.
getUrlPath ( ) : array Parses the URL and validates the result. This function will strip possible query string from speaking URL (we only need to decode the speaking URL!)
getVarsFromDomainConfiguration ( ) : array Obtains variables from the domain confuguration.
handleFileName ( array &$urlParts ) : array Processes the file name component. There can be several scenarios: 1. File name is mapped to a _GET var. We set a _GET var and discard the segment.
handleFileNameMappingToGetVar ( string &$fileNameSegment, array &$getVars, boolean &$putBack ) : boolean Handles mapping of file names to GET vars (like 'print.html' => 'type=98')
handleNonExistingPostVarSet ( integer $pageId, string $postVarSetKey, array &$pathSegments ) Handles non-existing postVarSet according to configuration.
initialize ( ) Initializes the decoder.
initializeConfiguration ( ) Initializes configuration reader.
isPostVar ( string $segment, integer $pageId ) : boolean Checks if the given segment is a name of the postVar.
isProperTsfe ( ) : boolean Checks if TSFE is initialized correctly.
isSpeakingUrl ( ) : boolean Checks if the current URL is a speaking URL.
makeRealPhpArrayFromRequestVars ( array $requestVariables ) : array Converts array('tx_ext[var1]' => 1, 'tx_ext[var2]' => 2) to array('tx_ext' => array('var1' => 1, 'var2' => 2)).
mergeGetVarsFromDomainsConfiguration ( ) : void Merges $_GET from domains configuration.
mergeWithExistingGetVars ( array &$requestVariables ) : void Merges generated request variables with existing $_GET variables. Those in $_GET override generated.
parseQueryStringParameters ( string $queryString ) : array Parses query string to a set of key/value.
putToPathCache ( DmitryDulepov\Realurl\Cache\PathCacheEntry $newCacheEntry ) : void Adds data to the path cache. Cache ntry should have page path, language id and page id set.
runDecoding ( ) : void Contains the actual decoding logic after $this->speakingUri is set.
searchForPathOverrideInPages ( string $path ) : DmitryDulepov\Realurl\Cache\PathCacheEntry | null Searches the given path in pages table.
searchForPathOverrideInPagesLanguageOverlay ( string $path ) : DmitryDulepov\Realurl\Cache\PathCacheEntry | null Searches the given path in page language overlays.
searchPages ( integer $currentPid, string $segment, boolean &$saveToCache ) : DmitryDulepov\Realurl\Cache\PathCacheEntry Searches pages for the match to the segment
searchPagesByPathOverride ( array $possibleSegments ) : DmitryDulepov\Realurl\Cache\PathCacheEntry | null Searches for a match in tx_realurl_pathsegment with override option.
searchPathInCache ( array &$pathSegments ) : DmitryDulepov\Realurl\Cache\PathCacheEntry | null Fetches the entry from the RealURL path cache. This would start stripping segments if the entry is not found until none is left. Effectively it is a search for the largest caching path for those segments.
setLanguageFromQueryString ( ) : void Sets current language from the query string variable ('L').
setRequestVariables ( DmitryDulepov\Realurl\Cache\UrlCacheEntry $cacheEntry ) Sets variables after the decoding.
setSpeakingUriFromSiteScript ( ) : void Obtains speaking URI from the site script.
throw404 ( string $errorMessage ) : void Throws a 404 error with the corresponding message.

Method Details

__construct() public method

Initializes the class.
public __construct ( )

callPreDecodeHooks() protected method

Calls user-defined hooks.
protected callPreDecodeHooks ( array $params )
$params array

canDecoderExecute() protected method

Checks if the decoder can execute.
protected canDecoderExecute ( ) : boolean
return boolean

checkExpiration() protected method

Checks if the entry is expired and redirects to a non-expired entry.
protected checkExpiration ( DmitryDulepov\Realurl\Cache\UrlCacheEntry $cacheEntry )
$cacheEntry DmitryDulepov\Realurl\Cache\UrlCacheEntry

checkMissingSlash() protected method

Checks if the missing slash should be corrected.
protected checkMissingSlash ( ) : void
return void

convertAliasToId() protected method

Converts alias to id.
protected convertAliasToId ( array $configuration, string $value ) : integer | string
$configuration array
$value string
return integer | string

createPathCacheEntry() protected method

Find a page entry for the current segment and returns a PathCacheEntry for it.
protected createPathCacheEntry ( string $segment, array $pages, array &$shortcutPages ) : DmitryDulepov\Realurl\Cache\PathCacheEntry
$segment string
$pages array
$shortcutPages array
return DmitryDulepov\Realurl\Cache\PathCacheEntry | NULL

createQueryStringParameter() protected method

Generates a parameter string from an array recursively
protected createQueryStringParameter ( array $parameters, string $prependString = '' ) : array
$parameters array Array to generate strings from
$prependString string path to prepend to every parameter
return array

decodeFixedPostVars() protected method

Decodes fixedPostVars into request variables.
protected decodeFixedPostVars ( integer $pageId, array &$pathSegments ) : array
$pageId integer
$pathSegments array
return array

decodePath() protected method

Decodes the path.
protected decodePath ( array &$pathSegments ) : integer
$pathSegments array
return integer

decodePathByOverride() protected method

Tries to decode the path by path override when the whole path is overriden.
protected decodePathByOverride ( array &$pathSegments ) : DmitryDulepov\Realurl\Cache\PathCacheEntry
$pathSegments array
return DmitryDulepov\Realurl\Cache\PathCacheEntry

decodePostVarSets() protected method

Decodes postVarSets into request variables.
protected decodePostVarSets ( integer $pageId, array &$pathSegments ) : array
$pageId integer
$pathSegments array
return array

decodePreVars() protected method

Decodes preVars into request variables.
protected decodePreVars ( array &$pathSegments ) : array
$pathSegments array
return array

decodeSingleVariable() protected method

Decodes a single variable and adds it to the list of request variables.
protected decodeSingleVariable ( array $varConfiguration, array &$pathSegments, array &$requestVariables, &$previousValue ) : void
$varConfiguration array
$pathSegments array
$requestVariables array
$previousValue
return void

decodeUrl() public method

Decodes the URL. This function is called from \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::checkAlternativeIdMethods()
public decodeUrl ( array $params ) : void
$params array
return void

decodeUrlParameterBlockUseAsIs() protected method

Sets segment value as is to the request variables
protected decodeUrlParameterBlockUseAsIs ( array $configuration, $getVarValue, array &$requestVariables ) : boolean
$configuration array
$getVarValue
$requestVariables array
return boolean

decodeUrlParameterBlockUsingLookupTable() protected method

Sets segment value as is to the request variables
protected decodeUrlParameterBlockUsingLookupTable ( array $configuration, $getVarValue, array &$requestVariables ) : boolean
$configuration array
$getVarValue
$requestVariables array
return boolean

decodeUrlParameterBlockUsingNoMatch() protected method

Sets segment value as is to the request variables
protected decodeUrlParameterBlockUsingNoMatch ( array $configuration, $getVarValue, array &$requestVariables, array &$pathSegments, boolean $isFakeValue ) : boolean
$configuration array
$getVarValue
$requestVariables array
$pathSegments array
$isFakeValue boolean
return boolean

decodeUrlParameterBlockUsingUserFunc() protected method

Sets segment value as is to the request variables
protected decodeUrlParameterBlockUsingUserFunc ( array $configuration, $getVarValue, array &$requestVariables, array &$pathSegments, boolean $isFakeValue ) : boolean
$configuration array
$getVarValue
$requestVariables array
$pathSegments array
$isFakeValue boolean
return boolean

decodeUrlParameterBlockUsingValueDefault() protected method

Sets segment value as is to the request variables
protected decodeUrlParameterBlockUsingValueDefault ( array $configuration, $getVarValue, array &$requestVariables ) : boolean
$configuration array
$getVarValue
$requestVariables array
return boolean

decodeUrlParameterBlockUsingValueMap() protected method

Sets segment value as is to the request variables
protected decodeUrlParameterBlockUsingValueMap ( array $configuration, $getVarValue, array &$requestVariables ) : boolean
$configuration array
$getVarValue
$requestVariables array
return boolean

doDecoding() protected method

Decodes the URL. This function is called only if the URL is not in the URL cache.
protected doDecoding ( string $path ) : DmitryDulepov\Realurl\Cache\UrlCacheEntry
$path string
return DmitryDulepov\Realurl\Cache\UrlCacheEntry with only pageId and requestVariables filled in

fixBracketsAfterParseStr() protected method

Fixes a problem with parse_str that returns a[b[c] instead of a[b[c]] when parsing a%5Bb%5Bc%5D%5D
protected fixBracketsAfterParseStr ( array &$array ) : void
$array array
return void

getFromUrlCache() protected method

Gets the entry from cache.
protected getFromUrlCache ( string $speakingUrl ) : DmitryDulepov\Realurl\Cache\UrlCacheEntry | null
$speakingUrl string
return DmitryDulepov\Realurl\Cache\UrlCacheEntry | null

getPathCacheEntryAfterExcludedPages() protected method

Searches a page below excluded pages and returns the PathCacheEntry if something was found.
protected getPathCacheEntryAfterExcludedPages ( string $segment, array $pages, string $pagesEnableFields, array &$shortcutPages ) : DmitryDulepov\Realurl\Cache\PathCacheEntry
$segment string
$pages array
$pagesEnableFields string
$shortcutPages array
return DmitryDulepov\Realurl\Cache\PathCacheEntry | NULL

getRootPageIdForPage() protected method

Obtains a root page id for the given page.
protected getRootPageIdForPage ( integer $pageUid ) : integer
$pageUid integer
return integer

getUrlPath() protected method

Parses the URL and validates the result. This function will strip possible query string from speaking URL (we only need to decode the speaking URL!)
protected getUrlPath ( ) : array
return array

getVarsFromDomainConfiguration() protected method

Obtains variables from the domain confuguration.
protected getVarsFromDomainConfiguration ( ) : array
return array

handleFileName() protected method

2. File name is a segment with suffix appended. We discard the suffix.
protected handleFileName ( array &$urlParts ) : array
$urlParts array
return array

handleFileNameMappingToGetVar() protected method

Handles mapping of file names to GET vars (like 'print.html' => 'type=98')
protected handleFileNameMappingToGetVar ( string &$fileNameSegment, array &$getVars, boolean &$putBack ) : boolean
$fileNameSegment string
$getVars array
$putBack boolean
return boolean

handleNonExistingPostVarSet() protected method

Handles non-existing postVarSet according to configuration.
protected handleNonExistingPostVarSet ( integer $pageId, string $postVarSetKey, array &$pathSegments )
$pageId integer
$postVarSetKey string
$pathSegments array

initialize() protected method

Initializes the decoder.
protected initialize ( )

initializeConfiguration() protected method

Initializes configuration reader.
protected initializeConfiguration ( )

isPostVar() protected method

Checks if the given segment is a name of the postVar.
protected isPostVar ( string $segment, integer $pageId ) : boolean
$segment string
$pageId integer
return boolean

isProperTsfe() protected method

Checks if TSFE is initialized correctly.
protected isProperTsfe ( ) : boolean
return boolean

isSpeakingUrl() protected method

Checks if the current URL is a speaking URL.
protected isSpeakingUrl ( ) : boolean
return boolean

makeRealPhpArrayFromRequestVars() protected method

Converts array('tx_ext[var1]' => 1, 'tx_ext[var2]' => 2) to array('tx_ext' => array('var1' => 1, 'var2' => 2)).
protected makeRealPhpArrayFromRequestVars ( array $requestVariables ) : array
$requestVariables array
return array

mergeGetVarsFromDomainsConfiguration() protected method

Merges $_GET from domains configuration.

mergeWithExistingGetVars() protected method

Merges generated request variables with existing $_GET variables. Those in $_GET override generated.
protected mergeWithExistingGetVars ( array &$requestVariables ) : void
$requestVariables array
return void

parseQueryStringParameters() protected method

Parses query string to a set of key/value.
protected parseQueryStringParameters ( string $queryString ) : array
$queryString string
return array

putToPathCache() protected method

Adds data to the path cache. Cache ntry should have page path, language id and page id set.
protected putToPathCache ( DmitryDulepov\Realurl\Cache\PathCacheEntry $newCacheEntry ) : void
$newCacheEntry DmitryDulepov\Realurl\Cache\PathCacheEntry
return void

runDecoding() protected method

Contains the actual decoding logic after $this->speakingUri is set.
protected runDecoding ( ) : void
return void

searchForPathOverrideInPages() protected method

Searches the given path in pages table.
protected searchForPathOverrideInPages ( string $path ) : DmitryDulepov\Realurl\Cache\PathCacheEntry | null
$path string
return DmitryDulepov\Realurl\Cache\PathCacheEntry | null

searchForPathOverrideInPagesLanguageOverlay() protected method

Searches the given path in page language overlays.
protected searchForPathOverrideInPagesLanguageOverlay ( string $path ) : DmitryDulepov\Realurl\Cache\PathCacheEntry | null
$path string
return DmitryDulepov\Realurl\Cache\PathCacheEntry | null

searchPages() protected method

Searches pages for the match to the segment
protected searchPages ( integer $currentPid, string $segment, boolean &$saveToCache ) : DmitryDulepov\Realurl\Cache\PathCacheEntry
$currentPid integer
$segment string
$saveToCache boolean
return DmitryDulepov\Realurl\Cache\PathCacheEntry

searchPagesByPathOverride() protected method

Searches for a match in tx_realurl_pathsegment with override option.
protected searchPagesByPathOverride ( array $possibleSegments ) : DmitryDulepov\Realurl\Cache\PathCacheEntry | null
$possibleSegments array
return DmitryDulepov\Realurl\Cache\PathCacheEntry | null

searchPathInCache() protected method

Fetches the entry from the RealURL path cache. This would start stripping segments if the entry is not found until none is left. Effectively it is a search for the largest caching path for those segments.
protected searchPathInCache ( array &$pathSegments ) : DmitryDulepov\Realurl\Cache\PathCacheEntry | null
$pathSegments array
return DmitryDulepov\Realurl\Cache\PathCacheEntry | null

setLanguageFromQueryString() protected method

Sets current language from the query string variable ('L').
protected setLanguageFromQueryString ( ) : void
return void

setRequestVariables() protected method

Sets variables after the decoding.
protected setRequestVariables ( DmitryDulepov\Realurl\Cache\UrlCacheEntry $cacheEntry )
$cacheEntry DmitryDulepov\Realurl\Cache\UrlCacheEntry

setSpeakingUriFromSiteScript() protected method

Obtains speaking URI from the site script.
protected setSpeakingUriFromSiteScript ( ) : void
return void

throw404() protected method

Throws a 404 error with the corresponding message.
protected throw404 ( string $errorMessage ) : void
$errorMessage string
return void

Property Details

$appendedSlash protected property

protected bool $appendedSlash
return boolean

$caller protected property

protected TypoScriptFrontendController,TYPO3\CMS\Frontend\Controller $caller
return TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController

$detectedLanguageId protected property

Finally preVar handling code will check for L after decoding and set this attribute either to the decoded value or to zero. This value can be null until preVars are decoded. After that it is either zero or the decoded language uid.
protected int|null $detectedLanguageId
return integer | null

$disallowedDoktypes protected property

protected string $disallowedDoktypes
return string

$expiredPath protected property

Holds information about expired path for the SEO redirect.
protected string $expiredPath
return string

$isExpiredPath protected property

Indicates that the path is expired but we could not redirect because non-expired path is missing from the path cache. In such case we do not cache the entry in the URL cache to force resolving of the path when the current URL is fetched.
protected bool $isExpiredPath
return boolean

$mimeType protected property

protected string $mimeType
return string

$mountPointStartPid protected property

Contains a mount point starting pid for the current branch. Zero means "no mount point in the path". This variable will direct the decoder to continue page look up from this branch of tree.
protected int $mountPointStartPid
return integer

$mountPointVariable protected property

Contains a generated $_GET['MP'] for the currently decoded branch.
protected string $mountPointVariable
return string

$originalPath protected property

This variable is set to the speaking path only if he decoding has to run.
protected string $originalPath
return string

$savedErrorHandler protected property

protected string $savedErrorHandler
return string

$siteScript protected property

protected string $siteScript
return string

$speakingUri protected property

protected string $speakingUri
return string