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


PHP sfDatabaseManager::getNames方法代码示例

本文整理汇总了PHP中sfDatabaseManager::getNames方法的典型用法代码示例。如果您正苦于以下问题:PHP sfDatabaseManager::getNames方法的具体用法?PHP sfDatabaseManager::getNames怎么用?PHP sfDatabaseManager::getNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sfDatabaseManager的用法示例。


在下文中一共展示了sfDatabaseManager::getNames方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getDoctrineDatabases

  /**
   * Returns Doctrine databases from the supplied database manager.
   *
   * @param sfDatabaseManager $databaseManager
   * @param array|null        $names An array of names or NULL for all databases
   *
   * @return array An associative array of {@link sfDoctrineDatabase} objects and their names
   *
   * @throws InvalidArgumentException If a requested database is not a Doctrine database
   */
  protected function getDoctrineDatabases(sfDatabaseManager $databaseManager, array $names = null)
  {
    $databases = array();

    if (null === $names)
    {
      foreach ($databaseManager->getNames() as $name)
      {
        $database = $databaseManager->getDatabase($name);

        if ($database instanceof sfDoctrineDatabase)
        {
          $databases[$name] = $database;
        }
      }
    }
    else
    {
      foreach ($names as $name)
      {
        $database = $databaseManager->getDatabase($name);

        if (!$database instanceof sfDoctrineDatabase)
        {
          throw new InvalidArgumentException(sprintf('The database "%s" is not a Doctrine database.', $name));
        }

        $databases[$name] = $database;
      }
    }

    return $databases;
  }
开发者ID:nationalfield,项目名称:symfony,代码行数:43,代码来源:sfDoctrineBaseTask.class.php

示例2: getDatabaseParams

 public static function getDatabaseParams($configuration, $dbname = false)
 {
     $dbManager = new sfDatabaseManager($configuration);
     $names = $dbManager->getNames();
     $db = $dbManager->getDatabase($dbname ? $dbname : $names[0]);
     if (!$db) {
         throw new sfException("No database connection called {$db} is defined");
     }
     $username = $db->getParameter('username');
     //root
     $dsn = $db->getParameter('dsn');
     //mysql:dbname=mydbtest;host=localhost because it's test config
     $password = $db->getParameter('password');
     //password
     if (!preg_match('/^mysql:(.*)\\s*$/', $dsn, $matches)) {
         throw new sfException("I don't understand the DSN {$dsn}, sorry");
     }
     $pairs = explode(';', $matches[1]);
     $data = array();
     foreach ($pairs as $pair) {
         list($key, $val) = explode('=', $pair);
         $data[$key] = $val;
     }
     $data['username'] = $username;
     $data['password'] = $password;
     return $data;
 }
开发者ID:pmoutet,项目名称:navinum,代码行数:27,代码来源:sfSyncContentTools.class.php

示例3: createPDOInstance

 public static function createPDOInstance()
 {
     $configuration = sfContext::getInstance()->getConfiguration();
     $config = ProjectConfiguration::getApplicationConfiguration($configuration->getApplication(), $configuration->getEnvironment(), $configuration->isDebug());
     $dbManager = new sfDatabaseManager($config);
     $names = $dbManager->getNames();
     $db = $dbManager->getDatabase($names[0]);
     return new PDO($db->getParameter('dsn'), $db->getParameter('username'), $db->getParameter('password'));
 }
开发者ID:nishizoe,项目名称:opTimelinePlugin,代码行数:9,代码来源:opTimelineDb.php

示例4: execute

 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     foreach ($databaseManager->getNames() as $connection) {
         if (!is_null($options['connection']) && $options['connection'] != $connection) {
             continue;
         }
         $this->reverseDatabase($databaseManager, $connection, $options);
     }
 }
开发者ID:yasirgit,项目名称:afids,代码行数:13,代码来源:sfPropelBuildSchemaTask.class.php

示例5: getMondongo

 /**
  * Returns the Mondongo.
  *
  * @return Mondongo The Mondongo.
  */
 protected function getMondongo()
 {
     if (null === $this->mondongo) {
         $this->mondongo = new Mondongo();
         $databaseManager = new sfDatabaseManager($this->configuration);
         foreach ($databaseManager->getNames() as $name) {
             $database = $databaseManager->getDatabase($name);
             if ($database instanceof sfMondongoDatabase) {
                 $this->mondongo->setConnection($name, $database->getMondongoConnection());
             }
         }
         Container::setDefault($this->mondongo);
     }
     return $this->mondongo;
 }
开发者ID:rafaelgou,项目名称:sfMondongoPlugin,代码行数:20,代码来源:sfMondongoTask.class.php

