|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Cycle Database package. |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Cycle\Database\Config\MySQL; |
|
13
|
|
|
|
|
14
|
|
|
use Cycle\Database\Config\ProvidesSourceString; |
|
15
|
|
|
|
|
16
|
|
|
class SocketConnectionConfig extends ConnectionConfig implements ProvidesSourceString |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @param non-empty-string $socket |
|
|
|
|
|
|
20
|
|
|
* @param non-empty-string $database |
|
21
|
|
|
* @param non-empty-string|null $charset |
|
22
|
|
|
* @param non-empty-string|null $user |
|
23
|
|
|
* @param non-empty-string|null $password |
|
24
|
|
|
* @param array<int, non-empty-string|non-empty-string> $options |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct( |
|
27
|
|
|
public string $database, |
|
28
|
|
|
public string $socket, |
|
29
|
|
|
public ?string $charset = null, |
|
30
|
|
|
?string $user = null, |
|
31
|
|
|
?string $password = null, |
|
32
|
|
|
array $options = [], |
|
33
|
|
|
) { |
|
34
|
|
|
parent::__construct($user, $password, $options); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getSourceString(): string |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->database; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Returns the MySQL-specific PDO DataSourceName with connection Unix socket, |
|
44
|
|
|
* that looks like: |
|
45
|
|
|
* <code> |
|
46
|
|
|
* mysql:unix_socket=/tmp/mysql.sock;dbname=dbname |
|
47
|
|
|
* </code> |
|
48
|
|
|
* |
|
49
|
|
|
* {@inheritDoc} |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getDsn(): string |
|
52
|
|
|
{ |
|
53
|
|
|
$config = [ |
|
54
|
|
|
'unix_socket' => $this->socket, |
|
55
|
|
|
'dbname' => $this->database, |
|
56
|
|
|
'charset' => $this->charset, |
|
57
|
|
|
]; |
|
58
|
|
|
|
|
59
|
|
|
return \sprintf('%s:%s', $this->getName(), $this->dsn($config)); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|