[FRAMEWORK] Avoid double initializing the framework

This commit is contained in:
Hugo Sales 2020-08-03 20:56:00 +00:00 committed by Hugo Sales
parent aac653d2bd
commit 152828ed68
Signed by untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -67,6 +67,7 @@ class GNUsocial implements EventSubscriberInterface
{ {
use TargetPathTrait; use TargetPathTrait;
protected bool $initialized = false;
protected LoggerInterface $logger; protected LoggerInterface $logger;
protected TranslatorInterface $translator; protected TranslatorInterface $translator;
protected EntityManagerInterface $entity_manager; protected EntityManagerInterface $entity_manager;
@ -92,7 +93,7 @@ class GNUsocial implements EventSubscriberInterface
SessionInterface $sess, SessionInterface $sess,
SSecurity $sec, SSecurity $sec,
MailerInterface $mail, MailerInterface $mail,
ModuleManager $mod) ModuleManager $mm)
{ {
$this->logger = $logger; $this->logger = $logger;
$this->translator = $trans; $this->translator = $trans;
@ -104,7 +105,7 @@ class GNUsocial implements EventSubscriberInterface
$this->session = $sess; $this->session = $sess;
$this->security = $sec; $this->security = $sec;
$this->mailer = $mail; $this->mailer = $mail;
$this->module_manager = $mod; $this->module_manager = $mm;
$this->initialize(); $this->initialize();
} }
@ -116,21 +117,27 @@ class GNUsocial implements EventSubscriberInterface
*/ */
public function initialize(): void public function initialize(): void
{ {
Log::setLogger($this->logger); if (!$this->initialized) {
Event::setDispatcher($this->event_dispatcher); Log::setLogger($this->logger);
I18n::setTranslator($this->translator); Event::setDispatcher($this->event_dispatcher);
DB::setManager($this->entity_manager); I18n::setTranslator($this->translator);
Router::setRouter($this->router); DB::setManager($this->entity_manager);
Form::setFactory($this->form_factory); Form::setFactory($this->form_factory);
Queue::setMessageBus($this->message_bus); Queue::setMessageBus($this->message_bus);
Security::setHelper($this->security); Security::setHelper($this->security);
Mailer::setMailer($this->mailer); Mailer::setMailer($this->mailer);
DefaultSettings::setDefaults(); DefaultSettings::setDefaults();
Cache::setupCache(); Cache::setupCache();
$this->module_manager->loadModules(); // Events are proloaded on compilation, but set at runtime
$this->module_manager->loadModules();
Router::setRouter($this->router);
$this->initialized = true;
}
} }
/** /**