‪TYPO3CMS  9.5
Driver.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
23 class ‪Driver extends \Doctrine\DBAL\Driver\PDOSqlsrv\Driver
24 {
28  public function ‪connect(array $params, $username = null, $password = null, array $driverOptions = [])
29  {
30  [$driverOptions, $connectionOptions] = $this->‪splitOptions($driverOptions);
31 
32  return new ‪Connection(
33  $this->‪_constructPdoDsn($params, $connectionOptions),
34  $username,
35  $password,
36  $driverOptions
37  );
38  }
39 
43  private function ‪_constructPdoDsn(array $params, array $connectionOptions)
44  {
45  $dsn = 'sqlsrv:server=';
46 
47  if (isset($params['host'])) {
48  $dsn .= $params['host'];
49  }
50 
51  if (isset($params['port']) && ! empty($params['port'])) {
52  $dsn .= ',' . $params['port'];
53  }
54 
55  if (isset($params['dbname'])) {
56  $connectionOptions['Database'] = $params['dbname'];
57  }
58 
59  if (isset($params['MultipleActiveResultSets'])) {
60  $connectionOptions['MultipleActiveResultSets'] = $params['MultipleActiveResultSets'] ? 'true' : 'false';
61  }
62 
63  return $dsn . $this->‪getConnectionOptionsDsn($connectionOptions);
64  }
65 
69  private function ‪splitOptions(array $options): array
70  {
71  $driverOptions = [];
72  $connectionOptions = [];
73 
74  foreach ($options as $optionKey => $optionValue) {
75  if (is_int($optionKey)) {
76  $driverOptions[$optionKey] = $optionValue;
77  } else {
78  $connectionOptions[$optionKey] = $optionValue;
79  }
80  }
81 
82  return [$driverOptions, $connectionOptions];
83  }
84 
88  private function ‪getConnectionOptionsDsn(array $connectionOptions): string
89  {
90  $connectionOptionsDsn = '';
91 
92  foreach ($connectionOptions as $paramName => $paramValue) {
93  $connectionOptionsDsn .= sprintf(';%s=%s', $paramName, $paramValue);
94  }
95 
96  return $connectionOptionsDsn;
97  }
98 
102  public function ‪getName()
103  {
104  return parent::getName();
105  }
106 }
‪TYPO3\CMS\Core\Database\Driver\PDOSqlsrv\Driver\getName
‪getName()
Definition: Driver.php:102
‪TYPO3\CMS\Core\Database\Driver\PDOSqlsrv\Driver
Definition: Driver.php:24
‪TYPO3\CMS\Core\Database\Driver\PDOSqlsrv\Connection
Definition: Connection.php:26
‪TYPO3\CMS\Core\Database\Driver\PDOSqlsrv\Driver\getConnectionOptionsDsn
‪getConnectionOptionsDsn(array $connectionOptions)
Definition: Driver.php:88
‪TYPO3\CMS\Core\Database\Driver\PDOSqlsrv\Driver\connect
‪connect(array $params, $username=null, $password=null, array $driverOptions=[])
Definition: Driver.php:28
‪TYPO3\CMS\Core\Database\Driver\PDOSqlsrv\Driver\splitOptions
‪splitOptions(array $options)
Definition: Driver.php:69
‪TYPO3\CMS\Core\Database\Driver\PDOSqlsrv\Driver\_constructPdoDsn
‪_constructPdoDsn(array $params, array $connectionOptions)
Definition: Driver.php:43
‪TYPO3\CMS\Core\Database\Driver\PDOSqlsrv
Definition: Connection.php:4