Inject dependencies to hooks directly
[MAILPOET-1689]
This commit is contained in:
@ -3,15 +3,15 @@
|
||||
namespace MailPoet\Config;
|
||||
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoetVendor\Psr\Container\ContainerInterface;
|
||||
use MailPoet\Subscription\Form;
|
||||
|
||||
class Hooks {
|
||||
|
||||
/** @var ContainerInterface */
|
||||
private $container;
|
||||
/** @var Form */
|
||||
private $subscription_form;
|
||||
|
||||
function __construct(ContainerInterface $container) {
|
||||
$this->container = $container;
|
||||
function __construct(Form $subscription_form) {
|
||||
$this->subscription_form = $subscription_form;
|
||||
}
|
||||
|
||||
function init() {
|
||||
@ -101,11 +101,11 @@ class Hooks {
|
||||
// Subscription form
|
||||
add_action(
|
||||
'admin_post_mailpoet_subscription_form',
|
||||
[$this, 'subscriptionFormOnSubmit']
|
||||
[$this->subscription_form, 'onSubmit']
|
||||
);
|
||||
add_action(
|
||||
'admin_post_nopriv_mailpoet_subscription_form',
|
||||
[$this, 'subscriptionFormOnSubmit']
|
||||
[$this->subscription_form, 'onSubmit']
|
||||
);
|
||||
}
|
||||
|
||||
@ -181,9 +181,4 @@ class Hooks {
|
||||
10, 3
|
||||
);
|
||||
}
|
||||
|
||||
// Callbacks
|
||||
function subscriptionFormOnSubmit($data = false) {
|
||||
$this->container->get(\MailPoet\Subscription\Form::class)->onSubmit($data);
|
||||
}
|
||||
}
|
||||
|
@ -50,10 +50,7 @@ class ContainerConfigurator implements IContainerConfigurator {
|
||||
$container->autowire(\MailPoet\API\JSON\v1\Subscribers::class)->setPublic(true);
|
||||
// Config
|
||||
$container->autowire(\MailPoet\Config\AccessControl::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Config\Hooks::class)
|
||||
->addArgument(new Reference(ContainerWrapper::class))
|
||||
->setPublic(true);
|
||||
|
||||
$container->autowire(\MailPoet\Config\Hooks::class)->setPublic(true);
|
||||
// Cron
|
||||
$container->autowire(\MailPoet\Cron\Daemon::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Cron\DaemonHttpRunner::class)->setPublic(true);
|
||||
|
@ -3,11 +3,10 @@ namespace MailPoet\Test\Config;
|
||||
|
||||
use MailPoet\Config\Hooks;
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\WP\Posts as WPPosts;
|
||||
|
||||
class HooksTest extends \MailPoetTest {
|
||||
function testItHooksSchedulerToMultiplePostTypes() {
|
||||
$hooks = new Hooks(ContainerWrapper::getInstance());
|
||||
$hooks = ContainerWrapper::getInstance()->get(Hooks::class);
|
||||
$hooks->setupPostNotifications();
|
||||
expect(has_filter('transition_post_status', '\MailPoet\Newsletter\Scheduler\Scheduler::transitionHook'))->notEmpty();
|
||||
}
|
||||
|
@ -697,7 +697,7 @@ class SchedulerTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testUnsearchablePostTypeDoesNotSchedulePostNotification() {
|
||||
$hook = new Hooks(ContainerWrapper::getInstance());
|
||||
$hook = ContainerWrapper::getInstance()->get(Hooks::class);
|
||||
|
||||
$newsletter = $this->_createNewsletter(Newsletter::TYPE_NOTIFICATION);
|
||||
|
||||
|
Reference in New Issue
Block a user