class Configuration

Same name in this branch
  1. 11.x core/tests/Drupal/TestTools/TestRunner/Configuration.php \Drupal\TestTools\TestRunner\Configuration

Configuration for DeprecationHandler.

@internal

Hierarchy

  • class \Drupal\TestTools\Extension\DeprecationBridge\Configuration

Expanded class hierarchy of Configuration

2 files declare their use of Configuration
BootstrapErrorHandler.php in core/tests/Drupal/TestTools/ErrorHandler/BootstrapErrorHandler.php
DrupalTestCaseTrait.php in core/tests/Drupal/Tests/DrupalTestCaseTrait.php
188 string references to 'Configuration'
action_settings.yml in core/modules/system/migrations/action_settings.yml
core/modules/system/migrations/action_settings.yml
AddComponentTest::testAddComponent in core/modules/layout_builder/tests/src/Kernel/Plugin/ConfigAction/AddComponentTest.php
Tests adding a component to a view display using a config action.
AddComponentTest::testAddComponentToEmptyRegionThatIsNotFirst in core/modules/layout_builder/tests/src/Kernel/Plugin/ConfigAction/AddComponentTest.php
Tests that adding a component to another section works as expected.
AddNavigationBlockConfigActionTest::testAddBlockToNavigation in core/modules/navigation/tests/src/Kernel/ConfigAction/AddNavigationBlockConfigActionTest.php
Tests add item logic.
block_content_body_field.yml in core/modules/block_content/migrations/block_content_body_field.yml
core/modules/block_content/migrations/block_content_body_field.yml

... See full list

File

core/tests/Drupal/TestTools/Extension/DeprecationBridge/Configuration.php, line 14

Namespace

Drupal\TestTools\Extension\DeprecationBridge
View source
final class Configuration {
  
  /**
   * The class singleton.
   */
  private static self $instance;
  
  /**
   * Indicates if the project deprecation ignores are enabled.
   */
  public bool $projectIgnoresEnabled = FALSE;
  
  /**
   * Path to the deprecation ignore file.
   */
  public string $projectIgnoreFile;
  
  /**
   * Indicates if the debug class loader is enabled.
   */
  public bool $debugClassLoaderEnabled = FALSE;
  
  /**
   * The list of deprecation message patterns that should be ignored.
   *
   * @var list<string>
   */
  public array $deprecationIgnorePatterns = [];
  
  /**
   * Returns the singleton.
   *
   * @return self
   *   The singleton.
   */
  public static function instance() : self {
    if (!isset(self::$instance)) {
      self::$instance = new self();
    }
    return self::$instance;
  }
  
  /**
   * Loads the configuration from an array.
   *
   * Overwrites each configuration key that is already existing.
   *
   * @param array<string,bool|string|list<string>> $parameters
   *   An array of configuration elements.
   */
  public function load(array $parameters) : void {
    if (array_key_exists('enableProjectIgnores', $parameters)) {
      $this->projectIgnoresEnabled = filter_var($parameters['enableProjectIgnores'] ?? FALSE, \FILTER_VALIDATE_BOOLEAN);
    }
    if (array_key_exists('projectIgnoreFile', $parameters)) {
      $this->projectIgnoreFile = $parameters['projectIgnoreFile'];
    }
    if (array_key_exists('enableDebugClassLoader', $parameters)) {
      $this->debugClassLoaderEnabled = filter_var($parameters['enableDebugClassLoader'] ?? FALSE, \FILTER_VALIDATE_BOOLEAN);
    }
  }
  
  /**
   * Loads the deprecation ignore patterns from the ignore file.
   */
  public function loadDeprecationIgnorePatterns() : void {
    assert(empty($this->deprecationIgnorePatterns), 'deprecationIgnorePatterns can only be loaded once');
    // Load the deprecation ignore patterns from the specified file.
    $path = $this->absoluteAndExistingPath($this->projectIgnoreFile);
    set_error_handler(static function () use ($path, &$line) : never {
      throw new \RuntimeException(sprintf('Invalid pattern found in "%s" on line %d', $path, 1 + $line));
    });
    try {
      foreach (file($path) as $line => $pattern) {
        if ((trim($pattern)[0] ?? '#') !== '#') {
          preg_match($pattern, '');
          $this->deprecationIgnorePatterns[] = $pattern;
        }
      }
    } finally {
      restore_error_handler();
    }
  }
  
  /**
   * Returns an absolute file path, resolving relative ones from Drupal root.
   *
   * @param string $path
   *   A file path.
   *
   * @return string
   *   An absolute file path.
   */
  private function absoluteAndExistingPath(string $path) : string {
    if (!str_starts_with($path, \DIRECTORY_SEPARATOR)) {
      $realPath = realpath(dirname(__DIR__, 6) . \DIRECTORY_SEPARATOR . $path);
    }
    else {
      $realPath = $path;
    }
    if ($realPath === FALSE || !is_file($realPath)) {
      throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $path));
    }
    return $realPath;
  }

}

Members

Title Sort descending Modifiers Object type Summary
Configuration::$debugClassLoaderEnabled public property Indicates if the debug class loader is enabled.
Configuration::$deprecationIgnorePatterns public property The list of deprecation message patterns that should be ignored.
Configuration::$instance private static property The class singleton.
Configuration::$projectIgnoreFile public property Path to the deprecation ignore file.
Configuration::$projectIgnoresEnabled public property Indicates if the project deprecation ignores are enabled.
Configuration::absoluteAndExistingPath private function Returns an absolute file path, resolving relative ones from Drupal root.
Configuration::instance public static function Returns the singleton.
Configuration::load public function Loads the configuration from an array.
Configuration::loadDeprecationIgnorePatterns public function Loads the deprecation ignore patterns from the ignore file.

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