Пример #1
0
 public function testStatusOfDefaultConfiguration()
 {
     $dist = (require __DIR__ . "/../config/zenddevelopertools.local.php.dist");
     $reportMock = $this->getMock("ZendDeveloperTools\\ReportInterface");
     $options = new Options($dist['zenddevelopertools'], $reportMock);
     $this->assertTrue($options->isEnabled());
     $this->assertTrue($options->isToolbarEnabled());
 }
Пример #2
0
 /**
  * Wrapper for Zend\Version::getLatest with caching functionality, so that
  * ZendDeveloperTools won't act as a "DDoS bot-network".
  *
  * @param  string $currentVersion
  * @return array
  */
 protected function getLatestVersion($currentVersion)
 {
     if (!$this->options->isVersionCheckEnabled()) {
         return array(true, '');
     }
     $cacheDir = $this->options->getCacheDir();
     // exit early if the cache dir doesn't exist,
     // to prevent hitting the GitHub API for every request.
     if (!is_dir($cacheDir)) {
         return array(true, '');
     }
     if (file_exists($cacheDir . '/ZDT_ZF_Version.cache')) {
         $cache = file_get_contents($cacheDir . '/ZDT_ZF_Version.cache');
         $cache = explode('|', $cache);
         if ($cache[0] + self::VERSION_CACHE_TTL > time()) {
             // the cache file was written before the version was upgraded.
             if ($currentVersion === $cache[2] || $cache[2] === 'N/A') {
                 return array(true, '');
             }
             return array($cache[1] === 'yes' ? true : false, $cache[2]);
         }
     }
     $isLatest = Version::isLatest();
     $latest = Version::getLatest();
     file_put_contents($cacheDir . '/ZDT_ZF_Version.cache', sprintf('%d|%s|%s', time(), $isLatest ? 'yes' : 'no', $latest === null ? 'N/A' : $latest));
     return array($isLatest, $latest);
 }
Пример #3
0
 /**
  * Registers toolbar listeners if enabled.
  *
  * @return self
  */
 protected function registerToolbar()
 {
     if ($this->options->isToolbarEnabled()) {
         $this->sharedEventManager->attach('profiler', $this->serviceLocator->get('ZDT_ToolbarListener'), null);
     }
     return $this;
 }
Пример #4
0
 /**
  * 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);
 }