Dud commit.
[xhtml-compiler.git] / XHTMLCompiler.php
blob4a4bc83179e3517dbfcbf303b6737cfd781ca6ac
1 <?php
3 /**
4 * Super singleton registry that manages application context.
5 */
6 class XHTMLCompiler
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() {
16 $this->loadConf();
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;
27 /**
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;
48 /**
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',
59 'indexed_dirs', 'web_path');
60 protected $config = array();
61 protected $filterManager;
63 public function loadConf() {
64 $filters = new XHTMLCompiler_FilterManager();
65 require 'config.default.php'; // defaults
66 require 'config.php'; // user
67 $this->config = compact($this->configKeys);
68 $this->filterManager = $filters;
70 public function getConf($key) {
71 if (!isset($this->config[$key])) throw new Exception('No such configuration keypair');
72 return $this->config[$key];
74 public function getFilterManager() {return $this->filterManager;}