Skip to content

Commit

Permalink
Merge pull request #1632 from Daniel-KM/feature/value_types
Browse files Browse the repository at this point in the history
Get values of different types in one time.
  • Loading branch information
zerocrates authored Sep 15, 2020
2 parents 8bb1b54 + 2f73f48 commit 42727a5
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,9 @@ public function values()
*
* @param string $term The prefix:local_part
* @param array $options
* - type: (null) Get values of this type only. Valid types are "literal",
* "uri", and "resource". Returns all types by default.
* - type (array|string): Get values of these types only. Default types are
* "literal", "uri", "resource", "resource:item", "resource:media" and
* "resource:itemset". Returns all types by default.
* - all: (false) If true, returns all values that match criteria. If false,
* returns the first matching value.
* - default: (null) Default value if no values match criteria. Returns null
Expand All @@ -322,9 +323,6 @@ public function values()
public function value($term, array $options = [])
{
// Set defaults.
if (!isset($options['type'])) {
$options['type'] = null;
}
if (!isset($options['all'])) {
$options['all'] = false;
}
Expand All @@ -343,12 +341,18 @@ public function value($term, array $options = [])
return $options['default'];
}

if (empty($options['type'])) {
$types = false;
} elseif (is_array($options['type'])) {
$types = $options['type'];
} else {
$types = [$options['type']];
}

// Match only the representations that fit all the criteria.
$matchingValues = [];
foreach ($this->values()[$term]['values'] as $value) {
if (!is_null($options['type'])
&& $value->type() !== $options['type']
) {
if ($types && !in_array($value->type(), $types)) {
continue;
}
if (!is_null($options['lang'])
Expand Down

0 comments on commit 42727a5

Please sign in to comment.