Moves current API under JSON namespace

This commit is contained in:
Vlad
2017-05-09 20:17:29 -04:00
parent b727ba423e
commit 398d7d3d80
38 changed files with 86 additions and 86 deletions

42
lib/API/JSON/Response.php Normal file
View File

@@ -0,0 +1,42 @@
<?php
namespace MailPoet\API\JSON;
if(!defined('ABSPATH')) exit;
abstract class Response {
const STATUS_OK = 200;
const STATUS_BAD_REQUEST = 400;
const STATUS_UNAUTHORIZED = 401;
const STATUS_FORBIDDEN = 403;
const STATUS_NOT_FOUND = 404;
public $status;
public $meta;
function __construct($status, $meta = array()) {
$this->status = $status;
$this->meta = $meta;
}
function send() {
status_header($this->status);
$data = $this->getData();
$response = array();
if(!empty($this->meta)) {
$response['meta'] = $this->meta;
}
if($data !== null) {
$response = array_merge($response, $data);
}
if(!empty($response)) {
@header('Content-Type: application/json; charset='.get_option('blog_charset'));
echo wp_json_encode($response);
}
die();
}
abstract function getData();
}