/**
* This method walks through the view configuration and applies
* matching configurations in the order of their specifity score.
* Possible options are currently the viewObjectName to specify
* a different class that will be used to create the view and
* an array of options that will be set on the view object.
*
* @param ActionRequest $request
* @return array
*/
public function getViewConfiguration(ActionRequest $request)
{
$cacheIdentifier = $this->createCacheIdentifier($request);
$viewConfiguration = $this->cache->get($cacheIdentifier);
if ($viewConfiguration === false) {
$configurations = $this->configurationManager->getConfiguration('Views');
$requestMatcher = new RequestMatcher($request);
$context = new Context($requestMatcher);
$viewConfiguration = [];
$highestWeight = -1;
foreach ($configurations as $order => $configuration) {
$requestMatcher->resetWeight();
if (!isset($configuration['requestFilter'])) {
$weight = $order;
} else {
$result = $this->eelEvaluator->evaluate($configuration['requestFilter'], $context);
if ($result === false) {
continue;
}
$weight = $requestMatcher->getWeight() + $order;
}
if ($weight > $highestWeight) {
$viewConfiguration = $configuration;
$highestWeight = $weight;
}
}
$this->cache->set($cacheIdentifier, $viewConfiguration);
}
return $viewConfiguration;
}