Page MenuHomePhabricator

Make StaticArrayWriter able to wrap things in a PHP class
Open, Needs TriagePublic

Description

cf https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/Babel/+/574823/

Hmm, why not make a class with a static property like Names.php? Then you could let autoloader deal with loading the stuff rather than doing it manually.

Nikerabbit: mostly because Wikimedia\StaticArrayWriter doesn't support outputting the array as a class property. It may make sense to support that in the future, but I'd rather not do that here.

It'd be useful if StaticArrayWriter (or some replacement) was able to output files wrapped in a PHP class, and a property/function, rather than just a php file with return []; or similar. This would allow usage of autoloading and work better than manually including/requiring php code files like we do in various places currently

		static $isoNames = false;
		if ( !$isoNames ) {
			$isoNames = require __DIR__ . '/../names.php';
		}
		if ( isset( $isoNames[$code] ) ) {
			return $isoNames[$code];
		}
		return false;