markjaquith / WP-TLC-Transients

GNU General Public License v2.0
341 stars 37 forks source link

Allow for class versioning, load the most recent version available #20

Open markjaquith opened 11 years ago

markjaquith commented 11 years ago

Multiple plugins could be bundling TLC Transients. Instead of letting the first one "win", we should use the most recent version available (and then just strive to avoid changes that break backwards compatibility).

Rarst commented 11 years ago

I see the issue (WP doesn't do dependencies) and there is prior art (mostly by @scribu that I know of) however my concerns are that it will probably need to cancel out class autoload and doing this in runtime every page load is hardly appealing.

There isn't really neat solution for bundling case that I can see. :\ Well, I see Composer for myself, but it has zilch adoption and nowhere near level of generic solution for WP context.

markjaquith commented 11 years ago

I think it could still be handled. There would just be different routes of inclusion. You'd do the autoloading Composer method, and WordPress plugins would manually include the file that would bootstrap an internal multi-version handler.

Rarst commented 11 years ago

So what would be technicalities of this... We have tlc-transients.php already acting as "direct" loader, Composer doesn't need it and can just ignore it. So custom version handling logic goes there.

On including that file it needs to add to registry of available versions and later the newest possible of them needs to be loaded.

Outstanding questions:

markjaquith commented 11 years ago

where does version information comes from?

I think each tlc-transients.php would stick it in a global (it would be cleaned up later). So something like:

$GLOBALS['wp_tlc_transients']['1.0'] = __FILE__;

Then the loader would inspect this global, and load and instantiate the singletons and load the correct tlc_transient() function definition.

at which point we are sure that all instances of lib had been pinged?

Well, the update server runs on init at priority 9999, so after that, including it won't work. So yeah, I think something on the init hook would be ideal.