Hi, I developed a simple service class to interface with paypal, and triying to instantiate using $modx->getService like this:
$admUsrMgr = $modx->getService(
‘PayPalConnector’,
‘PayPalConnector’,
‘/html/modxMonster/plugins/’
);
But everytime the code execution gets to this place, the constructor is called again, doing some deeper debug, I find that when it gets into the method, it creates the class and stores it into the services array, but on later calls, the service instance is gone, what Im misggin? below some of my code.
Snippet:
require_once(dirname($modx->getOption(‘base_path’)).‘/html/modxMonster/plugins/reportChangesOnAdminUsers.php’);
PayPalConnector::loadService($modx);
return $modx->PayPalConnector->processEvent();
Relevant class code
public static function loadService($modx) {
// $corePath = $modx->getOption(‘modxMonster.core_path’);
$admUsrMgr = $modx->getService(
‘ReportChangesOnAdminUsers’,
‘ReportChangesOnAdminUsers’,
‘/html/modxMonster/plugins/’
);if (!($admUsrMgr instanceof ReportChangesOnAdminUsers)){ $modx->log(modX::LOG_LEVEL_ERROR, "Could not load AdminUserChangesSupervisor!!!!"); }
}
The code itself works as expected, but I was wondering why the class instance isn’t kept and it worries me that it can lead to memory issues in the future.