| @@ 219-239 (lines=21) @@ | ||
| 216 | * @return ViewInterface Resolved View object. |
|
| 217 | * @throws FailedToInstantiateViewException If the view type could not be resolved. |
|
| 218 | */ |
|
| 219 | protected function resolveType($type, $uri, EngineInterface $engine = null) |
|
| 220 | { |
|
| 221 | if (is_string($type) && $this->config->hasKey(ViewBuilder::VIEW_FINDER_KEY)) { |
|
| 222 | $type = new $type($uri, $engine); |
|
| 223 | } |
|
| 224 | ||
| 225 | if (is_callable($type)) { |
|
| 226 | $type = $type($uri, $engine); |
|
| 227 | } |
|
| 228 | ||
| 229 | if (! $type instanceof ViewInterface) { |
|
| 230 | throw new FailedToInstantiateViewException( |
|
| 231 | sprintf( |
|
| 232 | _('Could not instantiate view "%s".'), |
|
| 233 | serialize($type) |
|
| 234 | ) |
|
| 235 | ); |
|
| 236 | } |
|
| 237 | ||
| 238 | return $type; |
|
| 239 | } |
|
| 240 | } |
|
| 241 | ||
| @@ 87-107 (lines=21) @@ | ||
| 84 | * @return ViewInterface Instantiated view. |
|
| 85 | * @throws FailedToInstantiateViewException If the view could not be instantiated. |
|
| 86 | */ |
|
| 87 | protected function initializeView($view, $uri, EngineInterface $engine = null) |
|
| 88 | { |
|
| 89 | if (is_string($view)) { |
|
| 90 | $view = new $view($uri, $engine); |
|
| 91 | } |
|
| 92 | ||
| 93 | if (is_callable($view)) { |
|
| 94 | $view = $view($uri, $engine); |
|
| 95 | } |
|
| 96 | ||
| 97 | if (! $view instanceof ViewInterface) { |
|
| 98 | throw new FailedToInstantiateViewException( |
|
| 99 | sprintf( |
|
| 100 | _('Could not instantiate view "%s".'), |
|
| 101 | serialize($view) |
|
| 102 | ) |
|
| 103 | ); |
|
| 104 | } |
|
| 105 | ||
| 106 | return $view; |
|
| 107 | } |
|
| 108 | ||
| 109 | /** |
|
| 110 | * Get the config key for the Findables definitions. |
|