PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.28
Booking for Appointments and Events Calendar – Amelia v1.2.28
2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Infrastructure / Connection.php
ameliabooking / src / Infrastructure Last commit date
Common 1 year ago ContainerConfig 1 year ago DB 1 year ago Licence 1 year ago Repository 1 year ago Routes 1 year ago Services 1 year ago WP 1 year ago Connection.php 1 year ago
Connection.php
112 lines
1 <?php
2
3 /**
4 * @author Slavko Babic
5 * @date 2017-08-21
6 */
7
8 namespace AmeliaBooking\Infrastructure;
9
10 use mysqli;
11 use PDO;
12
13 /**
14 * Class Connection
15 *
16 * @package Infrastructure
17 */
18 abstract class Connection
19 {
20 /** @var string $username */
21 protected $username;
22
23 /** @var string $password */
24 protected $password;
25
26 /** @var string $charset */
27 protected $charset;
28
29 /** @var PDO|mysqli $handler */
30 protected $handler;
31
32 /** @var int port */
33 protected $port;
34
35 /** @var string $host */
36 protected $host;
37
38 /** @var string $name */
39 protected $database;
40
41 /** @var string $socket */
42 protected $socket;
43
44 /** @var string $socketPath */
45 protected $socketPath;
46
47 /**
48 * Connection constructor.
49 *
50 * @param string $database
51 * @param string $username
52 * @param string $password
53 * @param string $host
54 * @param int $port
55 * @param string $charset
56 */
57 public function __construct(
58 $host,
59 $database,
60 $username,
61 $password,
62 $charset = 'utf8',
63 $port = 3306
64 ) {
65 $this->database = (string)$database;
66 $this->username = (string)$username;
67 $this->password = (string)$password;
68 $this->host = $this->socket = (string)$host;
69 $this->port = (int)$port;
70 $this->charset = (string)$charset;
71 }
72
73 /**
74 * @return PDO|mysqli
75 */
76 public function __invoke()
77 {
78 return $this->handler;
79 }
80
81 /**
82 *
83 */
84 protected function socketHandler()
85 {
86 if (strpos($this->socket, ':') === false) {
87 $this->host = $this->socket;
88
89 return;
90 }
91
92 $data = explode(':', $this->socket);
93
94 $this->host = $data[0];
95
96 if (isset($data[1]) && is_numeric($data[1]) && (int)$data[1]) {
97 $this->port = $data[1];
98 } elseif (isset($data[1]) && strpos($data[1], '/') !== false) {
99 $position = strpos($data[1], '/');
100
101 if ($position === 0) {
102 $this->socketPath = $data[1];
103 } else {
104 $this->port = substr($data[1], 0, $position);
105 $this->socketPath = substr($data[1], $position);
106 }
107 } elseif (isset($data[1]) && (int)$data[1]) {
108 $this->port = $data[1];
109 }
110 }
111 }
112