Example #1
0
 /**
  * Sets Toolbar options.
  *
  * @param array $options
  */
 public function setToolbar(array $options)
 {
     if (isset($options['enabled'])) {
         $this->toolbar['enabled'] = (bool) $options['enabled'];
     }
     if (isset($options['version_check'])) {
         $this->toolbar['version_check'] = (bool) $options['version_check'];
     }
     if (isset($options['position'])) {
         if ($options['position'] !== 'bottom' && $options['position'] !== 'top') {
             $this->report->addError(sprintf('[\'zenddevelopertools\'][\'toolbar\'][\'position\'] must be "top" or "bottom", %s given.', $options['position']));
         } else {
             $this->toolbar['position'] = $options['position'];
         }
     }
     if (isset($options['entries'])) {
         if (is_array($options['entries'])) {
             foreach ($options['entries'] as $collector => $template) {
                 if ($template === false || $template === null) {
                     unset($this->toolbar['entries'][$collector]);
                 } else {
                     $this->toolbar['entries'][$collector] = $template;
                 }
             }
         } else {
             $this->report->addError(sprintf('[\'zenddevelopertools\'][\'toolbar\'][\'entries\'] must be an array, %s given.', gettype($options['entries'])));
         }
     }
 }
Example #2
0
 /**
  * Runs all collectors.
  *
  * @triggers ProfilerEvent::EVENT_COLLECTED
  * @param    MvcEvent $mvcEvent
  * @return   Profiler
  * @throws   Exception\ProfilerException
  */
 public function collect(MvcEvent $mvcEvent)
 {
     $this->report->setToken(uniqid('zdt'))->setUri($mvcEvent->getRequest()->getUriString())->setMethod($mvcEvent->getRequest()->getMethod())->setTime(new \DateTime('now', new \DateTimeZone('UTC')))->setIp($mvcEvent->getRequest()->getServer()->get('REMOTE_ADDR'));
     if (isset($this->collectors)) {
         foreach ($this->collectors as $collector) {
             $collector->collect($mvcEvent);
             $this->report->addCollector(unserialize(serialize($collector)));
         }
         $this->eventManager->trigger(ProfilerEvent::EVENT_COLLECTED, $this->getEvent());
         return $this;
     }
     if ($this->strict === true) {
         throw new Exception\ProfilerException('There is nothing to collect.');
     }
     $this->report->addError('There is nothing to collect.');
     return $this;
 }
Example #3
0
 /**
  * Sets Profiler matcher options.
  *
  * @param array $options
  */
 protected function setMatcher($options)
 {
     if (!is_array($options)) {
         $report->addError(sprintf('[\'zdt\'][\'profiler\'][\'matcher\'] must be an array, %s given.', gettype($options)));
         return;
     }
     if (isset($options['enabled'])) {
         $this->profiler['matcher']['enabled'] = (bool) $options['enabled'];
     }
     if (isset($options['rules']) && is_array($options['rules'])) {
         $arrayPath = '[\'zdt\'][\'profiler\'][\'matcher\']';
         $added = array();
         foreach ($options['rules'] as $name => $rule) {
             if (is_array($rule)) {
                 $added[] = $name;
                 $this->profiler['matcher']['rules'][$name] = array();
                 if (isset($rule['action'])) {
                     if ($rule['action'] !== 'enable' && $rule['action'] !== 'disable') {
                         $report->addError(sprintf('%s[\'rules\'][\'%s\'][\'action\'] must be "enable" or "disable", %s given.', $arrayPath, $name, $rule['action']));
                     } else {
                         $this->profiler['matcher']['rules'][$name]['action'] = $rule['action'];
                     }
                 } else {
                     $this->profiler['matcher']['rules'][$name]['action'] = 'enable';
                 }
                 if (isset($rule['match'])) {
                     if (!is_array($rule['match'])) {
                         $report->addError(sprintf('%s[\'rules\'][\'%s\'][\'match\'] must be an array, %s given.', $arrayPath, gettype($rule['match'])));
                     } else {
                         $this->profiler['matcher']['rules'][$name]['match'] = $rule['action'];
                     }
                 }
             } else {
                 $this->report->addError(sprintf('%s[\'rules\'][\'%s\'] must be an array, %s given.', $arrayPath, $name, gettype($rule)));
             }
         }
         foreach ($added as $name) {
             if (!isset($this->profiler['matcher']['rules'][$name]['match'])) {
                 unset($this->profiler['matcher']['rules'][$name]);
             }
         }
     } else {
         $report->addError(sprintf('[\'zdt\'][\'profiler\'][\'matcher\'][\'rules\'] must be an array, %s given.', gettype($options['rules'])));
     }
 }
Example #4
0
 /**
  * Registers verbose listeners if enabled.
  *
  * @return self
  */
 protected function registerVerbose()
 {
     if ($this->options->isVerbose()) {
         foreach ($this->options->getVerboseListeners() as $id => $listeners) {
             foreach ($listeners as $service => $mode) {
                 if ($mode === true) {
                     if (!$this->serviceLocator->has($service)) {
                         $this->report->addError(sprintf('Unable to fetch or create an instance for %s.', $service));
                         continue;
                     }
                     $listener = $this->serviceLocator->get($service);
                     if ($listener instanceof DynamicIdentifierInterface) {
                         $listener->setIdentifier($id);
                     }
                     $this->sharedEventManager->attach($id, $listener, null);
                 }
             }
         }
     }
     return $this;
 }