Fix init author support to make email optional, fixes #10538
parent
6ea5b84bd9
commit
f1ebc1d2b6
|
@ -350,7 +350,7 @@ EOT
|
||||||
|
|
||||||
$self = $this;
|
$self = $this;
|
||||||
$author = $io->askAndValidate(
|
$author = $io->askAndValidate(
|
||||||
'Author [<comment>'.$author.'</comment>, n to skip]: ',
|
'Author ['.(is_string($author) ? '<comment>'.$author.'</comment>, ' : '') . 'n to skip]: ',
|
||||||
function ($value) use ($self, $author) {
|
function ($value) use ($self, $author) {
|
||||||
if ($value === 'n' || $value === 'no') {
|
if ($value === 'n' || $value === 'no') {
|
||||||
return;
|
return;
|
||||||
|
@ -358,6 +358,10 @@ EOT
|
||||||
$value = $value ?: $author;
|
$value = $value ?: $author;
|
||||||
$author = $self->parseAuthorString($value);
|
$author = $self->parseAuthorString($value);
|
||||||
|
|
||||||
|
if ($author['email'] === null) {
|
||||||
|
return $author['name'];
|
||||||
|
}
|
||||||
|
|
||||||
return sprintf('%s <%s>', $author['name'], $author['email']);
|
return sprintf('%s <%s>', $author['name'], $author['email']);
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
|
@ -471,22 +475,20 @@ EOT
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @param string $author
|
* @param string $author
|
||||||
* @return array{name: string, email: string}
|
* @return array{name: string, email: string|null}
|
||||||
*/
|
*/
|
||||||
public function parseAuthorString($author)
|
public function parseAuthorString($author)
|
||||||
{
|
{
|
||||||
if (Preg::isMatch('/^(?P<name>[- .,\p{L}\p{N}\p{Mn}\'’"()]+) <(?P<email>.+?)>$/u', $author, $match)) {
|
if (Preg::isMatch('/^(?P<name>[- .,\p{L}\p{N}\p{Mn}\'’"()]+)(?: <(?P<email>.+?)>)?$/u', $author, $match)) {
|
||||||
if ($this->isValidEmail($match['email'])) {
|
return array(
|
||||||
return array(
|
'name' => trim($match['name']),
|
||||||
'name' => trim($match['name']),
|
'email' => (isset($match['email']) && '' !== $match['email'] && $this->isValidEmail($match['email'])) ? $match['email'] : null,
|
||||||
'email' => $match['email'],
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \InvalidArgumentException(
|
throw new \InvalidArgumentException(
|
||||||
'Invalid author string. Must be in the format: '.
|
'Invalid author string. Must be in the formats: '.
|
||||||
'John Smith <john@example.com>'
|
'Jane Doe or John Smith <john@example.com>'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -684,11 +686,11 @@ EOT
|
||||||
/**
|
/**
|
||||||
* @param string $author
|
* @param string $author
|
||||||
*
|
*
|
||||||
* @return array<int, array{name: string, email: string}>
|
* @return array<int, array{name: string, email: string|null}>
|
||||||
*/
|
*/
|
||||||
protected function formatAuthors($author)
|
protected function formatAuthors($author)
|
||||||
{
|
{
|
||||||
return array($this->parseAuthorString($author));
|
return array(array_filter($this->parseAuthorString($author)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue