/** * Will include the class from the filename which is determined based on the registered * namespaces and autoload patterns. * * If the class does not exist, it will create an empty class which throws an exception * upon construct or static access. Like this you can recover from the error instead of * raising a fatal error. * * @param string $className * @throws Uber_Loader_Exception */ public static function autoload($className) { if (!self::_isValidClassName($className)) { throw new Uber_Loader_Exception('Class Name "' . $className . '" is invalid', -3); } $throwException = true; $found = false; $matched = false; $tryToInclude = false; if (!empty(self::$_namespaceRegex) && preg_match(':' . self::$_namespaceRegex . ':', $className, $matches)) { $matched = true; $baseDir = self::$_namespaces[$matches[1]]; $throwException = self::$_namespaceExceptionHandling[$matches[1]]; if ($baseDir !== true) { if (!is_array($baseDir)) { $fileName = rtrim($baseDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; if (is_readable($fileName)) { $tryToInclude = true; } } else { foreach ($baseDir as $bDir) { $fileName = rtrim($bDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; if (is_readable($fileName)) { $tryToInclude = true; break; } } } } else { $fileName = str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; /** * we cannot check for file existance here, since no basedir is given, * could be retrieved from the includepath */ $tryToInclude = true; } if ($tryToInclude && ($res = (include $fileName)) == true) { $found = true; } } else { if (isset(self::$_autoloadPatterns['classes'][$className])) { $fileName = array_pop(self::$_autoloadPatterns['classes'][$className]); $fileName = str_replace('$class', $className, $fileName); if (is_readable($fileName)) { include $fileName; } } else { if (!self::$_isOrdered) { usort(self::$_autoloadPatterns['dynamic'], array('Uber_Loader', 'sortDynamicPatterns')); self::$_isOrdered = true; } $found = false; foreach (self::$_autoloadPatterns['dynamic'] as $pattern) { switch ($pattern['type']) { case 'preg_match': $found = self::_handlePregMatchPattern($className, $pattern); break; case 'preg_replace': $found = self::_handlePregReplacePattern($className, $pattern); break; case 'str_replace': $found = self::_handleStrReplacePattern($className, $pattern); break; } if ($found === true) { $throwException = isset($pattern['throwException']) ? $pattern['throwException'] : true; break; } } } } if (($found || $matched) && $throwException === true && !class_exists($className, false) && !interface_exists($className, false)) { eval("class {$className} {\n function __construct() {\n throw new Uber_Loader_Exception('Class or interface {$className} not found',-1);\n }\n\n static function __callStatic(\$m, \$args) {\n throw new Uber_Loader_Exception('Class or interface {$className} not found',-2);\n }\n }"); } }
public static function initUberAutoload() { Uber_Loader::registerNamespace('Uber', dirname(__FILE__)); }
<?php define('PROJECT_PATH', dirname(dirname(__FILE__))); // sgl libs $root = dirname(dirname(dirname(__FILE__))); $sglLibDir = $root . '/sgl2/src/lib'; require $sglLibDir . '/Uber.php'; Uber::init(); Uber_Loader::registerNamespace('SGL2', $sglLibDir); Uber_Loader::registerNamespace('Zend', $sglLibDir); Uber_Loader::registerNamespace('Horde', $sglLibDir); try { $front = new SGL2_Controller_Front(); $output = $front->bootstrap()->dispatch(); } catch (Exception $e) { print '<pre>'; print_r($e); } echo $output;