diff --git a/src/Mods/Attribute/Common/DateAttribute.php b/src/Mods/Attribute/Common/DateAttribute.php
index a3a090b..8eb03db 100644
--- a/src/Mods/Attribute/Common/DateAttribute.php
+++ b/src/Mods/Attribute/Common/DateAttribute.php
@@ -12,6 +12,8 @@
namespace Slub\Mods\Attribute\Common;
+use Slub\Mods\Exception\IncorrectValueInAttributeException;
+
trait DateAttribute
{
@@ -47,31 +49,50 @@ trait DateAttribute
];
/**
- * Get the value of encoding
+ * Get the value of the 'encoding' attribute.
+ * @see https://www.loc.gov/standards/mods/userguide/attributes.html#encoding
*
* @access public
*
* @return string
+ *
+ * @throws IncorrectValueInAttributeException
*/
public function getEncoding(): string
{
- return $this->getStringAttribute('encoding');
+ $encoding = $this->getStringAttribute('encoding');
+
+ if (empty($encoding) || in_array($encoding, $this->allowedEncodings)) {
+ return $encoding;
+ }
+
+ throw new IncorrectValueInAttributeException('encoding', $encoding);
}
/**
- * Get the value of point
+ * Get the value of the 'point' attribute.
+ * @see https://www.loc.gov/standards/mods/userguide/attributes.html#point
*
* @access public
*
* @return string
+ *
+ * @throws IncorrectValueInAttributeException
*/
public function getPoint(): string
{
- return $this->getStringAttribute('point');
+ $point = $this->getStringAttribute('point');
+
+ if (empty($point) || in_array($point, $this->allowedPoints)) {
+ return $point;
+ }
+
+ throw new IncorrectValueInAttributeException('point', $point);
}
/**
- * Get the value of keyDate
+ * Get the value of the 'keyDate' attribute.
+ * @see https://www.loc.gov/standards/mods/userguide/attributes.html#keyDate
*
* @access public
*
@@ -83,19 +104,29 @@ public function isKeyDate(): bool
}
/**
- * Get the value of qualifier
+ * Get the value of the 'qualifier' attribute.
+ * @see https://www.loc.gov/standards/mods/userguide/attributes.html#qualifier
*
* @access public
*
* @return string
+ *
+ * @throws IncorrectValueInAttributeException
*/
public function getQualifier(): string
{
- return $this->getStringAttribute('qualifier');
+ $qualifier = $this->getStringAttribute('qualifier');
+
+ if (empty($qualifier) || in_array($qualifier, $this->allowedQualifiers)) {
+ return $qualifier;
+ }
+
+ throw new IncorrectValueInAttributeException('qualifier', $qualifier);
}
/**
- * Get the value of calendar
+ * Get the value of the 'calendar' attribute.
+ * @see https://www.loc.gov/standards/mods/userguide/attributes.html#calendar
*
* @access public
*
diff --git a/src/Mods/Attribute/Common/Miscellaneous/UsageAttribute.php b/src/Mods/Attribute/Common/Miscellaneous/UsageAttribute.php
index 5a67daf..51bc020 100644
--- a/src/Mods/Attribute/Common/Miscellaneous/UsageAttribute.php
+++ b/src/Mods/Attribute/Common/Miscellaneous/UsageAttribute.php
@@ -12,6 +12,8 @@
namespace Slub\Mods\Attribute\Common\Miscellaneous;
+use Slub\Mods\Exception\IncorrectValueInAttributeException;
+
/**
* Trait for usage common attribute
*/
@@ -28,14 +30,23 @@ trait UsageAttribute
];
/**
- * Get the value of usage
+ * Get the value of the 'usage' attribute.
+ * @see https://www.loc.gov/standards/mods/userguide/attributes.html#usage
*
* @access public
*
* @return string
+ *
+ * @throws IncorrectValueInAttributeException
*/
public function getUsage(): string
{
- return $this->getStringAttribute('usage');
+ $usage = $this->getStringAttribute('usage');
+
+ if (empty($usage) || in_array($usage, $this->allowedUsages)) {
+ return $usage;
+ }
+
+ throw new IncorrectValueInAttributeException('usage', $usage);
}
}
diff --git a/src/Mods/Attribute/Specific/TypeAttribute.php b/src/Mods/Attribute/Specific/TypeAttribute.php
index 85c097f..1145974 100644
--- a/src/Mods/Attribute/Specific/TypeAttribute.php
+++ b/src/Mods/Attribute/Specific/TypeAttribute.php
@@ -12,6 +12,8 @@
namespace Slub\Mods\Attribute\Specific;
+use Slub\Mods\Exception\IncorrectValueInAttributeException;
+
/**
* Trait for type specific attribute
*/
@@ -28,14 +30,22 @@ trait TypeAttribute
];
/**
- * Get the value of type
+ * Get the value of the 'type' attribute.
*
* @access public
*
* @return string
+ *
+ * @throws IncorrectValueInAttributeException
*/
public function getType(): string
{
- return $this->getStringAttribute('type');
+ $type = $this->getStringAttribute('type');
+
+ if (empty($type) || in_array($type, $this->allowedTypes)) {
+ return $type;
+ }
+
+ throw new IncorrectValueInAttributeException('type', $type);
}
}
diff --git a/src/Mods/Element/RelatedItem.php b/src/Mods/Element/RelatedItem.php
index 027d8ff..37185ff 100644
--- a/src/Mods/Element/RelatedItem.php
+++ b/src/Mods/Element/RelatedItem.php
@@ -17,6 +17,7 @@
use Slub\Mods\Attribute\Common\Miscellaneous\DisplayLabelAttribute;
use Slub\Mods\Attribute\Specific\OtherTypeAttribute;
use Slub\Mods\Element\Common\BaseElement;
+use Slub\Mods\Exception\IncorrectValueInAttributeException;
/**
* RelatedItem MODS metadata element class for the 'php-mods-reader' library.
@@ -62,14 +63,23 @@ public function __construct(\SimpleXMLElement $xml)
}
/**
- * Get the value of type
+ * Get the value of the 'type' attribute.
+ * @see https://www.loc.gov/standards/mods/userguide/relateditem.html#type
*
* @access public
*
* @return string
+ *
+ * @throws IncorrectValueInAttributeException
*/
public function getType(): string
{
- return $this->getStringAttribute('type');
+ $type = $this->getStringAttribute('type');
+
+ if (empty($type) || in_array($type, $this->allowedTypes)) {
+ return $type;
+ }
+
+ throw new IncorrectValueInAttributeException('type', $type);
}
}
diff --git a/src/Mods/Element/Specific/Location/Url.php b/src/Mods/Element/Specific/Location/Url.php
index 4a891f5..b1b8302 100644
--- a/src/Mods/Element/Specific/Location/Url.php
+++ b/src/Mods/Element/Specific/Location/Url.php
@@ -15,6 +15,7 @@
use Slub\Mods\Attribute\Common\Miscellaneous\DisplayLabelAttribute;
use Slub\Mods\Attribute\Common\Miscellaneous\UsageAttribute;
use Slub\Mods\Element\Common\BaseElement;
+use Slub\Mods\Exception\IncorrectValueInAttributeException;
/**
* Url MODS metadata element class for the 'php-mods-reader' library.
@@ -50,7 +51,8 @@ public function __construct(\SimpleXMLElement $xml)
}
/**
- * Get the value of dateLastAccessed
+ * Get the value of the 'dateLastAccessed' attribute.
+ * @see https://www.loc.gov/standards/mods/userguide/location.html#datelastaccessed
*
* @access public
*
@@ -62,7 +64,7 @@ public function getDateLastAccessed(): string
}
/**
- * Get the value of note
+ * Get the value of the 'note' attribute.
*
* @access public
*
@@ -74,14 +76,22 @@ public function getNote(): string
}
/**
- * Get the value of access
+ * Get the value of the 'access' attribute.
*
* @access public
*
* @return string
+ *
+ * @throws IncorrectValueInAttributeException
*/
public function getAccess(): string
{
- return $this->getStringAttribute('access');
+ $access = $this->getStringAttribute('access');
+
+ if (empty($access) || in_array($access, $this->allowedAccess)) {
+ return $access;
+ }
+
+ throw new IncorrectValueInAttributeException('access', $access);
}
}
diff --git a/src/Mods/Element/Specific/Name/AlternativeName.php b/src/Mods/Element/Specific/Name/AlternativeName.php
index 400deb5..b4a9f12 100644
--- a/src/Mods/Element/Specific/Name/AlternativeName.php
+++ b/src/Mods/Element/Specific/Name/AlternativeName.php
@@ -16,6 +16,7 @@
use Slub\Mods\Attribute\Common\Linking\IdAttribute;
use Slub\Mods\Attribute\Common\Linking\XlinkHrefAttribute;
use Slub\Mods\Attribute\Common\Miscellaneous\DisplayLabelAttribute;
+use Slub\Mods\Exception\IncorrectValueInAttributeException;
/**
* AlternativeName MODS metadata element class for the 'php-mods-reader' library.
@@ -60,9 +61,17 @@ public function __construct(\SimpleXMLElement $xml)
* @access public
*
* @return string
+ *
+ * @throws IncorrectValueInAttributeException
*/
public function getAlternativeType(): string
{
- return $this->getStringAttribute('altType');
+ $altType = $this->getStringAttribute('altType');
+
+ if (empty($altType) || in_array($altType, $this->allowedAlternativeTypes)) {
+ return $altType;
+ }
+
+ throw new IncorrectValueInAttributeException('altType', $altType);
}
}
diff --git a/src/Mods/Element/Specific/Name/NamePart.php b/src/Mods/Element/Specific/Name/NamePart.php
index a5edb1a..c477165 100644
--- a/src/Mods/Element/Specific/Name/NamePart.php
+++ b/src/Mods/Element/Specific/Name/NamePart.php
@@ -16,6 +16,7 @@
use Slub\Mods\Attribute\Common\Linking\AltRepGroupAttribute;
use Slub\Mods\Attribute\Common\Miscellaneous\DisplayLabelAttribute;
use Slub\Mods\Element\Common\BaseElement;
+use Slub\Mods\Exception\IncorrectValueInAttributeException;
/**
* NamePart MODS metadata element class for the 'php-mods-reader' library.
@@ -53,15 +54,23 @@ public function __construct(\SimpleXMLElement $xml)
}
/**
- * Get the value of the 'tpe' attribute.
+ * Get the value of the 'type' attribute.
* @see https://www.loc.gov/standards/mods/userguide/name.html#nameParttype
*
* @access public
*
* @return string
+ *
+ * @throws IncorrectValueInAttributeException
*/
public function getType(): string
{
- return $this->getStringAttribute('type');
+ $type = $this->getStringAttribute('type');
+
+ if (empty($type) || in_array($type, $this->allowedTypes)) {
+ return $type;
+ }
+
+ throw new IncorrectValueInAttributeException('type', $type);
}
}
diff --git a/src/Mods/Element/Specific/OriginInfo/Agent.php b/src/Mods/Element/Specific/OriginInfo/Agent.php
index a1e2058..418bb9c 100644
--- a/src/Mods/Element/Specific/OriginInfo/Agent.php
+++ b/src/Mods/Element/Specific/OriginInfo/Agent.php
@@ -27,9 +27,11 @@
use Slub\Mods\Element\Specific\Name\NameIdentifier;
use Slub\Mods\Element\Specific\Name\NamePart;
use Slub\Mods\Element\Specific\Name\Role;
+use Slub\Mods\Exception\IncorrectValueInAttributeException;
/**
* Agent MODS metadata element class for the 'php-mods-reader' library.
+ * @see https://www.loc.gov/standards/mods/userguide/origininfo.html#agent
*
* @access public
*/
@@ -120,15 +122,24 @@ public function __construct(\SimpleXMLElement $xml)
}
/**
- * Get the value of type
+ * Get the value of the 'type' attribute.
+ * @see https://www.loc.gov/standards/mods/userguide/name.html#type
*
* @access public
*
* @return string
+ *
+ * @throws IncorrectValueInAttributeException
*/
public function getType(): string
{
- return $this->getStringAttribute('type');
+ $type = $this->getStringAttribute('type');
+
+ if (empty($type) || in_array($type, $this->allowedTypes)) {
+ return $type;
+ }
+
+ throw new IncorrectValueInAttributeException('type', $type);
}
/**
diff --git a/src/Mods/Element/Specific/TitleInfo/NonSort.php b/src/Mods/Element/Specific/TitleInfo/NonSort.php
index bf6af03..220cb01 100644
--- a/src/Mods/Element/Specific/TitleInfo/NonSort.php
+++ b/src/Mods/Element/Specific/TitleInfo/NonSort.php
@@ -14,6 +14,7 @@
use Slub\Mods\Attribute\Common\LanguageAttribute;
use Slub\Mods\Element\Common\BaseElement;
+use Slub\Mods\Exception\IncorrectValueInAttributeException;
/**
* NonSort MODS metadata element class for the 'php-mods-reader' library.
@@ -49,14 +50,23 @@ public function __construct(\SimpleXMLElement $xml)
}
/**
- * Get the value of xmlSpace
+ * Get the value of the 'xmlSpace' attribute.
+ * @see https://www.loc.gov/standards/mods/userguide/attributes.html#xmlspace
*
* @access public
*
* @return string
+ *
+ * @throws IncorrectValueInAttributeException
*/
public function getXmlSpace(): string
{
- return $this->getStringAttribute('xmlSpace');
+ $xmlSpace = $this->getStringAttribute('xml:space');
+
+ if (empty($xmlSpace) || in_array($xmlSpace, $this->allowedXmlSpaces)) {
+ return $xmlSpace;
+ }
+
+ throw new IncorrectValueInAttributeException('xml:space', $xmlSpace);
}
}
diff --git a/src/Mods/Element/TitleInfo.php b/src/Mods/Element/TitleInfo.php
index d5d57fe..696cb5f 100644
--- a/src/Mods/Element/TitleInfo.php
+++ b/src/Mods/Element/TitleInfo.php
@@ -28,6 +28,7 @@
use Slub\Mods\Element\Common\LanguageElement;
use Slub\Mods\Element\Specific\TitleInfo\NonSort;
use Slub\Mods\Element\Xml\Element;
+use Slub\Mods\Exception\IncorrectValueInAttributeException;
/**
* TitleInfo MODS metadata element class for the 'php-mods-reader' library.
@@ -71,10 +72,18 @@ public function __construct(\SimpleXMLElement $xml)
* @access public
*
* @return string
+ *
+ * @throws IncorrectValueInAttributeException
*/
public function getType(): string
{
- return $this->getStringAttribute('type');
+ $type = $this->getStringAttribute('type');
+
+ if (empty($type) || in_array($type, $this->allowedTypes)) {
+ return $type;
+ }
+
+ throw new IncorrectValueInAttributeException('type', $type);
}
/**
diff --git a/src/Mods/Exception/IncorrectValueInAttributeException.php b/src/Mods/Exception/IncorrectValueInAttributeException.php
new file mode 100644
index 0000000..f25a66b
--- /dev/null
+++ b/src/Mods/Exception/IncorrectValueInAttributeException.php
@@ -0,0 +1,34 @@
+getValue());
self::assertEquals('preview', $urls[1]->getAccess());
self::assertEquals('http://www.slub-dresden.de/some-url/SLO-0000', $urls[1]->getValue());
+
+ $this->expectException(IncorrectValueInAttributeException::class);
+ $urls[3]->getAccess();
}
public function testGetNoLocationsByQueryForBookDocument()
@@ -512,18 +516,18 @@ public function testGetLocationsForSerialDocument()
self::assertEquals(2, count($locations));
self::assertNotEmpty($locations[0]->getUrls());
self::assertEquals('electronic resource', $locations[0]->getUrls()[0]->getDisplayLabel());
- self::assertEquals('primary display', $locations[0]->getUrls()[0]->getUsage());
+ self::assertEquals('primaryDisplay', $locations[0]->getUrls()[0]->getUsage());
self::assertEquals('http://bibpurl.oclc.org/web/7085', $locations[0]->getUrls()[0]->getValue());
}
public function testGetLocationsByQueryForSerialDocument()
{
- $locations = $this->serialReader->getLocations('[./mods:url[@usage="primary display"]]');
+ $locations = $this->serialReader->getLocations('[./mods:url[@usage="primaryDisplay"]]');
self::assertNotEmpty($locations);
self::assertEquals(1, count($locations));
self::assertNotEmpty($locations[0]->getUrls());
self::assertEquals('electronic resource', $locations[0]->getUrls()[0]->getDisplayLabel());
- self::assertEquals('primary display', $locations[0]->getUrls()[0]->getUsage());
+ self::assertEquals('primaryDisplay', $locations[0]->getUrls()[0]->getUsage());
self::assertEquals('http://bibpurl.oclc.org/web/7085', $locations[0]->getUrls()[0]->getValue());
}
@@ -968,7 +972,10 @@ public function testGetRecordInfosForSerialDocument()
self::assertEquals('marcorg', $recordInfos[0]->getRecordContentSources()[0]->getAuthority());
self::assertEquals('NLC', $recordInfos[0]->getRecordContentSources()[0]->getValue());
self::assertNotEmpty($recordInfos[0]->getRecordCreationDates());
- self::assertEquals('marc', $recordInfos[0]->getRecordCreationDates()[0]->getEncoding());
+
+ $this->expectException(IncorrectValueInAttributeException::class);
+ $recordInfos[0]->getRecordCreationDates()[0]->getEncoding();
+
self::assertEquals('021127', $recordInfos[0]->getRecordCreationDates()[0]->getValue());
self::assertNotEmpty($recordInfos[0]->getRecordChangeDates());
self::assertEquals('iso8601', $recordInfos[0]->getRecordChangeDates()[0]->getEncoding());
@@ -979,6 +986,7 @@ public function testGetRecordInfosForSerialDocument()
self::assertNotEmpty($recordInfos[0]->getRecordInfoNotes());
self::assertEquals(2, count($recordInfos[0]->getRecordInfoNotes()));
self::assertEquals('Some info', $recordInfos[0]->getRecordInfoNotes()[1]->getValue());
+
$languages = $recordInfos[0]->getLanguageOfCatalogings();
self::assertNotEmpty($languages);
self::assertNotNull($languages[0]->getLanguageTerm());
@@ -1003,7 +1011,10 @@ public function testGetRecordInfosByQueryForSerialDocument()
self::assertEquals('marcorg', $recordInfos[0]->getRecordContentSources()[0]->getAuthority());
self::assertEquals('NLC', $recordInfos[0]->getRecordContentSources()[0]->getValue());
self::assertNotEmpty($recordInfos[0]->getRecordCreationDates());
- self::assertEquals('marc', $recordInfos[0]->getRecordCreationDates()[0]->getEncoding());
+
+ $this->expectException(IncorrectValueInAttributeException::class);
+ $recordInfos[0]->getRecordCreationDates()[0]->getEncoding();
+
self::assertEquals('021127', $recordInfos[0]->getRecordCreationDates()[0]->getValue());
self::assertNotEmpty($recordInfos[0]->getRecordChangeDates());
self::assertEquals('iso8601', $recordInfos[0]->getRecordChangeDates()[0]->getEncoding());
@@ -1014,6 +1025,7 @@ public function testGetRecordInfosByQueryForSerialDocument()
self::assertNotEmpty($recordInfos[0]->getRecordInfoNotes());
self::assertEquals(2, count($recordInfos[0]->getRecordInfoNotes()));
self::assertEquals('Some info', $recordInfos[0]->getRecordInfoNotes()[1]->getValue());
+
$languages = $recordInfos[0]->getLanguageOfCatalogings();
self::assertNotEmpty($languages);
self::assertNotNull($languages[0]->getLanguageTerm());
diff --git a/tests/resources/mods_book.xml b/tests/resources/mods_book.xml
index 662fb22..4a7b90e 100644
--- a/tests/resources/mods_book.xml
+++ b/tests/resources/mods_book.xml
@@ -137,7 +137,7 @@
http://www.slub-dresden.de/some-url
http://www.slub-dresden.de/some-url/SLO-0000
http://www.slub-dresden.de/some-url/SLO-0000
- http://www.slub-dresden.de/some-url/SLO-0000
+ http://www.slub-dresden.de/some-url/SLO-0000
Use of this public-domain resource is unrestricted.
diff --git a/tests/resources/mods_serial.xml b/tests/resources/mods_serial.xml
index b353e1b..937c19a 100644
--- a/tests/resources/mods_serial.xml
+++ b/tests/resources/mods_serial.xml
@@ -84,7 +84,7 @@
027.7/05
- http://bibpurl.oclc.org/web/7085
+ http://bibpurl.oclc.org/web/7085
http://collection.nlc-bnc.ca/100/201/300/ejasl/index.html
@@ -109,7 +109,7 @@
aacr
NLC
- 021127
+ 021127
20080910160139.0
15446420
Converted from MARCXML to MODS version 3.8 using MARC21slim2MODS3-8_XSLT1-0.xsl (Revision 1.172 20230208)