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