/**
  * 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
 /**
  * @return void
  */
 protected function prepareRequestInformationMock()
 {
     $this->getMockBuilder('PunktDe\\PtExtbase\\Utility\\RequestInformation')->setMethods(array('getCurrentRequestId'))->setMockClassName('RequestInformationMock')->getMock();
     $requestInformationMock = $this->objectManager->get('RequestInformationMock');
     $requestInformationMock->expects($this->any())->method('getCurrentRequestId')->will($this->returnValue('CongratulationsThisIsRequestNumber1000000'));
     $this->objectContainer->registerImplementation('PunktDe\\PtExtbase\\Utility\\RequestInformation', 'RequestInformationMock');
 }
 /**
  * @return void
  */
 protected function prepareProxy()
 {
     $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
     $this->objectContainer = $objectManager->get('TYPO3\\CMS\\Extbase\\Object\\Container\\Container');
     /** @var \TYPO3\CMS\Extbase\Object\Container\Container $objectContainer */
     $this->getMockBuilder(\PunktDe\PtExtbase\Logger\Logger::class)->setMockClassName('LoggerMock')->getMock();
     $objectManager->get('LoggerMock');
     /** @var  $loggerMock \PHPUnit_Framework_MockObject_MockObject */
     $this->objectContainer->registerImplementation(\PunktDe\PtExtbase\Logger\Logger::class, 'LoggerMock');
     $this->getMockBuilder('PunktDe\\PtExtbase\\Utility\\ShellCommandService')->setMethods(array('execute'))->setMockClassName('ShellCommandServiceMock')->getMock();
     $this->shellCommandServiceMock = $objectManager->get('ShellCommandServiceMock');
     /** @var  $shellCommandServiceMock \PHPUnit_Framework_MockObject_MockObject */
     $this->objectContainer->registerImplementation('PunktDe\\PtExtbase\\Utility\\ShellCommandService', 'ShellCommandServiceMock');
     $proxyClass = $this->buildAccessibleProxy('PunktDe\\PtExtbase\\Utility\\Varnish\\VarnishAdministration');
     $this->proxy = $objectManager->get($proxyClass, '/usr/bin/varnishadm');
 }
Ejemplo n.º 4
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);
 }
 /**
  * @return void
  */
 protected function prepareProxy()
 {
     $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
     $this->objectContainer = $objectManager->get('TYPO3\\CMS\\Extbase\\Object\\Container\\Container');
     /** @var \TYPO3\CMS\Extbase\Object\Container\Container $objectContainer */
     $this->getMockBuilder('\\Tx_PtExtbase_Logger_Logger')->setMockClassName('LoggerMock')->getMock();
     $objectManager->get('LoggerMock');
     /** @var  $loggerMock \PHPUnit_Framework_MockObject_MockObject */
     $this->objectContainer->registerImplementation('\\Tx_PtExtbase_Logger_Logger', 'LoggerMock');
     $this->getMockBuilder('PunktDe\\PtExtbase\\Utility\\ShellCommandService')->setMethods(array('execute'))->setMockClassName('ShellCommandServiceMock')->getMock();
     $this->shellCommandServiceMock = $objectManager->get('ShellCommandServiceMock');
     /** @var  $shellCommandServiceMock \PHPUnit_Framework_MockObject_MockObject */
     $this->objectContainer->registerImplementation('PunktDe\\PtExtbase\\Utility\\ShellCommandService', 'ShellCommandServiceMock');
     $proxyClass = $this->buildAccessibleProxy('PunktDe\\PtExtbase\\Utility\\Git\\GitRepository');
     $this->getMockBuilder($proxyClass)->setMethods(array('initializeObject'))->setMockClassName('GitRepositoryMock')->getMock();
     $this->proxy = $objectManager->get('GitRepositoryMock', '/usr/bin/git', '~');
 }
Ejemplo n.º 6
0
 /**
  * @test
  */
 public function getTypeOfChildPropertyShouldUseReflectionServiceToDetermineType()
 {
     $this->mockReflectionService->expects($this->any())->method('hasMethod')->with('TheTargetType', 'setThePropertyName')->will($this->returnValue(false));
     $this->mockReflectionService->expects($this->any())->method('getMethodParameters')->with('TheTargetType', '__construct')->will($this->returnValue(array('thePropertyName' => array('type' => 'TheTypeOfSubObject', 'elementType' => null))));
     $this->mockContainer->expects($this->any())->method('getImplementationClassName')->will($this->returnValue('TheTargetType'));
     $configuration = new PropertyMappingConfiguration();
     $configuration->setTypeConverterOptions(\TYPO3\CMS\Extbase\Property\TypeConverter\ObjectConverter::class, array());
     $this->assertEquals('TheTypeOfSubObject', $this->converter->getTypeOfChildProperty('TheTargetType', 'thePropertyName', $configuration));
 }
