User Tools

Site Tools


Deep overrides (stewload example with discussion)

Cascading overrides? Chained overrides? Intermediate ? Dunno what to call them.

Here is what we mean.

stewLoader has built in methods to load libraries, services, components or anything else.

It is the “anything else” we are talking about now.

For one site, we needed to tweak the javascript in static/jscript/main.js

So we copied ./static/jscript/main.js to ./custom/static/jscript/main.js

Oh no! Nothing happened, we did not see our tweaks.

So we edited stewload.sett.php and turned on logging.

./file/cache/stewload.php showed us that main.js was picked out of the custom folder by stewLoader under the “required” section (not a lib, not a service, not a component). Good.

But ./file/log/stewload.log told us it had loaded the fox copy.

What gives?

It must be that fox is loading the jscript some other way. Which makes sense, js is not php, it would not be appear in a php require statement.

So we dig a little, and find where the content is loaded.

We find it in ./include/library/file/minimize.class.php

We need to make the minimize class recognize stewLoader.

So the minimize class is our “intermediate” or “deep” override. We expect to gather a few of these as time goes by. Here we are not customizing the script per se, we are just customizing so that it uses stewLoader.

So we copy the minimize class to the custom folder, then replace file_get_contents() with stewLoader::get_contents()


Grungy details

Here are the changes we made to ./include/custom/file/minimize.class.php

Notice we have separate entry points for file_get_contents when we know it is js vs css.

That is just hedging our code bets against future changes that might apply to css but not js or vice versa. Currently both calls resolve to stewLoader::get_contents, and that will be enough to cover most cases.

CUT AND PASTE (take your pick)

stewLoader::get_contents($sFile);         // replaces file_get_contents(PHPFOX_DIR,...)

Also note: this works for minified css and js. If we are not minimizing, then it will be loaded somewhere else, and that code needs to be tracked down.

It seems likely we will end up overriding template.class.php so it can use stewLoader for unminified js. But we do not know yet, we will cross that bridge when we come to it.

But that would be another case of an “intermediate” override. We had to customize the file that does the loading so it will use stewLoader.

Let this be a lesson for you future coders ;) It is generally unwise to load willy-nilly. A centralized strategy would make sense.

The only touchy part in all of the above is where we said “so we dig around a little”.

Some of you may not be able to dig much. Use the forums to ask for help or send an email ;)

products/stewload/jscript.txt · Last modified: 2014/07/02 14:39 by steward