Security update for Core, with self-updated composer
[yaffs-website] / vendor / twig / twig / lib / Twig / Profiler / Dumper / Base.php
1 <?php
2
3 /*
4  * This file is part of Twig.
5  *
6  * (c) Fabien Potencier
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 /**
13  * @author Fabien Potencier <fabien@symfony.com>
14  */
15 abstract class Twig_Profiler_Dumper_Base
16 {
17     private $root;
18
19     public function dump(Twig_Profiler_Profile $profile)
20     {
21         return $this->dumpProfile($profile);
22     }
23
24     abstract protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix);
25
26     abstract protected function formatNonTemplate(Twig_Profiler_Profile $profile, $prefix);
27
28     abstract protected function formatTime(Twig_Profiler_Profile $profile, $percent);
29
30     private function dumpProfile(Twig_Profiler_Profile $profile, $prefix = '', $sibling = false)
31     {
32         if ($profile->isRoot()) {
33             $this->root = $profile->getDuration();
34             $start = $profile->getName();
35         } else {
36             if ($profile->isTemplate()) {
37                 $start = $this->formatTemplate($profile, $prefix);
38             } else {
39                 $start = $this->formatNonTemplate($profile, $prefix);
40             }
41             $prefix .= $sibling ? '│ ' : '  ';
42         }
43
44         $percent = $this->root ? $profile->getDuration() / $this->root * 100 : 0;
45
46         if ($profile->getDuration() * 1000 < 1) {
47             $str = $start."\n";
48         } else {
49             $str = sprintf("%s %s\n", $start, $this->formatTime($profile, $percent));
50         }
51
52         $nCount = count($profile->getProfiles());
53         foreach ($profile as $i => $p) {
54             $str .= $this->dumpProfile($p, $prefix, $i + 1 !== $nCount);
55         }
56
57         return $str;
58     }
59 }
60
61 class_alias('Twig_Profiler_Dumper_Base', 'Twig\Profiler\Dumper\BaseDumper', false);
62 class_exists('Twig_Profiler_Profile');