本文整理汇总了PHP中eZ\Publish\Core\Persistence\Database\DatabaseHandler::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseHandler::getConnection方法的具体用法?PHP DatabaseHandler::getConnection怎么用?PHP DatabaseHandler::getConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZ\Publish\Core\Persistence\Database\DatabaseHandler
的用法示例。
在下文中一共展示了DatabaseHandler::getConnection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @param MigrationStep $step
* @return void
* @throws \Exception if migration step is not for this type of db
*/
public function execute(MigrationStep $step)
{
parent::execute($step);
$conn = $this->dbHandler->getConnection();
// @see http://doctrine-orm.readthedocs.io/projects/doctrine-dbal/en/latest/reference/platforms.html
$dbType = strtolower(preg_replace('/([0-9]+|Platform)/', '', $conn->getDatabasePlatform()->getName()));
$dsl = $step->dsl;
if (!isset($dsl[$dbType])) {
throw new \Exception("Current database type '{$dbType}' is not supported by the SQL migration");
}
$sql = $dsl[$dbType];
return $conn->exec($sql);
}
示例2: onBuildKernel
/**
* Adds settings to the parameters that will be injected into the legacy kernel
*
* @param \eZ\Publish\Core\MVC\Legacy\Event\PreBuildKernelEvent $event
*/
public function onBuildKernel(PreBuildKernelEvent $event)
{
if (!$this->enabled) {
return;
}
$databaseSettings = $this->legacyDbHandler->getConnection()->getParams();
$settings = array();
foreach (array("host" => "Server", "port" => "Port", "user" => "User", "password" => "Password", "dbname" => "Database", "unix_socket" => "Socket", "driver" => "DatabaseImplementation") as $key => $iniKey) {
if (isset($databaseSettings[$key])) {
$iniValue = $databaseSettings[$key];
switch ($key) {
case "driver":
$driverMap = array('pdo_mysql' => 'ezmysqli', 'pdo_pgsql' => 'ezpostgresql', 'oci8' => 'ezoracle');
if (!isset($driverMap[$iniValue])) {
throw new RuntimeException("Could not map database driver to Legacy Stack database implementation.\n" . "Expected one of '" . implode("', '", array_keys($driverMap)) . "', got '" . $iniValue . "'.");
}
$iniValue = $driverMap[$iniValue];
break;
}
$settings["site.ini/DatabaseSettings/{$iniKey}"] = $iniValue;
} else {
switch ($key) {
case "unix_socket":
$settings["site.ini/DatabaseSettings/{$iniKey}"] = "disabled";
break;
}
}
}
// Image settings
$settings += $this->getImageSettings();
// File settings
$settings += array('site.ini/FileSettings/VarDir' => $this->configResolver->getParameter('var_dir'), 'site.ini/FileSettings/StorageDir' => $this->configResolver->getParameter('storage_dir'));
// Multisite settings (PathPrefix and co)
$settings += $this->getMultiSiteSettings();
// User settings
$settings["site.ini/UserSettings/AnonymousUserID"] = $this->configResolver->getParameter("anonymous_user_id");
$event->getParameters()->set("injected-settings", $settings + (array) $event->getParameters()->get("injected-settings"));
if (class_exists('ezxFormToken')) {
// Inject csrf protection settings to make sure legacy & symfony stack work together
if ($this->container->hasParameter('form.type_extension.csrf.enabled') && $this->container->getParameter('form.type_extension.csrf.enabled')) {
ezxFormToken::setSecret($this->container->getParameter('kernel.secret'));
ezxFormToken::setFormField($this->container->getParameter('form.type_extension.csrf.field_name'));
} else {
ezxFormToken::setIsEnabled(false);
}
}
// Register http cache content/cache event listener
ezpEvent::getInstance()->attach('content/cache', array($this->gatewayCachePurger, 'purge'));
ezpEvent::getInstance()->attach('content/cache/all', array($this->gatewayCachePurger, 'purgeAll'));
// Register persistence cache event listeners
ezpEvent::getInstance()->attach('content/cache', array($this->persistenceCachePurger, 'content'));
ezpEvent::getInstance()->attach('content/cache/all', array($this->persistenceCachePurger, 'all'));
ezpEvent::getInstance()->attach('content/class/cache/all', array($this->persistenceCachePurger, 'contentType'));
ezpEvent::getInstance()->attach('content/class/cache', array($this->persistenceCachePurger, 'contentType'));
ezpEvent::getInstance()->attach('content/class/group/cache', array($this->persistenceCachePurger, 'contentTypeGroup'));
ezpEvent::getInstance()->attach('content/section/cache', array($this->persistenceCachePurger, 'section'));
ezpEvent::getInstance()->attach('user/cache/all', array($this->persistenceCachePurger, 'user'));
ezpEvent::getInstance()->attach('content/translations/cache', array($this->persistenceCachePurger, 'languages'));
}
示例3: tableExist
/**
* Check if a table exists in the database
*
* @param string $tableName
* @return bool
*/
protected function tableExist($tableName)
{
/** @var \Doctrine\DBAL\Schema\AbstractSchemaManager $sm */
$sm = $this->dbHandler->getConnection()->getSchemaManager();
foreach ($sm->listTables() as $table) {
if ($table->getName() == $tableName) {
return true;
}
}
return false;
}
示例4: onBuildKernel
/**
* Adds settings to the parameters that will be injected into the legacy kernel.
*
* @param \eZ\Publish\Core\MVC\Legacy\Event\PreBuildKernelEvent $event
*/
public function onBuildKernel(PreBuildKernelEvent $event)
{
if (!$this->enabled) {
return;
}
$databaseSettings = $this->legacyDbHandler->getConnection()->getParams();
$settings = array();
foreach (array('host' => 'Server', 'port' => 'Port', 'user' => 'User', 'password' => 'Password', 'dbname' => 'Database', 'unix_socket' => 'Socket', 'driver' => 'DatabaseImplementation') as $key => $iniKey) {
if (isset($databaseSettings[$key])) {
$iniValue = $databaseSettings[$key];
switch ($key) {
case 'driver':
$driverMap = array('pdo_mysql' => 'ezmysqli', 'pdo_pgsql' => 'ezpostgresql', 'oci8' => 'ezoracle');
if (!isset($driverMap[$iniValue])) {
throw new RuntimeException("Could not map database driver to Legacy Stack database implementation.\n" . "Expected one of '" . implode("', '", array_keys($driverMap)) . "', got '" . $iniValue . "'.");
}
$iniValue = $driverMap[$iniValue];
break;
}
$settings["site.ini/DatabaseSettings/{$iniKey}"] = $iniValue;
} else {
switch ($key) {
case 'unix_socket':
$settings["site.ini/DatabaseSettings/{$iniKey}"] = 'disabled';
break;
}
}
}
// Image settings
$settings += $this->getImageSettings();
// File settings
$settings += array('site.ini/FileSettings/VarDir' => $this->configResolver->getParameter('var_dir'), 'site.ini/FileSettings/StorageDir' => $this->configResolver->getParameter('storage_dir'));
// Multisite settings (PathPrefix and co)
$settings += $this->getMultiSiteSettings();
// User settings
$settings['site.ini/UserSettings/AnonymousUserID'] = $this->configResolver->getParameter('anonymous_user_id');
// Cache settings
// Enforce ViewCaching to be enabled in order to persistence/http cache to be purged correctly.
$settings['site.ini/ContentSettings/ViewCaching'] = 'enabled';
$event->getParameters()->set('injected-settings', $settings + (array) $event->getParameters()->get('injected-settings'));
if (class_exists('ezxFormToken')) {
// Inject csrf protection settings to make sure legacy & symfony stack work together
if ($this->container->hasParameter('form.type_extension.csrf.enabled') && $this->container->getParameter('form.type_extension.csrf.enabled')) {
ezxFormToken::setSecret($this->container->getParameter('kernel.secret'));
ezxFormToken::setFormField($this->container->getParameter('form.type_extension.csrf.field_name'));
} else {
ezxFormToken::setIsEnabled(false);
}
}
// Register http cache content/cache event listener
$ezpEvent = ezpEvent::getInstance();
$ezpEvent->attach('content/cache', array($this->gatewayCachePurger, 'purge'));
$ezpEvent->attach('content/cache/all', array($this->gatewayCachePurger, 'purgeAll'));
// Register persistence cache event listeners
$ezpEvent->attach('content/cache', array($this->persistenceCachePurger, 'content'));
$ezpEvent->attach('content/cache/all', array($this->persistenceCachePurger, 'all'));
$ezpEvent->attach('content/cache/version', array($this->persistenceCachePurger, 'contentVersion'));
$ezpEvent->attach('content/class/cache/all', array($this->persistenceCachePurger, 'contentType'));
$ezpEvent->attach('content/class/cache', array($this->persistenceCachePurger, 'contentType'));
$ezpEvent->attach('content/class/group/cache', array($this->persistenceCachePurger, 'contentTypeGroup'));
$ezpEvent->attach('content/section/cache', array($this->persistenceCachePurger, 'section'));
$ezpEvent->attach('user/cache/all', array($this->persistenceCachePurger, 'user'));
$ezpEvent->attach('content/translations/cache', array($this->persistenceCachePurger, 'languages'));
// Register image alias removal listeners
$ezpEvent->attach('image/removeAliases', array($this->aliasCleaner, 'removeAliases'));
$ezpEvent->attach('image/trashAliases', array($this->aliasCleaner, 'removeAliases'));
$ezpEvent->attach('image/purgeAliases', array($this->aliasCleaner, 'removeAliases'));
}