PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.15.3
Independent Analytics – WordPress Analytics Plugin v2.15.3
2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / illuminate / database / Connectors / SqlServerConnector.php
independent-analytics / vendor / illuminate / database / Connectors Last commit date
ConnectionFactory.php 3 weeks ago Connector.php 2 years ago ConnectorInterface.php 2 years ago MySqlConnector.php 2 years ago PostgresConnector.php 3 weeks ago SQLiteConnector.php 3 weeks ago SqlServerConnector.php 3 weeks ago
SqlServerConnector.php
188 lines
1 <?php
2
3 namespace IAWPSCOPED\Illuminate\Database\Connectors;
4
5 use IAWPSCOPED\Illuminate\Support\Arr;
6 use PDO;
7 /** @internal */
8 class SqlServerConnector extends Connector implements ConnectorInterface
9 {
10 /**
11 * The PDO connection options.
12 *
13 * @var array
14 */
15 protected $options = [PDO::ATTR_CASE => PDO::CASE_NATURAL, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, PDO::ATTR_STRINGIFY_FETCHES => \false];
16 /**
17 * Establish a database connection.
18 *
19 * @param array $config
20 * @return \PDO
21 */
22 public function connect(array $config)
23 {
24 $options = $this->getOptions($config);
25 $connection = $this->createConnection($this->getDsn($config), $config, $options);
26 $this->configureIsolationLevel($connection, $config);
27 return $connection;
28 }
29 /**
30 * Set the connection transaction isolation level.
31 *
32 * https://learn.microsoft.com/en-us/sql/t-sql/statements/set-transaction-isolation-level-transact-sql
33 *
34 * @param \PDO $connection
35 * @param array $config
36 * @return void
37 */
38 protected function configureIsolationLevel($connection, array $config)
39 {
40 if (!isset($config['isolation_level'])) {
41 return;
42 }
43 $connection->prepare("SET TRANSACTION ISOLATION LEVEL {$config['isolation_level']}")->execute();
44 }
45 /**
46 * Create a DSN string from a configuration.
47 *
48 * @param array $config
49 * @return string
50 */
51 protected function getDsn(array $config)
52 {
53 // First we will create the basic DSN setup as well as the port if it is in
54 // in the configuration options. This will give us the basic DSN we will
55 // need to establish the PDO connections and return them back for use.
56 if ($this->prefersOdbc($config)) {
57 return $this->getOdbcDsn($config);
58 }
59 if (\in_array('sqlsrv', $this->getAvailableDrivers())) {
60 return $this->getSqlSrvDsn($config);
61 } else {
62 return $this->getDblibDsn($config);
63 }
64 }
65 /**
66 * Determine if the database configuration prefers ODBC.
67 *
68 * @param array $config
69 * @return bool
70 */
71 protected function prefersOdbc(array $config)
72 {
73 return \in_array('odbc', $this->getAvailableDrivers()) && ($config['odbc'] ?? null) === \true;
74 }
75 /**
76 * Get the DSN string for a DbLib connection.
77 *
78 * @param array $config
79 * @return string
80 */
81 protected function getDblibDsn(array $config)
82 {
83 return $this->buildConnectString('dblib', \array_merge(['host' => $this->buildHostString($config, ':'), 'dbname' => $config['database']], Arr::only($config, ['appname', 'charset', 'version'])));
84 }
85 /**
86 * Get the DSN string for an ODBC connection.
87 *
88 * @param array $config
89 * @return string
90 */
91 protected function getOdbcDsn(array $config)
92 {
93 return isset($config['odbc_datasource_name']) ? 'odbc:' . $config['odbc_datasource_name'] : '';
94 }
95 /**
96 * Get the DSN string for a SqlSrv connection.
97 *
98 * @param array $config
99 * @return string
100 */
101 protected function getSqlSrvDsn(array $config)
102 {
103 $arguments = ['Server' => $this->buildHostString($config, ',')];
104 if (isset($config['database'])) {
105 $arguments['Database'] = $config['database'];
106 }
107 if (isset($config['readonly'])) {
108 $arguments['ApplicationIntent'] = 'ReadOnly';
109 }
110 if (isset($config['pooling']) && $config['pooling'] === \false) {
111 $arguments['ConnectionPooling'] = '0';
112 }
113 if (isset($config['appname'])) {
114 $arguments['APP'] = $config['appname'];
115 }
116 if (isset($config['encrypt'])) {
117 $arguments['Encrypt'] = $config['encrypt'];
118 }
119 if (isset($config['trust_server_certificate'])) {
120 $arguments['TrustServerCertificate'] = $config['trust_server_certificate'];
121 }
122 if (isset($config['multiple_active_result_sets']) && $config['multiple_active_result_sets'] === \false) {
123 $arguments['MultipleActiveResultSets'] = 'false';
124 }
125 if (isset($config['transaction_isolation'])) {
126 $arguments['TransactionIsolation'] = $config['transaction_isolation'];
127 }
128 if (isset($config['multi_subnet_failover'])) {
129 $arguments['MultiSubnetFailover'] = $config['multi_subnet_failover'];
130 }
131 if (isset($config['column_encryption'])) {
132 $arguments['ColumnEncryption'] = $config['column_encryption'];
133 }
134 if (isset($config['key_store_authentication'])) {
135 $arguments['KeyStoreAuthentication'] = $config['key_store_authentication'];
136 }
137 if (isset($config['key_store_principal_id'])) {
138 $arguments['KeyStorePrincipalId'] = $config['key_store_principal_id'];
139 }
140 if (isset($config['key_store_secret'])) {
141 $arguments['KeyStoreSecret'] = $config['key_store_secret'];
142 }
143 if (isset($config['login_timeout'])) {
144 $arguments['LoginTimeout'] = $config['login_timeout'];
145 }
146 if (isset($config['authentication'])) {
147 $arguments['Authentication'] = $config['authentication'];
148 }
149 return $this->buildConnectString('sqlsrv', $arguments);
150 }
151 /**
152 * Build a connection string from the given arguments.
153 *
154 * @param string $driver
155 * @param array $arguments
156 * @return string
157 */
158 protected function buildConnectString($driver, array $arguments)
159 {
160 return $driver . ':' . \implode(';', \array_map(function ($key) use($arguments) {
161 return \sprintf('%s=%s', $key, $arguments[$key]);
162 }, \array_keys($arguments)));
163 }
164 /**
165 * Build a host string from the given configuration.
166 *
167 * @param array $config
168 * @param string $separator
169 * @return string
170 */
171 protected function buildHostString(array $config, $separator)
172 {
173 if (empty($config['port'])) {
174 return $config['host'];
175 }
176 return $config['host'] . $separator . $config['port'];
177 }
178 /**
179 * Get the available PDO drivers.
180 *
181 * @return array
182 */
183 protected function getAvailableDrivers()
184 {
185 return PDO::getAvailableDrivers();
186 }
187 }
188