eZ\Publish\Core\REST\Common\Input\ParsingDispatcher::parse PHP Method

parse() public method

Parses the given $data according to $mediaType.
public parse ( array $data, string $mediaType ) : eZ\Publish\API\Repository\Values\ValueObject
$data array
$mediaType string
return eZ\Publish\API\Repository\Values\ValueObject
    public function parse(array $data, $mediaType)
    {
        list($mediaType, $version) = $this->parseMediaTypeVersion($mediaType);
        // Remove encoding type
        if (($plusPos = strrpos($mediaType, '+')) !== false) {
            $mediaType = substr($mediaType, 0, $plusPos);
        }
        if (!isset($this->parsers[$mediaType][$version])) {
            throw new Exceptions\Parser("Unknown content type specification: '{$mediaType} (version: {$version})'.");
        }
        return $this->parsers[$mediaType][$version]->parse($data, $this);
    }

Usage Example

 /**
  * Parse provided request.
  *
  * @param \eZ\Publish\Core\REST\Common\Message $message
  *
  * @return mixed
  */
 public function parse(Message $message)
 {
     if (!isset($message->headers['Content-Type'])) {
         throw new Exceptions\Parser('Missing Content-Type header in message.');
     }
     $mediaTypeParts = explode(';', $message->headers['Content-Type']);
     $contentTypeParts = explode('+', $mediaTypeParts[0]);
     if (count($contentTypeParts) !== 2) {
         // TODO expose default format
         $contentTypeParts[1] = 'xml';
     }
     $media = $contentTypeParts[0];
     $format = $contentTypeParts[1];
     if (!isset($this->handlers[$format])) {
         throw new Exceptions\Parser("Unknown format specification: '{$format}'.");
     }
     $rawArray = $this->handlers[$format]->convert($message->body);
     // Only 1 XML root node
     $rootNodeArray = reset($rawArray);
     // @todo: This needs to be refactored in order to make the called URL
     // available to parsers in the server in a sane way
     if (isset($message->headers['Url'])) {
         $rootNodeArray['__url'] = $message->headers['Url'];
     }
     if (isset($message->headers['__publish'])) {
         $rootNodeArray['__publish'] = $message->headers['__publish'];
     }
     return $this->parsingDispatcher->parse($rootNodeArray, $media);
 }
All Usage Examples Of eZ\Publish\Core\REST\Common\Input\ParsingDispatcher::parse