/** * @test */ public function getTypeOfChildPropertyImmediatelyReturnsConfiguredTargetTypeIfSetSo() { $propertyName = 'somePropertyName'; $expectedTargetType = 'someExpectedTargetType'; $configuration = new PropertyMappingConfiguration(); $configuration->forProperty($propertyName)->setTypeConverterOption(\TYPO3\Flow\Property\TypeConverter\ObjectConverter::class, ObjectConverter::CONFIGURATION_TARGET_TYPE, $expectedTargetType); $actual = $this->converter->getTypeOfChildProperty('irrelevant', $propertyName, $configuration); $this->assertEquals($expectedTargetType, $actual); }
/** * @test */ public function convertFromReturnsNullIfResourcePropertyIsNotConverted() { $this->mockObjectManager->expects($this->any())->method('getClassNameByObjectName')->will($this->returnCallback(function ($objectType) { return $objectType; })); $configuration = new PropertyMappingConfiguration(); $configuration->setTypeConverterOption(ImageInterfaceConverter::class, PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED, true); $this->assertNull($this->converter->convertFrom(array(), Image::class, array(), $configuration)); }
/** * @param HttpRequest $httpRequest * @param array $routingMatchResults * @return array */ protected function mergeArguments(HttpRequest $httpRequest, array $routingMatchResults = NULL) { // HTTP body arguments $this->propertyMappingConfiguration->setTypeConverterOption(\TYPO3\Flow\Property\TypeConverter\MediaTypeConverterInterface::class, MediaTypeConverterInterface::CONFIGURATION_MEDIA_TYPE, $httpRequest->getHeader('Content-Type')); $arguments = $this->propertyMapper->convert($httpRequest->getContent(), 'array', $this->propertyMappingConfiguration); // HTTP arguments (e.g. GET parameters) $arguments = Arrays::arrayMergeRecursiveOverrule($httpRequest->getArguments(), $arguments); // Routing results if ($routingMatchResults !== NULL) { $arguments = Arrays::arrayMergeRecursiveOverrule($arguments, $routingMatchResults); } return $arguments; }
/** * 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\Flow\Property\PropertyMappingConfiguration $propertyMappingConfiguration * @return void */ protected function modifyPropertyMappingConfiguration($propertyConfiguration, \TYPO3\Flow\Property\PropertyMappingConfiguration $propertyMappingConfiguration) { if (!is_array($propertyConfiguration)) { return; } if (isset($propertyConfiguration['__identity'])) { $propertyMappingConfiguration->setTypeConverterOption('TYPO3\\Flow\\Property\\TypeConverter\\PersistentObjectConverter', \TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED, TRUE); unset($propertyConfiguration['__identity']); } else { $propertyMappingConfiguration->setTypeConverterOption('TYPO3\\Flow\\Property\\TypeConverter\\PersistentObjectConverter', \TYPO3\Flow\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 unknownNodePropertiesAreSkippedIfTypeConverterIsConfiguredLikeThis() { $this->setupNodeWithShadowNodeInPersonalWorkspace(); $input = array('__contextNodePath' => '/headline@' . $this->currentTestWorkspaceName, 'title' => 'New title', 'non-existing-input' => 'test'); $propertyMappingConfiguration = new PropertyMappingConfiguration(); $propertyMappingConfiguration->skipUnknownProperties(); $headlineNode = $this->convert($input, $propertyMappingConfiguration); $this->assertSame('New title', $headlineNode->getProperty('title')); $this->assertSame('Brave new world', $headlineNode->getProperty('subtitle')); $this->assertFalse($headlineNode->hasProperty('non-existing-input')); }
/** * @param array $typeConverterOptions * @return PropertyMappingConfiguration */ protected function buildConfiguration($typeConverterOptions) { $configuration = new PropertyMappingConfiguration(); $configuration->setTypeConverterOptions(\TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::class, $typeConverterOptions); return $configuration; }
/** * @test */ public function forPropertyWithAsteriskAllowsArbitraryPropertyNamesWithShouldMap() { $this->propertyMappingConfiguration->forProperty('items.*')->setTypeConverterOptions('stdClass', array('k1' => 'v1')); $configuration = $this->propertyMappingConfiguration->forProperty('items'); $this->assertTrue($configuration->shouldMap(6)); }
/** * Parses the request body according to the media type. * * @param HttpRequest $httpRequest * @return array */ protected function parseRequestBody(HttpRequest $httpRequest) { $requestBody = $httpRequest->getContent(); if ($requestBody === null || $requestBody === '') { return []; } $mediaTypeConverter = $this->objectManager->get(MediaTypeConverterInterface::class); $propertyMappingConfiguration = new PropertyMappingConfiguration(); $propertyMappingConfiguration->setTypeConverter($mediaTypeConverter); $propertyMappingConfiguration->setTypeConverterOption(MediaTypeConverterInterface::class, MediaTypeConverterInterface::CONFIGURATION_MEDIA_TYPE, $httpRequest->getHeader('Content-Type')); $arguments = $this->propertyMapper->convert($requestBody, 'array', $propertyMappingConfiguration); return $arguments; }
/** * The content of the HTTP request is provided as json in a * jsonapi.org structure. * * @return mixed * @throws \TYPO3\Flow\Http\Exception */ protected function extractRequestBody() { $propertyMappingConfiguration = new PropertyMappingConfiguration(); $propertyMappingConfiguration->setTypeConverter($this->objectManager->get(MediaTypeConverterInterface::class)); $propertyMappingConfiguration->setTypeConverterOption(MediaTypeConverterInterface::class, MediaTypeConverterInterface::CONFIGURATION_MEDIA_TYPE, 'application/json'); $result = $this->objectManager->get(PropertyMapper::class)->convert($this->request->getHttpRequest()->getContent(), 'array', $propertyMappingConfiguration); return $result['data']; }
/** * @param PropertyMappingConfiguration $propertyMappingConfiguration * @param string $typeConverterClass * @param string $dataType * @return void */ protected function setTypeConverterOptionsForType(PropertyMappingConfiguration $propertyMappingConfiguration, $typeConverterClass, $dataType) { if (!isset($this->typesConfiguration[$dataType]['typeConverterOptions']) || !is_array($this->typesConfiguration[$dataType]['typeConverterOptions'])) { return; } foreach ($this->typesConfiguration[$dataType]['typeConverterOptions'] as $option => $value) { $propertyMappingConfiguration->setTypeConverterOption($typeConverterClass, $option, $value); } }