function DeprecationHandler::init

Initializes the extension.

Parameters

string|null $ignoreFile: The path to a file containing ignore patterns for deprecations.

1 call to DeprecationHandler::init()
bootstrap.php in core/tests/bootstrap.php

File

core/tests/Drupal/TestTools/Extension/DeprecationBridge/DeprecationHandler.php, line 98

Class

DeprecationHandler
Drupal's PHPUnit extension to manage code deprecation.

Namespace

Drupal\TestTools\Extension\DeprecationBridge

Code

public static function init(?string $ignoreFile = NULL) : void {
    if (self::isEnabled()) {
        throw new \LogicException(__CLASS__ . ' is already initialized');
    }
    // Load the deprecation ignore patterns from the specified file.
    if ($ignoreFile && !self::$deprecationIgnorePatterns) {
        if (!is_file($ignoreFile)) {
            throw new \InvalidArgumentException(sprintf('The ignoreFile "%s" does not exist.', $ignoreFile));
        }
        set_error_handler(static function ($t, $m) use ($ignoreFile, &$line) {
            throw new \RuntimeException(sprintf('Invalid pattern found in "%s" on line "%d"', $ignoreFile, 1 + $line) . substr($m, 12));
        });
        try {
            foreach (file($ignoreFile) as $line => $pattern) {
                if ((trim($pattern)[0] ?? '#') !== '#') {
                    preg_match($pattern, '');
                    self::$deprecationIgnorePatterns[] = $pattern;
                }
            }
        } finally {
            restore_error_handler();
        }
    }
    // Mark the extension as enabled.
    self::$enabled = TRUE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.