From 9f8feabd3d3e8da262a2e0b994674e62f3dc0bee Mon Sep 17 00:00:00 2001 From: Artem Vasilev Date: Mon, 4 Mar 2024 01:15:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BB=D0=B0=D0=B3=D0=B8=D0=BD=20=D1=80?= =?UTF-8?q?=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B8=D1=80=D1=83=D0=B5?= =?UTF-8?q?=D1=82=20=D0=BD=D1=83=D0=B6=D0=BD=D1=8B=D0=B9=20=D0=BC=D0=BD?= =?UTF-8?q?=D0=B5=20=D1=80=D0=BE=D1=83=D1=82=D0=B5=D1=80=20=D0=B1=D0=B5?= =?UTF-8?q?=D0=B7=20=D0=BC=D0=B5=D0=BD=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plg_system_oauthserver/services/provider.php | 27 +++++++- .../src/Extension/Plugin.php | 66 +++++++++---------- 2 files changed, 58 insertions(+), 35 deletions(-) diff --git a/plg_system_oauthserver/services/provider.php b/plg_system_oauthserver/services/provider.php index d9b5dd4..2f2b5b8 100644 --- a/plg_system_oauthserver/services/provider.php +++ b/plg_system_oauthserver/services/provider.php @@ -1,13 +1,36 @@ set( + PluginInterface::class, + function (Container $container) { + $dispatcher = $container->get(DispatcherInterface::class); + $plugin = new Plugin( + $dispatcher, + (array) PluginHelper::getPlugin('system', 'oauthserver') + ); + $plugin->setApplication(Factory::getApplication()); + + return $plugin; + } + ); } }; \ No newline at end of file diff --git a/plg_system_oauthserver/src/Extension/Plugin.php b/plg_system_oauthserver/src/Extension/Plugin.php index dba860b..5ecb685 100644 --- a/plg_system_oauthserver/src/Extension/Plugin.php +++ b/plg_system_oauthserver/src/Extension/Plugin.php @@ -2,60 +2,60 @@ namespace Webmasterskaya\Plugin\System\OauthServer\Extension; -use Joomla\CMS\Application\CMSApplicationInterface; +use Joomla\CMS\Factory; use Joomla\CMS\Plugin\CMSPlugin; +use Joomla\CMS\Router\SiteRouter; use Joomla\CMS\Uri\Uri; use Joomla\Event\SubscriberInterface; class Plugin extends CMSPlugin implements SubscriberInterface { - /** - * Affects constructor behavior. If true, language files will be loaded automatically. - * - * @var boolean - * @since 3.1 - */ - protected $autoloadLanguage = false; - - /** - * The application object - * - * @var CMSApplicationInterface - * - * @since 4.2.0 - */ - private $application; - public static function getSubscribedEvents(): array { - return ['onAfterInitialise' => 'onAfterInitialise']; + return ['onAfterInitialise' => 'attachOauthRouter']; } - public function onAfterInitialise(): void + public function attachOauthRouter(): void { - if (!$this->app->isClient('site')) { + /** @var \Joomla\CMS\Application\SiteApplication $app */ + $app = $this->getApplication(); + + if (!$app->isClient('site')) { return; } - $uri = Uri::getInstance(); - $path = $uri->getPath(); + /** @var \Joomla\CMS\Router\SiteRouter $siteRouter */ + $siteRouter = Factory::getContainer()->get(SiteRouter::class); + $siteRouter->attachParseRule([$this, 'parseOauthRoute'], $siteRouter::PROCESS_BEFORE); + } - // Адрес сервера аутентификации должен быть статичным, - // чтобы гарантировать 100% доступность сервера - if (str_starts_with($path, '/login/oauth/') === false) { + /** + * @param \Joomla\CMS\Router\SiteRouter $router + * @param \Joomla\CMS\Uri\Uri $uri + * @return void + * @since version + */ + public function parseOauthRoute(SiteRouter &$router, Uri &$uri): void + { + $route = trim($uri->getPath(), '/'); + + if (empty($route)) { return; } - $parts = explode('/', $path); - - if(empty($parts[2])){ - // TODO: Проверить, как стандартный роутер обработает этот вопрос и как отреагируют приложения на 404 от Joomla + // TODO: Переделать на ComponentRouter (пример в Joomla\CMS\Router\SiteRouterЖ::parseSefRoute()) + // 1. Зарегистрировать роутер компонента $router->setComponentRouter() + // 2. Вызвать $router->getComponentRouter($component) + if (!str_starts_with($route, 'login/oauth')) { return; } - $option = 'com_oauthserver'; - $task = $parts[2]; + $segments = explode('/', $route); - // TODO: Ставим в input option, task и view и запускаем компонент com_oauthserver + $uri->setVar('option', 'com_oauthserver'); + $uri->setVar('task', 'login.' . $segments[2]); + $uri->setVar('view', 'default'); + + $uri->setPath(''); } } \ No newline at end of file