public static function factory(RequestInterface $request, Response $response)
 {
     $e = new self('Not Found');
     $e->setResponse($response);
     $e->setRequest($request);
     return $e;
 }
 public static function fromBadResponseException(BadResponseException $old)
 {
     $new = new self($old->getMessage());
     $new->setRequest($old->getRequest());
     $new->setResponse($old->getResponse());
     return $new;
 }
 public static function factory(BadResponseException $exception)
 {
     $response = $exception->getResponse();
     $message = sprintf("This operation was forbidden; the API returned a %s status code with this message:\n%s", $response->getStatusCode(), (string) $response->getBody());
     $e = new self($message);
     $e->setResponse($response);
     $e->setRequest($exception->getRequest());
     return $e;
 }
 public static function factory(BadResponseException $exception)
 {
     $response = $exception->getResponse();
     $message = sprintf("This resource you were looking for could not be found; the API returned a %s status code with this message:\n%s", $response->getStatusCode(), (string) $response->getBody());
     $e = new self($message);
     $e->setResponse($response);
     $e->setRequest($exception->getRequest());
     return $e;
 }
 public static function factory(RequestInterface $request, Response $response)
 {
     if ($response->isClientError()) {
         $label = 'Client error response';
         $class = __NAMESPACE__ . '\\ClientErrorResponseException';
     } elseif ($response->isServerError()) {
         $label = 'Server error response';
         $class = __NAMESPACE__ . '\\ServerErrorResponseException';
     } else {
         $label = 'Unsuccessful response';
         $class = __CLASS__;
     }
     $message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
     $e = new self($message);
     $e->setResponse($response);
     $e->setRequest($request);
     return $e;
 }
Example #6
0
 /**
  * Create a new extraneous context. The context is filled with information
  * external to the current session.
  * - Title is specified by argument
  * - Request is a FauxRequest, or a FauxRequest can be specified by argument
  * - User is an anonymous user, for separation IPv4 localhost is used
  * - Language will be based on the anonymous user and request, may be content
  *   language or a uselang param in the fauxrequest data may change the lang
  * - Skin will be based on the anonymous user, should be the wiki's default skin
  *
  * @param Title $title Title to use for the extraneous request
  * @param WebRequest|array $request A WebRequest or data to use for a FauxRequest
  * @return RequestContext
  */
 public static function newExtraneousContext(Title $title, $request = [])
 {
     $context = new self();
     $context->setTitle($title);
     if ($request instanceof WebRequest) {
         $context->setRequest($request);
     } else {
         $context->setRequest(new FauxRequest($request));
     }
     $context->user = User::newFromName('127.0.0.1', false);
     return $context;
 }