PHP Class DmitryDulepov\Realurl\Encoder\UrlEncoder

Author: Dmitry Dulepov ([email protected])
Inheritance: extends DmitryDulepov\Realurl\EncodeDecoderBase
ファイルを表示 Open project: dmitryd/typo3-realurl

Protected Properties

Property Type Description
$encodedUrl string
$encoderParameters array
$originalUrl string This is the URL with sorted GET parameters. It is used for cache manipulation.
$originalUrlParameters array
$pageRepository TYPO3\CMS\Frontend\Page\PageRepository
$sysLanguageUid integer
$urlParameters array
$urlPrepend string
$urlPrependRegister array
$urlToEncode string
$usedAliases array

Public Methods

Method Description
__construct ( ) Initializes the class.
cleanUpAlias ( array $configuration, string $newAliasValue ) : string Cleans up the alias
encodeUrl ( array &$encoderParameters ) : void Entry point for the URL encoder.
getConfiguration ( ) : ConfigurationReader Returns the configuration reader. This can be used in hooks.
getOriginalUrlParameters ( ) : array Returns a coipy of original url parameters. This can be used in hooks.
getUtility ( ) : Utility Returns $this->utility. This can be used in hooks.
postProcessEncodedUrl ( array &$parameters, TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $pObj ) : void Post-processes the URL. If necessary prepends another domain to the URL.

Protected Methods

Method Description
addRemainingUrlParameters ( ) : void Adds remaining parameters to the generated URL. Note: parameters that are ignored by the 'cache/ignoredGetParametersRegExp' configuration option are not considered here!
addToPathCache ( string $pagePath ) : void Adds an entry to the path cache.
appendToEncodedUrl ( string $stringToAppend, boolean $addSlash = TRUE ) : void Appends a string to $this->encodedUrl properly handling slashes in between.
callPostEncodeHooks ( ) Calls user-defined hooks after encoding
canCacheUrl ( string $url ) : boolean Checks if the URL can be cached. This function may prevent RealURL cache pollution with Solr or Indexed search URLs. Also some doktypes are ignored for the cache.
canEncoderExecute ( ) : boolean Checks if RealURL can encode URLs.
checkForAllEmptySegments ( array &$segments ) : void Checks if all segments are empty and makes the empty array in such case.
createAliasForValue ( string $getVarValue, array $configuration ) : string Converts value to the alias
createPathComponent ( ) : void Creates a path part of the URL.
createPathComponentThroughOverride ( ) : boolean Checks if tx_realurl_pathoverride is set and goes the easy way.
createPathComponentUsingRootline ( ) : void Creates a path part of the URL.
createUniqueAlias ( array $configuration, $newAliasValue, $idValue ) : string Creates a unique alias.
encodeFixedPostVars ( ) : void Encodes fixed postVars.
encodePathComponents ( ) : void Encodes the path to the page.
encodePostVarSets ( ) : void Encodes 'postVarSets' into URL segments.
encodePreVars ( ) : void Encodes 'preVars' into URL segments.
encodeSingleVariable ( array $configuration, string &$previousValue, array &$segments ) Encodes a single variable for xxxVars.
encodeUrlParameterBlock ( array $configurationArray ) : string Encodes pre- or postVars according to the given configuration.
encodeUrlParameterBlockUseAsIs ( string $getVarName, string $getVarValue, array $configuration, array &$segments, string &$previousValue ) : boolean Just sets the value to the segment as is.
encodeUrlParameterBlockUsingLookupTable ( string $getVarName, string $getVarValue, array $configuration, array &$segments, string &$previousValue ) : boolean Uses lookUpMap to set the segment.
encodeUrlParameterBlockUsingNoMatch ( string $getVarName, string $getVarValue, array $configuration, array &$segments, string &$previousValue ) : boolean Uses 'noMatch' options to set the segment.
encodeUrlParameterBlockUsingUserFunc ( string $getVarName, string $getVarValue, array $configuration, array &$segments, string &$previousValue ) : boolean Calls the userFunc for the value to get the segment.
encodeUrlParameterBlockUsingValueDefault ( string $getVarName, string $getVarValue, array $configuration, array &$segments, string &$previousValue ) : boolean Just sets the default value to the segment.
encodeUrlParameterBlockUsingValueMap ( string $getVarName, string $getVarValue, array $configuration, array &$segments, string &$previousValue ) : boolean Uses the value map to determine the segment value.
executeEncoder ( ) : void Encodes the URL.
fetchFromUrlCache ( ) : boolean Attempts to fetch the speaking URL from the url cache.
fixEmptySegments ( array &$segments ) Changes empty segments to the value of $this->emptySegmentValue.
fixPageId ( ) Fixes page id if it is not a direct numeric page id.
getFromAliasCache ( array $configuration, string $getVarValue, integer $languageUid, string $onlyThisAlias = '' ) : string | null Obtains the value from the alias cache.
handleFileName ( ) : void Appends file name and suffix if necessary.
handleFileNameSetDefaultSuffix ( ) : void Sets the default suffix to the URL if configured so.
handleFileNameUsingGetVars ( ) : boolean Checks if the file name like 'rss.xml' should be produced according to _GET vars.
hasUrlParameters ( array $configurationArray ) : boolean Checks if any GETvar from the parameter block is present in $this->urlParameters.
initializeConfiguration ( ) Initializes configuration reader.
initializeUrlPrepend ( ) : void Checks if we should prpend URL according to _DOMAINS configuration.
isProperTsfe ( ) : boolean Checks if TSFE is initialized correctly.
isRealURLEnabled ( ) : boolean Checks if RealURL is enabled.
isSimulateStaticEnabled ( ) : boolean Checks if simulatestatic is enabled.
isTypo3Url ( ) : boolean Checks if a TYPO3 URL is going to be encoded.
parseUrlParameters ( ) : void Parses query string to a set of key/value inside $this->urlParameters.
prepareUrlPrepend ( ) : void Prepares the URL to use with _DOMAINS configuration.
reapplyAbsRefPrefix ( ) : void Reapplies absRefPrefix if necessary.
removeIgnoredUrlParameters ( ) Removes ignored parameters from various members.
removeIgnoredUrlParametersFromArray ( array $urlParameters ) : array Removes ignored URL parameters from the parameter list.
setLanguage ( ) : void Sets language for the encoder either from the URl or from the TSFE.
storeAliasToUrlCacheMapping ( string $urlCacheId ) : void Stores mapping between used aliases and url cache id. This information is used in the DataHandle hook to clear URl cache when record are renamed (= aliases change).
storeInAliasCache ( array $configuration, string $newAliasValue, string $idValue, integer $languageUid ) : string Adds the value to the alias cache.
storeInUrlCache ( ) : void Stores data in the URL cache.
trimMultipleSlashes ( ) Removes multiple slashes at the end of the encoded URL.

