public static function convert($xmlToParse)
    {
        if (!is_string($xmlToParse)) {
            throw new InvalidArgumentException("XmlToArrayConverter::convert method expects an xml file to parse, or a string containing valid xml");
        }

        $isFile = file_exists($xmlToParse);

        //Empty xml file returns empty array
        if (
            ($isFile && 0 === filesize($xmlToParse))
            or (!$isFile && '' === $xmlToParse)
        ) {
            return [];
        }

        if (
            ($isFile && file_get_contents($xmlToParse, false, null, 0, 1) !== '<')
            or (!$isFile && $xmlToParse[0] !== '<')
        ) {
            throw new InvalidArgumentException('Invalid xml content');
        }

        $currentInternalErrors = libxml_use_internal_errors(true);

        if ($isFile) {
            $xml = simplexml_load_file($xmlToParse);
            if ($xml instanceof SimpleXMLElement) {
                dom_import_simplexml($xml)->ownerDocument->xinclude();
            }
        } else {
            $xml = simplexml_load_string($xmlToParse);
        }

        $errors = libxml_get_errors();

        libxml_clear_errors();
        libxml_use_internal_errors($currentInternalErrors);

        if (count($errors) > 0) {
            throw new XmlParseException($errors);
        }

        $conf = self::simpleXmlToArray($xml);

        return $conf;
    }
public static function convert($xmlToParse)
    {
        if (!is_string($xmlToParse)) {
            throw new InvalidArgumentException("XmlToArrayConverter::convert method expects an xml file to parse, or a string containing valid xml");
        }

        $isFile = file_exists($xmlToParse);

        //Empty xml file returns empty array
        if (
            ($isFile && 0 === filesize($xmlToParse))
            or (!$isFile && '' === $xmlToParse)
        ) {
            return [];
        }

        if (
            ($isFile && file_get_contents($xmlToParse, false, null, 0, 1) !== '<')
            or (!$isFile && $xmlToParse[0] !== '<')
        ) {
            throw new InvalidArgumentException('Invalid xml content');
        }

        $currentInternalErrors = libxml_use_internal_errors(true);

        if ($isFile) {
            $xml = simplexml_load_file($xmlToParse);
            if ($xml instanceof SimpleXMLElement) {
                dom_import_simplexml($xml)->ownerDocument->xinclude();
            }
        } else {
            $xml = simplexml_load_string($xmlToParse);
        }

        $errors = libxml_get_errors();

        libxml_clear_errors();
        libxml_use_internal_errors($currentInternalErrors);

        if (count($errors) > 0) {
            throw new XmlParseException($errors);
        }

        $conf = self::simpleXmlToArray($xml);

        return $conf;
    }
public static function convert ( $ xmlToParse ) { if ( ! is_string ( $ xmlToParse ) ) { throw new InvalidArgumentException ( "XmlToArrayConverter::convert method expects an xml file to parse, or a string containing valid xml" ) ; } $ isFile = file_exists ( $ xmlToParse ) ; //Empty xml file returns empty array if ( ( $ isFile && 0 === filesize ( $ xmlToParse ) ) or ( ! $ isFile && '' === $ xmlToParse ) ) { return [ ] ; } if ( ( $ isFile && file_get_contents ( $ xmlToParse , false , null , 0 , 1 ) !== '<' ) or ( ! $ isFile && $ xmlToParse [ 0 ] !== '<' ) ) { throw new InvalidArgumentException ( 'Invalid xml content' ) ; } $ currentInternalErrors = libxml_use_internal_errors ( true ) ; if ( $ isFile ) { $ xml = simplexml_load_file ( $ xmlToParse ) ; if ( $ xml instanceof SimpleXMLElement ) { dom_import_simplexml ( $ xml ) -> ownerDocument -> xinclude ( ) ; } } else { $ xml = simplexml_load_string ( $ xmlToParse ) ; } $ errors = libxml_get_errors ( ) ; libxml_clear_errors ( ) ; libxml_use_internal_errors ( $ currentInternalErrors ) ; if ( count ( $ errors ) > 0 ) { throw new XmlParseException ( $ errors ) ; } $ conf = self :: simpleXmlToArray ( $ xml ) ; return $ conf ; }
Create a PHP array from the XML file

@param String $xmlToParse The XML file or a string containing xml to parse

@return array

@throws \Propel\Common\Config\Exception\XmlParseException if parse errors occur
Create a PHP array from the XML file