getParams() 공개 메소드

Gets the parameters used during instantiation.
public getParams ( ) : array
리턴 array
예제 #1
0
 /**
  * @throws \RuntimeException
  * @return string
  */
 public function getQuery()
 {
     $config = $this->connection->getParams();
     $driver = $config['driver'];
     if (!isset($this->configClasses[$driver])) {
         throw new \RuntimeException('Driver "%s" not found');
     }
     /** @var PdoMysql $className */
     $className = $this->configClasses[$driver];
     return $className::getPlainSql();
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function getDatabase(\Doctrine\DBAL\Connection $conn)
 {
     $params = $conn->getParams();
     if (isset($params['dbname'])) {
         return $params['dbname'];
     }
     return null;
 }
 /**
  * Add a connection to the pool
  *
  * @param Connection $connection
  */
 public function add(Connection $connection)
 {
     $key = md5(serialize($connection->getParams()));
     if (isset($this->connections[$key]) && $connection !== $this->connections[$key]) {
         throw new \InvalidArgumentException('Expects a non registered connection.');
     }
     $this->connections[$key] = $connection;
 }
예제 #4
0
 public function getDatabase(\Doctrine\DBAL\Connection $conn)
 {
     $params = $conn->getParams();
     if (isset($params['dbname'])) {
         return $params['dbname'];
     }
     return $conn->query('SELECT DATABASE()')->fetchColumn();
 }
예제 #5
0
 /**
  * @param Connection $conn
  * @param string $generatorTableName
  */
 public function __construct(Connection $conn, $generatorTableName = 'sequences')
 {
     $params = $conn->getParams();
     if ($params['driver'] == 'pdo_sqlite') {
         throw new \Doctrine\DBAL\DBALException("Cannot use TableGenerator with SQLite.");
     }
     $this->conn = DriverManager::getConnection($params, $conn->getConfiguration(), $conn->getEventManager());
     $this->generatorTableName = $generatorTableName;
 }
 protected function dropDatabaseForConnection(Connection $connection, OutputInterface $output)
 {
     $params = $connection->getParams();
     $name = isset($params['path']) ? $params['path'] : $params['dbname'];
     try {
         $connection->getSchemaManager()->dropDatabase($name);
         $output->writeln(sprintf('<info>Dropped database for connection named <comment>%s</comment></info>', $name));
     } catch (\Exception $e) {
         $output->writeln(sprintf('<error>Could not drop database for connection named <comment>%s</comment></error>', $name));
         $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
     }
 }
예제 #7
0
 /**
  * Create Newscoop Database
  *
  * @param Connection $connection
  */
 public function createNewscoopDatabase($connection)
 {
     $params = $connection->getParams();
     if (isset($params['master'])) {
         $params = $params['master'];
     }
     unset($params['dbname']);
     $tmpConnection = DriverManager::getConnection($params);
     $name = $tmpConnection->getDatabasePlatform()->quoteSingleIdentifier($connection->getDatabase());
     $tmpConnection->getSchemaManager()->createDatabase($name);
     unset($tmpConnection);
     $this->logger->addInfo('Database ' . $name . ' created');
 }
예제 #8
0
 /**
  * @return string
  */
 public function getPanel()
 {
     if (empty($this->queries)) {
         return '';
     }
     $connParams = $this->connection->getParams();
     if ($connParams['driver'] === 'pdo_sqlite' && isset($connParams['path'])) {
         $host = 'path: ' . basename($connParams['path']);
     } else {
         $host = sprintf('host: %s%s/%s', $this->connection->getHost(), ($p = $this->connection->getPort()) ? ':' . $p : '', $this->connection->getDatabase());
     }
     return $this->renderStyles() . sprintf('<h1>Queries: %s %s, %s</h1>', count($this->queries), $this->totalTime ? ', time: ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : '', $host) . '<div class="nette-inner tracy-inner nette-Doctrine2Panel">' . implode('<br>', array_filter([$this->renderPanelCacheStatistics(), $this->renderPanelQueries()])) . '</div>';
 }
예제 #9
0
파일: Table.php 프로젝트: pym/table
 public function __construct(Connection $db = null, $tableName, $tableAlias = null, $tablesAliases = null)
 {
     $this->db = $db;
     $this->tableName = $tableName;
     $this->tableAlias = $tableAlias;
     $this->tablesAliases = $tablesAliases;
     $this->table = $this->tableAlias !== null ? $this->tableAlias : "`{$this->tableName}`";
     if ($db !== null && $db->getParams()['driver'] !== 'pdo_sqlite') {
         $tableColumns = $db->executeQuery("DESCRIBE {$tableName}")->fetchAll(\PDO::FETCH_COLUMN);
         $this->isTimestampable = count(array_intersect(['created_at', 'updated_at'], $tableColumns)) == 2;
         $this->isSoftdeletable = in_array('deleted_at', $tableColumns);
     }
 }
 /**
  * Creates the configuration for this schema.
  *
  * @return \Doctrine\DBAL\Schema\SchemaConfig
  */
 public function createSchemaConfig()
 {
     $schemaConfig = new SchemaConfig();
     $schemaConfig->setMaxIdentifierLength($this->_platform->getMaxIdentifierLength());
     $searchPaths = $this->getSchemaSearchPaths();
     if (isset($searchPaths[0])) {
         $schemaConfig->setName($searchPaths[0]);
     }
     $params = $this->_conn->getParams();
     if (isset($params['defaultTableOptions'])) {
         $schemaConfig->setDefaultTableOptions($params['defaultTableOptions']);
     }
     return $schemaConfig;
 }
 protected function createDatabaseForConnection(Connection $connection, OutputInterface $output)
 {
     $params = $connection->getParams();
     $name = isset($params['path']) ? $params['path'] : $params['dbname'];
     unset($params['dbname']);
     $tmpConnection = \Doctrine\DBAL\DriverManager::getConnection($params);
     try {
         $tmpConnection->getSchemaManager()->createDatabase($name);
         $output->writeln(sprintf('<info>Created database for connection named <comment>%s</comment></info>', $name));
     } catch (\Exception $e) {
         $output->writeln(sprintf('<error>Could not create database for connection named <comment>%s</comment></error>', $name));
         $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
     }
     $tmpConnection->close();
 }
 /**
  * @param \Doctrine\DBAL\Connection $conn
  *
  * @throws \Doctrine\DBAL\Sharding\ShardingException
  */
 public function __construct(Connection $conn)
 {
     $this->conn = $conn;
     $params = $conn->getParams();
     if (!isset($params['sharding']['federationName'])) {
         throw ShardingException::missingDefaultFederationName();
     }
     if (!isset($params['sharding']['distributionKey'])) {
         throw ShardingException::missingDefaultDistributionKey();
     }
     if (!isset($params['sharding']['distributionType'])) {
         throw ShardingException::missingDistributionType();
     }
     $this->federationName = $params['sharding']['federationName'];
     $this->distributionKey = $params['sharding']['distributionKey'];
     $this->distributionType = $params['sharding']['distributionType'];
     $this->filteringEnabled = isset($params['sharding']['filteringEnabled']) ? (bool) $params['sharding']['filteringEnabled'] : false;
 }
예제 #13
0
 /**
  * Connect using the deprecated mysql extension.
  *
  * This method is often required when working with some legacy admin pages.
  *
  * Most people won't need this, but it is here if they do.
  *
  * @param array $params an array of mysql connection optons that match the PDO dsn.
  *                     If you do not specify any parameters. it will use the
  *                     <code>apps.store.database.default</code> settings.
  * @return resource an ext/mysql resource
  */
 public function mysql_connect($params = null)
 {
     if (!extension_loaded('mysql')) {
         throw new \RuntimeException('The mysql extension must be installed to use this method.');
     }
     $defaults = $this->conn->getParams();
     $params = array_merge($defaults, (array) $params);
     $link = mysql_connect($params['host'], $params['user'], $params['password'], true);
     if (is_resource($link) && mysql_select_db($params['dbname'])) {
         if (!isset($params['charset']) && !empty($params['charset'])) {
             mysql_set_charset($params['charset']);
         }
         $this->link = $link;
         return $this->link;
     } else {
         throw new RuntimeException(mysql_error(), mysql_errno());
     }
 }
예제 #14
0
 private function getServerVersion()
 {
     $params = $this->con->getParams();
     // Explicit platform version requested (supersedes auto-detection), so we respect it.
     if (isset($params['serverVersion'])) {
         return $params['serverVersion'];
     }
     $wrappedConnection = $this->con->getWrappedConnection();
     if ($wrappedConnection instanceof ServerInfoAwareConnection) {
         return $wrappedConnection->getServerVersion();
     }
     // Support DBAL 2.4 by accessing it directly when using PDO PgSQL
     if ($wrappedConnection instanceof \PDO) {
         return $wrappedConnection->getAttribute(\PDO::ATTR_SERVER_VERSION);
     }
     // If we cannot guess the version, the empty string will mean we won't use the code for newer versions when doing version checks.
     return '';
 }
예제 #15
0
 public function __construct(Connection $conn)
 {
     $this->pdo = $conn;
     $params = $conn->getParams();
     $driver = $params['driver'];
     $commands = [];
     switch ($driver) {
         case 'pdo_mysql':
             $commands[] = 'SET SQL_MODE=ANSI_QUOTES';
             break;
         case 'pdo_sqlite':
             break;
         case 'pdo_pgsql':
             break;
         case 'pdo_oci':
             break;
         case 'pdo_sqlsrv':
             $commands[] = 'SET QUOTED_IDENTIFIER ON';
             break;
     }
     foreach ($commands as $comm) {
         $this->pdo->exec($comm);
     }
 }
예제 #16
0
 private function getDbMockBuilder(Connection $db)
 {
     return $this->getMockBuilder('\\Doctrine\\DBAL\\Connection')->setConstructorArgs([$db->getParams(), $db->getDriver(), $db->getConfiguration(), $db->getEventManager()])->enableOriginalConstructor();
 }
예제 #17
0
파일: Driver.php 프로젝트: jay45/porn
 /**
  * {@inheritdoc}
  */
 public function getDatabase(Connection $conn)
 {
     $params = $conn->getParams();
     return $params['user'];
 }
예제 #18
0
 /**
  * {@inheritdoc}
  * @param \Doctrine\DBAL\Connection $connection
  *
  * @throws \umi\dbal\exception\RuntimeException
  */
 public function initConnection(Connection $connection)
 {
     /** @var $pdo PDO */
     $pdo = $connection->getWrappedConnection();
     $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
     $params = $connection->getParams();
     if (!isset($params['charset'])) {
         throw new RuntimeException("No connection charset specified");
     }
     $pdo->exec('SET NAMES ' . $pdo->quote($params['charset']));
 }
 /**
  * {@inheritdoc}
  */
 public function getDatabase(\Doctrine\DBAL\Connection $conn)
 {
     $params = $conn->getParams();
     return isset($params['dbname']) ? $params['dbname'] : $conn->query('SELECT CURRENT_DATABASE()')->fetchColumn();
 }
예제 #20
0
 /**
  * {@inheritdoc}
  */
 public function getParams()
 {
     return $this->activeShardId ? $this->connections[$this->activeShardId] : parent::getParams();
 }
 /**
  * @todo make the mysql bit dynamic
  * @param Connection $connection
  */
 private function formatDSN(Connection $connection)
 {
     $driver_name = $this->getPropelDriverName($connection->getDriver());
     if ($connection->getDriver()->getName() == 'pdo_sqlite') {
         return sprintf('%s://hack.nl/%s', $driver_name, $connection->getDatabase());
     }
     $params = $connection->getParams();
     return sprintf('%s://%s:%s@%s%s/%s?encoding=%s', $driver_name, $connection->getUsername(), $connection->getPassword(), $connection->getHost(), $connection->getPort() ? ':' . $connection->getPort() : '', $connection->getDatabase(), isset($params['charset']) ? $params['charset'] : 'utf8');
 }
예제 #22
0
 public function testConnectionDoesNotMaintainTwoReferencesToExternalPDO()
 {
     $params['pdo'] = new \stdClass();
     $driverMock = $this->getMock('Doctrine\\DBAL\\Driver');
     $conn = new Connection($params, $driverMock);
     $this->assertArrayNotHasKey('pdo', $conn->getParams(), "Connection is maintaining additional reference to the PDO connection");
 }
예제 #23
0
파일: Driver.php 프로젝트: ncud/sagalaya
 public function getDatabase(\Doctrine\DBAL\Connection $conn)
 {
     $params = $conn->getParams();
     return isset($params['path']) ? $params['path'] : null;
 }
예제 #24
0
 private function connectToDatabase(Connection $db, $databaseName)
 {
     $db->close();
     $db->__construct(['dbname' => $databaseName] + $db->getParams(), $db->getDriver(), $db->getConfiguration(), $db->getEventManager());
     $db->connect();
 }
 protected function getTableName($name)
 {
     return sprintf('%s_%s', $this->connection->getParams()['prefix'], $name);
 }
예제 #26
0
 public function getDatabase(Connection $conn)
 {
     return $conn->getParams()["dbname"];
 }
 /**
  * Restore the backup for the given connection / hash
  *
  * @param \Doctrine\DBAL\Connection $connection
  * @param string                    $hash
  */
 public function restoreBackup(Connection $connection, $hash)
 {
     $platform = $connection->getDatabasePlatform();
     $filename = $this->getBackupFile($hash);
     $database = $connection->getDatabase();
     $params = $connection->getParams();
     $platformName = $platform->getName();
     $this->getPlatformBackup($platformName)->restore($database, $filename, $params);
 }
예제 #28
0
 /**
  * @param ConnectionInterface $conn
  *
  * @return mixed
  */
 public function getDatabase(ConnectionInterface $conn)
 {
     $params = $conn->getParams();
     return $params['dbname'];
 }
예제 #29
0
 public function getDatabase(\Doctrine\DBAL\Connection $conn)
 {
     $params = $conn->getParams();
     return $params['user'];
 }
예제 #30
0
 /**
  * @param Connection $connection
  *
  * @return string
  */
 protected function getPrefix(Connection $connection)
 {
     $params = $connection->getParams();
     return array_get($params, 'prefix');
 }