]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - extlib/libomb/remoteserviceexception.php
Update to last upstream version of libomb: coding style updates, static call fix...
[quix0rs-gnu-social.git] / extlib / libomb / remoteserviceexception.php
1 <?php
2 /**
3  * This file is part of libomb
4  *
5  * PHP version 5
6  *
7  * LICENSE: This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  * @package OMB
21  * @author  Adrian Lang <mail@adrianlang.de>
22  * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
23  * @version 0.1a-20090828
24  * @link    http://adrianlang.de/libomb
25  */
26
27 /**
28  * Exception stating that the remote service had a failure
29  *
30  * This exception is raised when a remote service failed to return a valid
31  * response to a request or send a valid request.
32  */
33 class OMB_RemoteServiceException extends Exception
34 {
35     /**
36      * Create exception from Yadis response
37      *
38      * Creates an exception from a passed yadis result.
39      *
40      * @param string                  $request_uri The target URI for the failed
41      *                                             request
42      * @param Auth_Yadis_HTTPResponse $result      The result of the failed
43      *                                             request
44      *
45      * @return OMB_RemoteServiceException A new exception
46      */
47     public static function fromYadis($request_uri, $result)
48     {
49         if ($result->status == 200) {
50             $err = 'Got wrong response ' . $result->body;
51         } else {
52             $err = 'Got error code ' . $result->status . ' with response ' .
53                    $result->body;
54         }
55         return OMB_RemoteServiceException::forRequest($request_uri, $err);
56     }
57
58     /**
59      * Create exception for a call to a resource
60      *
61      * Creates an exception for a given error message and target URI.
62      *
63      * @param string $action_uri The target URI for the failed request
64      * @param string $failure    An error message
65      *
66      * @return OMB_RemoteServiceException A new exception
67      */
68     public static function forRequest($action_uri, $failure)
69     {
70         return new OMB_RemoteServiceException("Handler for $action_uri: $failure");
71     }
72 }
73 ?>