You are here

public static function FileLogRotationTest::tokenReplace in File Log 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Unit/FileLogRotationTest.php \Drupal\Tests\filelog\Unit\FileLogRotationTest::tokenReplace()

Mock Token::replace() only for [date:custom:...].

Parameters

string $text: The text to be replaced.

array $data: The placeholders.

Return value

string The formatted text.

File

tests/src/Unit/FileLogRotationTest.php, line 254

Class

FileLogRotationTest
Tests the log rotation of the file logger.

Namespace

Drupal\Tests\filelog\Unit

Code

public static function tokenReplace($text, array $data) : string {
  preg_match_all('/\\[date:custom:(.*?)]/', $text, $matches, PREG_SET_ORDER);
  $replace = [];
  foreach ((array) $matches as $match) {
    $replace[$match[0]] = date($match[1], $data['date']);
  }
  return strtr($text, $replace);
}