Delete htmlpurifier folder, svn:externals will create it for me.
[xhtml-compiler.git] / XHTMLCompiler.php
blob74dd476452f3f0f645899f56ff20f7a0a4f509d8
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');
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];