[CORE] Refactor GNUsocial.php so it initializes itself as a service
This commit is contained in:
parent
e482ecfb87
commit
284fbe2c5b
@ -59,29 +59,34 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||||||
|
|
||||||
class GNUsocial implements EventSubscriberInterface
|
class GNUsocial implements EventSubscriberInterface
|
||||||
{
|
{
|
||||||
protected LoggerInterface $logger;
|
protected LoggerInterface $logger;
|
||||||
protected TranslatorInterface $translator;
|
protected TranslatorInterface $translator;
|
||||||
protected EntityManagerInterface $entity_manager;
|
protected EntityManagerInterface $entity_manager;
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user