PluginProbe
Booking for Appointments and Events Calendar – Amelia / 1.2.23
Booking for Appointments and Events Calendar – Amelia v1.2.23
2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 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 All 59 releases
ameliabooking / src / Infrastructure / Connection.php
Connection.php
111 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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