/** * Imports a class by name or path. * * The full path is either provided in the $path argument or * constructued using the $path and $className. * * @param string $path The path to the class. * @param string $className The name of the class. * * @return void */ public static function importClass($path, $className = null) { if (StringHelper::endsWith($path, ".php")) { require_once $path; } else { require_once $path . "/" . $className . ".php"; } }
/** * Finds the class name of a file. * * @param string $filename The filename of PHP file. * * @return string the class name * @throws \Exception If the class could not be found. */ private static function findClass($filename) { $classFileName = basename($filename, ".php"); foreach (get_declared_classes() as $declaredClass) { if (StringHelper::endsWith($declaredClass, $classFileName)) { return $declaredClass; } } throw new \Exception($classFileName . " not found. Maybe you are missing a require() statement."); }