public function parse_db_host_constant($constant = 'DB_HOST')
{
// If we've been passed a Constant then grab it's contents
if (defined($constant)) {
$constant = constant($constant);
}
// If we weren't passed a Constant then just parse the string directly.
$this->host = (string) $constant;
// Grab the part after :, it could either be a port or a socket
$port_or_socket = strstr($constant, ':');
if ($port_or_socket) {
// The host is the bit up to the :
$this->host = substr($constant, 0, strpos($constant, ':'));
// Strip the :
$port_or_socket = substr($port_or_socket, 1);
if (0 !== strpos($port_or_socket, '/')) {
$this->port = intval($port_or_socket);
$maybe_socket = strstr($port_or_socket, ':');
if (!empty($maybe_socket)) {
$this->socket = substr($maybe_socket, 1);
}
} else {
$this->socket = $port_or_socket;
}
}
}