<?
///Used to keep track of inclusions and to get better errors on failed requires
/**
@note For this case, since phpe doesn't like it when you use "include" or "require" for method names, I have abbreviated the names.
*/
class Files{
static private $included;///<an array of included files along with other arguments
static private $currentInclude;///<internal use
///used to factor out common functionality
static function __callStatic($name,$arguments){
self::$currentInclude = array(
'file'=>$arguments[0],
'globals'=>$arguments[1],
'vars'=>$arguments[2],
'type'=>$name
);
return call_user_func_array(array('self',$name),$arguments);
}
///include a file
/**
@param file file path
@param globalize list of strings representing variables to globalize for the included file
@param vars variables to extract for use by the file
@return true if file successfully included, else false
*/
private static function inc($file,$globalize=null,$vars=null){
if(is_file($file)){
self::logIncluded(true);
if($globalize){
foreach($globalize as $global){
global $$global;
}
}
if($vars){
extract($vars,EXTR_SKIP);#don't overwrite existing
}
include($file);
return true;
}
self::logIncluded(false);
}
///include a file once
/**
@param file file path
@param globalize list of strings representing variables to globalize for the included file
@param vars variables to extract for use by the file
@return true if file successfully included, else false
*/
private static function incOnce($file,$globalize=null,$vars=null){
if(is_file($file)){
self::logIncluded(true);
if($globalize){
foreach($globalize as $global){
global $$global;
}
}
if($vars){
extract($vars,EXTR_SKIP);#don't overwrite existing
}
include_once($file);
return true;
}
self::logIncluded(false);
}
///require a file
/**
@param file file path
@param globalize list of strings representing variables to globalize for the included file
@param vars variables to extract for use by the file
@return true if file successfully included, else false
*/
private static function req($file,$globalize=null,$vars=null){
if(is_file($file)){
self::logIncluded(true);
if($globalize){
foreach($globalize as $global){
global $$global;
}
}
if($vars){
extract($vars,EXTR_SKIP);#don't overwrite existing
}
include($file);
return true;
}
self::logIncluded(false);
Debug::throwError('Could not include file "'.$file.'"');
}
///require a file once
/**
@param file file path
@param globalize list of strings representing variables to globalize for the included file
@param vars variables to extract for use by the file
@return true if file successfully included, else false
*/
private static function reqOnce($file,$globalize=null,$vars=null){
if(is_file($file)){
self::logIncluded(true);
if($globalize){
foreach($globalize as $global){
global $$global;
}
}
if($vars){
extract($vars,EXTR_SKIP);#don't overwrite existing
}
include_once($file);
return true;
}
self::logIncluded(false);
Debug::throwError('Could not include file "'.$file.'"');
}
private static function logIncluded($result){
self::$currentInclude['result'] = $result;
self::$included[] = self::$currentInclude;
}
///get all the included files included by functions from this class
static function getIncluded(){
return self::$included;
}
///remove relative parts of a path that could be used for exploits
static function removeRelative($path){
return preg_replace(array('@((\.\.)(/|$))+@','@//+@'),'/',$path);
}
}