> In *most* cases, the instance variable is a static variable defined in the
> getInstance function...making it difficult to override or change in any
> way[I think some complex work with the reflection class might be able to
> update it].
That is legacy PHP4 style.
> However, in the *new* code in the system, it tends to be a static variable
> for the class. See JForm, JFilterInput, JDatabase, JLanguage, and JURI
That's the way it should be in PHP5+ (although singletons are evil
regarding testability).
> So the question I have is if these classes are exceptions to the standard,
> or if these classes are the new standard?
The latter.
> My class is a subclass of JMail and then I just override what I
> want to change and add a system plugin to create my custom instance and
> override JMail's. If JMail had stored the $instance variable as a global,
> it would have been easier since then I could have accessed it directly and
> overridden it without having to hack core.
With a correct design, the Mailer instance would not depend on the name
"JMail", but would be created by the main controller (or a plugin to
it), and be injected into a dependency container for further use.
Unfortunately, a lot of the techniques used, are heritage from old Mambo
times and have not been corrected until now. Let's hope, this will be
done in future versions (there are a lot of signs showing this will happen).
Until then, don't derivate from JMail, but make a copy of it and change
it directly. Then register your class with JLoader at system start
(using a system plugin). Then the first call to JMail will pull *your*
class instead of the original - without changing the core.
HTH
Niels
--
| http://www.kolleg.de · Das Portal der Kollegs in Deutschland |
| http://www.bsds.de · BSDS Braczek Software- und DatenSysteme |
| Webdesign · Webhosting · e-Commerce · Joomla! Content Management |
------------------------------------------------------------------
--
You received this message because you are subscribed to the Google Groups "Joomla! Framework Development" group.
To post to this group, send an email to joomla-dev...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-frame...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-framework?hl=en-GB.
On 02.09.2011 16:24, garyamort wrote:The latter.
> My class is a subclass of JMail and then I just override what I
> want to change and add a system plugin to create my custom instance and
> override JMail's. If JMail had stored the $instance variable as a global,
> it would have been easier since then I could have accessed it directly and
> overridden it without having to hack core.With a correct design, the Mailer instance would not depend on the name
"JMail", but would be created by the main controller (or a plugin to
it), and be injected into a dependency container for further use.
Unfortunately, a lot of the techniques used, are heritage from old Mambo
times and have not been corrected until now. Let's hope, this will be
done in future versions (there are a lot of signs showing this will happen).Until then, don't derivate from JMail, but make a copy of it and change
it directly. Then register your class with JLoader at system start
(using a system plugin). Then the first call to JMail will pull *your*
class instead of the original - without changing the core.
>> Until then, don't derivate from JMail, but make a copy of it and change
>> it directly. Then register your class with JLoader at system start
>> (using a system plugin). Then the first call to JMail will pull *your*
>> class instead of the original - without changing the core.
> I still see that as hacking core, it's just keeping your code out of the
> core library folder.
Then you have a wrong perspective. The main advantage of my solution
over yours is, that it will survive updates to the core, because it is
*not* a core hack. It uses the way, Joomla! offers to override core
classes. As said, it is not the best technique, but it works well.
> What I do is make a minimally changed copy of the core file to allow me to
> override the getInstance method, then I create my own custom subclass.
But on any update, your change gets lost, because it is a core hack.
> That allows me to keep all my customization exclusive to the GMessage class,
> while still allowing it to 'just work' for other components which expect to
> use JMail.
JMail offers the possibilty to have different instances for different
purposes. Your solution is ok so far, but you should override the core
JMail with your modfied version as I described earlier.
Regards,
The other possibility of course is to commit to working on JMail so it is modernized and more usable.