class TemplatePaths extends TemplatePaths (View source)

Class TemplatePaths

Custom implementation for template paths resolving, one which differs from the base implementation in that it is capable of resolving template paths based on Fusion configuration when given a package name, and is aware of the Frontend/Backend contexts of TYPO3.

Properties

protected string $templateRootPathPattern
protected string $layoutRootPathPattern
protected string $partialRootPathPattern
protected string[] $patternReplacementVariables

A map of key => values to be replaced in path patterns.

protected array $options
protected PackageManager $packageManager

Methods

__construct(array $options = [])

No description

injectPackageManager(PackageManager $packageManager)

No description

string
getTemplateRootPathPattern()

No description

setTemplateRootPathPattern(string $templateRootPathPattern)

No description

setLayoutRootPathPattern(string $layoutRootPathPattern)

No description

setPartialRootPathPattern(string $partialRootPathPattern)

No description

setTemplateRootPath(string $templateRootPath)

No description

array
getTemplateRootPaths()

Resolves the template root to be used inside other paths.

array
getLayoutRootPaths()

No description

getPartialRootPaths()

No description

setLayoutRootPath(string $layoutRootPath)

No description

setPartialRootPath(string $partialRootPath)

No description

string[]
setPatternReplacementVariables(string[] $patternReplacementVariables)

No description

mixed|string
resolveTemplateFileForControllerAndActionAndFormat(string $controller, string $action, string $format = null)

Resolves a template file based on the given controller and action, together with eventually defined patternReplacementVariables.

string
getLayoutPathAndFilename(string $layoutName = 'Default')

Resolve the path and file name of the layout file, based on $this->options['layoutPathAndFilename'] and $this->options['layoutPathAndFilenamePattern'].

string
getPartialPathAndFilename(string $partialName)

Resolve the partial path and filename based on $this->options['partialPathAndFilenamePattern'].

string
getPackagePath(string $packageName)

No description

string
sanitizePath(string $path)

Sanitize a path, ensuring it is absolute and if a directory, suffixed by a trailing slash.

array
expandGenericPathPattern(string $pattern, array $patternReplacementVariables, bool $bubbleControllerAndSubpackage, bool $formatIsOptional)

Processes following placeholders inside $pattern:

  • "@templateRoot"
  • "@partialRoot"
  • "@layoutRoot"
  • "@subpackage"
  • "@controller"
  • "@format"

array
replacePatternVariable(array $paths, string $variableName, string $variableValue)

No description

array
expandSubPackageAndController(array $paths, string $controllerName, string $subPackageKey = '', bool $bubbleControllerAndSubpackage = false)

No description

array
expandPatterns(array $patterns, string $search, array $replacements)

Expands the given $patterns by adding an array element for each $replacement replacing occurrences of $search.

mixed
getOption(string $optionName)

Get a specific option of this object

void
setOption(string $optionName, mixed $value)

Set a specific option of this object

string
createIdentifierForFile(string|null $pathAndFilename, string $prefix)

Returns a unique identifier for the given file in the format

____ The SH1 hash is a checksum that is based on the file path and last modification date

Details

__construct(array $options = [])

No description

Parameters

array $options

injectPackageManager(PackageManager $packageManager)

No description

Parameters

PackageManager $packageManager

string getTemplateRootPathPattern()

No description

Return Value

string

setTemplateRootPathPattern(string $templateRootPathPattern)

No description

Parameters

string $templateRootPathPattern

setLayoutRootPathPattern(string $layoutRootPathPattern)

No description

Parameters

string $layoutRootPathPattern

setPartialRootPathPattern(string $partialRootPathPattern)

No description

Parameters

string $partialRootPathPattern

setTemplateRootPath(string $templateRootPath)

No description

Parameters

string $templateRootPath

array getTemplateRootPaths()

Resolves the template root to be used inside other paths.

Return Value

array

Path(s) to template root directory

array getLayoutRootPaths()

No description

Return Value

array

getPartialRootPaths()

No description

setLayoutRootPath(string $layoutRootPath)

No description

Parameters

string $layoutRootPath

setPartialRootPath(string $partialRootPath)

No description

Parameters

string $partialRootPath

string[] getPatternReplacementVariables()

No description

Return Value

string[]

setPatternReplacementVariables(string[] $patternReplacementVariables)

No description

Parameters

string[] $patternReplacementVariables

mixed|string resolveTemplateFileForControllerAndActionAndFormat(string $controller, string $action, string $format = null)