Method Details

__construct() public method

Initializes the class.
public __construct ( )

addRemainingUrlParameters() protected method

Adds remaining parameters to the generated URL. Note: parameters that are ignored by the 'cache/ignoredGetParametersRegExp' configuration option are not considered here!
protected addRemainingUrlParameters ( ) : void
return void

addToPathCache() protected method

Adds an entry to the path cache.
protected addToPathCache ( string $pagePath ) : void
$pagePath string
return void

appendToEncodedUrl() protected method

Appends a string to $this->encodedUrl properly handling slashes in between.
protected appendToEncodedUrl ( string $stringToAppend, boolean $addSlash = TRUE ) : void
$stringToAppend string
$addSlash boolean
return void

callPostEncodeHooks() protected method

Calls user-defined hooks after encoding
protected callPostEncodeHooks ( )

canCacheUrl() protected method

Checks if the URL can be cached. This function may prevent RealURL cache pollution with Solr or Indexed search URLs. Also some doktypes are ignored for the cache.
protected canCacheUrl ( string $url ) : boolean
$url string
return boolean

canEncoderExecute() protected method

Checks if RealURL can encode URLs.
protected canEncoderExecute ( ) : boolean
return boolean

checkForAllEmptySegments() protected method

Checks if all segments are empty and makes the empty array in such case.
protected checkForAllEmptySegments ( array &$segments ) : void
$segments array
return void

cleanUpAlias() public method

Cleans up the alias
public cleanUpAlias ( array $configuration, string $newAliasValue ) : string
$configuration array Configuration array
$newAliasValue string Alias value to clean up
return string

createAliasForValue() protected method

Converts value to the alias
protected createAliasForValue ( string $getVarValue, array $configuration ) : string
$getVarValue string
$configuration array 'lookUpTable' configuration
return string

createPathComponent() protected method

Creates a path part of the URL.
protected createPathComponent ( ) : void
return void

createPathComponentThroughOverride() protected method

Checks if tx_realurl_pathoverride is set and goes the easy way.

createPathComponentUsingRootline() protected method

Creates a path part of the URL.
protected createPathComponentUsingRootline ( ) : void
return void

