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

View File

@@ -0,0 +1,34 @@
<?php
namespace MailPoet\API\JSON;
if(!defined('ABSPATH')) exit;
class ErrorResponse extends Response {
public $errors;
function __construct($errors = array(), $meta = array(), $status = self::STATUS_NOT_FOUND) {
parent::__construct($status, $meta);
$this->errors = $this->formatErrors($errors);
}
function getData() {
if(empty($this->errors)) {
return null;
} else {
return array(
'errors' => $this->errors
);
}
}
function formatErrors($errors = array()) {
$formatted_errors = array();
foreach($errors as $error => $message) {
$formatted_errors[] = array(
'error' => $error,
'message' => $message
);
}
return $formatted_errors;
}
}