Resolves a template file based on the given controller and action, together with eventually defined patternReplacementVariables.

Parameters

string $controller
string $action
string $format

Return Value

mixed|string

Exceptions

InvalidTemplateResourceException

string getLayoutPathAndFilename(string $layoutName = 'Default')

Resolve the path and file name of the layout file, based on $this->options['layoutPathAndFilename'] and $this->options['layoutPathAndFilenamePattern'].

In case a layout has already been set with setLayoutPathAndFilename(), this method returns that path, otherwise a path and filename will be resolved using the layoutPathAndFilenamePattern.

Parameters

string $layoutName

Name of the layout to use. If none given, use "Default"

Return Value

string

Path and filename of layout files

Exceptions

InvalidTemplateResourceException

string getPartialPathAndFilename(string $partialName)

Resolve the partial path and filename based on $this->options['partialPathAndFilenamePattern'].

Parameters

string $partialName

The name of the partial

Return Value

string

the full path which should be used. The path definitely exists.

Exceptions

InvalidTemplateResourceException

protected string getPackagePath(string $packageName)

No description

Parameters

string $packageName

Return Value

string

protected string sanitizePath(string $path)

Sanitize a path, ensuring it is absolute and if a directory, suffixed by a trailing slash.

Parameters

string $path

Return Value

string

protected array expandGenericPathPattern(string $pattern, array $patternReplacementVariables, bool $bubbleControllerAndSubpackage, bool $formatIsOptional)

Processes following placeholders inside $pattern:

  • "@templateRoot"
  • "@partialRoot"
  • "@layoutRoot"
  • "@subpackage"
  • "@controller"
  • "@format"

This method is used to generate "fallback chains" for file system locations where a certain Partial can reside.

If $bubbleControllerAndSubpackage is false and $formatIsOptional is false, then the resulting array will only have one element with all the above placeholders replaced.

If you set $bubbleControllerAndSubpackage to true, then you will get an array with potentially many elements: The first element of the array is like above. The second element has the @ controller part set to "" (the empty string) The third element now has the @ controller part again stripped off, and has the last subpackage part stripped off as well. This continues until both "@subpackage" and "@controller" are empty.

Example for $bubbleControllerAndSubpackage is true, we have the MyCompany\MyPackage\MySubPackage\Controller\MyController as Controller Object Name and the current format is "html"

If pattern is "@templateRoot/@subpackage/@controller/@action.@format", then the resulting array is:

  • "Resources/Private/Templates/MySubPackage/My/@action.html"
  • "Resources/Private/Templates/MySubPackage/@action.html"
  • "Resources/Private/Templates/@action.html"

If you set $formatIsOptional to true, then for any of the above arrays, every element will be duplicated - once with "@format" replaced by the current request format, and once with ."@format" stripped off.

Parameters

string $pattern

Pattern to be resolved

array $patternReplacementVariables

The variables to replace in the pattern

bool $bubbleControllerAndSubpackage

if true, then we successively split off parts from "@controller" and "@subpackage" until both are empty.

bool $formatIsOptional

if true, then half of the resulting strings will have ."@format" stripped off, and the other half will have it.

Return Value

array

unix style paths

protected array replacePatternVariable(array $paths, string $variableName, string $variableValue)

No description

Parameters

array $paths
string $variableName
string $variableValue

Return Value

array

protected array expandSubPackageAndController(array $paths, string $controllerName, string $subPackageKey = '', bool $bubbleControllerAndSubpackage = false)

No description

Parameters

array $paths
string $controllerName
string $subPackageKey
bool $bubbleControllerAndSubpackage

Return Value

array

protected array expandPatterns(array $patterns, string $search, array $replacements)

Expands the given $patterns by adding an array element for each $replacement replacing occurrences of $search.

Parameters

array $patterns
string $search
array $replacements

Return Value

array

mixed getOption(string $optionName)

Get a specific option of this object

Parameters

string $optionName

Return Value

mixed

void setOption(string $optionName, mixed $value)

Set a specific option of this object

Parameters

string $optionName
mixed $value

Return Value

void

protected string createIdentifierForFile(string|null $pathAndFilename, string $prefix)

Returns a unique identifier for the given file in the format

____ The SH1 hash is a checksum that is based on the file path and last modification date

Parameters

string|null $pathAndFilename
string $prefix

Return Value

string

Exceptions

InvalidTemplateResourceException