/** * Ensures that a class is defined. If not, attempts to include the file * using the provided path. If unable to locate the class, an IncludeException * will be thrown. The path that will be used for include_once is * $classpath . "/" . $classname . ".php" * * @param string name of class (ex Phreeze) * @param string or array [optional] the relative path(s) where the file would be found */ public static function RequireClass($classname, $classpath = "") { if (class_exists($classname)) { return true; } // normalize this as an array $classpaths = is_array($classpath) ? $classpath : array($classpath); $attempts = ""; foreach ($classpaths as $path) { if (class_exists($classname)) { break; } try { // append a directory separater if necessary if ($path && substr($path, -1) != "/") { $path .= "/"; } Includer::IncludeFile($path . $classname . ".php"); } catch (IncludeException $ex) { $attempts .= " " . $ex->getMessage(); } } if (!class_exists($classname)) { // the class still isn't defined so there was a problem including the model throw new IncludeException("Unable to locate class '{$classname}': " . $attempts); } }
/** * Load the data driver * @throws Exception */ public function LoadDriver() { if ($this->_driver == null) { require_once "verysimple/IO/Includer.php"; // the driver was not explicitly provided so we will try to create one from // the connection setting based on the database types that we do know about switch ($this->ConnectionSetting->Type) { case "mysql": include_once "verysimple/DB/DataDriver/MySQL.php"; $this->_driver = new DataDriverMySQL(); break; case "mysqli": include_once "verysimple/DB/DataDriver/MySQLi.php"; $this->_driver = new DataDriverMySQLi(); break; case "sqlite": include_once "verysimple/DB/DataDriver/SQLite.php"; $this->_driver = new DataDriverSQLite(); break; default: try { Includer::IncludeFile("verysimple/DB/DataDriver/" . $this->ConnectionSetting->Type . ".php"); $classname = "DataDriver" . $this->ConnectionSetting->Type; $this->_driver = new $classname(); } catch (IncludeException $ex) { throw new Exception('Unknown DataDriver "' . $this->ConnectionSetting->Type . '" specified in connection settings'); } break; } DataAdapter::$DRIVER_INSTANCE = $this->_driver; } }