SparkPost\Transmission::toAddressObject PHP Method

toAddressObject() private method

Takes the shorthand form of an email address and converts it to the long form.
private toAddressObject ( $address ) : array
$address - the shorthand form of an email address "Name "
return array - the longhand form of an email address [ "name" => "John", "email" => "[email protected]" ]
    private function toAddressObject($address)
    {
        $formatted = $address;
        if (is_string($formatted)) {
            $formatted = [];
            if ($this->isEmail($address)) {
                $formatted['email'] = $address;
            } elseif (preg_match('/"?(.[^"]*)?"?\\s*<(.+)>/', $address, $matches)) {
                $name = trim($matches[1]);
                $formatted['name'] = $matches[1];
                $formatted['email'] = $matches[2];
            } else {
                throw new \Exception('Invalid address format: ' . $address);
            }
        }
        return $formatted;
    }