XF 2.0 Autoloading 3rd party classes?

Siropu

Well-known member
I've tried \XF::$autoLoader->add('someClass', \XF::getAddOnDirectory() . DIRECTORY_SEPARATOR . 'path/to/class'); in appSetup but doesn't include anything.
 
By my reckoning that should work.

I have an experimental add-on which generates fake data using a library called Faker and this works fine for me:
PHP:
public static function appSetup(\XF\App $app)
{
    \XF::$autoLoader->add('Faker', \XF::getAddOnDirectory() . '/TestAddOn/_vendor/fzaninotto/faker/src');
}
 
It doesn't work for me. The class I'm trying to load is a simple class with no namespaces.
 
Shouldn't need a namespace with that, you will probably need to reference the class as \someClass instead of someClass though
 
By my reckoning that should work.

I have an experimental add-on which generates fake data using a library called Faker and this works fine for me:
PHP:
public static function appSetup(\XF\App $app)
{
    \XF::$autoLoader->add('Faker', \XF::getAddOnDirectory() . '/TestAddOn/_vendor/fzaninotto/faker/src');
}
Is it worth waiting in xf2 or will there be an add-on for xf2?
 
I’m not sure what you’re asking but if it’s about the specifics of the add on then it’s nothing that is XF related it was just an experiment for the most part.
 
For simple classes, I believe you have to use a class map:
PHP:
\XF::$autoLoader->addClassMap([
    'Class_Name' => \XF::getAddOnDirectory().'/path/to/class.php',
]);

add() and addPsr4() are for adding PSR-0 and PSR-4 namespaced classes only.
 
I’m not sure what you’re asking but if it’s about the specifics of the add on then it’s nothing that is XF related it was just an experiment for the most part.
very sorry, would be a useful tool for developers
 
Back
Top Bottom