public function getRendered($options, \Twig_Environment $twig)
{
$options['noCache'] = isset($options['noCache']) ? (bool) $options['noCache'] : false;
$options['pathInfoCache'] = isset($options['pathInfoCache']) ? (bool) $options['pathInfoCache'] : false;
$view = $options['template'] ?: $options['view'];
$cacheKey = 'core/navigation/' . $this->pageStack->getCurrentPage()->getDomainId() . '.' . $this->pageStack->getCurrentPage()->getId() . ($options['pathInfoCache'] ? '_' . md5($this->pageStack->getRequest()->getPathInfo()) : '') . '_' . md5(json_encode($options));
$fromCache = false;
$viewPath = $this->jarves->resolvePath($view, 'Resources/views/');
if ('@' === $view[0]) {
$view = substr($view, 1);
}
if (!file_exists($viewPath)) {
throw new \Exception(sprintf('View `%s` not found.', $view));
} else {
$mtime = filemtime($viewPath);
}
if (!$options['noCache']) {
$cache = $this->cacher->getDistributedCache($cacheKey);
if ($cache && isset($cache['html']) && $cache['html'] !== null && $cache['mtime'] == $mtime) {
return $cache['html'];
}
}
$cache = $this->cacher->getDistributedCache($cacheKey);
if ($cache && isset($cache['object']) && $cache['mtime'] == $mtime) {
$navigation = unserialize($cache['object']);
$fromCache = true;
} else {
$navigation = $this->get($options);
}
$data['navigation'] = $navigation ?: false;
if ($navigation !== false) {
$html = $twig->render($view, $data);
if (!$options['noCache']) {
$this->cacher->setDistributedCache($cacheKey, array('mtime' => $mtime, 'html' => $html));
} elseif (!$fromCache) {
$this->cacher->setDistributedCache($cacheKey, array('mtime' => $mtime, 'object' => serialize($navigation)));
}
return $html;
}
//no navigation found, probably the template just uses the breadcrumb
return $twig->render($view, $data);
}