PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.11
Booking for Appointments and Events Calendar – Amelia v1.2.11
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 2 years ago ContainerConfig 1 year ago DB 2 years ago Licence 1 year ago Repository 1 year ago Routes 1 year ago Services 1 year ago WP 1 year ago Connection.php 5 years ago
Connection.php
111 lines
1 <?php
2 /**
3 * @author Slavko Babic
4 * @date 2017-08-21
5 */
6
7 namespace AmeliaBooking\Infrastructure;
8
9 use mysqli;
10 use \PDO;
11
12 /**
13 * Class Connection
14 *
15 * @package Infrastructure
16 */
17 abstract class Connection
18 {
19 /** @var string $username */
20 protected $username;
21
22 /** @var string $password */
23 protected $password;
24
25 /** @var string $charset */
26 protected $charset;
27
28 /** @var PDO|mysqli $handler */
29 protected $handler;
30
31 /** @var int port */
32 protected $port;
33
34 /** @var string $host */
35 protected $host;
36
37 /** @var string $name */
38 protected $database;
39
40 /** @var string $socket */
41 protected $socket;
42
43 /** @var string $socketPath */
44 protected $socketPath;
45
46 /**
47 * Connection constructor.
48 *
49 * @param string $database
50 * @param string $username
51 * @param string $password
52 * @param string $host
53 * @param int $port
54 * @param string $charset
55 */
56 public function __construct(
57 $host,
58 $database,
59 $username,
60 $password,
61 $charset = 'utf8',
62 $port = 3306
63 ) {
64 $this->database = (string)$database;
65 $this->username = (string)$username;
66 $this->password = (string)$password;
67 $this->host = $this->socket = (string)$host;
68 $this->port = (int)$port;
69 $this->charset = (string)$charset;
70 }
71
72 /**
73 * @return PDO|mysqli
74 */
75 public function __invoke()
76 {
77 return $this->handler;
78 }
79
80 /**
81 *
82 */
83 protected function socketHandler()
84 {
85 if (strpos($this->socket, ':') === false) {
86 $this->host = $this->socket;
87
88 return;
89 }
90
91 $data = explode(':', $this->socket);
92
93 $this->host = $data[0];
94
95 if (isset($data[1]) && is_numeric($data[1]) && (int)$data[1]) {
96 $this->port = $data[1];
97 } elseif (isset($data[1]) && strpos($data[1], '/') !== false) {
98 $position = strpos($data[1], '/');
99
100 if ($position === 0) {
101 $this->socketPath = $data[1];
102 } else {
103 $this->port = substr($data[1], 0, $position);
104 $this->socketPath = substr($data[1], $position);
105 }
106 } elseif (isset($data[1]) && (int)$data[1]) {
107 $this->port = $data[1];
108 }
109 }
110 }
111