We have a special situation where we include Joomla from within Yii 2, which worked fine with Joomla 3, but Joomla 4.2 is so far giving us some problems. The latest issue is:
Error: Class "Joomla\Plugin\Actionlog\Joomla\Extension\Joomla" not found
Some forum threads recommend to delete autoload cache in administrator/cache/ folder, but we have no such file.
Our current bootstrapping code looks like this:
// Include defines.php and framework.php omitted
$container = \Joomla\CMS\Factory::getContainer();
$container->alias(\Joomla\Session\SessionInterface::class, 'session.cli');
$app = \Joomla\CMS\Factory::getContainer()->get(\Joomla\CMS\Application\SiteApplication::class);
\Joomla\CMS\Factory::$application = $app;
\Joomla\CMS\Plugin\PluginHelper::importPlugin('system');
$app->triggerEvent('onAfterInitialise', []);
Note that we need to use SiteAppplication to get getDocument() to work properly.
It fails on PluginHelper::importPlugin().
Any tips? Should we perhaps hack the Yii 2 composer.json file to point the namespace correctly? Or is there a simple command missing to setup Joomla correctly? Another solution to maybe add a new spl_autoload_register.
This error appears both locally with a git clone joomla-cms, and on our live server.
Edit: Adding this PSR-4 instruction to our Yii 2 composer.json did not work, it seems
80 "psr-4": {
81 "Joomla\\Plugin\\": "joomla-src/plugin"
82 }
Maybe the autoloaders inside Joomla are not PSR-4 compliant?
Edit 2: No way to programmatically generate the autoloader psr4 file in cache folder? We have a copy from live site, but I need to figure out how to load it properly.
Trying this:
require_once JPATH_LIBRARIES . '/namespacemap.php';
$extensionPsr4Loader = new \JNamespacePsr4Map();
$extensionPsr4Loader->load();