PHP Class FluidTYPO3\Flux\View\TemplatePaths

Class used to hold and resolve template files and paths in multiple supported ways. The purpose of this class is to homogenise the API that is used when working with template paths coming from TypoScript, as well as serve as a way to quickly generate default template-, layout- and partial root paths by package. The constructor accepts two different types of input - anything not of those types is silently ignored: - a string input is assumed a package name and will call the fillDefaultsByPackageName value filling method. - an array input is assumed a TypoScript-style array of root paths in one or more of the supported structures and will call the fillFromTypoScriptArray method. Either method can also be called after instance is created, but both will overwrite any paths you have previously configured.
Show file Open project: fluidtypo3/flux Class Usage Examples

Protected Properties

Property Type Description
$layoutRootPaths array
$partialRootPaths array
$templateRootPaths array

Public Methods

Method Description
__construct ( string | null $packageOrPaths = NULL )
fillDefaultsByPackageName ( string $packageName ) : void Fills path arrays with default expected paths based on package name (converted to extension key automatically).
fillFromTypoScriptArray ( array $paths ) : void Fills path arrays based on a traditional TypoScript array which may contain one or more of the supported structures, in order of priority:
getLayoutRootPaths ( ) : array
getPartialRootPaths ( ) : array
getTemplateRootPaths ( ) : array
resolveAvailableLayoutFiles ( string $format = self::DEFAULT_FORMAT ) : array
resolveAvailablePartialFiles ( string $format = self::DEFAULT_FORMAT ) : array
resolveAvailableTemplateFiles ( string $controllerName, string $format = self::DEFAULT_FORMAT ) : array
resolveTemplateFileForControllerAndActionAndFormat ( string $controller, string $action, string $format = self::DEFAULT_FORMAT ) : string | null Attempts to resolve an absolute filename of a template (i.e. templateRootPaths) using a controller name, action and format.
setLayoutRootPaths ( array $layoutRootPaths ) : void
setPartialRootPaths ( array $partialRootPaths ) : void
setTemplateRootPaths ( array $templateRootPaths ) : void
toArray ( ) : array

Protected Methods

Method Description
ensureAbsolutePath ( mixed $reference ) : mixed Guarantees that $reference is turned into a correct, absolute path. The input can be a relative path or a FILE: or EXT: reference but cannot be a FAL resource identifier.
extractPathArrays ( array $paths ) : array Extract an array of three arrays of paths, one for each of the types of Fluid file resources.
resolveFilesInFolders ( array $folders, string $format ) : array

Method Details

__construct() public method

public __construct ( string | null $packageOrPaths = NULL )
$packageOrPaths string | null

ensureAbsolutePath() protected method

Guarantees that $reference is turned into a correct, absolute path. The input can be a relative path or a FILE: or EXT: reference but cannot be a FAL resource identifier.
protected ensureAbsolutePath ( mixed $reference ) : mixed
$reference mixed
return mixed

extractPathArrays() protected method

Accepts one or both of the singular and plural path definitions in the input - returns the combined collections of paths based on both the singular and plural entries with the singular entries being recorded first and plurals second. Sorts the passed paths by index in array, in reverse, so that the base View class will iterate the array in the right order when resolving files. Adds legacy singular name as last option, if set.
protected extractPathArrays ( array $paths ) : array
$paths array
return array

fillDefaultsByPackageName() public method

Will replace any currently configured paths.
public fillDefaultsByPackageName ( string $packageName ) : void
$packageName string
return void

fillFromTypoScriptArray() public method

- plugin.tx_yourext.view.templateRootPath and siblings. - plugin.tx_yourext.view.templateRootPaths and siblings. - plugin.tx_yourext.view.overlays.otherextension.templateRootPath and siblings. The paths are treated as follows, using the template-type paths as an example: - If templateRootPath is defined, it gets used as the _first_ path in the internal paths array. - If templateRootPaths is defined, all values from it are _appended_ to the internal paths array. - If overlays.* exists in the array it is iterated, each templateRootPath entry from it _appended_ to the internal array. The result is that after filling, the path arrays will contain one or more entries in the order described above, depending on how many of the possible configurations were present in the input array. Will replace any currently configured paths.
public fillFromTypoScriptArray ( array $paths ) : void
$paths array
return void

getLayoutRootPaths() public method

public getLayoutRootPaths ( ) : array
return array

getPartialRootPaths() public method

public getPartialRootPaths ( ) : array
return array

getTemplateRootPaths() public method

public getTemplateRootPaths ( ) : array
return array

resolveAvailableLayoutFiles() public method

public resolveAvailableLayoutFiles ( string $format = self::DEFAULT_FORMAT ) : array
$format string
return array

resolveAvailablePartialFiles() public method

public resolveAvailablePartialFiles ( string $format = self::DEFAULT_FORMAT ) : array
$format string
return array

resolveAvailableTemplateFiles() public method

public resolveAvailableTemplateFiles ( string $controllerName, string $format = self::DEFAULT_FORMAT ) : array
$controllerName string
$format string
return array

resolveFilesInFolders() protected method

protected resolveFilesInFolders ( array $folders, string $format ) : array
$folders array
$format string
return array

resolveTemplateFileForControllerAndActionAndFormat() public method

Works _backwards_ through template paths in order to achieve an "overlay"-type behavior where the last paths added are the first to be checked and the first path added acts as fallback if no other paths have the file. If the file does not exist in any path, including fallback path, NULL is returned. Path configurations filled from TypoScript is automatically recorded in the right order (see fillFromTypoScriptArray), but when manually setting the paths that should be checked, you as user must be aware of this reverse behavior (which you should already be, given that it is the same way TypoScript path configurations work).
public resolveTemplateFileForControllerAndActionAndFormat ( string $controller, string $action, string $format = self::DEFAULT_FORMAT ) : string | null
$controller string
$action string
$format string
return string | null

setLayoutRootPaths() public method

public setLayoutRootPaths ( array $layoutRootPaths ) : void
$layoutRootPaths array
return void

setPartialRootPaths() public method

public setPartialRootPaths ( array $partialRootPaths ) : void
$partialRootPaths array
return void

setTemplateRootPaths() public method

public setTemplateRootPaths ( array $templateRootPaths ) : void
$templateRootPaths array
return void

toArray() public method

public toArray ( ) : array
return array

Property Details

$layoutRootPaths protected property

protected array $layoutRootPaths
return array

$partialRootPaths protected property

protected array $partialRootPaths
return array

$templateRootPaths protected property

protected array $templateRootPaths
return array