/** * load class * @param string $className : the class to load * @throws Exception */ function __autoload($className) { if (class_exists('Zend', false)) { if (is_int(strrpos($className, '_Interface'))) { Zend::loadClass($className); } else { Zend::loadInterface($className); } } else { if (!defined('__CLASS_PATH__')) { define('__CLASS_PATH__', realpath(dirname(__FILE__))); } $file = __CLASS_PATH__ . '/' . str_replace('_', '/', $className) . '.php'; if (!file_exists($file)) { throw new Exception('Cannot load class file ' . $className); } else { require_once $file; } } }
/** * Tests that an exception is thrown when a file is loaded but the * class is not found within the file */ public function testLoadInterfaceNonexistent() { $dir = implode(array(dirname(__FILE__), 'Zend', '_files', '_testDir1'), DIRECTORY_SEPARATOR); try { Zend::loadInterface('ClassNonexistent', $dir); } catch (Zend_Exception $e) { $this->assertRegExp('/file(.*)loaded but interface(.*)not found/i', $e->getMessage()); return; } $this->fail('Zend_Exception was expected but never thrown.'); }