/**
  * @test
  */
 public function getTypeConverterReturnsTypeConverterIfItHasBeenSet()
 {
     $mockTypeConverter = $this->getMock('TYPO3\\Flow\\Property\\TypeConverterInterface');
     $this->propertyMappingConfiguration->setTypeConverter($mockTypeConverter);
     $this->assertSame($mockTypeConverter, $this->propertyMappingConfiguration->getTypeConverter());
 }
 /**
  * @param MediaTypeConverterInterface $mediaTypeConverter
  * @return void
  */
 public function injectMediaTypeConverter(MediaTypeConverterInterface $mediaTypeConverter)
 {
     $this->propertyMappingConfiguration = new PropertyMappingConfiguration();
     $this->propertyMappingConfiguration->setTypeConverter($mediaTypeConverter);
 }
示例#3
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'];
 }
 /**
  * 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;
 }
 /**
  * @param PropertyMappingConfiguration $propertyMappingConfiguration
  * @param string $dataType
  * @return boolean
  */
 protected function setTypeConverterForType(PropertyMappingConfiguration $propertyMappingConfiguration, $dataType)
 {
     if (!isset($this->typesConfiguration[$dataType]) || !isset($this->typesConfiguration[$dataType]['typeConverter'])) {
         return false;
     }
     $typeConverter = $this->objectManager->get($this->typesConfiguration[$dataType]['typeConverter']);
     $propertyMappingConfiguration->setTypeConverter($typeConverter);
     $this->setTypeConverterOptionsForType($propertyMappingConfiguration, $this->typesConfiguration[$dataType]['typeConverter'], $dataType);
     return true;
 }