/**
  * @test
  */
 public function setTypeConverterOptionShouldOverrideAlreadySetOptions()
 {
     $mockTypeConverterClass = $this->getMockClass('TYPO3\\Flow\\Property\\TypeConverterInterface');
     $this->propertyMappingConfiguration->setTypeConverterOptions($mockTypeConverterClass, array('k1' => 'v1', 'k2' => 'v2'));
     $this->propertyMappingConfiguration->setTypeConverterOption($mockTypeConverterClass, 'k1', 'v3');
     $this->assertEquals('v3', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k1'));
     $this->assertEquals('v2', $this->propertyMappingConfiguration->getConfigurationValue($mockTypeConverterClass, 'k2'));
 }
 /**
  * @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);
     }
 }
 /**
  * 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;
 }
예제 #6
0
 /**
  * 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);
     }
 }