Remove trailing whitespace.
[xhtml-compiler.git] / XHTMLCompiler / PHP.php
blob4095d9cbcdc984b344fb9645e892743b286f3f32
1 <?php
3 /**
4 * This class serves as a wrapper to native PHP functions that have
5 * external effects or influences; we are consequently able to stub
6 * this class for unit testing.
7 * @note Please retrieve this class using XHTMLCompiler::getPHPWrapper()
8 * @note PHP's original function names were normalized to use camel-caps
9 * @todo Factor out filesystem related functionality to another wrapper?
11 class XHTMLCompiler_PHP
14 /** Sends an HTTP header, equivalent to header() */
15 public function header() {
16 $args = func_get_args();
17 call_user_func_array('header', $args);
20 /** Sends HTTP headers to indicate output is XML **/
21 public function headerXML() {
22 $this->header('Content-type: application/xml');
25 /** Outputs text, equivalent to echo */
26 public function paint($text) { echo $text; }
28 /** Retrieves the relative URI with which the page was requested. */
29 public function getRequestURI() {return $_SERVER['REQUEST_URI'];}
31 /** Retrieves the relative URI which denotes the frontend PHP file */
32 public function getPHPSelf() {return $_SERVER['PHP_SELF'];}
34 /** Retrieves a parameter from GET superglobal, does magic quote cleaning */
35 public function getGVal($key) {
36 if (!isset($_GET[$key])) return false;
37 $val = $_GET[$key];
38 // ad hoc magic_quotes protection, not comprehensive because
39 // we don't deal with very complicated parameters.
40 if (is_string($val) && get_magic_quotes_gpc()) $val = stripslashes($val);
41 return $val;
44 /** Returns true if passed filename is directory */
45 public function isDir($dir) {return is_dir($dir);}
47 /** Returns true if passed filename is file */
48 public function isFile($file) {return is_file($file);}
50 /**
51 * Resolves a relative path into an absolute one
52 * @note This also normalizes Windows backslashes into forward slashes
54 public function realpath($path) {
55 $path = realpath($path);
56 if ($path === false) return false;
57 return str_replace('\\', '/', $path);
60 /** Returns HTTP status code server was originally going to send */
61 public function getRedirectStatus() {return (int) getenv("REDIRECT_STATUS");}