[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 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 namespace Symfony\Bridge\Twig\DataCollector; 13 14 use Symfony\Component\HttpFoundation\Request; 15 use Symfony\Component\HttpFoundation\Response; 16 use Symfony\Component\HttpKernel\DataCollector\DataCollector; 17 use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface; 18 use Twig\Markup; 19 use Twig\Profiler\Dumper\HtmlDumper; 20 use Twig\Profiler\Profile; 21 22 /** 23 * TwigDataCollector. 24 * 25 * @author Fabien Potencier <fabien@symfony.com> 26 */ 27 class TwigDataCollector extends DataCollector implements LateDataCollectorInterface 28 { 29 private $profile; 30 private $computed; 31 32 public function __construct(Profile $profile) 33 { 34 $this->profile = $profile; 35 } 36 37 /** 38 * {@inheritdoc} 39 */ 40 public function collect(Request $request, Response $response, \Exception $exception = null) 41 { 42 } 43 44 /** 45 * {@inheritdoc} 46 */ 47 public function lateCollect() 48 { 49 $this->data['profile'] = serialize($this->profile); 50 } 51 52 public function getTime() 53 { 54 return $this->getProfile()->getDuration() * 1000; 55 } 56 57 public function getTemplateCount() 58 { 59 return $this->getComputedData('template_count'); 60 } 61 62 public function getTemplates() 63 { 64 return $this->getComputedData('templates'); 65 } 66 67 public function getBlockCount() 68 { 69 return $this->getComputedData('block_count'); 70 } 71 72 public function getMacroCount() 73 { 74 return $this->getComputedData('macro_count'); 75 } 76 77 public function getHtmlCallGraph() 78 { 79 $dumper = new HtmlDumper(); 80 $dump = $dumper->dump($this->getProfile()); 81 82 // needed to remove the hardcoded CSS styles 83 $dump = str_replace(array( 84 '<span style="background-color: #ffd">', 85 '<span style="color: #d44">', 86 '<span style="background-color: #dfd">', 87 ), array( 88 '<span class="status-warning">', 89 '<span class="status-error">', 90 '<span class="status-success">', 91 ), $dump); 92 93 return new Markup($dump, 'UTF-8'); 94 } 95 96 public function getProfile() 97 { 98 if (null === $this->profile) { 99 $this->profile = unserialize($this->data['profile']); 100 } 101 102 return $this->profile; 103 } 104 105 private function getComputedData($index) 106 { 107 if (null === $this->computed) { 108 $this->computed = $this->computeData($this->getProfile()); 109 } 110 111 return $this->computed[$index]; 112 } 113 114 private function computeData(Profile $profile) 115 { 116 $data = array( 117 'template_count' => 0, 118 'block_count' => 0, 119 'macro_count' => 0, 120 ); 121 122 $templates = array(); 123 foreach ($profile as $p) { 124 $d = $this->computeData($p); 125 126 $data['template_count'] += ($p->isTemplate() ? 1 : 0) + $d['template_count']; 127 $data['block_count'] += ($p->isBlock() ? 1 : 0) + $d['block_count']; 128 $data['macro_count'] += ($p->isMacro() ? 1 : 0) + $d['macro_count']; 129 130 if ($p->isTemplate()) { 131 if (!isset($templates[$p->getTemplate()])) { 132 $templates[$p->getTemplate()] = 1; 133 } else { 134 ++$templates[$p->getTemplate()]; 135 } 136 } 137 138 foreach ($d['templates'] as $template => $count) { 139 if (!isset($templates[$template])) { 140 $templates[$template] = $count; 141 } else { 142 $templates[$template] += $count; 143 } 144 } 145 } 146 $data['templates'] = $templates; 147 148 return $data; 149 } 150 151 /** 152 * {@inheritdoc} 153 */ 154 public function getName() 155 { 156 return 'twig'; 157 } 158 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |