/** * Generates the list page. * * @param \Symfony\Component\HttpFoundation\Request $request * * @return array */ public function listAction(Request $request) { $limit = $request->get('limit', 10); $this->profiler->disable(); $ip = $request->query->get('ip'); $method = $request->query->get('method'); $url = $request->query->get('url'); $profiles = $this->profiler->find($ip, $url, $limit, $method, '', ''); $rows = []; if (count($profiles)) { foreach ($profiles as $profile) { $row = []; $row[] = $this->l($profile['token'], new Url('webprofiler.dashboard', ['profile' => $profile['token']])); $row[] = $profile['ip']; $row[] = $profile['method']; $row[] = $profile['url']; $row[] = $this->date->format($profile['time']); $rows[] = $row; } } else { $rows[] = [['data' => $this->t('No profiles found'), 'colspan' => 6]]; } $build = []; $storage_id = $this->config('webprofiler.config')->get('storage'); $storage = $this->storageManager->getStorage($storage_id); $build['resume'] = ['#type' => 'inline_template', '#template' => '<p>{{ message }}</p>', '#context' => ['message' => $this->t('Profiles stored with %storage service.', ['%storage' => $storage['title']])]]; $build['filters'] = $this->formBuilder()->getForm('Drupal\\webprofiler\\Form\\ProfilesFilterForm'); $build['table'] = ['#type' => 'table', '#rows' => $rows, '#header' => [$this->t('Token'), ['data' => $this->t('Ip'), 'class' => [RESPONSIVE_PRIORITY_LOW]], ['data' => $this->t('Method'), 'class' => [RESPONSIVE_PRIORITY_LOW]], $this->t('Url'), ['data' => $this->t('Time'), 'class' => [RESPONSIVE_PRIORITY_MEDIUM]]], '#sticky' => TRUE]; return $build; }
public function getWebprofilerForms() { $tokens = $this->profiler->find(null, null, 1000, null, '', ''); $forms = array(); foreach ($tokens as $token) { $token = [$token['token']]; $profile = $this->profiler->loadProfile($token); $formCollector = $profile->getCollector('forms'); $collectedForms = $formCollector->getForms(); if (empty($forms)) { $forms = $collectedForms; } elseif (!empty($collectedForms)) { $forms = array_merge($forms, $collectedForms); } } return $forms; }
/** * Exports all stored profiles (cap limit at 1000 items). * * @param \Drupal\webprofiler\Profiler\Profiler $profiler * @param string $directory * @param \Symfony\Component\Console\Output\OutputInterface $output * * @return string */ private function exportAll(Profiler $profiler, $directory, $output) { $filename = $directory . DIRECTORY_SEPARATOR . 'profiles_' . time() . '.tar.gz'; $archiver = new ArchiveTar($filename, 'gz'); $profiles = $profiler->find(NULL, NULL, 1000, NULL, '', ''); $progress = new ProgressBar($output, count($profiles) + 2); $progress->setFormat(' %current%/%max% [%bar%] %percent:3s%% %message%'); $files = []; $progress->start(); $progress->setMessage($this->trans('commands.webprofiler.export.progress.exporting')); foreach ($profiles as $profile) { $data = $profiler->export($profiler->loadProfile($profile['token'])); $profileFilename = $directory . "/{$profile['token']}.txt"; file_put_contents($profileFilename, $data); $files[] = $profileFilename; $progress->advance(); } $progress->setMessage($this->trans('commands.webprofiler.export.progress.archive')); $archiver->createModify($files, '', $directory); $progress->advance(); $progress->setMessage($this->trans('commands.webprofiler.export.progress.delete_tmp')); foreach ($files as $file) { unlink($file); } $progress->advance(); $progress->setMessage($this->trans('commands.webprofiler.export.progress.done')); $progress->finish(); $output->writeln(''); $output->writeln(sprintf($this->trans('commands.webprofiler.export.messages.exported_count'), count($profiles))); return $filename; }