Inject Listing Handler and Segments Subscriber Listing using DI
[MAILPOET-1689]
This commit is contained in:
@ -18,12 +18,19 @@ class Forms extends APIEndpoint {
|
||||
/** @var Listing\BulkActionController */
|
||||
private $bulk_action;
|
||||
|
||||
/** @var Listing\Handler */
|
||||
private $listing_handler;
|
||||
|
||||
public $permissions = array(
|
||||
'global' => AccessControl::PERMISSION_MANAGE_FORMS
|
||||
);
|
||||
|
||||
function __construct(Listing\BulkActionController $bulk_action) {
|
||||
function __construct(
|
||||
Listing\BulkActionController $bulk_action,
|
||||
Listing\Handler $listing_handler
|
||||
) {
|
||||
$this->bulk_action = $bulk_action;
|
||||
$this->listing_handler = $listing_handler;
|
||||
}
|
||||
|
||||
function get($data = array()) {
|
||||
@ -39,8 +46,7 @@ class Forms extends APIEndpoint {
|
||||
}
|
||||
|
||||
function listing($data = array()) {
|
||||
$listing = new Listing\Handler();
|
||||
$listing_data = $listing->get('\MailPoet\Models\Form', $data);
|
||||
$listing_data = $this->listing_handler->get('\MailPoet\Models\Form', $data);
|
||||
|
||||
$data = array();
|
||||
foreach($listing_data['items'] as $form) {
|
||||
|
@ -30,12 +30,19 @@ class Newsletters extends APIEndpoint {
|
||||
/** @var Listing\BulkActionController */
|
||||
private $bulk_action;
|
||||
|
||||
/** @var Listing\Handler */
|
||||
private $listing_handler;
|
||||
|
||||
public $permissions = array(
|
||||
'global' => AccessControl::PERMISSION_MANAGE_EMAILS
|
||||
);
|
||||
|
||||
function __construct(Listing\BulkActionController $bulk_action) {
|
||||
function __construct(
|
||||
Listing\BulkActionController $bulk_action,
|
||||
Listing\Handler $listing_handler
|
||||
) {
|
||||
$this->bulk_action = $bulk_action;
|
||||
$this->listing_handler = $listing_handler;
|
||||
}
|
||||
|
||||
function get($data = array()) {
|
||||
@ -383,8 +390,7 @@ class Newsletters extends APIEndpoint {
|
||||
}
|
||||
|
||||
function listing($data = array()) {
|
||||
$listing = new Listing\Handler();
|
||||
$listing_data = $listing->get('\MailPoet\Models\Newsletter', $data);
|
||||
$listing_data = $this->listing_handler->get('\MailPoet\Models\Newsletter', $data);
|
||||
|
||||
$data = array();
|
||||
foreach($listing_data['items'] as $newsletter) {
|
||||
|
@ -19,8 +19,15 @@ class Segments extends APIEndpoint {
|
||||
/** @var Listing\BulkActionController */
|
||||
private $bulk_action;
|
||||
|
||||
function __construct(Listing\BulkActionController $bulk_action) {
|
||||
/** @var Listing\Handler */
|
||||
private $listing_handler;
|
||||
|
||||
function __construct(
|
||||
Listing\BulkActionController $bulk_action,
|
||||
Listing\Handler $listing_handler
|
||||
) {
|
||||
$this->bulk_action = $bulk_action;
|
||||
$this->listing_handler = $listing_handler;
|
||||
}
|
||||
|
||||
function get($data = array()) {
|
||||
@ -36,8 +43,7 @@ class Segments extends APIEndpoint {
|
||||
}
|
||||
|
||||
function listing($data = array()) {
|
||||
$listing = new Listing\Handler();
|
||||
$listing_data = $listing->get('\MailPoet\Models\Segment', $data);
|
||||
$listing_data = $this->listing_handler->get('\MailPoet\Models\Segment', $data);
|
||||
|
||||
$data = array();
|
||||
foreach($listing_data['items'] as $segment) {
|
||||
|
@ -32,8 +32,25 @@ class Subscribers extends APIEndpoint {
|
||||
/** @var Listing\BulkActionController */
|
||||
private $bulk_action_controller;
|
||||
|
||||
public function __construct(Listing\BulkActionController $bulk_action_controller) {
|
||||
/** @var SubscribersListings */
|
||||
private $subscribers_listings;
|
||||
|
||||
/** @var RequiredCustomFieldValidator */
|
||||
private $required_custom_field_validator;
|
||||
|
||||
/** @var Listing\Handler */
|
||||
private $listing_handler;
|
||||
|
||||
public function __construct(
|
||||
Listing\BulkActionController $bulk_action_controller,
|
||||
SubscribersListings $subscribers_listings,
|
||||
RequiredCustomFieldValidator $required_custom_field_validator,
|
||||
Listing\Handler $listing_handler
|
||||
) {
|
||||
$this->bulk_action_controller = $bulk_action_controller;
|
||||
$this->subscribers_listings = $subscribers_listings;
|
||||
$this->required_custom_field_validator = $required_custom_field_validator;
|
||||
$this->listing_handler = $listing_handler;
|
||||
}
|
||||
|
||||
function get($data = array()) {
|
||||
@ -56,12 +73,9 @@ class Subscribers extends APIEndpoint {
|
||||
function listing($data = array()) {
|
||||
|
||||
if(!isset($data['filter']['segment'])) {
|
||||
$listing = new Listing\Handler();
|
||||
|
||||
$listing_data = $listing->get('\MailPoet\Models\Subscriber', $data);
|
||||
$listing_data = $this->listing_handler->get('\MailPoet\Models\Subscriber', $data);
|
||||
} else {
|
||||
$listings = new SubscribersListings();
|
||||
$listing_data = $listings->getListingsInSegment($data);
|
||||
$listing_data = $this->subscribers_listings->getListingsInSegment($data);
|
||||
}
|
||||
|
||||
$data = array();
|
||||
@ -130,8 +144,7 @@ class Subscribers extends APIEndpoint {
|
||||
$data = $this->deobfuscateFormPayload($data);
|
||||
|
||||
try {
|
||||
$validator = new RequiredCustomFieldValidator();
|
||||
$validator->validate($data);
|
||||
$this->required_custom_field_validator->validate($data);
|
||||
} catch (\Exception $e) {
|
||||
return $this->badRequest([APIError::BAD_REQUEST => $e->getMessage()]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user