XRL  latest
Simple XML-RPC Library (both client and server)
Autoload.php
1 <?php
2 /*
3  * This file is part of XRL, a simple XML-RPC Library for PHP.
4  *
5  * Copyright (c) 2012, XRL Team. All rights reserved.
6  * XRL is licensed under the 3-clause BSD License.
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace fpoirotte\XRL;
13 
20 class Autoload
21 {
43  public static function load($class)
44  {
45  // This code only applies to PHP 5.3.7 & 5.3.8.
46  // It prevents a case of remote code execution (CVE 2011-3379).
47  if (strpos($class, ':') !== false) {
48  // @codeCoverageIgnoreStart
49  throw new \Exception('Possible remote execution attempt');
50  // @codeCoverageIgnoreEnd
51  }
52 
53  $class = ltrim($class, '\\');
54  if (strncmp($class, 'fpoirotte\\XRL\\', 14)) {
55  return false;
56  }
57 
58  $class = substr($class, 14);
59  if (!strncmp($class, 'tests\\', 6)) {
60  $path = dirname(__DIR__);
61  } else {
62  $path = __DIR__;
63  }
64 
65  $class = str_replace(array('_', '\\'), DIRECTORY_SEPARATOR, $class);
66  include($path . DIRECTORY_SEPARATOR . $class . '.php');
67  $res = (class_exists($class, false) || interface_exists($class, false));
68  return $res;
69  }
70 
77  public static function register()
78  {
79  static $registered = false;
80 
81  if (!$registered) {
82  spl_autoload_register(array(__CLASS__, "load"));
83  }
84  }
85 }
static load($class)
Definition: Autoload.php:43
An helper class that wraps XRL&#39;s autoloader.
Definition: Autoload.php:20