Hi all,
Looking at AutoLoader's __autoload() method, I see that the mappings are kept in a static internal variable called $localClasses. Would anyone have a problem with allowing this to be augmented by a global?
For example, say in LocalSettings or an extension you had:
$wgAutoloadClassMappings['Article'] = 'extensions/myextension/MyArticle.php';
And MyArticle extends Article, but with extra processing (presumably something which can't currently be done with hooks).
Then, the code inside AutoLoader::__autoload() would contain something like this:
------------ static $localClasses = array( .... ); static $firstRun = true; if ($firstRun) { $firstRun = false; global $wgAutoloadClassMappings; if (!empty($wgAutoloadClassMappings)) { $localClasses = array_merge( $localClasses, $wgAutoloadClassMappings ); } } ------------
I think this could go a long way towards the goals of having a single abstract factory pattern for object instantiation discussed previously as the "Massive Hook Proposal".
I fully expect there's a better way to implement this than what's proposed above. Any thoughts you have about this are much appreciated. Thanks in advance.
-- Jim R. Wilson (jimbojw)
Jim Wilson wrote:
Hi all,
Looking at AutoLoader's __autoload() method, I see that the mappings are kept in a static internal variable called $localClasses. Would anyone have a problem with allowing this to be augmented by a global?
It's called $wgAutoloadClasses. It's there already.
-- Tim Starling
It's called $wgAutoloadClasses. It's there already.
Oh yeah. I see what you're saying - that's great!
Then my new question is, would it be alright to switch the order that $localClases and $wgAutoloadClasses are searched? Currently there is no unilateral way to override existing classes, but there could be if $wgAutoloadClasses were searched first.
-- Jim
On 11/5/07, Tim Starling tstarling@wikimedia.org wrote:
Jim Wilson wrote:
Hi all,
Looking at AutoLoader's __autoload() method, I see that the mappings are kept in a static internal variable called $localClasses. Would anyone have a problem with allowing this to be augmented by a global?
It's called $wgAutoloadClasses. It's there already.
-- Tim Starling
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/wikitech-l
Jim Wilson wrote:
It's called $wgAutoloadClasses. It's there already.
Oh yeah. I see what you're saying - that's great!
Then my new question is, would it be alright to switch the order that $localClases and $wgAutoloadClasses are searched? Currently there is no unilateral way to override existing classes, but there could be if $wgAutoloadClasses were searched first.
I think that would be a recipe for bad coding style: copy, paste and change. Plus it would be fragile, you never know when a class is going to be loaded, it may well be loaded before you manage to override it. Much better to use dynamic class names and factory functions.
-- Tim Starling
Tim Starling wrote:
Jim Wilson wrote:
It's called $wgAutoloadClasses. It's there already.
Oh yeah. I see what you're saying - that's great!
Then my new question is, would it be alright to switch the order that $localClases and $wgAutoloadClasses are searched? Currently there is no unilateral way to override existing classes, but there could be if $wgAutoloadClasses were searched first.
I think that would be a recipe for bad coding style: copy, paste and change. Plus it would be fragile, you never know when a class is going to be loaded, it may well be loaded before you manage to override it. Much better to use dynamic class names and factory functions.
-- Tim Starling
So, what's the preferred method for overriding a core class? Edit its file to change the factory functions??
On 11/11/07, Platonides Platonides@gmail.com wrote:
Tim Starling wrote:
I think that would be a recipe for bad coding style: copy, paste and change. Plus it would be fragile, you never know when a class is going to be loaded, it may well be loaded before you manage to override it. Much better to use dynamic class names and factory functions.
-- Tim Starling
So, what's the preferred method for overriding a core class? Edit its file to change the factory functions??
They would have hooks allowing arbitrary modification or wholesale replacement with descendants, I take it. Except they don't, currently, partly because factory functions aren't used for a lot of important classes (like Article).
It's on my TODO list to make a well-formed Factory class with hooks surrounding object instantiation as well as optional replacement classes - just keep getting busy doing other things.
Centralizing the instatiation of all classes into a single (abstract) Factory would make a wide range of sweeping alterations possible which currently are difficult/impossible to do with existing hooks. For example, sending Images to a third-party for storage and display (such as S3 or Flickr).
-- Jim
On Nov 11, 2007 4:34 PM, Simetrical Simetrical+wikilist@gmail.com wrote:
On 11/11/07, Platonides Platonides@gmail.com wrote:
Tim Starling wrote:
I think that would be a recipe for bad coding style: copy, paste and change. Plus it would be fragile, you never know when a class is going to be loaded, it may well be loaded before you manage to override it. Much better to use dynamic class names and factory functions.
-- Tim Starling
So, what's the preferred method for overriding a core class? Edit its file to change the factory functions??
They would have hooks allowing arbitrary modification or wholesale replacement with descendants, I take it. Except they don't, currently, partly because factory functions aren't used for a lot of important classes (like Article).
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/wikitech-l
wikitech-l@lists.wikimedia.org