当前位置: 首页>>代码示例>>PHP>>正文


PHP PartKeepr::createConnectionOptionsFromConfig方法代码示例

本文整理汇总了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;
}
开发者ID:JohnEffland,项目名称:PartKeepr,代码行数:31,代码来源:check-database-connectivity.php

示例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);
 }
开发者ID:JohnEffland,项目名称:PartKeepr,代码行数:59,代码来源:PartKeepr.php


注:本文中的PartKeepr\PartKeepr::createConnectionOptionsFromConfig方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。