*/
public $tags = [];
+ /**
+ * @var array
+ * List of authors.
+ * Ex: [0 => ['name' => 'Alice', 'email' => 'a@b', 'homepage' => 'https://example.com', 'role' => 'Person']]
+ */
+ public $authors = [];
+
+ /**
+ * @var array|null
+ * The current maintainer at time of publication.
+ * This is deprecated in favor of $authors.
+ * @deprecated
+ */
+ public $maintainer = NULL;
+
/**
* Load extension info an XML file.
*
elseif ($attr === 'requires') {
$this->requires = $this->filterRequirements($val);
}
+ elseif ($attr === 'maintainer') {
+ $this->maintainer = CRM_Utils_XML::xmlObjToArray($val);
+ $this->authors[] = [
+ 'name' => (string) $val->author,
+ 'email' => (string) $val->email,
+ 'role' => 'Maintainer',
+ ];
+ }
+ elseif ($attr === 'authors') {
+ foreach ($val->author as $author) {
+ $this->authors[] = $thisAuthor = CRM_Utils_XML::xmlObjToArray($author);
+ if ('maintainer' === strtolower($thisAuthor['role'] ?? '')) {
+ $this->maintainer = ['author' => $thisAuthor['name'], 'email' => $thisAuthor['email'] ?? NULL];
+ }
+ }
+ }
else {
$this->$attr = CRM_Utils_XML::xmlObjToArray($val);
}
$this->assertEquals(['org.civicrm.a', 'org.civicrm.b'], $info->requires);
}
+ public function getExampleAuthors() {
+ $authorAliceXml = '<author><name>Alice</name><email>alice@example.org</email><role>Maintainer</role></author>';
+ $authorAliceArr = ['name' => 'Alice', 'email' => 'alice@example.org', 'role' => 'Maintainer'];
+ $authorBobXml = ' <author><name>Bob</name><homepage>https://example.com/bob</homepage><role>Developer</role></author>';
+ $authorBobArr = ['name' => 'Bob', 'homepage' => 'https://example.com/bob', 'role' => 'Developer'];
+
+ $maintAliceXml = '<maintainer><author>Alice</author><email>alice@example.org</email></maintainer>';
+ $maintAliceArr = ['author' => 'Alice', 'email' => 'alice@example.org'];
+
+ $hdr = "<extension key='test.author' type='module'><file>testauthor</file>";
+ $ftr = "</extension>";
+
+ // Maintainers can be inputted via either <maintainer> or <authors> (with role).
+ // Maintainers are outputted via both `$info->maintainer` and `$info->authors` (with role)
+
+ $cases = [];
+ $cases[] = ["{$hdr}{$maintAliceXml}{$ftr}", [$authorAliceArr], $maintAliceArr];
+ $cases[] = ["{$hdr}<authors>{$authorAliceXml}</authors>{$ftr}", [$authorAliceArr], $maintAliceArr];
+ $cases[] = ["{$hdr}<authors>{$authorAliceXml}{$authorBobXml}</authors>{$ftr}", [$authorAliceArr, $authorBobArr], $maintAliceArr];
+ $cases[] = ["{$hdr}<authors>{$authorBobXml}</authors>{$ftr}", [$authorBobArr], NULL];
+ return $cases;
+ }
+
+ /**
+ * @dataProvider getExampleAuthors
+ */
+ public function testAuthors($xmlString, $expectAuthors, $expectMaintainer) {
+ $info = CRM_Extension_Info::loadFromString($xmlString);
+ $this->assertEquals($expectAuthors, $info->authors);
+ $this->assertEquals($expectMaintainer, $info->maintainer);
+ }
+
public function testBad_string() {
// <file> vs file>
$data = "<extension key='test.foo' type='module'>file>foo</file></extension>";