Add container factory and initialize container in Initializer
[MAILPOET-1605]
This commit is contained in:
@ -4,6 +4,7 @@ namespace MailPoet\Config;
|
||||
|
||||
use MailPoet\API;
|
||||
use MailPoet\Cron\CronTrigger;
|
||||
use MailPoet\DI\ContainerFactory;
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\Router;
|
||||
use MailPoet\Util\ConflictResolver;
|
||||
@ -18,6 +19,7 @@ require_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
||||
class Initializer {
|
||||
private $access_control;
|
||||
private $renderer;
|
||||
private $container;
|
||||
|
||||
const INITIALIZED = 'MAILPOET_INITIALIZED';
|
||||
|
||||
@ -50,6 +52,8 @@ class Initializer {
|
||||
));
|
||||
}
|
||||
|
||||
$this->compileContainer();
|
||||
|
||||
// activation function
|
||||
register_activation_hook(
|
||||
Env::$file,
|
||||
@ -170,7 +174,7 @@ class Initializer {
|
||||
}
|
||||
|
||||
function setupAccessControl() {
|
||||
$this->access_control = new AccessControl();
|
||||
$this->access_control = $this->container->get(AccessControl::class);
|
||||
}
|
||||
|
||||
function setupInstaller() {
|
||||
|
26
lib/DI/ContainerFactory.php
Normal file
26
lib/DI/ContainerFactory.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\DI;
|
||||
|
||||
use MailPoet\Dependencies\Symfony\Component\Config\FileLocator;
|
||||
use MailPoet\Dependencies\Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use MailPoet\Dependencies\Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
|
||||
class ContainerFactory {
|
||||
|
||||
/** @var ContainerBuilder */
|
||||
private static $container;
|
||||
|
||||
static function getContainer() {
|
||||
if (!self::$container) {
|
||||
self::createContainer();
|
||||
}
|
||||
return self::$container;
|
||||
}
|
||||
|
||||
private static function createContainer() {
|
||||
self::$container = new ContainerBuilder();
|
||||
$loader = new YamlFileLoader(self::$container, new FileLocator(__DIR__));
|
||||
$loader->load('services.yml');
|
||||
}
|
||||
}
|
5
lib/DI/services.yml
Normal file
5
lib/DI/services.yml
Normal file
@ -0,0 +1,5 @@
|
||||
parameters:
|
||||
|
||||
services:
|
||||
_defaults:
|
||||
autowire: true
|
Reference in New Issue
Block a user