本文整理匯總了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);
}
}
示例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)));
}