/** * Modify the passed $propertyMappingConfiguration according to the $propertyConfiguration which * has been generated by Fluid. In detail, if the $propertyConfiguration contains * an __identity field, we allow modification of objects; else we allow creation. * * All other properties are specified as allowed properties. * * @param array $propertyConfiguration * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration $propertyMappingConfiguration * * @return void */ protected function modifyPropertyMappingConfiguration($propertyConfiguration, \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration $propertyMappingConfiguration) { if (!is_array($propertyConfiguration)) { return; } if (isset($propertyConfiguration['__identity'])) { $propertyMappingConfiguration->setTypeConverterOption(\TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::class, \TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED, true); unset($propertyConfiguration['__identity']); } else { $propertyMappingConfiguration->setTypeConverterOption(\TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::class, \TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED, true); } foreach ($propertyConfiguration as $innerKey => $innerValue) { if (is_array($innerValue)) { $this->modifyPropertyMappingConfiguration($innerValue, $propertyMappingConfiguration->forProperty($innerKey)); } $propertyMappingConfiguration->allowProperties($innerKey); } }
/** * @test */ public function forPropertyWithAsteriskAllowsArbitraryPropertyNamesWithShouldMap() { $this->propertyMappingConfiguration->forProperty('items.*')->setTypeConverterOptions('stdClass', array('k1' => 'v1')); $configuration = $this->propertyMappingConfiguration->forProperty('items'); $this->assertTrue($configuration->shouldMap(6)); }
/** * @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)); }
/** * Configure the property mapper to expect date strings in configured BE format * * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration $propertyMapperDate * @return void */ protected function configurePropertyMapperForDateTimeFormat(\TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration $propertyMapperDate) { $propertyMapperDate->setTypeConverterOption('TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter', \TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT, $this->settings['dateFormat'] . ' ' . $this->settings['timeFormat']); }