/** * Parse Request body into array of params. * * @param string $encodedBody Posted content from request. * @return array|null Return NULL if content is invalid. * @throws \InvalidArgumentException * @throws \Magento\Framework\Webapi\Exception If decoding error was encountered. */ public function deserialize($encodedBody) { if (!is_string($encodedBody)) { throw new \InvalidArgumentException(sprintf('"%s" data type is invalid. String is expected.', gettype($encodedBody))); } try { $decodedBody = $this->decoder->decode($encodedBody); } catch (\Zend_Json_Exception $e) { if ($this->_appState->getMode() !== State::MODE_DEVELOPER) { throw new \Magento\Framework\Webapi\Exception(new Phrase('Decoding error.')); } else { throw new \Magento\Framework\Webapi\Exception(new Phrase('Decoding error: %1%2%3%4', [PHP_EOL, $e->getMessage(), PHP_EOL, $e->getTraceAsString()])); } } return $decodedBody; }
/** * Filters parser by language. * * @param \DOMXPath $xpath XPath access to the document parsed. * @param string $rootNodeName Parsing root node. * @param string $nodeName Name of the nodes look up. * @param string $language Language searched. * * @return array */ private function parseFilters(\DOMXPath $xpath, $rootNodeName, $nodeName, $language = 'default') { $filters = []; $languagePath = sprintf("[@language='%s']", $language); $searchPath = sprintf("/%s/%s/%s%s", self::ROOT_NODE_NAME, $rootNodeName, $nodeName, $languagePath); $filterNodes = $xpath->query($searchPath); foreach ($filterNodes as $filterNode) { $filterName = $filterNode->getAttribute('name'); $filter = ['type' => $filterNode->getAttribute('type')]; foreach ($filterNode->childNodes as $childNode) { if ($childNode instanceof \DOMElement) { try { $filter[$childNode->tagName] = $this->jsonDecoder->decode($childNode->nodeValue); } catch (\Exception $e) { $filter[$childNode->tagName] = $childNode->nodeValue; } } } $filters[$filterName] = $filter; } return $filters; }
/** * Get config * * @return array */ public function getConfig() { return $this->jsonDecoder->decode($this->getData(self::CONFIG)); }