/**
  * MvcEvent::EVENT_FINISH event callback
  *
  * @param  MvcEvent $event
  * @throws ServiceNotFoundException
  */
 public function onFinish(MvcEvent $event)
 {
     $strict = $this->options->isStrict();
     $collectors = $this->options->getCollectors();
     $report = $this->serviceLocator->get('JcNavigation\\Report');
     $profiler = $this->serviceLocator->get('JcNavigation\\Profiler');
     $profiler->setErrorMode($strict);
     foreach ($collectors as $name => $collector) {
         if ($this->serviceLocator->has($collector)) {
             $profiler->addCollector($this->serviceLocator->get($collector));
         } else {
             $error = sprintf('Unable to fetch or create an instance for %s.', $collector);
             if ($strict === true) {
                 throw new ServiceNotFoundException($error);
             } else {
                 $report->addError($error);
             }
         }
     }
     $profiler->collect($event);
 }
 /**
  * Renders all toolbar entries.
  *
  * @param  ProfilerEvent $event
  * @return array
  * @throws InvalidOptionException
  */
 protected function renderEntries(ProfilerEvent $event)
 {
     $entries = array();
     $report = $event->getReport();
     list($isLatest, $latest) = $this->getLatestVersion(Version::VERSION);
     if (false === ($pos = strpos(Version::VERSION, 'dev'))) {
         $docUri = sprintf(self::DOC_URI_PATTERN, substr(Version::VERSION, 0, 3));
     } else {
         // unreleased dev branch - compare minor part of versions
         $partsCurrent = explode('.', substr(Version::VERSION, 0, $pos));
         $partsLatestRelease = explode('.', $latest);
         $docUri = sprintf(self::DEV_DOC_URI_PATTERN, current($partsLatestRelease) == $partsCurrent[1] ? 'latest' : 'develop');
     }
     $errors = array();
     $collectors = $this->options->getCollectors();
     $templates = $this->options->getToolbarEntries();
     foreach ($templates as $name => $template) {
         if (isset($collectors[$name])) {
             try {
                 $collector = new ViewModel(array('report' => $report, 'collector' => $report->getCollector($name)));
                 $collector->setTemplate($template);
                 $entries[] = $this->renderer->render($collector);
             } catch (RuntimeException $e) {
                 $errors[$name] = $template;
             }
         }
     }
     if (!empty($errors) || $report->hasErrors()) {
         $tmp = array();
         foreach ($errors as $name => $template) {
             $cur = sprintf('Unable to render toolbar template %s (%s).', $name, $template);
             $tmp[] = $cur;
             $report->addError($cur);
         }
         if ($this->options->isStrict()) {
             throw new InvalidOptionException(implode(' ', $tmp));
         }
     }
     if ($report->hasErrors()) {
         $errorTpl = new ViewModel(array('errors' => $report->getErrors()));
         $errorTpl->setTemplate('jc-navigation/toolbar/error');
         $entries[] = $this->renderer->render($errorTpl);
     }
     return $entries;
 }