Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / http-kernel / DataCollector / LoggerDataCollector.php
index 0e4df12baa8d7fba58a9ae9033191ca832cf49d1..358a411ab003271f2b710d7eee6e4d6bd53499ce 100644 (file)
@@ -11,6 +11,7 @@
 
 namespace Symfony\Component\HttpKernel\DataCollector;
 
+use Symfony\Component\Debug\Exception\SilencedErrorContext;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
@@ -22,24 +23,6 @@ use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
  */
 class LoggerDataCollector extends DataCollector implements LateDataCollectorInterface
 {
-    private $errorNames = array(
-        E_DEPRECATED => 'E_DEPRECATED',
-        E_USER_DEPRECATED => 'E_USER_DEPRECATED',
-        E_NOTICE => 'E_NOTICE',
-        E_USER_NOTICE => 'E_USER_NOTICE',
-        E_STRICT => 'E_STRICT',
-        E_WARNING => 'E_WARNING',
-        E_USER_WARNING => 'E_USER_WARNING',
-        E_COMPILE_WARNING => 'E_COMPILE_WARNING',
-        E_CORE_WARNING => 'E_CORE_WARNING',
-        E_USER_ERROR => 'E_USER_ERROR',
-        E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
-        E_COMPILE_ERROR => 'E_COMPILE_ERROR',
-        E_PARSE => 'E_PARSE',
-        E_ERROR => 'E_ERROR',
-        E_CORE_ERROR => 'E_CORE_ERROR',
-    );
-
     private $logger;
 
     public function __construct($logger = null)
@@ -93,6 +76,11 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
         return isset($this->data['deprecation_count']) ? $this->data['deprecation_count'] : 0;
     }
 
+    public function countWarnings()
+    {
+        return isset($this->data['warning_count']) ? $this->data['warning_count'] : 0;
+    }
+
     public function countScreams()
     {
         return isset($this->data['scream_count']) ? $this->data['scream_count'] : 0;
@@ -108,74 +96,53 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
 
     private function sanitizeLogs($logs)
     {
-        $errorContextById = array();
         $sanitizedLogs = array();
 
         foreach ($logs as $log) {
-            $context = $this->sanitizeContext($log['context']);
-
-            if (isset($context['type'], $context['file'], $context['line'], $context['level'])) {
-                $errorId = md5("{$context['type']}/{$context['line']}/{$context['file']}\x00{$log['message']}", true);
-                $silenced = !($context['type'] & $context['level']);
-                if (isset($this->errorNames[$context['type']])) {
-                    $context = array_merge(array('name' => $this->errorNames[$context['type']]), $context);
-                }
+            if (!$this->isSilencedOrDeprecationErrorLog($log)) {
+                $log['context'] = $log['context'] ? $this->cloneVar($log['context']) : $log['context'];
+                $sanitizedLogs[] = $log;
 
-                if (isset($errorContextById[$errorId])) {
-                    if (isset($errorContextById[$errorId]['errorCount'])) {
-                        ++$errorContextById[$errorId]['errorCount'];
-                    } else {
-                        $errorContextById[$errorId]['errorCount'] = 2;
-                    }
+                continue;
+            }
 
-                    if (!$silenced && isset($errorContextById[$errorId]['scream'])) {
-                        unset($errorContextById[$errorId]['scream']);
-                        $errorContextById[$errorId]['level'] = $context['level'];
-                    }
+            $exception = $log['context']['exception'];
+            $errorId = md5("{$exception->getSeverity()}/{$exception->getLine()}/{$exception->getFile()}".($exception instanceof \Exception ? "\0".$exception->getMessage() : ''), true);
 
-                    continue;
-                }
+            if (isset($sanitizedLogs[$errorId])) {
+                ++$sanitizedLogs[$errorId]['errorCount'];
+            } else {
+                $log['context'] = $log['context'] ? $this->cloneVar($log['context']) : $log['context'];
 
-                $errorContextById[$errorId] = &$context;
-                if ($silenced) {
-                    $context['scream'] = true;
-                }
+                $log += array(
+                    'errorCount' => 1,
+                    'scream' => $exception instanceof SilencedErrorContext,
+                );
 
-                $log['context'] = &$context;
-                unset($context);
-            } else {
-                $log['context'] = $context;
+                $sanitizedLogs[$errorId] = $log;
             }
-
-            $sanitizedLogs[] = $log;
         }
 
-        return $sanitizedLogs;
+        return array_values($sanitizedLogs);
     }
 
-    private function sanitizeContext($context)
+    private function isSilencedOrDeprecationErrorLog(array $log)
     {
-        if (is_array($context)) {
-            foreach ($context as $key => $value) {
-                $context[$key] = $this->sanitizeContext($value);
-            }
-
-            return $context;
+        if (!isset($log['context']['exception'])) {
+            return false;
         }
 
-        if (is_resource($context)) {
-            return sprintf('Resource(%s)', get_resource_type($context));
-        }
+        $exception = $log['context']['exception'];
 
-        if (is_object($context)) {
-            if ($context instanceof \Exception) {
-                return sprintf('Exception(%s): %s', get_class($context), $context->getMessage());
-            }
+        if ($exception instanceof SilencedErrorContext) {
+            return true;
+        }
 
-            return sprintf('Object(%s)', get_class($context));
+        if ($exception instanceof \ErrorException && in_array($exception->getSeverity(), array(E_DEPRECATED, E_USER_DEPRECATED), true)) {
+            return true;
         }
 
-        return $context;
+        return false;
     }
 
     private function computeErrorsCount()
@@ -183,6 +150,7 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
         $count = array(
             'error_count' => $this->logger->countErrors(),
             'deprecation_count' => 0,
+            'warning_count' => 0,
             'scream_count' => 0,
             'priorities' => array(),
         );
@@ -196,12 +164,15 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
                     'name' => $log['priorityName'],
                 );
             }
+            if ('WARNING' === $log['priorityName']) {
+                ++$count['warning_count'];
+            }
 
-            if (isset($log['context']['type'], $log['context']['level'])) {
-                if (E_DEPRECATED === $log['context']['type'] || E_USER_DEPRECATED === $log['context']['type']) {
-                    ++$count['deprecation_count'];
-                } elseif (!($log['context']['type'] & $log['context']['level'])) {
+            if ($this->isSilencedOrDeprecationErrorLog($log)) {
+                if ($log['context']['exception'] instanceof SilencedErrorContext) {
                     ++$count['scream_count'];
+                } else {
+                    ++$count['deprecation_count'];
                 }
             }
         }