[ Index ] |
PHP Cross Reference of phpBB-3.1.12-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\Component\HttpKernel\DataCollector; 13 14 use Symfony\Component\Debug\ErrorHandler; 15 use Symfony\Component\HttpFoundation\Request; 16 use Symfony\Component\HttpFoundation\Response; 17 use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; 18 19 /** 20 * LogDataCollector. 21 * 22 * @author Fabien Potencier <fabien@symfony.com> 23 */ 24 class LoggerDataCollector extends DataCollector 25 { 26 private $logger; 27 28 public function __construct($logger = null) 29 { 30 if (null !== $logger && $logger instanceof DebugLoggerInterface) { 31 $this->logger = $logger; 32 } 33 } 34 35 /** 36 * {@inheritdoc} 37 */ 38 public function collect(Request $request, Response $response, \Exception $exception = null) 39 { 40 if (null !== $this->logger) { 41 $this->data = array( 42 'error_count' => $this->logger->countErrors(), 43 'logs' => $this->sanitizeLogs($this->logger->getLogs()), 44 'deprecation_count' => $this->computeDeprecationCount(), 45 ); 46 } 47 } 48 49 /** 50 * Gets the called events. 51 * 52 * @return array An array of called events 53 * 54 * @see TraceableEventDispatcherInterface 55 */ 56 public function countErrors() 57 { 58 return isset($this->data['error_count']) ? $this->data['error_count'] : 0; 59 } 60 61 /** 62 * Gets the logs. 63 * 64 * @return array An array of logs 65 */ 66 public function getLogs() 67 { 68 return isset($this->data['logs']) ? $this->data['logs'] : array(); 69 } 70 71 public function countDeprecations() 72 { 73 return isset($this->data['deprecation_count']) ? $this->data['deprecation_count'] : 0; 74 } 75 76 /** 77 * {@inheritdoc} 78 */ 79 public function getName() 80 { 81 return 'logger'; 82 } 83 84 private function sanitizeLogs($logs) 85 { 86 foreach ($logs as $i => $log) { 87 $logs[$i]['context'] = $this->sanitizeContext($log['context']); 88 } 89 90 return $logs; 91 } 92 93 private function sanitizeContext($context) 94 { 95 if (is_array($context)) { 96 foreach ($context as $key => $value) { 97 $context[$key] = $this->sanitizeContext($value); 98 } 99 100 return $context; 101 } 102 103 if (is_resource($context)) { 104 return sprintf('Resource(%s)', get_resource_type($context)); 105 } 106 107 if (is_object($context)) { 108 return sprintf('Object(%s)', get_class($context)); 109 } 110 111 return $context; 112 } 113 114 private function computeDeprecationCount() 115 { 116 $count = 0; 117 foreach ($this->logger->getLogs() as $log) { 118 if (isset($log['context']['type']) && ErrorHandler::TYPE_DEPRECATION === $log['context']['type']) { 119 ++$count; 120 } 121 } 122 123 return $count; 124 } 125 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |