Html.php (1482B)
1 <?php 2 3 /* 4 * This file is part of Twig. 5 * 6 * (c) 2015 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 class Twig_Profiler_Dumper_Html extends Twig_Profiler_Dumper_Text 16 { 17 private static $colors = array( 18 'block' => '#dfd', 19 'macro' => '#ddf', 20 'template' => '#ffd', 21 'big' => '#d44', 22 ); 23 24 public function dump(Twig_Profiler_Profile $profile) 25 { 26 return '<pre>'.parent::dump($profile).'</pre>'; 27 } 28 29 protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix) 30 { 31 return sprintf('%s└ <span style="background-color: %s">%s</span>', $prefix, self::$colors['template'], $profile->getTemplate()); 32 } 33 34 protected function formatNonTemplate(Twig_Profiler_Profile $profile, $prefix) 35 { 36 return sprintf('%s└ %s::%s(<span style="background-color: %s">%s</span>)', $prefix, $profile->getTemplate(), $profile->getType(), isset(self::$colors[$profile->getType()]) ? self::$colors[$profile->getType()] : 'auto', $profile->getName()); 37 } 38 39 protected function formatTime(Twig_Profiler_Profile $profile, $percent) 40 { 41 return sprintf('<span style="color: %s">%.2fms/%.0f%%</span>', $percent > 20 ? self::$colors['big'] : 'auto', $profile->getDuration() * 1000, $percent); 42 } 43 }