Skip to content

Commit

Permalink
Import all namespaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-meyer authored Jul 8, 2024
1 parent f5494d7 commit 6d0164d
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions Classes/Common/MetsDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

namespace Kitodo\Dlf\Common;

use \DOMDocument;
use \DOMElement;
use \DOMNode;
use \DOMNodeList;
use \DOMXPath;
use \SimpleXMLElement;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
Expand Down Expand Up @@ -566,12 +569,12 @@ private function processMetadataSections(string $id, int $cPid, array $metadata)
/**
* @param array $allSubentries
* @param string $parentIndex
* @param \DOMNode $parentNode
* @param DOMNode $parentNode
* @return array|false
*/
private function getSubentries($allSubentries, string $parentIndex, \DOMNode $parentNode)
private function getSubentries($allSubentries, string $parentIndex, DOMNode $parentNode)
{
$domXPath = new \DOMXPath($parentNode->ownerDocument);
$domXPath = new DOMXPath($parentNode->ownerDocument);
$this->registerNamespaces($domXPath);
$theseSubentries = [];
foreach ($allSubentries as $subentry) {
Expand Down Expand Up @@ -604,7 +607,7 @@ private function getSubentryValue($values, $subentry)
{
$theseSubentries = [];
if (
($values instanceof \DOMNodeList
($values instanceof DOMNodeList
&& $values->length > 0) || is_string($values)
) {
if (is_string($values)) {
Expand All @@ -617,7 +620,7 @@ private function getSubentryValue($values, $subentry)
}
}
}
} elseif (!($values instanceof \DOMNodeList)) {
} elseif (!($values instanceof DOMNodeList)) {
$theseSubentries[$subentry['index_name']] = [trim((string) $values->nodeValue)];
}
return $theseSubentries;
Expand Down Expand Up @@ -671,7 +674,7 @@ private function extractAndProcessMetadata(string $dmdId, string $mdSectionType,
}

$additionalMetadata = $this->getAdditionalMetadataFromDatabase($cPid, $dmdId);
// We need a \DOMDocument here, because SimpleXML doesn't support XPath functions properly.
// We need a DOMDocument here, because SimpleXML doesn't support XPath functions properly.
$domNode = dom_import_simplexml($this->mdSec[$dmdId]['xml']);
$domXPath = new DOMXPath($domNode->ownerDocument);
$this->registerNamespaces($domXPath);
Expand Down Expand Up @@ -740,7 +743,7 @@ private function setMetadataFieldValues(array $resArray, DOMXPath $domXPath, DOM
{
if ($resArray['format'] > 0 && !empty($resArray['xpath'])) {
$values = $domXPath->evaluate($resArray['xpath'], $domNode);
if ($values instanceof \DOMNodeList && $values->length > 0) {
if ($values instanceof DOMNodeList && $values->length > 0) {
$metadata[$resArray['index_name']] = [];
foreach ($values as $value) {
$subentries = $this->getSubentries($subentryResults, $resArray['index_name'], $value);
Expand All @@ -750,7 +753,7 @@ private function setMetadataFieldValues(array $resArray, DOMXPath $domXPath, DOM
$metadata[$resArray['index_name']][] = trim((string) $value->nodeValue);
}
}
} elseif (!($values instanceof \DOMNodeList)) {
} elseif (!($values instanceof DOMNodeList)) {
$metadata[$resArray['index_name']] = [trim((string) $values)];
}
}
Expand Down Expand Up @@ -793,9 +796,9 @@ private function setSortableMetadataValue(array $resArray, DOMXPath $domXPath, D
if (!empty($metadata[$indexName]) && $resArray['is_sortable']) {
if ($resArray['format'] > 0 && !empty($resArray['xpath_sorting'])) {
$values = $domXPath->evaluate($resArray['xpath_sorting'], $domNode);
if ($values instanceof \DOMNodeList && $values->length > 0) {
if ($values instanceof DOMNodeList && $values->length > 0) {
$metadata[$indexName . '_sorting'][0] = trim((string) $values->item(0)->nodeValue);
} elseif (!($values instanceof \DOMNodeList)) {
} elseif (!($values instanceof DOMNodeList)) {
$metadata[$indexName . '_sorting'][0] = trim((string) $values);
}
}
Expand Down Expand Up @@ -1623,7 +1626,7 @@ public function __sleep(): array
*/
public function __toString(): string
{
$xml = new \DOMDocument('1.0', 'utf-8');
$xml = new DOMDocument('1.0', 'utf-8');
$xml->appendChild($xml->importNode(dom_import_simplexml($this->mets), true));
$xml->formatOutput = true;
return $xml->saveXML();
Expand Down

0 comments on commit 6d0164d

Please sign in to comment.