3
require_once('Exception.php');
8
static public function loadClass ( $class_name, $class_path=null, $real_name=null ) {
11
if ( class_exists ( $class_name, false ) ) {
15
// autodiscover the path from the class name
16
$path = $class_path ? $class_path . DIRECTORY_SEPARATOR : '';
17
$path .= str_replace ( '_', DIRECTORY_SEPARATOR, $class_name ) . '.php' ;
20
$included = self::loadFile ( $path, true ) ;
25
throw new Gecka_Exception ( "Could not include \"" . ( $real_name ? $real_name : $class_name) ."\" " ) ;
31
if (!class_exists ( $real_name ? $real_name : $class_name, false )) {
32
throw new Gecka_Exception ( "File \"" . ( $real_name ? $real_name : $class_name) ."\" was included " . "but class \"$class_name\" was not found within." ) ;
38
static public function loadFile ($filepath, $dirs=null, $once=false) {
41
if (preg_match ( '/[^a-z0-9\-_.\/:\\' . DIRECTORY_SEPARATOR . ']/i', $filepath )) {
42
throw new Gecka_Exception ( 'Security check: Illegal character in filename' ) ;
46
if (self::isReadable($filepath)) {
48
return self::includeFile($filepath, $once);
51
throw new Gecka_Exception("File \"$filepath\" was not found");
55
static public function includeFile ( $filepath , $once = false ) {
58
$status = include_once ($filepath) ;
60
$status = include ($filepath) ;
66
static public function isReadable($filename) {
68
if (@is_readable($filename)) {
72
$path = get_include_path();
73
$dirs = explode(PATH_SEPARATOR, $path);
75
foreach ($dirs as $dir) {
76
// No need to check against current dir -- already checked
81
if (@is_readable($dir . DIRECTORY_SEPARATOR . $filename)) {
89
static public function registerAutoload() {
90
spl_autoload_register(array('Gecka_Loader', 'autoload'));
93
static public function autoload( $className ) {
94
self::loadClass($className);
97
static public function setIncludePath ($path) {
99
set_include_path($path);
103
static public function addIncludePath ($path) {
105
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
109
static public function is_in_base_dir($filePath, $baseDir) {
111
$_filePath = realpath($filePath);
112
if(!$_filePath) trigger_error('Le fichier ' . $filePath . ' n\'existe pas. ');
114
if( strpos($_filePath, $baseDir) === 0 ) return true;
b'\\ No newline at end of file'