From 0d9b10ef8b0ec23030d095d126493c946332f677 Mon Sep 17 00:00:00 2001 From: Artem Vasilev Date: Mon, 11 Mar 2024 00:16:56 +0300 Subject: [PATCH] code style --- .../src/Extension/Plugin.php | 95 +++++++++++-------- 1 file changed, 56 insertions(+), 39 deletions(-) diff --git a/plg_system_oauthserver/src/Extension/Plugin.php b/plg_system_oauthserver/src/Extension/Plugin.php index 3ae821c..e28499d 100644 --- a/plg_system_oauthserver/src/Extension/Plugin.php +++ b/plg_system_oauthserver/src/Extension/Plugin.php @@ -1,4 +1,11 @@ + * @license MIT; see LICENSE.txt + **/ namespace Webmasterskaya\Plugin\System\OauthServer\Extension; @@ -8,54 +15,64 @@ use Joomla\CMS\Router\SiteRouter; use Joomla\CMS\Uri\Uri; use Joomla\Event\SubscriberInterface; +// phpcs:disable PSR1.Files.SideEffects +\defined('_JEXEC') or die; + +// phpcs:enable PSR1.Files.SideEffects + class Plugin extends CMSPlugin implements SubscriberInterface { - public static function getSubscribedEvents(): array - { - return ['onAfterInitialise' => 'attachOauthRouter']; - } + public static function getSubscribedEvents(): array + { + return ['onAfterInitialise' => 'attachOauthRouter']; + } - public function attachOauthRouter(): void - { - /** @var \Joomla\CMS\Application\SiteApplication $app */ - $app = $this->getApplication(); + /** + * @return void + * @since version + */ + public function attachOauthRouter(): void + { + /** @var \Joomla\CMS\Application\SiteApplication $app */ + $app = $this->getApplication(); - if (!$app->isClient('site')) { - return; - } + if (!$app->isClient('site')) + { + return; + } - /** @var \Joomla\CMS\Router\SiteRouter $siteRouter */ - $siteRouter = Factory::getContainer()->get(SiteRouter::class); - $siteRouter->attachParseRule([$this, 'parseOauthRoute'], $siteRouter::PROCESS_BEFORE); - } + /** @var \Joomla\CMS\Router\SiteRouter $siteRouter */ + $siteRouter = Factory::getContainer()->get(SiteRouter::class); + $siteRouter->attachParseRule([$this, 'parseOauthRoute'], $siteRouter::PROCESS_BEFORE); + } - /** - * @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(), '/'); + /** + * @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; - } + if (empty($route)) + { + return; + } - // TODO: Переделать на ComponentRouter (пример в Joomla\CMS\Router\SiteRouter::parseSefRoute()) - // 1. Зарегистрировать роутер компонента $router->setComponentRouter() - // 2. Вызвать $router->getComponentRouter($component) - if (!str_starts_with($route, 'login/oauth')) { - return; - } + if (!str_starts_with($route, 'login/oauth')) + { + return; + } - $segments = explode('/', $route); + $segments = explode('/', $route); - $uri->setVar('option', 'com_oauthserver'); - $uri->setVar('task', 'login.' . $segments[2]); - $uri->setVar('view', 'default'); + $uri->setVar('option', 'com_oauthserver'); + $uri->setVar('task', 'login.' . $segments[2]); + $uri->setVar('view', 'default'); - $uri->setPath(''); - } + $uri->setPath(''); + } } \ No newline at end of file