Last couple of threads I’ve been in here have been grousing about this problem. I recently got slightly burned with a dependency issue that took 20 minutes to figure out. After fixing it I moved to address the problem itself.
The class HTMLResponder needs a map of the available template files. This is normally provided by an array built by the SettingBuilder class during testing, or from a cache file during production. I was attaching the the output to core. After the little needle in haystack game I’m going to try this.
class HTMLResponder extends Responder {
protected static $templateFiles = array();
/**
* The name of the master template used to frame the page contents
* and write the HTML heading.
*
* @var string
*/
protected static $masterTemplate = 'master';
public static function setTemplates ( $templates ) {
assert(is_array($templates));
self::$templateFiles = $templates;
}
public static function setMasterTemplate( $master ) {
self::$masterTemplate = strval($master);
}
public function __get( $var ) {
// PHP is weird sometimes. This is a workaround so that instantiated
// Responders can see the static properties of the class.
if ( $var == 'templateFiles') {
return self::$templateFiles;
} else if ($var == 'masterTemplate') {
return self::$masterTemplate;
} else {
throw new FatalException('No access to '.$var);
}
}
That isn’t the whole class of course, just what’s relevant here. With this approach the HTMLResponder::setTemplates method needs to be called statically and the array supplied before any instances can be started.
I wonder why the makers of PHP saw fit to make the __get function above necessary (without it the instantiated objects cannot smoothly call the static elements in $this->var format ).
A Unit Tester can supply a proper array and run the class now without the rest of the framework being called. That should be useful eventually.