private \Joomla\CMS\Extension\ComponentInterface|\Joomla\CMS\Extension\ModuleInterface|\Joomla\CMS\Extension\PluginInterface
loadExtension
(mixed $type, mixed $extensionName, mixed $extensionPath)
/**
* Loads the extension.
*
* @param string $type The extension type
* @param string $extensionName The extension name
* @param string $extensionPath The path of the extension
*
* @return ComponentInterface|ModuleInterface|PluginInterface
*
* @since 4.0.0
*/
private function loadExtension($type, $extensionName, $extensionPath)
{
// Check if the extension is already loaded
if (!empty(ExtensionHelper::$extensions[$type][$extensionName])) {
return ExtensionHelper::$extensions[$type][$extensionName];
}
// The container to get the services from
$container = $this->getContainer()->createChild();
$container->get(DispatcherInterface::class)->dispatch('onBeforeExtensionBoot', AbstractEvent::create('onBeforeExtensionBoot', ['subject' => $this, 'type' => $type, 'extensionName' => $extensionName, 'container' => $container]));
// The path of the loader file
$path = $extensionPath . '/services/provider.php';
if (is_file($path)) {
// Load the file
$provider = (require_once $path);
// Check if the extension supports the service provider interface
if ($provider instanceof ServiceProviderInterface) {
$provider->register($container);
}
}
// Fallback to legacy
if (!$container->has($type)) {
switch ($type) {
case ComponentInterface::class:
$container->set($type, new LegacyComponent('com_' . $extensionName));
break;
case ModuleInterface::class:
$container->set($type, new Module(new ModuleDispatcherFactory(''), new HelperFactory('')));
break;
case PluginInterface::class:
list($pluginName, $pluginType) = explode(':', $extensionName);
$container->set($type, $this->loadPluginFromFilesystem($pluginName, $pluginType));
}
}
$container->get(DispatcherInterface::class)->dispatch('onAfterExtensionBoot', AbstractEvent::create('onAfterExtensionBoot', ['subject' => $this, 'type' => $type, 'extensionName' => $extensionName, 'container' => $container]));
$extension = $container->get($type);
if ($extension instanceof BootableExtensionInterface) {
$extension->boot($container);
}
// Cache the extension
ExtensionHelper::$extensions[$type][$extensionName] = $extension;
return $extension;
}