- Add test folder
[xhtml-compiler.git] / singleton.php
blobfa164547c94694a5abc7cbbfafd656fee375901d
1 <?php
3 /**
4 * Super singleton object that does everything. Used for unit testing.
5 */
6 class XHTMLCompiler
9 /** Private instance of singleton */
10 private static $_instance;
12 /** Private constructor, prevents other people from making it */
13 private function __construct() {}
15 /** Retrieves the single instance of the object */
16 static public function getInstance() {
17 if(is_null(self::$_instance)) {
18 self::$_instance = new self();
20 return self::$_instance;
23 /**
24 * Overloads the instance with another one, usually a mock object
25 * @param Object substitute for XHTMLCompiler
27 static public function setInstance($stub) {
28 // unit testing only!
29 self::$_instance = $stub;
32 /** Aborts script execution, equivalent to exit */
33 public function quit() {exit;}
35 /** Sends an HTTP header, equivalent to header() */
36 public function header() {
37 $args = func_get_args();
38 call_user_func_array('header', $args);
41 /** Outputs text, equivalent to echo */
42 public function paint($text) {echo $text;}
44 /** Retrieves the relative URI with which the page was requested. */
45 public function getRequestURI() {return $_SERVER['REQUEST_URI'];}
47 /** Retrieves the relative URI which denotes the frontend PHP file */
48 public function getPHPSelf() {return $_SERVER['PHP_SELF'];}