6 use Services\Http\IHttpResponse
;
7 use Services\IStatusReporter
;
9 class StatusReporter
implements IStatusReporter
15 const ERROR
= 'error';
16 const SUCCESS
= 'success';
17 const EXCEPTION
= 'exception';
19 public function __construct(IHttpResponse
$response) {
20 $this->_response
= $response;
23 public function error($message)
25 $this->_message
= $message;
26 $this->_type
= self
::ERROR
;
27 $this->_response
->setHeader('Content-Type', 'application/json')
28 ->setBody($this->json())
33 public function success($message)
35 $this->_message
= $message;
36 $this->_type
= self
::SUCCESS
;
37 $this->_response
->setHeader('Content-Type', 'application/json')
38 ->setBody($this->json())
43 //no need to exit here, exceptions stop the program.
44 public function exception(Exception
$exception)
46 //we'll be instatic context here so I have to do it this way.
47 header('Content-Type: application/json');
48 echo json_encode(array(self
::EXCEPTION
=> $exception->getMessage()));
51 public function json()
54 array($this->_type
=> $this->_message
)