ApplicationException.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
11 namespace wcmf\lib\presentation;
12 
16 
17 /**
18  * ApplicationException signals a general application exception.
19  *
20  * @author ingo herwig <ingo@wemove.com>
21  */
22 class ApplicationException extends \Exception {
23 
24  private $request = null;
25  private $response = null;
26  private $error = null;
27 
28  /**
29  * Constructor
30  * @param $request The current request
31  * @param $response The current response
32  * @param $error An ApplicationError instance
33  */
34  public function __construct(Request $request, Response $response,
35  ApplicationError $error) {
36 
37  // set status code on response
38  $response->setStatus($error->getStatusCode());
39 
40  $this->request = $request;
41  $this->response = $response;
42  $this->error = $error;
43 
44  parent::__construct($error->getMessage());
45  }
46 
47  /**
48  * Get the current request
49  * @return The Request instance
50  */
51  public function getRequest() {
52  return $this->request;
53  }
54 
55  /**
56  * Get the current response
57  * @return The Response instance
58  */
59  public function getResponse() {
60  return $this->response;
61  }
62 
63  /**
64  * Get the error
65  * @return The ApplicationError instance
66  */
67  public function getError() {
68  return $this->error;
69  }
70 
71  /**
72  * Get a string representation of the exception
73  * @return String
74  */
75  public function __toString() {
76  $str = $this->error->__toString().", ";
77  if ($this->request) {
78  $str .= "Request: ".$this->request->__toString().", ";
79  }
80  if ($this->response) {
81  $str .= "Response: ".$this->response->__toString().", ";
82  }
83  $str .= "\n".parent::getTraceAsString();
84  return $str;
85  }
86 }
87 ?>
Response holds the response values that are used as output from Controller instances.
Definition: Response.php:20
Request holds the request values that are used as input to Controller instances.
Definition: Request.php:18
__toString()
Get a string representation of the exception.
getStatusCode()
Get the associated HTTP status code.
__construct(Request $request, Response $response, ApplicationError $error)
Constructor.
ApplicationError is used to signal errors that occur while processing a request.
ApplicationException signals a general application exception.
setStatus($status)
Set the response HTTP status code.
Presentation related interfaces and classes.
Definition: namespaces.php:59