Add bulk action factory to be able to use custom classes for actions [MAILPOET-1922]

This commit is contained in:
wxa
2019-03-20 19:13:57 +03:00
committed by M. Shull
parent 92f5ef200f
commit a822114c6d
4 changed files with 44 additions and 8 deletions

View File

@ -4,10 +4,14 @@ namespace MailPoet\Listing;
if (!defined('ABSPATH')) exit;
class BulkActionController {
/** @var BulkActionFactory */
private $factory;
/** @var Handler */
private $handler;
function __construct(Handler $handler) {
function __construct(BulkActionFactory $factory, Handler $handler) {
$this->factory = $factory;
$this->handler = $handler;
}
@ -15,14 +19,10 @@ class BulkActionController {
$bulk_action_method = 'bulk'.ucfirst($data['action']);
unset($data['action']);
if (!method_exists($model_class, $bulk_action_method)) {
throw new \Exception(
$model_class. ' has no method "'.$bulk_action_method.'"'
);
}
$action_class = $this->factory->getActionClass($model_class, $bulk_action_method);
return call_user_func_array(
array($model_class, $bulk_action_method),
array($action_class, $bulk_action_method),
array($this->handler->getSelection($model_class, $data['listing']), $data)
);
}