src/Decoder.php
public function decodeResponse($URI)
    {
        if (!is_string($URI)) {
            throw new \InvalidArgumentException('A string was expected');
        }

        $error  = null;
        $reader = $this->getReader($URI, false);
        $ldel = libxml_disable_entity_loader(true);
        $luie = libxml_use_internal_errors(true);
        libxml_clear_errors();
        try {
            $this->expectStartTag($reader, 'methodResponse');
            try {
                // Try to parse a successful response first.
                $this->expectStartTag($reader, 'params');
                $this->expectStartTag($reader, 'param');
                $this->expectStartTag($reader, 'value');
                $response = $this->decodeValue($reader);
                $this->expectEndTag($reader, 'value');
                $this->expectEndTag($reader, 'param');
                $this->expectEndTag($reader, 'params');
            } catch (\InvalidArgumentException $error) {
                // Try to parse a fault instead.
                $this->expectStartTag($reader, 'fault');
                $this->expectStartTag($reader, 'value');

                $response = $this->decodeValue($reader);
                if (!($response instanceof \fpoirotte\XRL\Types\Struct) ||
                    count($response) != 2) {
                    throw new \UnexpectedValueException(
                        'An associative array with exactly '.
                        'two entries was expected'
                    );
                }

                if (!isset($response['faultCode'])) {
                    throw new \DomainException('The failure lacks a faultCode');
                }

                if (!isset($response['faultString'])) {
                    throw new \DomainException('The failure lacks a faultString');
                }

                $this->expectEndTag($reader, 'value');
                $this->expectEndTag($reader, 'fault');
            }
            $this->expectEndTag($reader, 'methodResponse');

            $endOfFile = null;
            try {
                $this->readNode($reader);
            } catch (\InvalidArgumentException $endOfFile) {
            }

            if (!$endOfFile) {
                throw new \InvalidArgumentException('Expected end of document');
            }

            if ($error) {
                throw new \fpoirotte\XRL\Exception(
                    (string) $response['faultString'],
                    $response['faultCode']->get()
                );
            }

            libxml_disable_entity_loader($ldel);
            libxml_clear_errors();
            libxml_use_internal_errors($luie);
            return $response;
        } catch (\Exception $e) {
            libxml_disable_entity_loader($ldel);
            libxml_clear_errors();
            libxml_use_internal_errors($luie);
            throw $e;
        }
    }
public function decodeResponse($URI)
    {
        if (!is_string($URI)) {
            throw new \InvalidArgumentException('A string was expected');
        }

        $error  = null;
        $reader = $this->getReader($URI, false);
        $ldel = libxml_disable_entity_loader(true);
        $luie = libxml_use_internal_errors(true);
        libxml_clear_errors();
        try {
            $this->expectStartTag($reader, 'methodResponse');
            try {
                // Try to parse a successful response first.
                $this->expectStartTag($reader, 'params');
                $this->expectStartTag($reader, 'param');
                $this->expectStartTag($reader, 'value');
                $response = $this->decodeValue($reader);
                $this->expectEndTag($reader, 'value');
                $this->expectEndTag($reader, 'param');
                $this->expectEndTag($reader, 'params');
            } catch (\InvalidArgumentException $error) {
                // Try to parse a fault instead.
                $this->expectStartTag($reader, 'fault');
                $this->expectStartTag($reader, 'value');

                $response = $this->decodeValue($reader);
                if (!($response instanceof \fpoirotte\XRL\Types\Struct) ||
                    count($response) != 2) {
                    throw new \UnexpectedValueException(
                        'An associative array with exactly '.
                        'two entries was expected'
                    );
                }

                if (!isset($response['faultCode'])) {
                    throw new \DomainException('The failure lacks a faultCode');
                }

                if (!isset($response['faultString'])) {
                    throw new \DomainException('The failure lacks a faultString');
                }

                $this->expectEndTag($reader, 'value');
                $this->expectEndTag($reader, 'fault');
            }
            $this->expectEndTag($reader, 'methodResponse');

            $endOfFile = null;
            try {
                $this->readNode($reader);
            } catch (\InvalidArgumentException $endOfFile) {
            }

            if (!$endOfFile) {
                throw new \InvalidArgumentException('Expected end of document');
            }

            if ($error) {
                throw new \fpoirotte\XRL\Exception(
                    (string) $response['faultString'],
                    $response['faultCode']->get()
                );
            }

            libxml_disable_entity_loader($ldel);
            libxml_clear_errors();
            libxml_use_internal_errors($luie);
            return $response;
        } catch (\Exception $e) {
            libxml_disable_entity_loader($ldel);
            libxml_clear_errors();
            libxml_use_internal_errors($luie);
            throw $e;
        }
    }
/ \copydoc fpoirotte::XRL::DecoderInterface::decodeResponse()