當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Doctrine_Connection::addListener方法代碼示例

本文整理匯總了PHP中Doctrine_Connection::addListener方法的典型用法代碼示例。如果您正苦於以下問題:PHP Doctrine_Connection::addListener方法的具體用法?PHP Doctrine_Connection::addListener怎麽用?PHP Doctrine_Connection::addListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine_Connection的用法示例。


在下文中一共展示了Doctrine_Connection::addListener方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: initialize

 /**
  * Initialize a sfDoctrineDatabase connection with the given parameters.
  *
  * <code>
  * $parameters = array(
  *    'name'       => 'doctrine',
  *    'dsn'        => 'sqlite:////path/to/sqlite/db');
  *
  * $p = new sfDoctrineDatabase($parameters);
  * </code>
  *
  * @param array $parameters  Array of parameters used to initialize the database connection
  * @return void
  */
 public function initialize($parameters = array())
 {
     parent::initialize($parameters);
     $dsn = $this->getParameter('dsn');
     $name = $this->getParameter('name');
     // Make sure we pass non-PEAR style DSNs as an array
     if (!strpos($dsn, '://')) {
         $dsn = array($dsn, $this->getParameter('username'), $this->getParameter('password'));
     }
     // Make the Doctrine connection for $dsn and $name
     $this->_doctrineConnection = Doctrine_Manager::connection($dsn, $name);
     $attributes = $this->getParameter('attributes', array());
     foreach ($attributes as $name => $value) {
         $this->_doctrineConnection->setAttribute($name, $value);
     }
     $encoding = $this->getParameter('encoding', 'UTF8');
     $eventListener = new sfDoctrineConnectionListener($this->_doctrineConnection, $encoding);
     $this->_doctrineConnection->addListener($eventListener);
     // Load Query Logger Listener
     if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
         $this->_doctrineConnection->addListener(new sfDoctrineLogger());
     }
     // Invoke the configuration methods for the connection if they exist
     $configuration = sfProjectConfiguration::getActive();
     $method = sprintf('configureDoctrineConnection%s', ucwords($this->_doctrineConnection->getName()));
     if (method_exists($configuration, 'configureDoctrineConnection') && !method_exists($configuration, $method)) {
         $configuration->configureDoctrineConnection($this->_doctrineConnection);
     }
     if (method_exists($configuration, $method)) {
         $configuration->{$method}($this->_doctrineConnection);
     }
 }
開發者ID:JimmyVB,項目名稱:Symfony-v1.2,代碼行數:46,代碼來源:sfDoctrineDatabase.class.php

示例2: initialize

 /**
  * Initialize a sfDoctrineDatabase connection with the given parameters.
  *
  * <code>
  * $parameters = array(
  *    'name'       => 'doctrine',
  *    'dsn'        => 'sqlite:////path/to/sqlite/db');
  *
  * $p = new sfDoctrineDatabase($parameters);
  * </code>
  *
  * @param array $parameters  Array of parameters used to initialize the database connection
  * @return void
  */
 public function initialize($parameters = array())
 {
     parent::initialize($parameters);
     if (null !== $this->_doctrineConnection) {
         return;
     }
     $dsn = $this->getParameter('dsn');
     $name = $this->getParameter('name');
     // Make sure we pass non-PEAR style DSNs as an array
     if (!strpos($dsn, '://')) {
         $dsn = array($dsn, $this->getParameter('username'), $this->getParameter('password'));
     }
     // Make the Doctrine connection for $dsn and $name
     $configuration = sfProjectConfiguration::getActive();
     $dispatcher = $configuration->getEventDispatcher();
     $manager = Doctrine_Manager::getInstance();
     $this->_doctrineConnection = $manager->openConnection($dsn, $name);
     $attributes = $this->getParameter('attributes', array());
     foreach ($attributes as $name => $value) {
         if (is_string($name)) {
             $stringName = $name;
             $name = constant('Doctrine_Core::ATTR_' . strtoupper($name));
         }
         if (is_string($value)) {
             $valueConstantName = 'Doctrine_Core::' . strtoupper($stringName) . '_' . strtoupper($value);
             $value = defined($valueConstantName) ? constant($valueConstantName) : $value;
         }
         $this->_doctrineConnection->setAttribute($name, $value);
     }
     $encoding = $this->getParameter('encoding', 'UTF8');
     $eventListener = new sfDoctrineConnectionListener($this->_doctrineConnection, $encoding);
     $this->_doctrineConnection->addListener($eventListener);
     // Load Query Profiler
     if ($this->getParameter('profiler', sfConfig::get('sf_debug'))) {
         $this->profiler = new sfDoctrineConnectionProfiler($dispatcher, array('logging' => $this->getParameter('logging', sfConfig::get('sf_logging_enabled'))));
         $this->_doctrineConnection->addListener($this->profiler, 'symfony_profiler');
     }
     // Invoke the configuration methods for the connection if they exist (deprecated in favor of the "doctrine.configure_connection" event)
     $method = sprintf('configureDoctrineConnection%s', ucwords($this->_doctrineConnection->getName()));
     if (method_exists($configuration, 'configureDoctrineConnection') && !method_exists($configuration, $method)) {
         $configuration->configureDoctrineConnection($this->_doctrineConnection);
     }
     if (method_exists($configuration, $method)) {
         $configuration->{$method}($this->_doctrineConnection);
     }
     $dispatcher->notify(new sfEvent($manager, 'doctrine.configure_connection', array('connection' => $this->_doctrineConnection, 'database' => $this)));
 }
開發者ID:seven07ve,項目名稱:vendorepuestos,代碼行數:61,代碼來源:sfDoctrineDatabase.class.php


注:本文中的Doctrine_Connection::addListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。