@ -349,7 +349,7 @@ EOT
}
$author = $io->askAndValidate(
'Author [< comment > '.$author.'< / comment > , n to skip]: ',
'Author ['.(is_string($author) ? ' < comment > '.$author.'< / comment > , ' : '') . ' n to skip]: ',
function ($value) use ($author) {
if ($value === 'n' || $value === 'no') {
return;
@ -357,6 +357,10 @@ EOT
$value = $value ?: $author;
$author = $this->parseAuthorString($value);
if ($author['email'] === null) {
return $author['name'];
}
return sprintf('%s < %s>', $author['name'], $author['email']);
},
null,
@ -470,33 +474,41 @@ EOT
/**
* @private
* @param string $author
* @return array{name: string, email: string}
* @return array{name: string, email: string|null }
*/
public function parseAuthorString($author)
{
if (Preg::isMatch('/^(?P< name > [- .,\p{L}\p{N}\p{Mn}\'’ "()]+) < (?P< email > .+?)>$/u', $author, $match)) {
if ($this->isValidEmail($match['email'])) {
return array(
'name' => trim($match['name']),
'email' => $match['email'],
);
if (Preg::isMatch('/^(?P< name > [- .,\p{L}\p{N}\p{Mn}\'’ "()]+)(?:\s+< (?P< email > .+?)>)?$/u', $author, $match)) {
$hasEmail = isset($match['email']) & & '' !== $match['email'];
if ($hasEmail & & !$this->isValidEmail($match['email'])) {
throw new \InvalidArgumentException('Invalid email "'.$match['email'].'"');
}
return array(
'name' => trim($match['name']),
'email' => $hasEmail ? $match['email'] : null,
);
}
throw new \InvalidArgumentException(
'Invalid author string. Must be in the format: '.
'John Smith < john @ example . com > '
'Invalid author string. Must be in the formats : '.
'Jane Doe or J ohn Smith < john @ example . com > '
);
}
/**
* @param string $author
*
* @return array< int , array { name: string , email : string } >
* @return array< int , array { name: string , email ? : string } >
*/
protected function formatAuthors($author)
{
return array($this->parseAuthorString($author));
$author = $this->parseAuthorString($author);
if (null === $author['email']) {
unset($author['email']);
}
return array($author);
}
/**