You are here

class HumanNameParser in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x src/HumanNameParser.php \Drupal\bibcite\HumanNameParser

Human name parser service.

Hierarchy

Expanded class hierarchy of HumanNameParser

1 string reference to 'HumanNameParser'
bibcite.services.yml in ./bibcite.services.yml
bibcite.services.yml
1 service uses HumanNameParser
bibcite.human_name_parser in ./bibcite.services.yml
Drupal\bibcite\HumanNameParser

File

src/HumanNameParser.php, line 10

Namespace

Drupal\bibcite
View 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

Namesort descending Modifiers Type Description Overrides
HumanNameParser::$parser protected property Parser object.
HumanNameParser::parse public function Parse the name into its constituent parts. Overrides HumanNameParserInterface::parse
HumanNameParser::__construct public function HumanNameParser constructor.