carlwhat:
i turned the DEBUG_AUTOLOAD on. and i could not get the proper file path to come up with for an observer from within the encapsulated directory. so instantiating it is kind of besides the point.
file paths are much trickier from within the encapsulated plugins. i'm not sure how much you have played with them. the auto load does a whole bunch of different things which unfortunately i do not have time to debug and play with.
my testing suggests that currently you will have to do some tricky things from within the auto_loaders config file to get to an observer from within an encapsulated plugin.
would love for you to prove me wrong or show me the way!
best.
Challenge accepted?! :)
DrByte:
zcwilt just mentioned that there does exist a getPluginVersionDirectory() function:
https://github.com/zencart/zencart/blob/v157/includes/classes/PluginManager.php
which is also used in the various methods of
https://github.com/zencart/zencart/blob/v157/includes/classes/InitSystem.php
The second link provides functionality that would get you to the point of loading and instantiating an observer class through the use of the auto_loaders type structure. Basically whatever "function" you wanted to be done would be the 'autoType' in the auto_loaders file. Effectively the method called within the InitSystem is 'processAutoLoader' . $var['autoType'] (yes there is some case play, but lets say you wanted to load a class file (such as an observer), then the 'autoType' would be 'class' to load the class, then 'classInstantiate' to initialize the class (calling its __construct method).)
To "simply" require a file would in fact need some "path" information as discussed above about "finding" where things are currently located so that the associated processAutoLoaderRequire method could pull in the correct file(s).
For loading a class would likely have the autoloader look something like:
<?php
if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
}
$autoLoadConfig[200][] = [
'autoType' => 'class',
'classPath' => 'observers/',
'loadFile' => 'new_observer.php',
];
$autoLoadConfig[200][] = [
'autoType' => 'classInstantiate',
'className' => 'zcObserverNewObserverClass',
'objectName' => 'myObsVariable',
'classSession' => false,
'checkInstantiated' => false,
];
This seems as if it would load an observers class in the admin directory of the plugins section for "this" version of the plugin.
The last two variables of the classInstantiate section are not required, but at least provide a template for what might be expected in instantiating a class through the plugin controller...
ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...