createUniqueAlias() protected method

Creates a unique alias.
protected createUniqueAlias ( array $configuration, $newAliasValue, $idValue ) : string
$configuration array
$newAliasValue
$idValue
return string

encodeFixedPostVars() protected method

Encodes fixed postVars.
protected encodeFixedPostVars ( ) : void
return void

encodePathComponents() protected method

Encodes the path to the page.
protected encodePathComponents ( ) : void
return void

encodePostVarSets() protected method

Encodes 'postVarSets' into URL segments.
protected encodePostVarSets ( ) : void
return void

encodePreVars() protected method

Encodes 'preVars' into URL segments.
protected encodePreVars ( ) : void
return void

encodeSingleVariable() protected method

Encodes a single variable for xxxVars.
protected encodeSingleVariable ( array $configuration, string &$previousValue, array &$segments )
$configuration array
$previousValue string
$segments array

encodeUrl() public method

Entry point for the URL encoder.
public encodeUrl ( array &$encoderParameters ) : void
$encoderParameters array
return void

encodeUrlParameterBlock() protected method

Encodes pre- or postVars according to the given configuration.
protected encodeUrlParameterBlock ( array $configurationArray ) : string
$configurationArray array
return string

encodeUrlParameterBlockUseAsIs() protected method

Just sets the value to the segment as is.
protected encodeUrlParameterBlockUseAsIs ( string $getVarName, string $getVarValue, array $configuration, array &$segments, string &$previousValue ) : boolean
$getVarName string
$getVarValue string
$configuration array
$segments array
$previousValue string
return boolean

encodeUrlParameterBlockUsingLookupTable() protected method

Uses lookUpMap to set the segment.
protected encodeUrlParameterBlockUsingLookupTable ( string $getVarName, string $getVarValue, array $configuration, array &$segments, string &$previousValue ) : boolean
$getVarName string
$getVarValue string
$configuration array
$segments array
$previousValue string
return boolean

encodeUrlParameterBlockUsingNoMatch() protected method

Uses 'noMatch' options to set the segment.
protected encodeUrlParameterBlockUsingNoMatch ( string $getVarName, string $getVarValue, array $configuration, array &$segments, string &$previousValue ) : boolean
$getVarName string
$getVarValue string
$configuration array
$segments array
$previousValue string
return boolean

encodeUrlParameterBlockUsingUserFunc() protected method

Calls the userFunc for the value to get the segment.
protected encodeUrlParameterBlockUsingUserFunc ( string $getVarName, string $getVarValue, array $configuration, array &$segments, string &$previousValue ) : boolean
$getVarName string
$getVarValue string
$configuration array
$segments array
$previousValue string
return boolean

encodeUrlParameterBlockUsingValueDefault() protected method

Just sets the default value to the segment.
protected encodeUrlParameterBlockUsingValueDefault ( string $getVarName, string $getVarValue, array $configuration, array &$segments, string &$previousValue ) : boolean
$getVarName string
$getVarValue string
$configuration array
$segments array
$previousValue string
return boolean

encodeUrlParameterBlockUsingValueMap() protected method

Uses the value map to determine the segment value.
protected encodeUrlParameterBlockUsingValueMap ( string $getVarName, string $getVarValue, array $configuration, array &$segments, string &$previousValue ) : boolean
$getVarName string
$getVarValue string
$configuration array
$segments array
$previousValue string
return boolean

executeEncoder() protected method

Encodes the URL.
protected executeEncoder ( ) : void
return void

fetchFromUrlCache() protected method

Attempts to fetch the speaking URL from the url cache.
protected fetchFromUrlCache ( ) : boolean
return boolean

fixEmptySegments() protected method

Changes empty segments to the value of $this->emptySegmentValue.
protected fixEmptySegments ( array &$segments )
$segments array

fixPageId() protected method

Fixes page id if it is not a direct numeric page id.
protected fixPageId ( )

getConfiguration() public method

Returns the configuration reader. This can be used in hooks.
public getConfiguration ( ) : ConfigurationReader
return DmitryDulepov\Realurl\Configuration\ConfigurationReader

getFromAliasCache() protected method

Obtains the value from the alias cache.
protected getFromAliasCache ( array $configuration, string $getVarValue, integer $languageUid, string $onlyThisAlias = '' ) : string | null
$configuration array
$getVarValue string
$languageUid integer
$onlyThisAlias string
return string | null

getOriginalUrlParameters() public method

