Quote from: BobRay at Jan 24, 2009, 05:12 PM
Those methods seem *way* more complicated then getWebUserInfo(), or does $modx->user contain all the info that used to come from the *UserInfo() functions?
I would not call this *way* more complicated; the array merge may seem awkward at first, but this is because of habit and expectation. It’s a lot more flexible and powerful now that we are dealing with something other than simple arrays, and I think it is such a completely different way of dealing with data that it is making people perceive this as more complicated than it really is. Well, that and a lack of good documentation to help folks more fully understand the new object-oriented, xPDO-based API.
We’re changing paradigms to an object-oriented one based on important design patterns, and though it seems more complicated at first, those methods are the core of the new API. Once you know the core object methods of xPDO (i.e. getObject(), getCollection(), getObjectGraph(), getCollectionGraph()), and the related object methods of xPDOObject (i.e. getOne() and getMany()), you can access any of the MODx data, regardless of where it is stored or managed, and do things previously impossible without hard-code programming skills or duplicating/hacking core code. And because the methods are consistent across every class, you don’t have to look up the crazy name of the method for dealing with each different piece of data.
What we have in Revolution is a user domain object (for credentials) and a user profile domain object (for identity), whereas the deprecated methods simply returned an array of data combined from the user and user_attributes tables. The difference may seem trivial, but the new structure allows us to change the storage and behavior of the objects completely if we so choose without changing anything in the core; we simply provide a derivative user and/or user profile class. And it gets an instance of a class: an object.
Once you have the object (any object, not just a user), you can get an array of it’s data with the simple xPDOObject function toArray(). Now you have the equivalent of what the function returns. But the object provides a whole lot more. With the object you now have access to any data that is related to it, again through a consistent set of core functions that do not change from class to class.
Ultimately, the code cost of maintaining the class specific functions in the modX class, which is required by every request to modX, be it via requests to MODx or API integration with other code, outweighs the small amount of convenience they appear to provide on the surface. But, once you fully understand all of the additional power and flexibility you gain by dealing with the objects directly, using the generic methods xPDO provides to get an array of the data you want will become a trivial task.