Skip to content

Commit

Permalink
Get values of different types in one time.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Berthereau authored and Daniel Berthereau committed Sep 14, 2020
1 parent ea99176 commit 2f73f48
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 2f73f48

Please sign in to comment.