Ejemplo n.º 7
0
 /**
  * @return $this
  */
 public function initializeReplacementImplementations()
 {
     $this->objectContainer->registerImplementation('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface', 'FluidTYPO3\\Development\\NullConfigurationManager');
     $this->objectContainer->registerImplementation('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface', 'FluidTYPO3\\Development\\NullPersistenceManager');
     $this->objectContainer->registerImplementation('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\BackendInterface', 'FluidTYPO3\\Development\\NullPersistenceBackend');
     $this->objectContainer->registerImplementation('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface', 'TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Query');
     $this->objectContainer->registerImplementation('TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface', 'TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryResult');
     $this->objectContainer->registerImplementation('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface', 'TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');
     return $this;
 }
Ejemplo n.º 8
0
 /**
  * @return void
  */
 protected function prepareProxy()
 {
     $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
     $this->objectContainer = $objectManager->get('TYPO3\\CMS\\Extbase\\Object\\Container\\Container');
     /** @var \TYPO3\CMS\Extbase\Object\Container\Container $objectContainer */
     $this->getMockBuilder(\PunktDe\PtExtbase\Logger\Logger::class)->setMockClassName('LoggerMock')->getMock();
     $objectManager->get('LoggerMock');
     /** @var  $loggerMock \PHPUnit_Framework_MockObject_MockObject */
     $this->objectContainer->registerImplementation(\PunktDe\PtExtbase\Logger\Logger::class, 'LoggerMock');
     $this->proxy = $objectManager->get('PunktDe\\PtExtbase\\Utility\\Git\\GitRepository', $this->pathToGitCommand, $this->repositoryRootPath);
     $this->remoteProxy = $objectManager->get('PunktDe\\PtExtbase\\Utility\\Git\\GitRepository', $this->pathToGitCommand, $this->remoteRepositoryRootPath);
 }
 /**
  * @test
  * @expectedException \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException
  */
 public function convertFromShouldThrowExceptionIfRequiredConstructorParameterWasNotFound()
 {
     $source = array('propertyX' => 'bar');
     $object = new \TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor('param1');
     $convertedChildProperties = array('property2' => 'bar');
     $this->mockReflectionService->expects($this->any())->method('getMethodParameters')->with(\TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor::class, '__construct')->will($this->returnValue(array('property1' => array('optional' => false))));
     $this->mockReflectionService->expects($this->any())->method('hasMethod')->with(\TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor::class, '__construct')->will($this->returnValue(true));
     $this->mockContainer->expects($this->any())->method('getImplementationClassName')->will($this->returnValue(\TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor::class));
     $configuration = $this->buildConfiguration(array(PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED => true));
     $result = $this->converter->convertFrom($source, \TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor::class, $convertedChildProperties, $configuration);
     $this->assertSame($object, $result);
 }
 /**
  * Unserialize an object
  *
  * @param string $str
  * @return object
  */
 public function unserialize($str)
 {
     $o = unserialize($str);
     $className = $o['className'];
     $object = $this->objectContainer->getEmptyObject($className);
     foreach ($o['properties'] as $property => $value) {
         if (method_exists($object, 'set' . ucfirst($property))) {
             call_user_func(array($object, 'set' . ucfirst($property)), $value);
         }
     }
     return $object;
 }
Ejemplo n.º 11
0
	/**
	 * Builds a new instance of $objectType with the given $possibleConstructorArgumentValues. If
	 * constructor argument values are missing from the given array the method
	 * looks for a default value in the constructor signature. Furthermore, the constructor arguments are removed from $possibleConstructorArgumentValues
	 *
	 * @param array &$possibleConstructorArgumentValues
	 * @param string $objectType
	 * @return object The created instance
	 * @throws \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException if a required constructor argument is missing
	 */
	protected function buildObject(array &$possibleConstructorArgumentValues, $objectType) {
		$specificObjectType = $this->objectContainer->getImplementationClassName($objectType);
		if ($this->reflectionService->hasMethod($specificObjectType, '__construct')) {
			$constructorSignature = $this->reflectionService->getMethodParameters($specificObjectType, '__construct');
			$constructorArguments = array();
			foreach ($constructorSignature as $constructorArgumentName => $constructorArgumentInformation) {
				if (array_key_exists($constructorArgumentName, $possibleConstructorArgumentValues)) {
					$constructorArguments[] = $possibleConstructorArgumentValues[$constructorArgumentName];
					unset($possibleConstructorArgumentValues[$constructorArgumentName]);
				} elseif ($constructorArgumentInformation['optional'] === TRUE) {
					$constructorArguments[] = $constructorArgumentInformation['defaultValue'];
				} else {
					throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException('Missing constructor argument "' . $constructorArgumentName . '" for object of type "' . $objectType . '".', 1268734872);
				}
			}
			return call_user_func_array(array($this->objectManager, 'get'), array_merge(array($objectType), $constructorArguments));
		} else {
			return $this->objectManager->get($objectType);
		}
	}
 /**
  * Create an instance of $className without calling its constructor
  *
  * @param string $className
  * @return object
  * @api
  */
 public function getEmptyObject($className)
 {
     return $this->objectContainer->getEmptyObject($className);
 }