Move dependencies creation to DI container
[MAILPOET-1571]
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
namespace MailPoet\Cron\Workers;
|
||||
|
||||
use MailPoet\Config\Renderer;
|
||||
use MailPoet\Cron\Workers\StatsNotifications\Scheduler as StatsNotificationScheduler;
|
||||
use MailPoet\Cron\Workers\Scheduler as SchedulerWorker;
|
||||
use MailPoet\Cron\Workers\SendingQueue\SendingQueue as SendingQueueWorker;
|
||||
use MailPoet\Cron\Workers\SendingQueue\Migration as MigrationWorker;
|
||||
@ -11,14 +12,29 @@ use MailPoet\Cron\Workers\Bounce as BounceWorker;
|
||||
use MailPoet\Cron\Workers\KeyCheck\PremiumKeyCheck as PremiumKeyCheckWorker;
|
||||
use MailPoet\Cron\Workers\KeyCheck\SendingServiceKeyCheck as SendingServiceKeyCheckWorker;
|
||||
use MailPoet\Cron\Workers\SendingQueue\SendingErrorHandler;
|
||||
use MailPoet\Mailer\Mailer;
|
||||
|
||||
class WorkersFactory {
|
||||
|
||||
/** @var SendingErrorHandler */
|
||||
private $sending_error_handler;
|
||||
|
||||
public function __construct(SendingErrorHandler $sending_error_handler) {
|
||||
/** @var StatsNotificationScheduler */
|
||||
private $scheduler;
|
||||
|
||||
/** @var Mailer */
|
||||
private $mailer;
|
||||
|
||||
/**
|
||||
* @var Renderer
|
||||
*/
|
||||
private $renderer;
|
||||
|
||||
public function __construct(SendingErrorHandler $sending_error_handler, StatsNotificationScheduler $scheduler, Mailer $mailer, Renderer $renderer) {
|
||||
$this->sending_error_handler = $sending_error_handler;
|
||||
$this->scheduler = $scheduler;
|
||||
$this->mailer = $mailer;
|
||||
$this->renderer = $renderer;
|
||||
}
|
||||
|
||||
/** @return SchedulerWorker */
|
||||
@ -28,16 +44,10 @@ class WorkersFactory {
|
||||
|
||||
/** @return SendingQueueWorker */
|
||||
function createQueueWorker($timer) {
|
||||
return new SendingQueueWorker($this->sending_error_handler, $this->createStatsNotificationsWorker($timer), $timer);
|
||||
return new SendingQueueWorker($this->sending_error_handler, $this->scheduler, $timer);
|
||||
}
|
||||
|
||||
function createStatsNotificationsWorker($timer) {
|
||||
//TODO get those from DI
|
||||
$caching = !WP_DEBUG;
|
||||
$debugging = WP_DEBUG;
|
||||
$this->renderer = new Renderer($caching, $debugging);
|
||||
$this->mailer = new \MailPoet\Mailer\Mailer();
|
||||
|
||||
return new StatsNotificationsWorker($this->mailer, $this->renderer, $timer);
|
||||
}
|
||||
|
||||
|
@ -51,11 +51,13 @@ class ContainerConfigurator implements IContainerConfigurator {
|
||||
// Config
|
||||
$container->autowire(\MailPoet\Config\AccessControl::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Config\Hooks::class)->setPublic(true);
|
||||
$container->register(\MailPoet\Config\Renderer::class)->setFactory([__CLASS__, 'createRenderer']);
|
||||
// Cron
|
||||
$container->autowire(\MailPoet\Cron\Daemon::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Cron\DaemonHttpRunner::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Cron\Workers\WorkersFactory::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Cron\Workers\SendingQueue\SendingErrorHandler::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Cron\Workers\StatsNotifications\Scheduler::class);
|
||||
// Listing
|
||||
$container->autowire(\MailPoet\Listing\BulkActionController::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Listing\Handler::class)->setPublic(true);
|
||||
@ -64,6 +66,8 @@ class ContainerConfigurator implements IContainerConfigurator {
|
||||
$container->autowire(\MailPoet\Router\Endpoints\Subscription::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Router\Endpoints\Track::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Router\Endpoints\ViewInBrowser::class)->setPublic(true);
|
||||
// Mailer
|
||||
$container->autowire(\MailPoet\Mailer\Mailer::class);
|
||||
// Subscribers
|
||||
$container->autowire(\MailPoet\Subscribers\NewSubscriberNotificationMailer::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Subscribers\ConfirmationEmailMailer::class)->setPublic(true);
|
||||
@ -96,4 +100,10 @@ class ContainerConfigurator implements IContainerConfigurator {
|
||||
}
|
||||
return $container->get(IContainerConfigurator::PREMIUM_CONTAINER_SERVICE_SLUG)->get($id);
|
||||
}
|
||||
|
||||
static function createRenderer() {
|
||||
$caching = !WP_DEBUG;
|
||||
$debugging = WP_DEBUG;
|
||||
return new \MailPoet\Config\Renderer($caching, $debugging);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user