1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Yep package. |
4
|
|
|
* Copyright (c) 2016 Martin Zeman (Zemistr) (http://www.zemistr.eu) |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Yep\Dsn; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class MySQLDsn |
11
|
|
|
* |
12
|
|
|
* @package Yep\Dsn |
13
|
|
|
* @author Martin Zeman (Zemistr) <[email protected]> |
14
|
|
|
* |
15
|
|
|
* PDO_MYSQL |
16
|
|
|
* mysql:unix_socket=/tmp/mysql.sock;dbname=testdb |
17
|
|
|
*/ |
18
|
|
|
class MySqlUnixSocketDsn implements IDsn { |
19
|
|
|
/** @var string */ |
20
|
|
|
private $unixSocket; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
private $dbName; |
24
|
|
|
|
25
|
3 |
|
public function __construct(string $unixSocket, string $dbName) { |
26
|
3 |
|
$this->setUnixSocket($unixSocket); |
27
|
3 |
|
$this->setDbName($dbName); |
28
|
3 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string $unixSocket |
32
|
|
|
* @return MySqlUnixSocketDsn |
|
|
|
|
33
|
|
|
* @throws EmptyArgumentException |
34
|
|
|
*/ |
35
|
3 |
|
public function setUnixSocket(string $unixSocket) : self { |
36
|
3 |
|
$this->unixSocket = trim($unixSocket); |
37
|
|
|
|
38
|
3 |
|
if ($this->unixSocket == '') { |
39
|
1 |
|
throw new EmptyArgumentException('unixSocket'); |
40
|
|
|
} |
41
|
|
|
|
42
|
3 |
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
1 |
|
public function getUnixSocket() : string { |
49
|
1 |
|
return $this->unixSocket; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $dbName |
54
|
|
|
* @return MySqlUnixSocketDsn |
|
|
|
|
55
|
|
|
* @throws EmptyArgumentException |
56
|
|
|
*/ |
57
|
3 |
View Code Duplication |
public function setDbName(string $dbName) : self { |
|
|
|
|
58
|
3 |
|
$this->dbName = trim($dbName); |
59
|
|
|
|
60
|
3 |
|
if ($this->dbName == '') { |
61
|
1 |
|
throw new EmptyArgumentException('dbName'); |
62
|
|
|
} |
63
|
|
|
|
64
|
3 |
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
1 |
|
public function getDbName() : string { |
71
|
1 |
|
return $this->dbName; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
1 |
|
public function toString() : string { |
78
|
1 |
|
return 'mysql:unix_socket=' . $this->getUnixSocket() . ';dbname=' . $this->getDbName(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
1 |
|
public function __toString() : string { |
85
|
1 |
|
return $this->toString(); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.