4 * Super singleton registry that manages application context.
9 // SINGLETON FUNCTIONALITY
11 /** Private instance of singleton */
12 private static $_instance;
14 /** Private constructor, prevents other people from making it */
15 private function __construct() {
19 /** Retrieves the single instance of the object */
20 static public function getInstance() {
21 if(is_null(self
::$_instance)) {
22 self
::$_instance = new self();
24 return self
::$_instance;
28 * Overloads the instance with another one, usually a mock object
29 * @param Object substitute for XHTMLCompiler
31 static public function setInstance($stub) {
32 self
::$_instance = $stub;
35 // REGISTRY FUNCTIONALITY
37 /** Private instance of PHP wrapper */
38 private static $_PHPWrapperInstance;
40 /** Retrieves the single instance of the PHP wrapper */
41 static public function getPHPWrapper() {
42 if(is_null(self
::$_PHPWrapperInstance)) {
43 self
::$_PHPWrapperInstance = new XHTMLCompiler_PHP();
45 return self
::$_PHPWrapperInstance;
49 * Overloads the instance with another one, usually a mock object
50 * @param Object substitute for XHTMLCompiler
52 static public function setPHPWrapper($stub) {
53 self
::$_PHPWrapperInstance = $stub;
56 // PLUGIN/CONFIGURATION FUNCTIONALITY
58 protected $configKeys = array('allowed_dirs', 'directory_index',
60 protected $config = array();
62 public function loadConf() {
63 require 'config.default.php'; // defaults
64 require 'config.php'; // user
65 $this->config
= compact($this->configKeys
);
67 public function getConf($key) {
68 if (!isset($this->config
[$key])) throw new Exception('No such configuration keypair');
69 return $this->config
[$key];