Добавил ComponentHelper

This commit is contained in:
Artem Vasilev 2024-03-08 14:34:33 +03:00
parent a1e89a0463
commit cf9d7d0889
2 changed files with 24 additions and 17 deletions

View File

@ -10,6 +10,7 @@ use Joomla\CMS\Extension\BootableExtensionInterface;
use Joomla\CMS\Extension\MVCComponent; use Joomla\CMS\Extension\MVCComponent;
use Joomla\CMS\HTML\HTMLRegistryAwareTrait; use Joomla\CMS\HTML\HTMLRegistryAwareTrait;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use Webmasterskaya\Component\OauthServer\Administrator\Helper\ComponentHelper;
\defined('JPATH_PLATFORM') or die; \defined('JPATH_PLATFORM') or die;
@ -32,22 +33,6 @@ class Component extends MVCComponent implements
*/ */
public function boot(ContainerInterface $container): void public function boot(ContainerInterface $container): void
{ {
self::requireDependency(); ComponentHelper::registerComponentDependencies();
}
public static function requireDependency(): void
{
static $required;
if (!isset($required)) {
/** @var \Composer\Autoload\ClassLoader $loader */
$loader = require JPATH_LIBRARIES . '/lib_oauthserver/vendor/autoload.php';
$loader->unregister();
spl_autoload_register([new \Joomla\CMS\Autoload\ClassLoader($loader), 'loadClass'], true, true);
$required = true;
}
} }
} }

View File

@ -0,0 +1,22 @@
<?php
namespace Webmasterskaya\Component\OauthServer\Administrator\Helper;
abstract class ComponentHelper
{
public static function registerComponentDependencies(): void
{
static $registered;
if (!isset($registered)) {
/** @var \Composer\Autoload\ClassLoader $loader */
$loader = require JPATH_LIBRARIES . '/lib_oauthserver/vendor/autoload.php';
$loader->unregister();
if (spl_autoload_register([new \Joomla\CMS\Autoload\ClassLoader($loader), 'loadClass'])) {
$registered = true;
}
}
}
}