XOOPS  2.6.0
Loader.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  */
11 
12 namespace Xmf;
13 
26 class Loader
27 {
36  public static function loadFile($file, $once = true)
37  {
38  self::securityCheck($file);
39  if (file_exists($file)) {
40  if ($once) {
41  include_once $file;
42  } else {
43  include $file;
44  }
45 
46  return true;
47  }
48 
49  return false;
50  }
51 
59  public static function loadClass($class)
60  {
61  if (class_exists($class, false) || interface_exists($class, false)) {
62  return true;
63  }
64 
65  $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
66  if (!self::loadFile(dirname(__DIR__) . DIRECTORY_SEPARATOR . $file)) {
67  return false;
68  }
69 
70  if (!class_exists($class, false) && !interface_exists($class, false)) {
71  trigger_error(
72  "File \"$file\" does not exist or class \"$class\" was not found in the file",
73  E_USER_WARNING
74  );
75 
76  return false;
77  }
78 
79  return true;
80  }
81 
91  protected static function securityCheck($filename)
92  {
96  if (preg_match('/[^a-z0-9\\/\\\\_.:-]/i', $filename)) {
97  exit('Security check: Illegal character in filename');
98  }
99  }
100 }
static loadFile($file, $once=true)
Definition: Loader.php:36
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
Definition: browse.php:55
exit
Definition: browse.php:104
defined('DS') or define('DS' DIRECTORY_SEPARATOR
Definition: common.php:41
static loadClass($class)
Definition: Loader.php:59
static securityCheck($filename)
Definition: Loader.php:91