/** * Loads a class from a PHP file. The filename must be formatted * as "$class.php". * * @param string $class * @return void * @throws RuntimeException */ public static function loadClass($class) { if (class_exists($class, false) || interface_exists($class, false)) { return; } if (!self::$basePath) { self::$basePath = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..') . DIRECTORY_SEPARATOR; } $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; $pathName = self::$basePath . $file; if (!is_file($pathName)) { throw new RuntimeException('Unable to load class "' . $class . '" as file "' . $file . '" does not exist.'); } if (!@is_readable($pathName)) { throw new RuntimeException('Unable to load class "' . $class . '" as file "' . $file . '" is not readable.'); } require $pathName; if (!class_exists($class, false) && !interface_exists($class, false)) { throw new RuntimeException('File "' . $file . '" was loaded but class "' . $class . '" was not found in the file.'); } }