HM\BackUpWordPress\Database_Backup_Engine::parse_db_host_constant PHP Method

parse_db_host_constant() public method

The DB_HOST constant potentially contains the hostname, port or socket. We need to parse it to figure out the type of mysql connection to make.
public parse_db_host_constant ( string $constant = 'DB_HOST' )
$constant string The Constant to parse. If the string isn't a defined Constant then it will be parsed directly.
    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;
            }
        }
    }