2020-03-11 20:29:08 +00:00
|
|
|
<?php
|
2020-03-15 21:21:11 +00:00
|
|
|
|
2020-05-20 17:53:53 +01:00
|
|
|
// {{{ License
|
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
// }}}
|
|
|
|
|
2020-03-11 20:29:08 +00:00
|
|
|
/**
|
|
|
|
* Main GNU social entry point
|
|
|
|
*
|
|
|
|
* @package GNUsocial
|
|
|
|
* @category Framework
|
2020-03-15 21:21:11 +00:00
|
|
|
*
|
2020-03-21 20:18:05 +00:00
|
|
|
* StatusNet and GNU social 1
|
|
|
|
*
|
|
|
|
* @author Refer to CREDITS.md
|
|
|
|
* @copyright 2010 Free Software Foundation, Inc http://www.fsf.org
|
|
|
|
*
|
|
|
|
* GNU social 2
|
|
|
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
2020-03-11 20:29:08 +00:00
|
|
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
2020-03-21 20:18:05 +00:00
|
|
|
*
|
|
|
|
* GNU social 3
|
2020-03-11 20:29:08 +00:00
|
|
|
* @author Hugo Sales <hugo@fc.up.pt>
|
2020-03-21 20:18:05 +00:00
|
|
|
* @copyright 2018-2020 Free Software Foundation, Inc http://www.fsf.org
|
2020-03-11 20:29:08 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2020-05-11 19:15:08 +01:00
|
|
|
namespace App\Core;
|
2020-03-11 20:29:08 +00:00
|
|
|
|
2020-06-04 22:00:05 +01:00
|
|
|
use App\Core\DB\DB;
|
|
|
|
use App\Core\DB\DefaultSettings;
|
2020-06-04 22:53:34 +01:00
|
|
|
use App\Core\I18n\I18nHelper;
|
2020-07-09 16:00:58 +01:00
|
|
|
use App\Core\Queue\Queue;
|
2020-06-04 22:00:05 +01:00
|
|
|
use App\Core\Router\Router;
|
2020-05-13 13:10:24 +01:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2020-03-15 21:21:11 +00:00
|
|
|
use Psr\Log\LoggerInterface;
|
2020-03-20 22:48:27 +00:00
|
|
|
use Symfony\Component\Console\Event\ConsoleCommandEvent;
|
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
2020-03-11 20:29:08 +00:00
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
2020-06-23 21:27:02 +01:00
|
|
|
use Symfony\Component\Form\FormFactoryInterface;
|
2020-03-15 21:21:11 +00:00
|
|
|
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
2020-03-11 20:29:08 +00:00
|
|
|
use Symfony\Component\HttpKernel\KernelEvents;
|
2020-07-09 16:00:58 +01:00
|
|
|
use Symfony\Component\Messenger\MessageBusInterface;
|
2020-06-04 22:00:05 +01:00
|
|
|
use Symfony\Component\Routing\RouterInterface;
|
2020-03-15 21:21:11 +00:00
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
2020-03-11 20:29:08 +00:00
|
|
|
|
|
|
|
class GNUsocial implements EventSubscriberInterface
|
|
|
|
{
|
2020-06-04 22:00:05 +01:00
|
|
|
protected LoggerInterface $logger;
|
|
|
|
protected TranslatorInterface $translator;
|
2020-05-13 13:10:24 +01:00
|
|
|
protected EntityManagerInterface $entity_manager;
|
2020-06-04 22:00:05 +01:00
|
|
|
protected RouterInterface $router;
|
2020-06-23 21:27:02 +01:00
|
|
|
protected FormFactoryInterface $form_factory;
|
2020-07-09 16:00:58 +01:00
|
|
|
protected MessageBusInterface $message_bus;
|
2020-03-11 20:29:08 +00:00
|
|
|
|
2020-03-21 20:18:05 +00:00
|
|
|
/**
|
|
|
|
* Symfony dependency injection gives us access to these services
|
|
|
|
*/
|
2020-06-08 13:04:20 +01:00
|
|
|
public function __construct(LoggerInterface $logger,
|
2020-05-13 13:10:24 +01:00
|
|
|
TranslatorInterface $translator,
|
2020-06-04 22:00:05 +01:00
|
|
|
EntityManagerInterface $em,
|
2020-06-23 21:27:02 +01:00
|
|
|
RouterInterface $router,
|
2020-07-09 16:00:58 +01:00
|
|
|
FormFactoryInterface $ff,
|
|
|
|
MessageBusInterface $message_bus)
|
2020-03-11 20:29:08 +00:00
|
|
|
{
|
2020-05-13 13:10:24 +01:00
|
|
|
$this->logger = $logger;
|
|
|
|
$this->translator = $translator;
|
|
|
|
$this->entity_manager = $em;
|
2020-06-04 22:00:05 +01:00
|
|
|
$this->router = $router;
|
2020-06-23 21:27:02 +01:00
|
|
|
$this->form_factory = $ff;
|
2020-07-09 16:00:58 +01:00
|
|
|
$this->message_bus = $message_bus;
|
2020-03-15 21:21:11 +00:00
|
|
|
}
|
2020-03-13 22:31:56 +00:00
|
|
|
|
2020-03-21 20:18:05 +00:00
|
|
|
/**
|
2020-03-28 14:39:48 +00:00
|
|
|
* Store these services to be accessed statically and load modules
|
2020-05-11 18:39:12 +01:00
|
|
|
*
|
2020-05-10 21:43:15 +01:00
|
|
|
* @param EventDispatcherInterface $event_dispatcher
|
2020-03-21 20:18:05 +00:00
|
|
|
*/
|
2020-03-20 22:48:27 +00:00
|
|
|
public function register(EventDispatcherInterface $event_dispatcher): void
|
2020-03-15 21:21:11 +00:00
|
|
|
{
|
2020-03-20 22:10:01 +00:00
|
|
|
Log::setLogger($this->logger);
|
2020-06-23 21:37:29 +01:00
|
|
|
Event::setDispatcher($event_dispatcher);
|
2020-06-04 22:53:34 +01:00
|
|
|
I18nHelper::setTranslator($this->translator);
|
2020-05-14 22:55:04 +01:00
|
|
|
DB::setManager($this->entity_manager);
|
2020-06-04 22:00:05 +01:00
|
|
|
Router::setRouter($this->router);
|
2020-06-23 21:27:02 +01:00
|
|
|
Form::setFactory($this->form_factory);
|
2020-07-09 16:00:58 +01:00
|
|
|
Queue::setMessageBus($this->message_bus);
|
2020-05-13 13:10:24 +01:00
|
|
|
|
2020-05-14 22:55:04 +01:00
|
|
|
DefaultSettings::setDefaults();
|
2020-03-28 14:39:48 +00:00
|
|
|
ModulesManager::loadModules();
|
2020-03-20 22:48:27 +00:00
|
|
|
}
|
|
|
|
|
2020-03-21 20:18:05 +00:00
|
|
|
/**
|
|
|
|
* Event very early on in the Symfony HTTP lifecycle, but after everyting is registered
|
|
|
|
* where we get access to the event dispatcher
|
2020-05-11 18:39:12 +01:00
|
|
|
*
|
|
|
|
* @param RequestEvent $event
|
|
|
|
* @param string $event_name
|
2020-05-10 21:43:15 +01:00
|
|
|
* @param EventDispatcherInterface $event_dispatcher
|
2020-05-11 18:39:12 +01:00
|
|
|
*
|
2020-05-10 21:43:15 +01:00
|
|
|
* @return RequestEvent
|
2020-03-21 20:18:05 +00:00
|
|
|
*/
|
2020-03-20 22:48:27 +00:00
|
|
|
public function onKernelRequest(RequestEvent $event,
|
|
|
|
string $event_name,
|
|
|
|
EventDispatcherInterface $event_dispatcher): RequestEvent
|
|
|
|
{
|
|
|
|
$this->register($event_dispatcher);
|
|
|
|
return $event;
|
|
|
|
}
|
2020-03-20 22:10:01 +00:00
|
|
|
|
2020-03-21 20:18:05 +00:00
|
|
|
/**
|
|
|
|
* Event after everything is initialized when using the `bin/console` command
|
2020-05-11 18:39:12 +01:00
|
|
|
*
|
|
|
|
* @param ConsoleCommandEvent $event
|
|
|
|
* @param string $event_name
|
2020-05-10 21:43:15 +01:00
|
|
|
* @param EventDispatcherInterface $event_dispatcher
|
2020-05-11 18:39:12 +01:00
|
|
|
*
|
2020-05-10 21:43:15 +01:00
|
|
|
* @return ConsoleCommandEvent
|
2020-03-21 20:18:05 +00:00
|
|
|
*/
|
2020-03-20 22:48:27 +00:00
|
|
|
public function onCommand(ConsoleCommandEvent $event,
|
|
|
|
string $event_name,
|
|
|
|
EventDispatcherInterface $event_dispatcher): ConsoleCommandEvent
|
|
|
|
{
|
|
|
|
$this->register($event_dispatcher);
|
2020-03-11 20:29:08 +00:00
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
2020-03-21 20:18:05 +00:00
|
|
|
/**
|
|
|
|
* Tell Symfony which events we want to listen to, which Symfony detects and autowires
|
|
|
|
* due to this implementing the `EventSubscriberInterface`
|
|
|
|
*/
|
2020-03-11 20:29:08 +00:00
|
|
|
public static function getSubscribedEvents()
|
|
|
|
{
|
2020-03-20 22:48:27 +00:00
|
|
|
return [
|
|
|
|
KernelEvents::REQUEST => 'onKernelRequest',
|
|
|
|
'console.command' => 'onCommand',
|
|
|
|
];
|
2020-03-11 20:29:08 +00:00
|
|
|
}
|
|
|
|
}
|