xml = $xml; $this->json = $json; } /** * @param array $array * * @return string */ public function arrayToJson(array $array) { return $this->json->fromArray($array); } /** * @param $jsonString * * @return array */ public function jsonToArray($jsonString) { return $this->json->toArray($jsonString); } /** * @param array $array * @param string $rootNode * * @return string */ public function arrayToXml(array $array, $rootNode = 'xml') { return $this->xml->convertArrayToXmlString($array, $rootNode); } /** * @param string $xmlString * @param bool $wrap * * @return array */ public function xmlToArray($xmlString, $wrap = false) { return $this->xml->convertXmlStringToArray($xmlString, $wrap); } /** * @param string $type * @param array $data * * @return string */ public function arrayTo($type, array $data) { $type = strtolower($type); if (!in_array($type, $this->getSupportedTypes(), true)) { throw new \RuntimeException(sprintf( 'Converter type "%s" is not supported.', $type )); } return $this->{$type}->fromArray($data); } /** * @param string $type * @param string $content * * @return array */ public function toArray($type, $content) { $type = strtolower($type); if (!in_array($type, $this->getSupportedTypes(), true)) { throw new \RuntimeException(sprintf( 'Converter type "%s" is not supported.', $type )); } return $this->{$type}->toArray($content); } /** * @return array */ public function getSupportedTypes() { return self::$validTypes; } }