|
@@ 987-995 (lines=9) @@
|
| 984 |
|
* Only one resolver shall be registered per type. Otherwise a |
| 985 |
|
* \OutOfBoundsException has to thrown. |
| 986 |
|
*/ |
| 987 |
|
public function registerDisplayNameResolver($type, \Closure $closure) { |
| 988 |
|
if (!is_string($type)) { |
| 989 |
|
throw new \InvalidArgumentException('String expected.'); |
| 990 |
|
} |
| 991 |
|
if (isset($this->displayNameResolvers[$type])) { |
| 992 |
|
throw new \OutOfBoundsException('Displayname resolver for this type already registered'); |
| 993 |
|
} |
| 994 |
|
$this->displayNameResolvers[$type] = $closure; |
| 995 |
|
} |
| 996 |
|
|
| 997 |
|
/** |
| 998 |
|
* resolves a given ID of a given Type to a display name. |
|
@@ 1010-1018 (lines=9) @@
|
| 1007 |
|
* be thrown. It is upon the resolver discretion what to return of the |
| 1008 |
|
* provided ID is unknown. It must be ensured that a string is returned. |
| 1009 |
|
*/ |
| 1010 |
|
public function resolveDisplayName($type, $id) { |
| 1011 |
|
if (!is_string($type)) { |
| 1012 |
|
throw new \InvalidArgumentException('String expected.'); |
| 1013 |
|
} |
| 1014 |
|
if (!isset($this->displayNameResolvers[$type])) { |
| 1015 |
|
throw new \OutOfBoundsException('No Displayname resolver for this type registered'); |
| 1016 |
|
} |
| 1017 |
|
return (string)$this->displayNameResolvers[$type]($id); |
| 1018 |
|
} |
| 1019 |
|
|
| 1020 |
|
/** |
| 1021 |
|
* returns valid, registered entities |