Laravel\Envoy\SSHConfigFile::parseString PHP Method

parseString() public static method

Parse the given configuration string.
public static parseString ( string $string ) : SSHConfigFile
$string string
return SSHConfigFile
    public static function parseString($string)
    {
        $groups = [];
        $index = 0;
        $matchSection = false;
        foreach (explode(PHP_EOL, $string) as $line) {
            $line = trim($line);
            if ('' == $line || starts_with($line, '#')) {
                continue;
            }
            // Keys and values may get separated via an equals, so we'll parse them both
            // out here and hang onto their values. We will also lower case this keys
            // and unquotes the values so they are properly formatted for next use.
            if (preg_match('/^\\s*(\\S+)\\s*=(.*)$/', $line, $match)) {
                $key = strtolower($match[1]);
                $value = self::unquote($match[2]);
            } else {
                $segments = preg_split('/\\s+/', $line, 2);
                $key = strtolower($segments[0]);
                $value = self::unquote($segments[1]);
            }
            // The configuration file contains sections separated by Host and / or Match
            // specifications. Therefore, if we come across a Host keyword we start a
            // new group. If it's a Match we ignore declarations until next 'Host'.
            if ('host' === $key) {
                $index++;
                $matchSection = false;
            } elseif ('match' === $key) {
                $matchSection = true;
            }
            if (!$matchSection) {
                $groups[$index][$key] = $value;
            }
        }
        return new self(array_values($groups));
    }