/** * Exception autoload method * * This method loads exception class files from the ae/classes/ path. * Since most exception classes are declared inside the general class files, * this method also converts the class name to the respective general class, * to autodetect that class's path: * <code> throw new AeFooBarBazException('Not found', 404); * // Will search for the AeFoo_Bar_Baz class * // inside the ae/classes/foo/bar/baz.class.php file</code> * * @see AeAutoload * @see AeAutoload::extensions() * * @param string $class class name * * @return bool true if the class file has been successfully found and * loaded. False otherwise */ public static function autoload($class) { if (class_exists($class, false) || interface_exists($class, false)) { return true; } if (substr($class, -9) != 'Exception' || substr($class, 0, 2) != 'Ae') { return false; } $class = preg_replace('#([a-z])([A-Z])#', '\\1_\\2', substr($class, 2, -9)); $file = AeCore::getClassPath('Ae' . $class); if (!$file) { // Not an internal exception class return false; } $file = $file . '.class'; return AeAutoload::findFile($file); }
/** * Load and initialize the framework * * Loads the {@link AeAutoload} class and registers two basic autoload * methods: * * - {@link AeCore::autoload()} * - {@link AeException::autoload()} * * Also calls {@link AeAutoload::detect()} instantly for any custom autoload * handlers. * * @throws AeException #505 if PHP version is less than 5.2.0 */ public static function load() { if (!defined('SLASH')) { /** * DIRECTORY_SEPARATOR shortcut */ define('SLASH', DIRECTORY_SEPARATOR); } set_include_path(realpath(dirname(__FILE__) . SLASH . '..') . PATH_SEPARATOR . get_include_path()); if (!version_compare(PHP_VERSION, '5.2.0', '>=')) { // *** Explicitly include exception file require_once 'ae' . SLASH . 'classes' . SLASH . 'exception.class.php'; throw new AeException('AnEngine framework requires PHP version 5.2.0 or later', 505); } require_once 'ae' . SLASH . 'autoload.class.php'; AeAutoload::extensions('.php'); AeAutoload::register(array('AeCore', 'autoload')); AeAutoload::register(array('AeException', 'autoload')); AeAutoload::detect(); }