TYPO3 CMS  TYPO3_6-2
AbstractCompiledTemplate.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
19 
23  protected $viewHelpersByPositionAndContext = array();
24 
25  // These tokens are replaced by the Backporter for implementing different behavior in TYPO3 v4
29  static protected $objectContainer;
30 
34  static protected $defaultEncoding = NULL;
35 
45  public function getViewHelper($uniqueCounter, \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext, $viewHelperName) {
46  if (self::$objectContainer === NULL) {
47  self::$objectContainer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\Container\\Container');
48  }
49  if (isset($this->viewHelpersByPositionAndContext[$uniqueCounter])) {
50  if ($this->viewHelpersByPositionAndContext[$uniqueCounter]->contains($renderingContext)) {
51  $viewHelper = $this->viewHelpersByPositionAndContext[$uniqueCounter][$renderingContext];
52  $viewHelper->resetState();
53  return $viewHelper;
54  } else {
55  $viewHelperInstance = self::$objectContainer->getInstance($viewHelperName);
56  if ($viewHelperInstance instanceof \TYPO3\CMS\Core\SingletonInterface) {
57  $viewHelperInstance->resetState();
58  }
59  $this->viewHelpersByPositionAndContext[$uniqueCounter]->attach($renderingContext, $viewHelperInstance);
60  return $viewHelperInstance;
61  }
62  } else {
63  $this->viewHelpersByPositionAndContext[$uniqueCounter] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage');
64  $viewHelperInstance = self::$objectContainer->getInstance($viewHelperName);
65  if ($viewHelperInstance instanceof \TYPO3\CMS\Core\SingletonInterface) {
66  $viewHelperInstance->resetState();
67  }
68  $this->viewHelpersByPositionAndContext[$uniqueCounter]->attach($renderingContext, $viewHelperInstance);
69  return $viewHelperInstance;
70  }
71  }
72 
76  public function isCompilable() {
77  return FALSE;
78  }
79 
83  public function isCompiled() {
84  return TRUE;
85  }
86 
91  static public function resolveDefaultEncoding() {
92  if (static::$defaultEncoding === NULL) {
93  static::$defaultEncoding = 'UTF-8';
94  }
95  return static::$defaultEncoding;
96  }
97 }
getViewHelper($uniqueCounter, \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext, $viewHelperName)