Open Journal Systems  3.3.0
NamePart.php
1 <?php
2 /*
3  * citeproc-php
4  *
5  * @link http://github.com/seboettg/citeproc-php for the source repository
6  * @copyright Copyright (c) 2016 Sebastian Böttger.
7  * @license https://opensource.org/licenses/MIT
8  */
9 
11 
16 use SimpleXMLElement;
17 
39 class NamePart
40 {
41 
42  use FormattingTrait,
43  TextCaseTrait,
44  AffixesTrait;
45 
46  private $name;
47 
51  private $parent;
52 
58  public function __construct(SimpleXMLElement $node, $parent)
59  {
60  $this->parent = $parent;
61 
63  foreach ($node->attributes() as $attribute) {
64  if ($attribute->getName() === 'name') {
65  $this->name = (string) $attribute;
66  }
67  }
68 
69  $this->initFormattingAttributes($node);
70  $this->initTextCaseAttributes($node);
71  $this->initAffixesAttributes($node);
72  }
73 
79  public function render($data)
80  {
81  if (!isset($data->{$this->name})) {
82  return "";
83  }
84 
85  switch ($this->name) {
86  /* If set to “given”, formatting and text-case attributes on cs:name-part affect the “given” and
87  “dropping-particle” name-parts. affixes surround the “given” name-part, enclosing any demoted name particles
88  for inverted names.*/
89  case 'given':
90  return $this->addAffixes($this->format($this->applyTextCase($data->given)));
91 
92  /* if name set to “family”, formatting and text-case attributes affect the “family” and
93  “non-dropping-particle” name-parts. affixes surround the “family” name-part, enclosing any preceding name
94  particles, as well as the “suffix” name-part for non-inverted names.*/
95  case 'family':
96  return $this->addAffixes($this->format($this->applyTextCase($data->family)));
97  }
98  throw new CiteProcException("This shouldn't happen.");
99  }
100 
104  public function getName()
105  {
106  return $this->name;
107  }
108 }
Seboettg\CiteProc\Styles\AffixesTrait
trait AffixesTrait
Definition: AffixesTrait.php:21
Seboettg\CiteProc\Styles\FormattingTrait
trait FormattingTrait
Definition: FormattingTrait.php:21
Seboettg\CiteProc\Rendering\Name\NamePart\render
render($data)
Definition: NamePart.php:82
Seboettg\CiteProc\Rendering\Name
Definition: EtAl.php:10
Seboettg\CiteProc\Rendering\Name\NamePart\getName
getName()
Definition: NamePart.php:107
Seboettg\CiteProc\Styles\TextCaseTrait
trait TextCaseTrait
Definition: TextCaseTrait.php:23
Seboettg\CiteProc\Exception\CiteProcException
Definition: CiteProcException.php:20
Seboettg\CiteProc\Rendering\Name\NamePart
Definition: NamePart.php:39
Seboettg\CiteProc\Rendering\Name\NamePart\__construct
__construct(SimpleXMLElement $node, $parent)
Definition: NamePart.php:61