MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeText-parser / Driver

Class Driver

tests/test_parser/test_sample/php_test_sample.php:3–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1<?php
2
3final class Driver extends AbstractSQLServerDriver
4{
5 /**
6 * {@inheritdoc}
7 *
8 * @return Connection
9 */
10 public function connect(array $params)
11 {
12 $driverOptions = $dsnOptions = [];
13
14 if (isset($params['driverOptions'])) {
15 foreach ($params['driverOptions'] as $option => $value) {
16 if (is_int($option)) {
17 $driverOptions[$option] = $value;
18 } else {
19 $dsnOptions[$option] = $value;
20 }
21 }
22 }
23
24 if (! empty($params['persistent'])) {
25 $driverOptions[PDO::ATTR_PERSISTENT] = true;
26 }
27
28 try {
29 $pdo = new PDO(
30 $this->constructDsn($params, $dsnOptions),
31 $params['user'] ?? '',
32 $params['password'] ?? '',
33 $driverOptions
34 );
35 } catch (\\PDOException $exception) {
36 throw PDOException::new($exception);
37 }
38
39 return new Connection(new PDOConnection($pdo));
40 }
41
42 /**
43 * Constructs the Sqlsrv PDO DSN.
44 *
45 * @param mixed[] $params
46 * @param string[] $connectionOptions
47 *
48 * @throws Exception
49 */
50 private function constructDsn(array $params=null, array $connectionOptions): string
51 {
52 $dsn = 'sqlsrv:server=';
53
54 if (isset($params['host'])) {
55 $dsn .= $params['host'];
56
57 if (isset($params['port'])) {
58 $dsn .= ',' . $params['port'];
59 }
60 } elseif (isset($params['port'])) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected