expmail/Response.class.php

24 lines
654 B
PHP
Raw Normal View History

<?php
class Response {
private $error;
private $warnings;
function handle_warning($warning) {
if (!$this->warnings) $this->warnings = array();
array_push($this->warnings, $warning);
}
function handle_exception($e) {
$this->error = $e->getMessage();
$this->respond();
}
function respond() {
header('Content-Type: application/json');
$response = array("status" => $this->error ? "error" : "success");
if ($this->error) $response["error"] = $this->error;
if ($this->warnings) $response["warnings"] = $this->warnings;
die(json_encode($response));
}
}