129 $this->templateParser = \TYPO3\CMS\Fluid\Compatibility\TemplateParserBuilder::build();
131 $this->
setRenderingContext($this->objectManager->get(
'TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContextInterface'));
189 public function getTemplateRootPaths() {
190 if ($this->templateRootPaths !== NULL) {
194 $actionRequest = $this->controllerContext->getRequest();
195 return array(str_replace(
'@packageResourcesPath', \
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($actionRequest->getControllerExtensionKey()) .
'Resources/', $this->templateRootPathPattern));
250 protected function getPartialRootPaths() {
251 if ($this->partialRootPaths !== NULL) {
255 $actionRequest = $this->controllerContext->getRequest();
256 return array(str_replace(
'@packageResourcesPath', \
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($actionRequest->getControllerExtensionKey()) .
'Resources/', $this->partialRootPathPattern));
299 protected function getLayoutRootPaths() {
300 if ($this->layoutRootPaths !== NULL) {
304 $actionRequest = $this->controllerContext->getRequest();
305 return array(str_replace(
'@packageResourcesPath', \
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($actionRequest->getControllerExtensionKey()) .
'Resources/', $this->layoutRootPathPattern));
317 if ($actionName === NULL) {
319 $actionRequest = $this->controllerContext->getRequest();
320 $actionName = $actionRequest->getControllerActionName();
322 $prefix =
'action_' . $actionName;
337 if ($templateSource === FALSE) {
338 throw new Exception\InvalidTemplateResourceException(
'"' .
$templatePathAndFilename .
'" is not a valid template resource URI.', 1257246929);
340 return $templateSource;
351 protected function getTemplatePathAndFilename($actionName = NULL) {
352 if ($this->templatePathAndFilename !== NULL) {
355 if ($actionName === NULL) {
357 $actionRequest = $this->controllerContext->getRequest();
358 $actionName = $actionRequest->getControllerActionName();
360 $actionName = ucfirst($actionName);
362 $paths = $this->expandGenericPathPattern($this->templatePathAndFilenamePattern, FALSE, FALSE);
364 $templatePathAndFilename = $this->
resolveFileNamePath(str_replace(
'@action', $actionName, $templatePathAndFilename));
365 if (is_file($templatePathAndFilename)) {
369 throw new Exception\InvalidTemplateResourceException(
'Template could not be loaded. I tried "' . implode(
'", "', $paths) .
'"', 1225709595);
381 $prefix =
'layout_' . $layoutName;
400 if ($layoutSource === FALSE) {
401 throw new Exception\InvalidTemplateResourceException(
'"' .
$layoutPathAndFilename .
'" is not a valid template resource URI.', 1257246930);
403 return $layoutSource;
419 if ($this->layoutPathAndFilename !== NULL) {
422 $paths = $this->expandGenericPathPattern($this->layoutPathAndFilenamePattern, TRUE, TRUE);
423 $layoutName = ucfirst($layoutName);
425 $layoutPathAndFilename = $this->
resolveFileNamePath(str_replace(
'@layout', $layoutName, $layoutPathAndFilename));
426 if (is_file($layoutPathAndFilename)) {
430 throw new Exception\InvalidTemplateResourceException(
'The template files "' . implode(
'", "', $paths) .
'" could not be loaded.', 1225709596);
442 $prefix =
'partial_' . $partialName;
443 return $this->createIdentifierForFile($partialPathAndFilename, $prefix);
455 $partialSource = file_get_contents($partialPathAndFilename);
456 if ($partialSource === FALSE) {
457 throw new Exception\InvalidTemplateResourceException(
'"' . $partialPathAndFilename .
'" is not a valid template resource URI.', 1257246931);
459 return $partialSource;
470 $paths = $this->expandGenericPathPattern($this->partialPathAndFilenamePattern, TRUE, TRUE);
471 foreach ($paths as &$partialPathAndFilename) {
472 $partialPathAndFilename = $this->
resolveFileNamePath(str_replace(
'@partial', $partialName, $partialPathAndFilename));
473 if (is_file($partialPathAndFilename)) {
474 return $partialPathAndFilename;
477 throw new Exception\InvalidTemplateResourceException(
'The template files "' . implode(
'", "', $paths) .
'" could not be loaded.', 1225709597);
532 protected function expandGenericPathPattern($pattern, $bubbleControllerAndSubpackage, $formatIsOptional) {
533 $paths = array($pattern);
534 $this->
expandPatterns($paths,
'@templateRoot', $this->getTemplateRootPaths());
535 $this->
expandPatterns($paths,
'@partialRoot', $this->getPartialRootPaths());
536 $this->
expandPatterns($paths,
'@layoutRoot', $this->getLayoutRootPaths());
539 $actionRequest = $this->controllerContext->getRequest();
540 $subpackageKey = $actionRequest->getControllerSubpackageKey();
541 $controllerName = $actionRequest->getControllerName();
542 if ($subpackageKey !== NULL) {
548 $subpackageKeyParts = explode($namespaceSeparator, $subpackageKey);
550 $subpackageKeyParts = array();
552 if ($bubbleControllerAndSubpackage) {
553 $numberOfPathsBeforeSubpackageExpansion = count($paths);
554 $numberOfSubpackageParts = count($subpackageKeyParts);
555 $subpackageReplacements = array();
556 for ($i = 0; $i <= $numberOfSubpackageParts; $i++) {
557 $subpackageReplacements[] = implode(
'/', ($i < 0 ? $subpackageKeyParts : array_slice($subpackageKeyParts, $i)));
559 $this->
expandPatterns($paths,
'@subpackage', $subpackageReplacements);
561 for ($i = ($numberOfPathsBeforeSubpackageExpansion - 1) * ($numberOfSubpackageParts + 1); $i >= 0; $i -= ($numberOfSubpackageParts + 1)) {
562 array_splice($paths, $i, 0, str_replace(
'@controller', $controllerName, $paths[$i]));
566 $i = $controllerName === NULL ? 0 : -1;
567 $this->
expandPatterns($paths,
'@subpackage', array(implode(
'/', $i < 0 ? $subpackageKeyParts :
568 array_slice($subpackageKeyParts, $i))));
569 $this->
expandPatterns($paths,
'@controller', array($controllerName));
572 if ($formatIsOptional) {
573 $this->
expandPatterns($paths,
'.@format', array(
'.' . $actionRequest->getFormat(),
''));
574 $this->
expandPatterns($paths,
'@format', array($actionRequest->getFormat(),
''));
576 $this->
expandPatterns($paths,
'.@format', array(
'.' . $actionRequest->getFormat()));
577 $this->
expandPatterns($paths,
'@format', array($actionRequest->getFormat()));
579 return array_values(array_unique($paths));
591 protected function expandPatterns(array &$patterns, $search, array $replacements) {
592 $patternsWithReplacements = array();
593 foreach ($patterns as $pattern) {
594 foreach ($replacements as $replacement) {
598 $patterns = $patternsWithReplacements;
610 protected function createIdentifierForFile($pathAndFilename, $prefix) {
612 $actionRequest = $this->controllerContext->getRequest();
613 $extensionName = $actionRequest->getControllerExtensionName();
614 $subPackageKey = $actionRequest->getControllerSubpackageKey();
615 if ($subPackageKey !== NULL) {
616 $extensionName .=
'_' . $subPackageKey;
618 $controllerName = $actionRequest->getControllerName();
619 $templateModifiedTimestamp = filemtime($pathAndFilename);
620 $templateIdentifier = sprintf(
'%s_%s_%s_%s', $extensionName, $controllerName, $prefix, sha1($pathAndFilename .
'|' . $templateModifiedTimestamp));
621 return $templateIdentifier;
setTemplatePathAndFilename($templatePathAndFilename)
$templatePathAndFilenamePattern
getPartialIdentifier($partialName)
setTemplateRootPath($templateRootPath)
getPartialPathAndFilename($partialName)
getTemplateIdentifier($actionName=NULL)
setPartialRootPath($partialRootPath)
canRender(ControllerContext $controllerContext)
setRenderingContext(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
static logDeprecatedFunction()
static makeInstance($className)
const NAMESPACE_SEPARATOR
$partialPathAndFilenamePattern
$layoutPathAndFilenamePattern
resolveFileNamePath($pathAndFilename)
getLayoutPathAndFilename($layoutName='Default')
getLayoutIdentifier($layoutName='Default')
setPartialRootPaths(array $partialRootPaths)
getLayoutSource($layoutName='Default')
static fixWindowsFilePath($theFile)
getPartialSource($partialName)
setLayoutRootPath($layoutRootPath)
setControllerContext(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext)
expandPatterns(array &$patterns, $search, array $replacements)
getTemplateSource($actionName=NULL)
const LEGACY_NAMESPACE_SEPARATOR
setLayoutPathAndFilename($layoutPathAndFilename)
setTemplateRootPaths(array $templateRootPaths)
static getFileAbsFileName($filename, $onlyRelative=TRUE, $relToTYPO3_mainDir=FALSE)
setLayoutRootPaths(array $layoutRootPaths)