private \Joomla\CMS\Plugin\CMSPlugin
loadPluginFromFilesystem
(string $plugin, string $type)
/**
* Creates a CMS plugin from the filesystem.
*
* @param string $plugin The plugin
* @param string $type The type
*
* @return CMSPlugin
*
* @since 4.0.0
*/
private function loadPluginFromFilesystem(string $plugin, string $type)
{
// The dispatcher
$dispatcher = $this->getContainer()->get(DispatcherInterface::class);
// Clear the names
$plugin = preg_replace('/[^A-Z0-9_\\.-]/i', '', $plugin);
$type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type);
// The path of the plugin
$path = JPATH_PLUGINS . '/' . $type . '/' . $plugin . '/' . $plugin . '.php';
// Return an empty class when the file doesn't exist
if (!is_file($path)) {
return new DummyPlugin($dispatcher);
}
// Include the file of the plugin
require_once $path;
// Compile the classname
$className = 'Plg' . str_replace('-', '', $type) . $plugin;
if ($type === 'editors-xtd') {
// This type doesn't follow the convention
$className = 'PlgEditorsXtd' . $plugin;
if (!class_exists($className)) {
$className = 'PlgButton' . $plugin;
}
}
// Return an empty class when the class doesn't exist
if (!class_exists($className)) {
return new DummyPlugin($dispatcher);
}
// Instantiate the plugin
return new $className($dispatcher, (array) PluginHelper::getPlugin($type, $plugin));
}