externalize Success/ErrorResponse classes into their own files

This commit is contained in:
Jonathan Labreuille
2016-08-01 17:22:23 +02:00
parent 9410d4f10a
commit ed30d8f639
4 changed files with 64 additions and 53 deletions

View File

@@ -0,0 +1,34 @@
<?php
namespace MailPoet\API;
if(!defined('ABSPATH')) exit;
class APIErrorResponse extends APIResponse {
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 false;
} 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;
}
}