/**
  * Public such that it is callable from within closures
  *
  * @param int $uniqueCounter
  * @param \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext
  * @param string $viewHelperName
  * @return \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
  * @internal
  */
 public function getViewHelper($uniqueCounter, \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext, $viewHelperName)
 {
     if (self::$objectContainer === NULL) {
         self::$objectContainer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class);
     }
     if (isset($this->viewHelpersByPositionAndContext[$uniqueCounter])) {
         if ($this->viewHelpersByPositionAndContext[$uniqueCounter]->contains($renderingContext)) {
             $viewHelper = $this->viewHelpersByPositionAndContext[$uniqueCounter][$renderingContext];
             $viewHelper->resetState();
             return $viewHelper;
         } else {
             $viewHelperInstance = self::$objectContainer->getInstance($viewHelperName);
             if ($viewHelperInstance instanceof \TYPO3\CMS\Core\SingletonInterface) {
                 $viewHelperInstance->resetState();
             }
             $this->viewHelpersByPositionAndContext[$uniqueCounter]->attach($renderingContext, $viewHelperInstance);
             return $viewHelperInstance;
         }
     } else {
         $this->viewHelpersByPositionAndContext[$uniqueCounter] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class);
         $viewHelperInstance = self::$objectContainer->getInstance($viewHelperName);
         if ($viewHelperInstance instanceof \TYPO3\CMS\Core\SingletonInterface) {
             $viewHelperInstance->resetState();
         }
         $this->viewHelpersByPositionAndContext[$uniqueCounter]->attach($renderingContext, $viewHelperInstance);
         return $viewHelperInstance;
     }
 }
Ejemplo n.º 2
0
 /**
  * test class TwoConstructorArgumentsBothOptional
  * @test
  */
 public function getInstanceOnTwoOptionalGivesOneArgumentToConstructorIfFirstIsNullAndSecondIsObject()
 {
     $second = new Fixtures\ArgumentTestClass();
     $object = $this->container->getInstance('TYPO3\\CMS\\Extbase\\Tests\\Unit\\Object\\Container\\Fixtures\\TwoConstructorArgumentsBothOptional', array(NULL, $second));
     $this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Tests\\Unit\\Object\\Container\\Fixtures\\TwoConstructorArgumentsBothOptional', $object);
     $this->assertNull($object->argumentTestClass);
     $this->assertSame($second, $object->argumentTestClassTwo);
 }
Ejemplo n.º 3
0
	/**
	 * Returns a fresh or existing instance of the object specified by $objectName.
	 *
	 * @param string $objectName The name of the object to return an instance of
	 * @return object The object instance
	 * @api
	 */
	public function get($objectName) {
		$arguments = func_get_args();
		array_shift($arguments);
		if ($objectName === 'DateTime') {
			array_unshift($arguments, $objectName);
			$instance = call_user_func_array(array(\TYPO3\CMS\Core\Utility\GeneralUtility::class, 'makeInstance'), $arguments);
		} else {
			$instance = $this->objectContainer->getInstance($objectName, $arguments);
		}
		return $instance;
	}
 /**
  * Creates a fresh instance of the object specified by $objectName.
  *
  * This factory method can only create objects of the scope prototype.
  * Singleton objects must be either injected by some type of Dependency Injection or
  * if that is not possible, be retrieved by the get() method of the
  * Object Manager
  *
  * @param string $objectName The name of the object to create
  * @throws Exception\WrongScopeException
  * @return object The new object instance
  * @api
  */
 public function create($objectName)
 {
     $arguments = func_get_args();
     array_shift($arguments);
     if ($objectName === 'DateTime') {
         array_unshift($arguments, $objectName);
         $instance = call_user_func_array(array(\TYPO3\CMS\Core\Utility\GeneralUtility::class, 'makeInstance'), $arguments);
     } else {
         $instance = $this->objectContainer->getInstance($objectName, $arguments);
     }
     if ($instance instanceof \TYPO3\CMS\Core\SingletonInterface) {
         throw new \TYPO3\CMS\Extbase\Object\Exception\WrongScopeException('Object "' . $objectName . '" is of not of scope prototype, but only prototype is supported by create()', 1265203124);
     }
     return $instance;
 }