Hi Bob, it certainly makes sense in a theoretical way, but lets take the OnUserActivate event. When the plugin is invoked,
$profile = $modx->user->getOne('Profile');
is of no use whatsoever. The "user" is the "anonymous" user. So lets turn to the "passed parameter" (which was my original question in my original post which led me to start this one). That question was, more or less, "Using the passed parameter, how do I access the "username" and user profile information for the user who "has just been activated?" [For what it is worth, after the plugin returns, whether the plugin does anything or not, the user will be put into a logged-in state.]
The documentation for the Login extra (which I’m using) states: "ConfirmRegister also fires the OnUserActivate plugin event after the User is activated, and passes in a ’user’ parameter, which contains the newly-activated modUser object."
I, perhaps not understanding how the object-oriented PHP code works, or perhaps what some things represent in MODx, went through the MODx documentation and found that modUser::getSettings: "Gets all user settings in array format." So I thought,
$actUser = $modx->getOption('user', $scriptProperties, '');
$formPlaceHolderPairs = $actUser->getSettings();
Would do what I wanted. That’s not the case, which is why I turned to the forums in the first place. My post was called "Processing parameter(s) passed to plugin". What I was told was: "in the plugin, the user object is available as $user and $scriptProperties is not available.".
NOW I started to question how the architecture was set up (or perhaps documented): What is $user? The documentation doesn’t say $scriptProperties is not available. What it says is: "Plugins are similar to snippets in that they are snippets of code that have access to the MODx API - however the big difference is that Plugins are associated with specific System Events." Now the examples given only access data through the modx object, so they certainly implied that parameters should be accessed the same way. The documentation on properties says: "You can also get a snippet property with $modx->getOption() like this:" (and gives an example).
So, this technically doesn’t qualify as looking at the "core code", but I did look at the ConfirmRegister snippet code. After a bit of code that prevents the snippet doing any further processing if it "Could not save activated user", we have the following:
/* invoke OnUserActivate event */
$modx->invokeEvent('OnUserActivate',array(
'user' => &$user,
));
I think that would suggest that a parameter called "user" is being passed using a "modx" mechanism.
I thought (and still do) that what I’ve read about the MODx architecture makes it the kind of CMS (or CMS Framework) that I want to use; but I do start to question things when I cannot find out how to use the documented parameter-passing mechanism — especially when I do dig enough to see the above code is how the plugin in question is being invoked. That code seems to me (a retired, old-fashioned procedural language programmer) to say:
- Call the "invokeEvent" method of the "modx" object
- Tell it to fire the "OnUserActivate" event
- Pass the invoked event handler(s) a parameter array with the parameter "user" and the value "$user" being passed by reference
It certainly doesn’t suggest accessing the variable "$user" (it is a variable, though you can call it an object handle, or whatever you want in an OOP environment). Presumably other event handlers may get passed other parameters. Perhaps none of the MODx code relies on any of its variables being left untouched after a snippet or plugin has been invoked. I don’t know. I do know that regardless of whether the variable is "global" by a strict PHP definition, if some code is to be invoked in isolation, it shouldn’t be accessing variables not defined in its code except via a parameter passing mechanism (the modx object is one such mechanism).
In my opinion it is not inappropriate to raise such an issue or question whether relying on such accesses is violating architectural integrity — without a prerequisite being to read all the code. If one reads all the code (probably close to impossible, especially if one strives to understand it), then one has no need to ask questions as one will know the answers.
It’s really no different than questioning the performance of the system (which people do). I’ve noticed the performance issue. I understand how such problems arise and that there are techniques that can be used to address them — and undoubtedly will be used as MODx Revolution matures. But I also know that there are limits to improving the performance of computer software without using different algorithms and architecture. So if someone questions the architecture or what algorithms are being used, they are not being inappropriate just because they haven’t read the code.