You are here

public static function FileLogRotationTest::tokenReplace in File Log 2.0.x

Same name and namespace in other branches
  1. 8 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 250

Class

FileLogRotationTest
Tests the log rotation of the file logger.

Namespace

Drupal\Tests\filelog\Unit

Code

public static function tokenReplace(string $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);
}