-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functions to get the elements by index of value
Move readers to traits to increase code readability
- Loading branch information
1 parent
1996268
commit e3ff7f2
Showing
21 changed files
with
1,861 additions
and
1,131 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright (C) 2024 Saxon State and University Library Dresden | ||
* | ||
* This file is part of the php-mods-reader. | ||
* | ||
* @license GNU General Public License version 3 or later. | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Slub\Mods\Reader; | ||
|
||
use Slub\Mods\Element\AbstractElement; | ||
use Slub\Mods\Element\Xml\Element; | ||
|
||
/** | ||
* Trait for reading Abstract element | ||
*/ | ||
trait AbstractReader | ||
{ | ||
|
||
/** | ||
* Get the value of the <abstract> element. | ||
* @see https://www.loc.gov/standards/mods/userguide/abstract.html | ||
* | ||
* @access public | ||
* | ||
* @param string $query for metadata search | ||
* | ||
* @return ?AbstractElement | ||
*/ | ||
public function getAbstract(string $query = ''): ?AbstractElement | ||
{ | ||
$xpath = './mods:abstract' . $query; | ||
$element = new Element($this->xml, $xpath); | ||
if ($element->exists()) { | ||
return new AbstractElement($element->getFirstValue()); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright (C) 2024 Saxon State and University Library Dresden | ||
* | ||
* This file is part of the php-mods-reader. | ||
* | ||
* @license GNU General Public License version 3 or later. | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Slub\Mods\Reader; | ||
|
||
use Slub\Mods\Element\AccessCondition; | ||
|
||
/** | ||
* Trait for reading AccessCondition element | ||
*/ | ||
trait AccessConditionReader | ||
{ | ||
|
||
/** | ||
* Get the the array of the <accessCondition> elements. | ||
* @see https://www.loc.gov/standards/mods/userguide/accesscondition.html | ||
* | ||
* @access public | ||
* | ||
* @param string $query for metadata search | ||
* | ||
* @return AccessCondition[] | ||
*/ | ||
public function getAccessConditions(string $query = ''): array | ||
{ | ||
$accessConditions = []; | ||
$values = $this->getValues('./mods:accessCondition' . $query); | ||
foreach ($values as $value) { | ||
$accessConditions[] = new AccessCondition($value); | ||
} | ||
return $accessConditions; | ||
} | ||
|
||
/** | ||
* Get the matching <accessCondition> element. | ||
* @see https://www.loc.gov/standards/mods/userguide/accesscondition.html | ||
* | ||
* @access public | ||
* | ||
* @param int $index of the searched element | ||
* @param string $query for metadata search | ||
* | ||
* @return ?AccessCondition | ||
*/ | ||
public function getAccessCondition(int $index, string $query = ''): ?AccessCondition | ||
{ | ||
$values = $this->getValues('./mods:accessCondition' . $query); | ||
if (array_key_exists($index, $values)) { | ||
return new AccessCondition($values[$index]); | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Get the the first matching <accessCondition> element. | ||
* @see https://www.loc.gov/standards/mods/userguide/accesscondition.html | ||
* | ||
* @access public | ||
* | ||
* @param string $query for metadata search | ||
* | ||
* @return ?AccessCondition | ||
*/ | ||
public function getFirstAccessCondition(string $query = ''): ?AccessCondition | ||
{ | ||
return $this->getAccessCondition(0, $query); | ||
} | ||
|
||
/** | ||
* Get the the last matching <accessCondition> element. | ||
* @see https://www.loc.gov/standards/mods/userguide/accesscondition.html | ||
* | ||
* @access public | ||
* | ||
* @param string $query for metadata search | ||
* | ||
* @return ?AccessCondition | ||
*/ | ||
public function getLastAccessCondition(string $query = ''): ?AccessCondition | ||
{ | ||
$elements = $this->getAccessConditions($query); | ||
$count = count($elements); | ||
if ($count > 0) { | ||
return $elements[$count - 1]; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright (C) 2024 Saxon State and University Library Dresden | ||
* | ||
* This file is part of the php-mods-reader. | ||
* | ||
* @license GNU General Public License version 3 or later. | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Slub\Mods\Reader; | ||
|
||
use Slub\Mods\Element\Classification; | ||
|
||
/** | ||
* Trait for reading Classification element | ||
*/ | ||
trait ClassificationReader | ||
{ | ||
/** | ||
* Get the the array of the <classification> elements. | ||
* @see https://www.loc.gov/standards/mods/userguide/classification.html | ||
* | ||
* @access public | ||
* | ||
* @param string $query for metadata search | ||
* | ||
* @return Classification[] | ||
*/ | ||
public function getClassifications(string $query = ''): array | ||
{ | ||
$classifications = []; | ||
$values = $this->getValues('./mods:classification' . $query); | ||
foreach ($values as $value) { | ||
$classifications[] = new Classification($value); | ||
} | ||
return $classifications; | ||
} | ||
|
||
/** | ||
* Get the matching <classification> element. | ||
* @see https://www.loc.gov/standards/mods/userguide/classification.html | ||
* | ||
* @access public | ||
* | ||
* @param int $index of the searched element | ||
* @param string $query for metadata search | ||
* | ||
* @return ?Classification | ||
*/ | ||
public function getClassification(int $index, string $query = ''): ?Classification | ||
{ | ||
$values = $this->getValues('./mods:classification' . $query); | ||
if (array_key_exists($index, $values)) { | ||
return new Classification($values[$index]); | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Get the the first matching <classification> element. | ||
* @see https://www.loc.gov/standards/mods/userguide/classification.html | ||
* | ||
* @access public | ||
* | ||
* @param string $query for metadata search | ||
* | ||
* @return ?Classification | ||
*/ | ||
public function getFirstClassification(string $query = ''): ?Classification | ||
{ | ||
return $this->getClassification(0, $query); | ||
} | ||
|
||
/** | ||
* Get the the last matching <classification> element. | ||
* @see https://www.loc.gov/standards/mods/userguide/classification.html | ||
* | ||
* @access public | ||
* | ||
* @param string $query for metadata search | ||
* | ||
* @return ?Classification | ||
*/ | ||
public function getLastClassification(string $query = ''): ?Classification | ||
{ | ||
$elements = $this->getClassifications($query); | ||
$count = count($elements); | ||
if ($count > 0) { | ||
return $elements[$count - 1]; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright (C) 2024 Saxon State and University Library Dresden | ||
* | ||
* This file is part of the php-mods-reader. | ||
* | ||
* @license GNU General Public License version 3 or later. | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Slub\Mods\Reader; | ||
|
||
use Slub\Mods\Element\Extension; | ||
use Slub\Mods\Element\Xml\Element; | ||
|
||
/** | ||
* Trait for reading Extension element | ||
*/ | ||
trait ExtensionReader | ||
{ | ||
|
||
/** | ||
* Get the the array of the <extension> elements. | ||
* @see https://www.loc.gov/standards/mods/userguide/extension.html | ||
* | ||
* @access public | ||
* | ||
* @param string $query for metadata search | ||
* | ||
* @return Extension[] | ||
*/ | ||
public function getExtensions(string $query = ''): array | ||
{ | ||
$extensions = []; | ||
$values = $this->getValues('./mods:extension' . $query); | ||
foreach ($values as $value) { | ||
$extensions[] = new Extension($value); | ||
} | ||
return $extensions; | ||
} | ||
|
||
/** | ||
* Get the matching <extension> element. | ||
* @see https://www.loc.gov/standards/mods/userguide/extension.html | ||
* | ||
* @access public | ||
* | ||
* @param int $index of the searched element | ||
* @param string $query for metadata search | ||
* | ||
* @return ?Extension | ||
*/ | ||
public function getExtension(int $index, string $query = ''): ?Extension | ||
{ | ||
$values = $this->getValues('./mods:extension' . $query); | ||
if (array_key_exists($index, $values)) { | ||
return new Extension($values[$index]); | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Get the the first matching <extension> element. | ||
* @see https://www.loc.gov/standards/mods/userguide/extension.html | ||
* | ||
* @access public | ||
* | ||
* @param string $query for metadata search | ||
* | ||
* @return ?Extension | ||
*/ | ||
public function getFirstExtension(string $query = ''): ?Extension | ||
{ | ||
return $this->getExtension(0, $query); | ||
} | ||
|
||
/** | ||
* Get the the last matching <extension> element. | ||
* @see https://www.loc.gov/standards/mods/userguide/extension.html | ||
* | ||
* @access public | ||
* | ||
* @param string $query for metadata search | ||
* | ||
* @return ?Extension | ||
*/ | ||
public function getLastExtension(string $query = ''): ?Extension | ||
{ | ||
$elements = $this->getExtensions($query); | ||
$count = count($elements); | ||
if ($count > 0) { | ||
return $elements[$count - 1]; | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.