class HumanNameParser in Bibliography & Citation 8
Same name and namespace in other branches
- 2.0.x src/HumanNameParser.php \Drupal\bibcite\HumanNameParser
Human name parser service.
Hierarchy
- class \Drupal\bibcite\HumanNameParser implements HumanNameParserInterface
Expanded class hierarchy of HumanNameParser
1 string reference to 'HumanNameParser'
1 service uses HumanNameParser
File
- src/
HumanNameParser.php, line 10
Namespace
Drupal\bibciteView source
class HumanNameParser implements HumanNameParserInterface {
/**
* Parser object.
*
* @var \ADCI\FullNameParser\Parser
*/
protected $parser;
/**
* HumanNameParser constructor.
*/
public function __construct() {
$this->parser = new Parser([
'mandatory_last_name' => FALSE,
'mandatory_middle_name' => FALSE,
]);
}
/**
* Parse the name into its constituent parts.
*
* @param string $name
* Human name string.
*
* @return array
* Parsed name parts.
*
* @throws \ADCI\FullNameParser\Exception\NameParsingException
*/
public function parse($name) {
$parsed_name = $this->parser
->parse($name);
return [
'leading_title' => $parsed_name
->getLeadingInitial(),
'prefix' => $parsed_name
->getAcademicTitle(),
'first_name' => $parsed_name
->getFirstName(),
'middle_name' => $parsed_name
->getMiddleName(),
'last_name' => $parsed_name
->getLastName(),
'nick' => $parsed_name
->getNicknames(),
'suffix' => $parsed_name
->getSuffix(),
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
HumanNameParser:: |
protected | property | Parser object. | |
HumanNameParser:: |
public | function |
Parse the name into its constituent parts. Overrides HumanNameParserInterface:: |
|
HumanNameParser:: |
public | function | HumanNameParser constructor. |