I'm working on a custom Joomla! CLI application and would like to rely on an external PHP library to reuse some functionality.
// Set flag that this is a parent file. const _JEXEC = 1; error_reporting(E_ALL | E_NOTICE); //error_reporting(E_ALL & ~E_NOTICE); ini_set('display_errors', 1); // Load system defines if (file_exists(dirname(__DIR__) . '/defines.php')) { require_once dirname(__DIR__) . '/defines.php'; } if (!defined('_JDEFINES')) { define('JPATH_BASE', dirname(__DIR__)); require_once JPATH_BASE . '/includes/defines.php'; } require_once JPATH_LIBRARIES . '/import.legacy.php'; require_once JPATH_LIBRARIES . '/cms.php'; // Load the configuration require_once JPATH_CONFIGURATION . '/configuration.php'; require_once JPATH_SITE . '/modules/gng/gng_shared.php'; $myApp = JApplicationCli::getInstance('GNGEmailToGuideDownloader'); $hostname = GNGParam::getParam('email', 'hostname'); $username = GNGParam::getParam('email_account_guides', 'username'); $password = GNGParam::getParam('email_account_guides', 'password'); $myApp->initStream($hostname, $username, $password); $myApp->execute(); The CLI application is based on the GNGEmailToGuideDownloader class that is stored in the gng_shared.php file. This class should use the functionalities of the external library.
I copied the directory structure of the source code of the library in the same folder where the gng_shared.php file is stored:
Finally I tried to use the JLoader::register mechanism to load the classes in the library, so that I can instantiate and use them:
//retrieves new guides@ email from the server, saves it in the DB and notifies the guide class GNGEmailToGuideDownloader extends GNGEmailDownloader { //downloads the emails from the stream and assigns them to a tour or inquiry public function loadEmails() { $filepath = JPATH_SITE . '/modules/gng/EmailReplyParser/Parser/EmailParser.php'; if (file_exists($filepath)) { JLoader::register('EmailParser', $filepath); $parser = new EmailParser(); } In the EmailParser.php there is the appropriate class:
namespace EmailReplyParser\Parser; use EmailReplyParser\Email; use EmailReplyParser\Fragment; /** * @author William Durand <[email protected]> */ class EmailParser { const QUOTE_REGEX = '/>+$/s'; However on the line where I'm trying to create the parser object I get the following error message when I'm running the CLI app:
Fatal error: Class 'EmailParser' not found in /home/gonative/public_html/dev/modules/gng/gng_shared.php on line 1737
What am I doing wrong?

modules/gngfolder contain a Joomla module? If it does, it should havemod_prefix (the folder should bemodules/mod_gngand the main module filemod_gng.php) to avoid various issues across Joomla. If not, it should not be installed in Joomla's modules directory.