2024-03-02 04:44:33 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Webmasterskaya\Plugin\System\OauthServer\Extension;
|
|
|
|
|
2024-03-04 01:15:47 +03:00
|
|
|
use Joomla\CMS\Factory;
|
2024-03-02 04:44:33 +03:00
|
|
|
use Joomla\CMS\Plugin\CMSPlugin;
|
2024-03-04 01:15:47 +03:00
|
|
|
use Joomla\CMS\Router\SiteRouter;
|
2024-03-02 04:44:33 +03:00
|
|
|
use Joomla\CMS\Uri\Uri;
|
|
|
|
use Joomla\Event\SubscriberInterface;
|
|
|
|
|
|
|
|
class Plugin extends CMSPlugin implements SubscriberInterface
|
|
|
|
{
|
|
|
|
public static function getSubscribedEvents(): array
|
|
|
|
{
|
2024-03-04 01:15:47 +03:00
|
|
|
return ['onAfterInitialise' => 'attachOauthRouter'];
|
2024-03-02 04:44:33 +03:00
|
|
|
}
|
|
|
|
|
2024-03-04 01:15:47 +03:00
|
|
|
public function attachOauthRouter(): void
|
2024-03-02 04:44:33 +03:00
|
|
|
{
|
2024-03-04 01:15:47 +03:00
|
|
|
/** @var \Joomla\CMS\Application\SiteApplication $app */
|
|
|
|
$app = $this->getApplication();
|
|
|
|
|
|
|
|
if (!$app->isClient('site')) {
|
2024-03-02 04:44:33 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-04 01:15:47 +03:00
|
|
|
/** @var \Joomla\CMS\Router\SiteRouter $siteRouter */
|
|
|
|
$siteRouter = Factory::getContainer()->get(SiteRouter::class);
|
|
|
|
$siteRouter->attachParseRule([$this, 'parseOauthRoute'], $siteRouter::PROCESS_BEFORE);
|
|
|
|
}
|
2024-03-02 04:44:33 +03:00
|
|
|
|
2024-03-04 01:15:47 +03:00
|
|
|
/**
|
|
|
|
* @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)) {
|
2024-03-02 04:44:33 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-04 01:15:47 +03:00
|
|
|
// TODO: Переделать на ComponentRouter (пример в Joomla\CMS\Router\SiteRouterЖ::parseSefRoute())
|
|
|
|
// 1. Зарегистрировать роутер компонента $router->setComponentRouter()
|
|
|
|
// 2. Вызвать $router->getComponentRouter($component)
|
|
|
|
if (!str_starts_with($route, 'login/oauth')) {
|
2024-03-02 04:44:33 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-04 01:15:47 +03:00
|
|
|
$segments = explode('/', $route);
|
|
|
|
|
|
|
|
$uri->setVar('option', 'com_oauthserver');
|
|
|
|
$uri->setVar('task', 'login.' . $segments[2]);
|
|
|
|
$uri->setVar('view', 'default');
|
2024-03-02 04:44:33 +03:00
|
|
|
|
2024-03-04 01:15:47 +03:00
|
|
|
$uri->setPath('');
|
2024-03-02 04:44:33 +03:00
|
|
|
}
|
|
|
|
}
|