Klaus-Uwe Mitterer
730ad8c0e1
Implement warning output Implement warning when URL and string provided for HTML/plain Turn allowempty to config key Add option to prefer URL over string for HTML/plain Add user agent to curl requests Update OpenAPI Bump version to 0.5
24 lines
No EOL
654 B
PHP
24 lines
No EOL
654 B
PHP
<?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));
|
|
}
|
|
} |