/** * Registers listeners if enabled. * * @return self */ public function init() { if ($this->options->isEnabled()) { if ($this->options->canFlushEarly()) { $this->eventManager->attachAggregate($this->serviceLocator->get('ZDT_FlushListener')); } if ($this->options->isStrict() && $this->report->hasErrors()) { throw new Exception\InvalidOptionException(implode(' ', $this->report->getErrors())); } $this->eventManager->attachAggregate($this->serviceLocator->get('ZDT_ProfileListener')); $this->registerVerbose()->registerToolbar(); if ($this->options->isStrict() && $this->report->hasErrors()) { throw new Exception\ProfilerException(implode(' ', $this->report->getErrors())); } } return $this; }
/** * MvcEvent::EVENT_FINISH event callback * * @param MvcEvent $event */ public function onFinish(MvcEvent $event) { $strict = $this->options->isStrict(); $collectors = $this->options->getCollectors(); $report = $this->serviceLocator->get('ZendDeveloperTools\\Report'); $profiler = $this->serviceLocator->get('ZendDeveloperTools\\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'); } $zfEntry = new ViewModel(array('zf_version' => Version::VERSION, 'is_latest' => $isLatest, 'latest' => $latest, 'php_version' => phpversion(), 'has_intl' => extension_loaded('intl'), 'doc_uri' => $docUri, 'modules' => $this->getModules($event))); $zfEntry->setTemplate('zend-developer-tools/toolbar/zendframework'); $entries[] = $this->renderer->render($zfEntry); $errors = array(); $collectors = $this->options->getCollectors(); $templates = $this->options->getToolbarEntries(); foreach ($templates as $name => $template) { if (isset($collectors[$name])) { try { $collectorInstance = $report->getCollector($name); if ($this->options->getToolbarAutoHide() && $collectorInstance instanceof AutoHideInterface && $collectorInstance->canHide()) { continue; } $collector = new ViewModel(array('report' => $report, 'collector' => $collectorInstance)); $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('zend-developer-tools/toolbar/error'); $entries[] = $this->renderer->render($errorTpl); } return $entries; }
/** * 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); $zfEntry = new ViewModel(array('zf_version' => Version::VERSION, 'is_latest' => $isLatest, 'latest' => $latest, 'php_version' => phpversion(), 'has_intl' => extension_loaded('intl'))); $zfEntry->setTemplate('zend-developer-tools/toolbar/zendframework'); $entries[] = $this->renderer->render($zfEntry); $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('zend-developer-tools/toolbar/error'); $entries[] = $this->renderer->render($errorTpl); } return $entries; }