Inject Renderer to Initializer
[MAILPOET-1823]
This commit is contained in:
committed by
M. Shull
parent
d8503cf3c2
commit
171b3564f9
@ -18,16 +18,26 @@ if (!defined('ABSPATH')) exit;
|
|||||||
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
||||||
|
|
||||||
class Initializer {
|
class Initializer {
|
||||||
|
|
||||||
private $access_control;
|
private $access_control;
|
||||||
|
|
||||||
|
/** @var Renderer */
|
||||||
private $renderer;
|
private $renderer;
|
||||||
|
|
||||||
|
/** @var RendererFactory */
|
||||||
|
private $renderer_factory;
|
||||||
|
|
||||||
/** @var ContainerInterface */
|
/** @var ContainerInterface */
|
||||||
private $container;
|
private $container;
|
||||||
|
|
||||||
const INITIALIZED = 'MAILPOET_INITIALIZED';
|
const INITIALIZED = 'MAILPOET_INITIALIZED';
|
||||||
|
|
||||||
function __construct(ContainerWrapper $container) {
|
function __construct(
|
||||||
|
ContainerWrapper $container,
|
||||||
|
RendererFactory $renderer_factory
|
||||||
|
) {
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
|
$this->renderer_factory = $renderer_factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
@ -109,17 +119,13 @@ class Initializer {
|
|||||||
|
|
||||||
function preInitialize() {
|
function preInitialize() {
|
||||||
try {
|
try {
|
||||||
$this->setupRenderer();
|
$this->renderer = $this->renderer_factory->getRenderer();
|
||||||
$this->setupWidget();
|
$this->setupWidget();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->handleFailedInitialization($e);
|
$this->handleFailedInitialization($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupRenderer() {
|
|
||||||
$this->renderer = $this->container->get(Renderer::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setupWidget() {
|
function setupWidget() {
|
||||||
register_widget('\MailPoet\Form\Widget');
|
register_widget('\MailPoet\Form\Widget');
|
||||||
}
|
}
|
||||||
|
20
lib/Config/RendererFactory.php
Normal file
20
lib/Config/RendererFactory.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MailPoet\Config;
|
||||||
|
|
||||||
|
if (!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
|
class RendererFactory {
|
||||||
|
|
||||||
|
/** @var Renderer */
|
||||||
|
private $renderer;
|
||||||
|
|
||||||
|
function getRenderer() {
|
||||||
|
if (!$this->renderer) {
|
||||||
|
$caching = !WP_DEBUG;
|
||||||
|
$debugging = WP_DEBUG;
|
||||||
|
$this->renderer = new Renderer($caching, $debugging);
|
||||||
|
}
|
||||||
|
return $this->renderer;
|
||||||
|
}
|
||||||
|
}
|
@ -55,9 +55,10 @@ class ContainerConfigurator implements IContainerConfigurator {
|
|||||||
$container->autowire(\MailPoet\Config\Hooks::class)->setPublic(true);
|
$container->autowire(\MailPoet\Config\Hooks::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\Config\Initializer::class)->setPublic(true);
|
$container->autowire(\MailPoet\Config\Initializer::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\Config\Menu::class)->setPublic(true);
|
$container->autowire(\MailPoet\Config\Menu::class)->setPublic(true);
|
||||||
|
$container->autowire(\MailPoet\Config\RendererFactory::class)->setPublic(true);
|
||||||
$container->register(\MailPoet\Config\Renderer::class)
|
$container->register(\MailPoet\Config\Renderer::class)
|
||||||
->setPublic(true)
|
->setPublic(true)
|
||||||
->setFactory([__CLASS__, 'createRenderer']);
|
->setFactory([new Reference(\MailPoet\Config\RendererFactory::class), 'getRenderer']);
|
||||||
// Cron
|
// Cron
|
||||||
$container->autowire(\MailPoet\Cron\Daemon::class)->setPublic(true);
|
$container->autowire(\MailPoet\Cron\Daemon::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\Cron\DaemonHttpRunner::class)->setPublic(true);
|
$container->autowire(\MailPoet\Cron\DaemonHttpRunner::class)->setPublic(true);
|
||||||
@ -115,10 +116,4 @@ class ContainerConfigurator implements IContainerConfigurator {
|
|||||||
}
|
}
|
||||||
return $container->get(IContainerConfigurator::PREMIUM_CONTAINER_SERVICE_SLUG)->get($id);
|
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