So, I'm facing the almighty "Class Bla not found" error on one of my website.
The class file sits in the vendor
folder and I'm using an event observer for the autoload:
<events>
<resource_get_tablename>
<observers>
<composer_autoloader>
<type>singleton</type>
<class>module/observer</class>
<method>addComposerAutoloader</method>
</composer_autoloader>
</observers>
</resource_get_tablename>
</events>
Here's my observer:
class Vendor_Module_Model_Observer
{
/**
* @var bool
*/
protected static $added = false;
/**
* Register the Composer autoloader
* @param Varien_Event_Observer $observer
*/
public function addComposerAutoloader(Varien_Event_Observer $observer)
{
if (self::$added === false) {
/** @var $helper Vendor_Module_Helper_Data */
$helper = Mage::helper('module');
$helper->registerAutoloader();
self::$added = true;
}
}
}
And here's my helper method:
public function registerAutoloader($path = null, $filename = null)
{
if ($path === null) {
$path = $this->getVendorDirectoryPath();
}
if ($filename === null) {
$filename = self::AUTOLOAD_FILENAME;
}
if (file_exists($path . DS . $filename)) {
require_once($path . DS . $filename);
}
}
According to my tests using xDebug, the observer is properly triggered and the require_once
leading to my vendor/autoload.php
is called.
I've checked the namespace I use to call my custom class and I'm 100% sure there's no typo.
NB: please note that if I get rid of this composer code and if I patch the app/Mage.php
directly with the following code, it does not work either:
/** AUTOLOADER PATCH **/
if (file_exists($autoloaderPath = BP . DS . '../vendor/autoload.php') ||
file_exists($autoloaderPath = BP . DS . 'vendor/autoload.php')
) {
require $autoloaderPath;
}
/** AUTOLOADER PATCH **/
So my question is: how do I debug that error ? Any usual suspects ?