eZ\Publish\Core\REST\Common\Input\Handler\Xml::convert PHP Method

convert() public method

Converts the given string to an array structure.
public convert ( string $string ) : array
$string string
return array
    public function convert($string)
    {
        $oldXmlErrorHandling = libxml_use_internal_errors(true);
        libxml_clear_errors();
        $dom = new \DOMDocument();
        $dom->loadXml($string);
        $errors = libxml_get_errors();
        libxml_clear_errors();
        libxml_use_internal_errors($oldXmlErrorHandling);
        if ($errors) {
            $message = "Detected errors in input XML:\n";
            foreach ($errors as $error) {
                $message .= sprintf(" - In line %d character %d: %s\n", $error->line, $error->column, $error->message);
            }
            $message .= "\nIn XML: \n\n" . $string;
            throw new Exceptions\Parser($message);
        }
        return $this->convertDom($dom);
    }

Usage Example

Esempio n. 1
0
 /**
  * @dataProvider getXmlFixtures
  */
 public function testConvertXml($xml, $expectation)
 {
     $handler = new Common\Input\Handler\Xml();
     $this->assertSame($expectation, $handler->convert($xml));
 }