Returns a coipy of original url parameters. This can be used in hooks.
public getOriginalUrlParameters ( ) : array
return array

getUtility() public method

Returns $this->utility. This can be used in hooks.
public getUtility ( ) : Utility
return DmitryDulepov\Realurl\Utility

handleFileName() protected method

Appends file name and suffix if necessary.
protected handleFileName ( ) : void
return void

handleFileNameSetDefaultSuffix() protected method

Sets the default suffix to the URL if configured so.
protected handleFileNameSetDefaultSuffix ( ) : void
return void

handleFileNameUsingGetVars() protected method

Checks if the file name like 'rss.xml' should be produced according to _GET vars.
protected handleFileNameUsingGetVars ( ) : boolean
return boolean

hasUrlParameters() protected method

Checks if any GETvar from the parameter block is present in $this->urlParameters.
protected hasUrlParameters ( array $configurationArray ) : boolean
$configurationArray array
return boolean

initializeConfiguration() protected method

Initializes configuration reader.
protected initializeConfiguration ( )

initializeUrlPrepend() protected method

Checks if we should prpend URL according to _DOMAINS configuration.
protected initializeUrlPrepend ( ) : void
return void

isProperTsfe() protected method

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

isRealURLEnabled() protected method

Checks if RealURL is enabled.
protected isRealURLEnabled ( ) : boolean
return boolean

isSimulateStaticEnabled() protected method

Checks if simulatestatic is enabled.
protected isSimulateStaticEnabled ( ) : boolean
return boolean

isTypo3Url() protected method

Checks if a TYPO3 URL is going to be encoded.
protected isTypo3Url ( ) : boolean
return boolean

parseUrlParameters() protected method

Parses query string to a set of key/value inside $this->urlParameters.
protected parseUrlParameters ( ) : void
return void

postProcessEncodedUrl() public method

Post-processes the URL. If necessary prepends another domain to the URL.
public postProcessEncodedUrl ( array &$parameters, TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $pObj ) : void
$parameters array
$pObj TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
return void

prepareUrlPrepend() protected method

Prepares the URL to use with _DOMAINS configuration.
protected prepareUrlPrepend ( ) : void
return void

reapplyAbsRefPrefix() protected method

Reapplies absRefPrefix if necessary.
protected reapplyAbsRefPrefix ( ) : void
return void

removeIgnoredUrlParameters() protected method

Removes ignored parameters from various members.

removeIgnoredUrlParametersFromArray() protected method

Removes ignored URL parameters from the parameter list.
protected removeIgnoredUrlParametersFromArray ( array $urlParameters ) : array
$urlParameters array
return array

setLanguage() protected method

Sets language for the encoder either from the URl or from the TSFE.
protected setLanguage ( ) : void
return void

storeAliasToUrlCacheMapping() protected method

Stores mapping between used aliases and url cache id. This information is used in the DataHandle hook to clear URl cache when record are renamed (= aliases change).
protected storeAliasToUrlCacheMapping ( string $urlCacheId ) : void
$urlCacheId string
return void

storeInAliasCache() protected method

Adds the value to the alias cache.
protected storeInAliasCache ( array $configuration, string $newAliasValue, string $idValue, integer $languageUid ) : string
$configuration array
$newAliasValue string
$idValue string
$languageUid integer
return string

storeInUrlCache() protected method

Stores data in the URL cache.
protected storeInUrlCache ( ) : void
return void

trimMultipleSlashes() protected method

Removes multiple slashes at the end of the encoded URL.
protected trimMultipleSlashes ( )

Property Details

$encodedUrl protected_oe property

protected string $encodedUrl
return string

$encoderParameters protected_oe property

protected array $encoderParameters
return array

$originalUrl protected_oe property

This is the URL with sorted GET parameters. It is used for cache manipulation.
protected string $originalUrl
return string

$originalUrlParameters protected_oe property

protected array $originalUrlParameters
return array

$pageRepository protected_oe property

protected PageRepository,TYPO3\CMS\Frontend\Page $pageRepository
return TYPO3\CMS\Frontend\Page\PageRepository

$sysLanguageUid protected_oe property

protected int $sysLanguageUid
return integer

$urlParameters protected_oe property

protected array $urlParameters
return array

$urlPrepend protected_oe property

protected string $urlPrepend
return string

$urlPrependRegister protected_oe static_oe property

protected static array $urlPrependRegister
return array

$urlToEncode protected_oe property

protected string $urlToEncode
return string

$usedAliases protected_oe property

protected array $usedAliases
return array