[CORE] Refactor GNUsocial.php so it initializes itself as a service

This commit is contained in:
Hugo Sales 2020-07-22 01:54:01 +00:00 committed by Hugo Sales
parent e482ecfb87
commit 284fbe2c5b
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -65,23 +65,28 @@ class GNUsocial implements EventSubscriberInterface
protected RouterInterface $router; protected RouterInterface $router;
protected FormFactoryInterface $form_factory; protected FormFactoryInterface $form_factory;
protected MessageBusInterface $message_bus; protected MessageBusInterface $message_bus;
protected EventDispatcherInterface $event_dispatcher;
/** /**
* Symfony dependency injection gives us access to these services * Symfony dependency injection gives us access to these services
*/ */
public function __construct(LoggerInterface $logger, public function __construct(LoggerInterface $logger,
TranslatorInterface $translator, TranslatorInterface $trans,
EntityManagerInterface $em, EntityManagerInterface $em,
RouterInterface $router, RouterInterface $router,
FormFactoryInterface $ff, FormFactoryInterface $ff,
MessageBusInterface $message_bus) MessageBusInterface $mb,
EventDispatcherInterface $ed)
{ {
$this->logger = $logger; $this->logger = $logger;
$this->translator = $translator; $this->translator = $trans;
$this->entity_manager = $em; $this->entity_manager = $em;
$this->router = $router; $this->router = $router;
$this->form_factory = $ff; $this->form_factory = $ff;
$this->message_bus = $message_bus; $this->message_bus = $mb;
$this->event_dispatcher = $ed;
$this->register();
} }
/** /**
@ -89,10 +94,10 @@ class GNUsocial implements EventSubscriberInterface
* *
* @param EventDispatcherInterface $event_dispatcher * @param EventDispatcherInterface $event_dispatcher
*/ */
public function register(EventDispatcherInterface $event_dispatcher): void public function register(): void
{ {
Log::setLogger($this->logger); Log::setLogger($this->logger);
Event::setDispatcher($event_dispatcher); Event::setDispatcher($this->event_dispatcher);
I18n::setTranslator($this->translator); I18n::setTranslator($this->translator);
DB::setManager($this->entity_manager); DB::setManager($this->entity_manager);
Router::setRouter($this->router); Router::setRouter($this->router);
@ -115,10 +120,9 @@ class GNUsocial implements EventSubscriberInterface
* @return RequestEvent * @return RequestEvent
*/ */
public function onKernelRequest(RequestEvent $event, public function onKernelRequest(RequestEvent $event,
string $event_name, string $event_name): RequestEvent
EventDispatcherInterface $event_dispatcher): RequestEvent
{ {
$this->register($event_dispatcher); $this->register();
return $event; return $event;
} }
@ -132,10 +136,9 @@ class GNUsocial implements EventSubscriberInterface
* @return ConsoleCommandEvent * @return ConsoleCommandEvent
*/ */
public function onCommand(ConsoleCommandEvent $event, public function onCommand(ConsoleCommandEvent $event,
string $event_name, string $event_name): ConsoleCommandEvent
EventDispatcherInterface $event_dispatcher): ConsoleCommandEvent
{ {
$this->register($event_dispatcher); $this->register();
return $event; return $event;
} }