public static function setUpBeforeClass() { parent::setUpBeforeClass(); self::$Default = \jf\DatabaseManager::$DefaultIndex; $setting = \jf\DatabaseManager::Configuration(); $config = new \jf\DatabaseSetting("mysqli", $setting->DatabaseName, $setting->Username, $setting->Password, $setting->Host, $setting->TablePrefix); \jf\DatabaseManager::AddConnection($config, 2); \jf\DatabaseManager::$DefaultIndex = \jf\DatabaseManager::FindIndex($config); }
/** * @depends testAddConnection */ function testFindIndex() { $userConfig = \jf\DatabaseManager::Configuration("test"); $dbConfig = new \jf\DatabaseSetting($userConfig->Adapter, "db_find", $userConfig->Username, $userConfig->Password, $userConfig->Host, $userConfig->TablePrefix); \jf\DatabaseManager::AddConnection($dbConfig, "find_index"); $this->assertEquals("find_index", \jf\DatabaseManager::FindIndex($dbConfig)); $anotherConfig = new \jf\DatabaseSetting($userConfig->Adapter, "db_another_find", $userConfig->Username, $userConfig->Password, $userConfig->Host, $userConfig->TablePrefix); $this->assertFalse(\jf\DatabaseManager::FindIndex($anotherConfig)); }
function __construct() { $userConfig = \jf\DatabaseManager::Configuration(); switch ($userConfig->Adapter) { case "mysqli": case "pdo_mysql": case "mariaDB": $this->add("jf/test/lib/db/adapter/pdo_mysql"); $this->add("jf/test/lib/db/adapter/mysqli"); $this->add("jf/test/lib/db/adapter/mariaDB"); break; case "pdo_sqlite": $this->add("jf/test/lib/db/adapter/pdo_mysql"); break; } }
public static function Config($prefix = "app_") { self::$config = new Doctrine\ORM\Configuration(); // (2) // Proxy Configuration (3) self::$config->setProxyDir(__DIR__ . "/doctrine/proxy_cache"); self::$config->setProxyNamespace(jf_Application_Name . '\\Proxies'); self::$config->setAutoGenerateProxyClasses(jf::$RunMode->IsDevelop()); // Mapping Configuration (4) //$driverImpl = new Doctrine\ORM\Mapping\Driver\XmlDriver(__DIR__."/entities/xml"); //$driverImpl = new Doctrine\ORM\Mapping\Driver\XmlDriver(__DIR__."/config/mappings/yml"); $driverImpl = self::$config->newDefaultAnnotationDriver(__DIR__ . "/../model"); self::$config->setMetadataDriverImpl($driverImpl); // Caching Configuration (5) if (jf::$RunMode->IsDeploy() and function_exists("apc_exists")) { self::$cache = new \Doctrine\Common\Cache\ApcCache(); } else { self::$cache = new \Doctrine\Common\Cache\ArrayCache(); } self::$config->setMetadataCacheImpl(self::$cache); self::$config->setQueryCacheImpl(self::$cache); // database configuration parameters (6) $db = \jf\DatabaseManager::Configuration(); $adapter = $db->Adapter; if ($adapter == "mysql" or $adapter == "mysqli" or !$adapter) { $adapter = "pdo_mysql"; } $conn = array('driver' => $adapter, 'user' => $db->Username, 'password' => $db->Password, 'host' => $db->Host, 'dbname' => $db->DatabaseName, 'charset' => 'utf8', 'path' => $db->DatabaseName); require_once __DIR__ . "/doctrine/sqllogger.php"; self::$config->setSQLLogger(new Doctrine\DBAL\Logging\jframeworkSQLLogger()); // obtaining the entity manager (7) self::$eventManager = new Doctrine\Common\EventManager(); self::$tablePrefix = new \Doctrine\Extensions\TablePrefix($prefix); self::$eventManager->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, self::$tablePrefix); self::$entityManager = \Doctrine\ORM\EntityManager::create($conn, self::$config, self::$eventManager); }
* Siteroot * * jframework requires to know where your site root is, e.g http://jframework.info * or http://tld.com/myfolder/myjf/deploy * automatically determines this, so change it and define it manually only when necessary * you can use this constant in your views for absolute urls */ define("SiteRoot", HttpRequest::Root()); /** * Database Setup * * jframework requires at least a database for its core functionality. * You can also use "no database-setup" if you do not need jframework libraries and want a semi-static * web application, in that case, comment or remove the database username definition */ \jf\DatabaseManager::AddConnection(new \jf\DatabaseSetting("mysqli", "DBNAME", "DBUSER", "DBPASS")); /** * Error Handling * * jframework has an advanced error handler built-in. * Errors should not be presented to the end user on a release environment, * this is automatically handled by presentErrors, which toggles between logging * and displaying. */ if (jf::$RunMode->IsCLI() or jf::$RunMode->IsEmbed()) { jf\ErrorHandler::$Enabled = false; //disable it if embedded or CLI because another system is handling it. } else { jf\ErrorHandler::$Enabled = true; //Enables jframework's built-in error handler }
/** * Returns a database connection which is already established * If no index provided, first (default) connection will be returned * @param integer $Index * @return BaseDatabase */ static function db($Index = null) { return \jf\DatabaseManager::Database($Index); }
function TablePrefix() { return \jf\DatabaseManager::Configuration()->TablePrefix; }