|
@@ 819-827 (lines=9) @@
|
| 816 |
|
* Only one resolver shall be registered per type. Otherwise a |
| 817 |
|
* \OutOfBoundsException has to thrown. |
| 818 |
|
*/ |
| 819 |
|
public function registerDisplayNameResolver($type, \Closure $closure) { |
| 820 |
|
if (!is_string($type)) { |
| 821 |
|
throw new \InvalidArgumentException('String expected.'); |
| 822 |
|
} |
| 823 |
|
if (isset($this->displayNameResolvers[$type])) { |
| 824 |
|
throw new \OutOfBoundsException('Displayname resolver for this type already registered'); |
| 825 |
|
} |
| 826 |
|
$this->displayNameResolvers[$type] = $closure; |
| 827 |
|
} |
| 828 |
|
|
| 829 |
|
/** |
| 830 |
|
* resolves a given ID of a given Type to a display name. |
|
@@ 842-850 (lines=9) @@
|
| 839 |
|
* be thrown. It is upon the resolver discretion what to return of the |
| 840 |
|
* provided ID is unknown. It must be ensured that a string is returned. |
| 841 |
|
*/ |
| 842 |
|
public function resolveDisplayName($type, $id) { |
| 843 |
|
if (!is_string($type)) { |
| 844 |
|
throw new \InvalidArgumentException('String expected.'); |
| 845 |
|
} |
| 846 |
|
if (!isset($this->displayNameResolvers[$type])) { |
| 847 |
|
throw new \OutOfBoundsException('No Displayname resolver for this type registered'); |
| 848 |
|
} |
| 849 |
|
return (string)$this->displayNameResolvers[$type]($id); |
| 850 |
|
} |
| 851 |
|
|
| 852 |
|
/** |
| 853 |
|
* returns valid, registered entities |