Implement ConfigLinker, transforming <a xc:configdoc="...">
[xhtml-compiler.git] / XHTMLCompiler.php
blobd8e256349cfc5dd096afe5d4e203d5749e573d58
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', 'web_domain', 'viewvc_url',
60 'svn_headurl_munge', 'debug', 'error_xsl', 'admin_email',
61 'error_log', 'error_mute', 'configdoc');
62 protected $config = array();
63 protected $filterManager;
65 public function loadConf() {
66 $filters = new XHTMLCompiler_FilterManager();
67 require 'config.default.php'; // defaults
69 // user configuration
70 if (file_exists($f = dirname(__FILE__) . '/conf/config.php')) require $f;
71 if (file_exists($f = dirname(__FILE__) . '/config.php')) require $f;
73 $this->config = compact($this->configKeys);
74 $this->filterManager = $filters;
76 public function getConf($key) {
77 if (!isset($this->config[$key])) throw new Exception('No such configuration keypair');
78 return $this->config[$key];
80 public function getFilterManager() {return $this->filterManager;}