2 namespace TYPO3\CMS\Fluid\View;
138 $this->templateParser = TemplateParserBuilder::build();
195 public function getTemplateRootPaths()
197 if ($this->templateRootPaths !== null) {
201 $actionRequest = $this->controllerContext->getRequest();
202 return array(str_replace(
'@packageResourcesPath',
ExtensionManagementUtility::extPath($actionRequest->getControllerExtensionKey()) .
'Resources/', $this->templateRootPathPattern));
250 protected function getPartialRootPaths()
252 if ($this->partialRootPaths !== null) {
256 $actionRequest = $this->controllerContext->getRequest();
257 return array(str_replace(
'@packageResourcesPath',
ExtensionManagementUtility::extPath($actionRequest->getControllerExtensionKey()) .
'Resources/', $this->partialRootPathPattern));
292 protected function getLayoutRootPaths()
294 if ($this->layoutRootPaths !== null) {
298 $actionRequest = $this->controllerContext->getRequest();
299 return array(str_replace(
'@packageResourcesPath',
ExtensionManagementUtility::extPath($actionRequest->getControllerExtensionKey()) .
'Resources/', $this->layoutRootPathPattern));
312 if ($actionName === null) {
314 $actionRequest = $this->controllerContext->getRequest();
315 $actionName = $actionRequest->getControllerActionName();
317 $prefix =
'action_' . $actionName;
333 if ($templateSource ===
false) {
334 throw new Exception\InvalidTemplateResourceException(
'"' .
$templatePathAndFilename .
'" is not a valid template resource URI.', 1257246929);
336 return $templateSource;
347 protected function getTemplatePathAndFilename($actionName = null)
349 if ($this->templatePathAndFilename !== null) {
352 if ($actionName === null) {
354 $actionRequest = $this->controllerContext->getRequest();
355 $actionName = $actionRequest->getControllerActionName();
358 $paths = $this->expandGenericPathPattern($this->templatePathAndFilenamePattern,
false,
false);
365 throw new Exception\InvalidTemplateResourceException(
'Template could not be loaded. I tried "' . implode(
'", "', $possibleFileNames) .
'"', 1225709595);
378 $prefix =
'layout_' . $layoutName;
398 if ($layoutSource ===
false) {
399 throw new Exception\InvalidTemplateResourceException(
'"' .
$layoutPathAndFilename .
'" is not a valid template resource URI.', 1257246930);
401 return $layoutSource;
418 if ($this->layoutPathAndFilename !== null) {
421 $paths = $this->expandGenericPathPattern($this->layoutPathAndFilenamePattern,
true,
true);
428 throw new Exception\InvalidTemplateResourceException(
'The layout files "' . implode(
'", "', $possibleFileNames) .
'" could not be loaded.', 1225709596);
441 $prefix =
'partial_' . $partialName;
442 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;
471 $paths = $this->expandGenericPathPattern($this->partialPathAndFilenamePattern,
true,
true);
473 foreach ($possibleFileNames as $partialPathAndFilename) {
475 return $partialPathAndFilename;
478 throw new Exception\InvalidTemplateResourceException(
'The partial files "' . implode(
'", "', $possibleFileNames) .
'" could not be loaded.', 1225709597);
492 $possibleFileNames = array();
493 foreach ($paths as $partialPathAndFilename) {
494 $possibleFileNames[] = $this->
resolveFileNamePath(str_replace($marker, $upperCasedTemplateName, $partialPathAndFilename));
495 if ($templateName !== $upperCasedTemplateName) {
496 $possibleFileNames[] = $this->
resolveFileNamePath(str_replace($marker, $templateName, $partialPathAndFilename));
499 return $possibleFileNames;
555 protected function expandGenericPathPattern($pattern, $bubbleControllerAndSubpackage, $formatIsOptional)
557 $paths = array($pattern);
558 $this->
expandPatterns($paths,
'@templateRoot', $this->getTemplateRootPaths());
559 $this->
expandPatterns($paths,
'@partialRoot', $this->getPartialRootPaths());
560 $this->
expandPatterns($paths,
'@layoutRoot', $this->getLayoutRootPaths());
563 $actionRequest = $this->controllerContext->getRequest();
564 $subpackageKey = $actionRequest->getControllerSubpackageKey();
565 $controllerName = $actionRequest->getControllerName();
566 if ($subpackageKey !== null) {
572 $subpackageKeyParts = explode($namespaceSeparator, $subpackageKey);
574 $subpackageKeyParts = array();
576 if ($bubbleControllerAndSubpackage) {
577 $numberOfPathsBeforeSubpackageExpansion = count($paths);
578 $numberOfSubpackageParts = count($subpackageKeyParts);
579 $subpackageReplacements = array();
580 for ($i = 0; $i <= $numberOfSubpackageParts; $i++) {
581 $subpackageReplacements[] = implode(
'/', ($i < 0 ? $subpackageKeyParts : array_slice($subpackageKeyParts, $i)));
583 $this->
expandPatterns($paths,
'@subpackage', $subpackageReplacements);
585 for ($i = ($numberOfPathsBeforeSubpackageExpansion - 1) * ($numberOfSubpackageParts + 1); $i >= 0; $i -= ($numberOfSubpackageParts + 1)) {
586 array_splice($paths, $i, 0, str_replace(
'@controller', $controllerName, $paths[$i]));
590 $i = $controllerName === null ? 0 : -1;
591 $this->
expandPatterns($paths,
'@subpackage', array(implode(
'/', $i < 0 ? $subpackageKeyParts :
592 array_slice($subpackageKeyParts, $i))));
593 $this->
expandPatterns($paths,
'@controller', array($controllerName));
596 if ($formatIsOptional) {
597 $this->
expandPatterns($paths,
'.@format', array(
'.' . $actionRequest->getFormat(),
''));
598 $this->
expandPatterns($paths,
'@format', array($actionRequest->getFormat(),
''));
600 $this->
expandPatterns($paths,
'.@format', array(
'.' . $actionRequest->getFormat()));
601 $this->
expandPatterns($paths,
'@format', array($actionRequest->getFormat()));
603 return array_values(array_unique($paths));
615 protected function expandPatterns(array &$patterns, $search, array $replacements)
617 $patternsWithReplacements = array();
618 foreach ($patterns as $pattern) {
619 foreach ($replacements as $replacement) {
623 $patterns = $patternsWithReplacements;
635 protected function createIdentifierForFile($pathAndFilename, $prefix)
638 $actionRequest = $this->controllerContext->getRequest();
639 $extensionName = $actionRequest->getControllerExtensionName();
640 $subPackageKey = $actionRequest->getControllerSubpackageKey();
641 if ($subPackageKey !== null) {
642 $extensionName .=
'_' . $subPackageKey;
644 $controllerName = $actionRequest->getControllerName();
645 $templateModifiedTimestamp = filemtime($pathAndFilename);
646 $templateIdentifier = sprintf(
'%s_%s_%s_%s', $extensionName, $controllerName, $prefix, sha1($pathAndFilename .
'|' . $templateModifiedTimestamp));
647 return $templateIdentifier;