summaryrefslogtreecommitdiffstats
path: root/library/SSRS/Soap/ServerException.php
blob: a11bd57ed4820470e4fb1bd6ed1af34a77431816 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php

namespace SSRS\Soap;

class ServerException extends \Exception {

    public $faultcode;
    public $faultstring;
    public $faultactor;

    static function fromResponse($string) {
        $xml = new \SimpleXMLElement($string);
        $ns = $xml->getNamespaces(true);

        $soap = $xml->children($ns['soap']);
        $body = $soap->Body->children($ns['soap']);
        if (isset($body->Fault)) {
            $fault = $body->Fault->children();

            $exception = new ServerException((string) $fault->faultstring);
            $exception->faultcode = (string) $fault->faultcode;
            $exception->faultstring = (string) $fault->faultstring;
            $exception->faultactor = (string) $fault->faultactor;
        } else {
            throw new Exception('Invalid server response');
        }

        return $exception;
    }

}