本文整理汇总了PHP中PartKeepr\PartKeepr::createConnectionOptionsFromConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP PartKeepr::createConnectionOptionsFromConfig方法的具体用法?PHP PartKeepr::createConnectionOptionsFromConfig怎么用?PHP PartKeepr::createConnectionOptionsFromConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PartKeepr\PartKeepr
的用法示例。
在下文中一共展示了PartKeepr::createConnectionOptionsFromConfig方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: catch
$config = new \Doctrine\DBAL\Configuration();
/**
* Test if the requested driver is available
*/
$drivers = PDO::getAvailableDrivers();
$bDriverAvailable = false;
if (!in_array($_REQUEST["driver"], $drivers)) {
echo json_encode(array("error" => true, "message" => "The requested driver isn't installed as PHP pdo module. Please install the PDO driver for PHP."));
exit;
}
/**
* Check which driver we are going to use, and set the connection parameters accordingly.
*/
try {
$onnectionOptions = Setup::setDatabaseConfigurationFromRequest();
$connectionOptions = PartKeepr::createConnectionOptionsFromConfig();
} catch (\Exception $e) {
echo json_encode(array("error" => true, "message" => $e->getMessage()));
exit;
}
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionOptions, $config);
try {
$conn->connect();
} catch (\PDOException $e) {
$additionalMessage = getPlatformSpecificErrorMessage($_REQUEST["driver"], $e->getCode());
echo json_encode(array("error" => true, "message" => "There was an error connecting to the database:<br/><code>" . $e->getMessage() . "</code>" . $additionalMessage));
exit;
} catch (\Exception $e) {
echo json_encode(array("error" => true, "message" => "An unknown error occured. The error is: <code>" . $e->getMessage() . "</code>"));
exit;
}
示例2: initializeDoctrine
/**
* Initializes the doctrine framework and
* sets all required configuration options.
*
* @param none
* @return nothing
*/
public static function initializeDoctrine()
{
$config = new Configuration();
$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__));
$config->setMetadataDriverImpl($driverImpl);
$connectionOptions = PartKeepr::createConnectionOptionsFromConfig();
switch (strtolower(PartKeeprConfiguration::getOption("partkeepr.cache.implementation", "default"))) {
case "apc":
$cache = new \Doctrine\Common\Cache\ApcCache();
break;
case "xcache":
if (php_sapi_name() !== "cli") {
$cache = new \Doctrine\Common\Cache\XcacheCache();
} else {
// For CLI SAPIs, revert to the ArrayCache as Xcache spits out strange warnings when running in CLI.
$cache = new \Doctrine\Common\Cache\ArrayCache();
}
break;
case "memcache":
$memcache = new \Memcache();
$memcache->connect(PartKeeprConfiguration::getOption("partkeepr.cache.memcache.host", "localhost"), PartKeeprConfiguration::getOption("partkeepr.cache.memcache.port", "11211"));
$cache = new \Doctrine\Common\Cache\MemcacheCache();
$cache->setMemcache($memcache);
break;
case "default":
case "auto":
if (extension_loaded("xcache")) {
$cache = new \Doctrine\Common\Cache\XcacheCache();
} else {
if (extension_loaded("apc")) {
$cache = new \Doctrine\Common\Cache\ApcCache();
} else {
$cache = new \Doctrine\Common\Cache\ArrayCache();
}
}
break;
case "none":
$cache = new \Doctrine\Common\Cache\ArrayCache();
break;
}
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
$config->setProxyDir(self::getRootDirectory() . '/data/proxies');
$config->setProxyNamespace('Proxies');
$config->setEntityNamespaces(self::getEntityClasses());
$config->setAutoGenerateProxyClasses(false);
if (PartKeeprConfiguration::getOption("partkeepr.database.echo_sql_log", false) === true) {
$logger = new \Doctrine\DBAL\Logging\EchoSQLLogger();
$config->setSQLLogger($logger);
}
self::$entityManager = EntityManager::create($connectionOptions, $config);
}