4 * This file is part of Twig.
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
13 * @author Fabien Potencier <fabien@symfony.com>
15 abstract class Twig_Profiler_Dumper_Base
19 public function dump(Twig_Profiler_Profile $profile)
21 return $this->dumpProfile($profile);
24 abstract protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix);
26 abstract protected function formatNonTemplate(Twig_Profiler_Profile $profile, $prefix);
28 abstract protected function formatTime(Twig_Profiler_Profile $profile, $percent);
30 private function dumpProfile(Twig_Profiler_Profile $profile, $prefix = '', $sibling = false)
32 if ($profile->isRoot()) {
33 $this->root = $profile->getDuration();
34 $start = $profile->getName();
36 if ($profile->isTemplate()) {
37 $start = $this->formatTemplate($profile, $prefix);
39 $start = $this->formatNonTemplate($profile, $prefix);
41 $prefix .= $sibling ? '│ ' : ' ';
44 $percent = $this->root ? $profile->getDuration() / $this->root * 100 : 0;
46 if ($profile->getDuration() * 1000 < 1) {
49 $str = sprintf("%s %s\n", $start, $this->formatTime($profile, $percent));
52 $nCount = count($profile->getProfiles());
53 foreach ($profile as $i => $p) {
54 $str .= $this->dumpProfile($p, $prefix, $i + 1 !== $nCount);
61 class_alias('Twig_Profiler_Dumper_Base', 'Twig\Profiler\Dumper\BaseDumper', false);
62 class_exists('Twig_Profiler_Profile');