/**
  * Creates Fluid's temporary directory - or at least asserts that it exists and is
  * writable.
  *
  * @param string $temporaryDirectoryBase Full path to the base for the temporary directory
  * @return string The full path to the temporary directory
  * @throws \TYPO3\Fluid\Utility\Exception if the temporary directory could not be created or is not writable
  */
 protected function createTemporaryDirectory($temporaryDirectoryBase)
 {
     $temporaryDirectoryBase = \TYPO3\Fluid\Utility\Files::getUnixStylePath($temporaryDirectoryBase);
     if (substr($temporaryDirectoryBase, -1, 1) !== '/') {
         $temporaryDirectoryBase .= '/';
     }
     $temporaryDirectory = $temporaryDirectoryBase . str_replace('/', '/SubContext', (string) $this->context) . '/';
     if (!is_dir($temporaryDirectory) && !is_link($temporaryDirectory)) {
         try {
             \TYPO3\Fluid\Utility\Files::createDirectoryRecursively($temporaryDirectory);
         } catch (\TYPO3\Flow\Error\Exception $exception) {
             throw new \TYPO3\Flow\Utility\Exception('The temporary directory "' . $temporaryDirectory . '" could not be created. Please make sure permissions are correct for this path or define another temporary directory in your Settings.yaml with the path "TYPO3.Flow.utility.environment.temporaryDirectoryBase".', 1335382361);
         }
     }
     if (!is_writable($temporaryDirectory)) {
         throw new \TYPO3\Fluid\Utility\Exception('The temporary directory "' . $temporaryDirectory . '" is not writable. Please make this directory writable or define another temporary directory in your Settings.yaml with the path "TYPO3.Flow.utility.environment.temporaryDirectoryBase".', 1216287176);
     }
     return $temporaryDirectory;
 }
 /**
  * Sets a reference to the cache frontend which uses this backend and
  * initializes the default cache directory.
  *
  * @param \TYPO3\Fluid\Cache\Frontend\FrontendInterface $cache The cache frontend
  * @return void
  * @throws \TYPO3\Fluid\Cache\Exception
  */
 public function setCache(FrontendInterface $cache)
 {
     parent::setCache($cache);
     $codeOrData = $cache instanceof PhpFrontend ? 'Code' : 'Data';
     $cacheDirectory = $this->environment->getPathToTemporaryDirectory() . 'Cache/' . $codeOrData . '/' . $this->cacheIdentifier . '/';
     if (!is_writable($cacheDirectory)) {
         try {
             \TYPO3\Fluid\Utility\Files::createDirectoryRecursively($cacheDirectory);
         } catch (\TYPO3\Fluid\Utility\Exception $exception) {
             throw new \TYPO3\Fluid\Cache\Exception('The cache directory "' . $cacheDirectory . '" could not be created.', 1264426237);
         }
     }
     if (!is_dir($cacheDirectory) && !is_link($cacheDirectory)) {
         throw new \TYPO3\Fluid\Cache\Exception('The cache directory "' . $cacheDirectory . '" does not exist.', 1203965199);
     }
     if (!is_writable($cacheDirectory)) {
         throw new \TYPO3\Fluid\Cache\Exception('The cache directory "' . $cacheDirectory . '" is not writable.', 1203965200);
     }
     $this->cacheDirectory = $cacheDirectory;
     $this->cacheEntryFileExtension = $cache instanceof PhpFrontend ? '.php' : '';
     if (strlen($this->cacheDirectory) + 23 > $this->environment->getMaximumPathLength()) {
         throw new \TYPO3\Fluid\Cache\Exception('The length of the temporary cache path "' . $this->cacheDirectory . '" exceeds the maximum path length of ' . ($this->environment->getMaximumPathLength() - 23) . '. Please consider setting the temporaryDirectoryBase option to a shorter path. ', 1248710426);
     }
 }
 /**
  * Processes "@templateRoot", "@subpackage", "@controller", and "@format" placeholders inside $pattern.
  * 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.
  *
  * @param string $pattern Pattern to be resolved
  * @param boolean $bubbleControllerAndSubpackage if TRUE, then we successively split off parts from "@controller" and "@subpackage" until both are empty.
  * @param boolean $formatIsOptional if TRUE, then half of the resulting strings will have ."@format" stripped off, and the other half will have it.
  * @return array unix style path
  */
 protected function expandGenericPathPattern($pattern, $bubbleControllerAndSubpackage, $formatIsOptional)
 {
     $pattern = str_replace('@templateRoot', $this->getTemplateRootPath(), $pattern);
     $pattern = str_replace('@partialRoot', $this->getPartialRootPath(), $pattern);
     $pattern = str_replace('@layoutRoot', $this->getLayoutRootPath(), $pattern);
     $controllerName = $this->templateContext->getControllerName();
     $subpackageParts = $subpackageKey !== NULL ? explode(\TYPO3\Fluid\Fluid::NAMESPACE_SEPARATOR, $subpackageKey) : array();
     $results = array();
     $i = $controllerName === NULL ? 0 : -1;
     do {
         $temporaryPattern = $pattern;
         if ($i < 0) {
             $temporaryPattern = str_replace('@controller', $controllerName, $temporaryPattern);
         } else {
             $temporaryPattern = str_replace('//', '/', str_replace('@controller', '', $temporaryPattern));
         }
         $temporaryPattern = str_replace('@subpackage', implode('/', $i < 0 ? $subpackageParts : array_slice($subpackageParts, $i)), $temporaryPattern);
         $results[] = \TYPO3\Fluid\Utility\Files::getUnixStylePath(str_replace('@format', $this->templateContext->getFormat(), $temporaryPattern));
         if ($formatIsOptional) {
             $results[] = \TYPO3\Fluid\Utility\Files::getUnixStylePath(str_replace('.@format', '', $temporaryPattern));
         }
     } while ($i++ < count($subpackageParts) && $bubbleControllerAndSubpackage);
     return $results;
 }
 /**
  * Resolve the path and file name of the layout file, based on
  * $this->layoutPathAndFilename and $this->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.
  *
  * @param string $layoutName Name of the layout to use. If none given, use "Default"
  * @return string contents of the layout template
  * @throws \TYPO3\Fluid\View\Exception\InvalidTemplateResourceException
  */
 protected function getLayoutSource($layoutName = 'Default')
 {
     $layoutPathAndFilename = $this->getLayoutPathAndFilename($layoutName);
     $layoutSource = \TYPO3\FLuid\Utility\Files::getFileContents($layoutPathAndFilename, FILE_TEXT);
     if ($layoutSource === FALSE) {
         throw new \TYPO3\Fluid\View\Exception\InvalidTemplateResourceException('"' . $layoutPathAndFilename . '" is not a valid template resource URI.', 1257246929);
     }
     return $layoutSource;
 }