4 * Super singleton object that does everything. Used for unit testing.
6 // TODO: Factor out configuration and PHP wrapper/gateway, possibly
7 // also creating Filesystem subclass
11 // SINGLETON FUNCTIONALITY
13 /** Private instance of singleton */
14 private static $_instance;
16 /** Private constructor, prevents other people from making it */
17 private function __construct() {
21 /** Retrieves the single instance of the object */
22 static public function getInstance() {
23 if(is_null(self
::$_instance)) {
24 self
::$_instance = new self();
26 return self
::$_instance;
30 * Overloads the instance with another one, usually a mock object
31 * @param Object substitute for XHTMLCompiler
33 static public function setInstance($stub) {
35 self
::$_instance = $stub;
38 // REGISTRY FUNCTIONALITY
40 /** Private instance of PHP wrapper */
41 private static $_PHPWrapperInstance;
43 /** Retrieves the single instance of the PHP wrapper */
44 static public function getPHPWrapper() {
45 if(is_null(self
::$_PHPWrapperInstance)) {
46 self
::$_PHPWrapperInstance = new XHTMLCompiler_PHP();
48 return self
::$_PHPWrapperInstance;
52 * Overloads the instance with another one, usually a mock object
53 * @param Object substitute for XHTMLCompiler
55 static public function setPHPWrapper($stub) {
56 self
::$_PHPWrapperInstance = $stub;
59 // PLUGIN/CONFIGURATION FUNCTIONALITY
61 protected $configKeys = array('allowed_dirs', 'directory_index', 'filename_chars');
62 protected $config = array();
64 public function loadConf() {
65 require 'config.default.php'; // defaults
66 require 'config.php'; // user
67 $this->config
= compact($this->configKeys
);
69 public function getConf($key) {
70 if (!isset($this->config
[$key])) throw new Exception('No such configuration keypair');
71 return $this->config
[$key];