Add dependency checking for included files.
[htmlpurifier-web.git] / xhtml-compiler / XHTMLCompiler / PHP.php
blob77c72d36421ade4f6e335d912a96e6cc36ed2b18
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 /** Outputs text, equivalent to echo */
21 public function paint($text) {echo $text;}
23 /** Retrieves the relative URI with which the page was requested. */
24 public function getRequestURI() {return $_SERVER['REQUEST_URI'];}
26 /** Retrieves the relative URI which denotes the frontend PHP file */
27 public function getPHPSelf() {return $_SERVER['PHP_SELF'];}
29 /** Retrieves a parameter from GET superglobal, does magic quote cleaning */
30 public function getGVal($key) {
31 if (!isset($_GET[$key])) return false;
32 $val = $_GET[$key];
33 // ad hoc magic_quotes protection, not comprehensive because
34 // we don't deal with very complicated parameters.
35 if (is_string($val) && get_magic_quotes_gpc()) $val = stripslashes($val);
36 return $val;
39 /** Returns true if passed filename is directory */
40 public function isDir($dir) {return is_dir($dir);}
42 /** Returns true if passed filename is file */
43 public function isFile($file) {return is_file($file);}
45 /**
46 * Resolves a relative path into an absolute one
47 * @note This also normalizes Windows backslashes into forward slashes
49 public function realpath($path) {return str_replace('\\', '/', realpath($path));}
51 /** Returns HTTP status code server was originally going to send */
52 public function getRedirectStatus() {return (int) getenv("REDIRECT_STATUS");}