示例6: __construct

 public function __construct($testMode = false, $debugMode = false, $configuration = null, $user = null, $browserTimeout = 30)
 {
     $this->appConfiguration = $configuration;
     //initialize database manager with configuration
     $doctrineManager = Doctrine_Manager::getInstance();
     $databaseManager = new sfDatabaseManager($configuration);
     $databaseManager->initialize($configuration);
     //set db array
     foreach ($databaseManager->getNames() as $name) {
         $this->conn[$name] = $doctrineManager->openConnection($databaseManager->getDatabase($name)->getParameter('dsn'), $name);
     }
     //set db
     $doctrineManager->setCurrentConnection('main');
     $this->db = $doctrineManager->getCurrentConnection();
     //logging (DISABLED UNTIL NOTICES CAN BE REMOVED)
     /*
     require_once 'Log.php';
     $this->logDir = sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'log'.DIRECTORY_SEPARATOR.'scraper'.DIRECTORY_SEPARATOR;
     $this->logFile = get_class($this);
     $this->logger = &Log::singleton('file', $this->logDir . $this->logFile, 'SCRAPER');
     */
     //browser
     $this->defaultHeaders = array('User-Agent' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.1) Gecko/20061205 Iceweasel/2.0.0.1 (Debian-2.0.0.1+dfsg-2)');
     $this->browser = new sfWebBrowser($this->defaultHeaders, 'sfCurlAdapter', array('Timeout' => $browserTimeout));
     $this->cookieBrowser = new sfWebBrowser($this->defaultHeaders, 'sfCurlAdapter', array('cookies' => true, 'Timeout' => $browserTimeout));
     //modes
     $this->testMode = $testMode;
     $this->debugMode = $debugMode;
     //meta
     if ($this->testMode) {
         $this->testMode = false;
         $this->testMeta = $this->getAllMeta();
         $this->testMode = true;
     }
     //login as scraper user
     if (!$user) {
         $context = sfContext::createInstance($configuration);
         $user = $context->getUser();
         $user->setAttribute('user_id', sfGuardUserTable::SCRAPER_USER_ID, 'sfGuardSecurityUser');
     }
     if (!$user->isAuthenticated()) {
         $user->setAuthenticated(true);
         $user->clearCredentials();
     }
     $this->user = $user->getGuardUser();
 }
开发者ID:silky,项目名称:littlesis,代码行数:46,代码来源:Scraper.class.php

示例7: execute

 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $compiledFile = sfConfig::get('sf_cache_dir') . '/doctrine.compiled.php';
     if (file_exists($compiledFile)) {
         $this->logSection('error', $compiledFile . ' already exists', null, 'ERROR');
         $this->logBlock('Run symfony:cache-clear first', 'INFO');
         return;
     }
     $drivers = array();
     foreach ($databaseManager->getNames() as $name) {
         $drivers[] = strtolower($databaseManager->getDatabase($name)->getDoctrineConnection()->getDriverName());
     }
     $drivers = array_unique($drivers);
     $this->logSection('compile', 'Included drivers: ' . implode(', ', $drivers));
     Doctrine_Core::compile($compiledFile, $drivers);
     $this->logSection('file+', $compiledFile);
 }
开发者ID:Phennim,项目名称:symfony1,代码行数:21,代码来源:sfDoctrineCompileTask.class.php

示例8: getDatabaseParams

 public static function getDatabaseParams()
 {
     echo "appConfig\n";
     $appConfig = self::$configuration ? self::$configuration : sfContext::getInstance()->getConfiguration();
     echo "appManager\n";
     $dbManager = new sfDatabaseManager($appConfig);
     echo "after appManager\n";
     $names = $dbManager->getNames();
     $db = $dbManager->getDatabase($names[0]);
     $username = $db->getParameter('username');
     //root
     $dsn = $db->getParameter('dsn');
     //mysql:dbname=mydbtest;host=localhost because it's test config
     $password = $db->getParameter('password');
     //password
     if (!preg_match('/^mysql:(.*)\\s*$/', $dsn, $matches)) {
         throw new sfException("I don't understand the DSN {$dsn}, sorry");
     }
     $pairs = explode(';', $matches[1]);
     $data = array();
     foreach ($pairs as $pair) {
         list($key, $val) = explode('=', $pair);
         $data[$key] = $val;
     }
     $data['username'] = $username;
     $data['password'] = $password;
     return $data;
 }
开发者ID:quafzi,项目名称:timpany-prototype,代码行数:28,代码来源:aTestTools.class.php

示例9: autoload_again

sfCoreAutoload::register();
require_once dirname(__FILE__) . '/cleanup.php';
$projectPath = dirname(__FILE__) . '/../fixtures/project';
require_once $projectPath . '/config/ProjectConfiguration.class.php';
if (!isset($app)) {
    $configuration = new ProjectConfiguration($projectPath);
} else {
    $configuration = ProjectConfiguration::getApplicationConfiguration($app, 'test', isset($debug) ? $debug : true);
    $context = sfContext::createInstance($configuration);
}
if (isset($app)) {
    $configuration->initializeDoctrine(isset($fixtures) && $fixtures ? true : false);
    $databaseManager = $context->getDatabaseManager();
} else {
    if (isset($database) && $database) {
        $databaseManager = new sfDatabaseManager($configuration);
        $configuration->initializeDoctrine(isset($fixtures) && $fixtures ? true : false);
    }
}
if (isset($databaseManager)) {
    $names = $databaseManager->getNames();
    $em = $databaseManager->getDatabase(end($names))->getEntityManager();
}
require_once $configuration->getSymfonyLibDir() . '/vendor/lime/lime.php';
function autoload_again($class)
{
    $autoload = sfSimpleAutoload::getInstance();
    $autoload->reload();
    return $autoload->autoload($class);
}
spl_autoload_register('autoload_again');
开发者ID:blt04,项目名称:sfDoctrine2Plugin,代码行数:31,代码来源:unit.php

示例10: executeStepThree

 public function executeStepThree(sfWebRequest $request)
 {
     $error = 0;
     $configuration = sfProjectConfiguration::getActive();
     $db = new sfDatabaseManager($configuration);
     foreach ($db->getNames() as $connection) {
         try {
             @$db->getDatabase($connection)->getConnection();
         } catch (Exception $e) {
             $error = 1;
         }
     }
     if ($error == 1) {
         $this->getUser()->setFlash('error', $e->getMessage());
         $this->redirect('firstBoot/stepOne');
     }
     $moderator = new Moderator();
     $login = new Login();
     $login->setIsModerator(true);
     $moderator->setLogin($login);
     $this->form = new ModeratorForm($moderator, array('new' => true));
 }
开发者ID:xmasclaux,项目名称:OpenGenepi,代码行数:22,代码来源:actions.class.php


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