Pull merge.
[yaffs-website] / web / core / lib / Drupal / Core / Logger / LogMessageParser.php
1 <?php
2
3 namespace Drupal\Core\Logger;
4
5 /**
6  * Parses log messages and their placeholders.
7  */
8 class LogMessageParser implements LogMessageParserInterface {
9
10   /**
11    * {@inheritdoc}
12    */
13   public function parseMessagePlaceholders(&$message, array &$context) {
14     $variables = [];
15     $has_psr3 = FALSE;
16     if (($start = strpos($message, '{')) !== FALSE && strpos($message, '}') > $start) {
17       $has_psr3 = TRUE;
18       // Transform PSR3 style messages containing placeholders to
19       // \Drupal\Component\Render\FormattableMarkup style.
20       $message = preg_replace('/\{(.*)\}/U', '@$1', $message);
21     }
22     foreach ($context as $key => $variable) {
23       // PSR3 style placeholders.
24       if ($has_psr3) {
25         // Keys are not prefixed with anything according to PSR3 specs.
26         // If the message is "User {username} created" the variable key will be
27         // just "username".
28         if (strpos($message, '@' . $key) !== FALSE) {
29           $key = '@' . $key;
30         }
31       }
32       if (!empty($key) && ($key[0] === '@' || $key[0] === '%' || $key[0] === '!')) {
33         // The key is now in \Drupal\Component\Render\FormattableMarkup style.
34         $variables[$key] = $variable;
35       }
36     }
37
38     return $variables;
39   }
40
41 }