function CollectPathsToExcludeEvent::addPathsRelativeToProjectRoot

Flags paths to be ignored, relative to the project root.

Parameters

string[] $paths: The paths to ignore. Absolute paths will be made relative to the project root; relative paths are assumed to be relative to the project root.

Throws

\LogicException If any of the given paths are absolute, but not inside the project root.

File

core/modules/package_manager/src/Event/CollectPathsToExcludeEvent.php, line 91

Class

CollectPathsToExcludeEvent
Defines an event that collects paths to exclude.

Namespace

Drupal\package_manager\Event

Code

public function addPathsRelativeToProjectRoot(array $paths) : void {
    $project_root = $this->pathLocator
        ->getProjectRoot();
    foreach ($paths as $path) {
        if ($this->pathFactory
            ->create($path)
            ->isAbsolute()) {
            if (!str_starts_with($path, $project_root)) {
                throw new \LogicException("{$path} is not inside the project root: {$project_root}.");
            }
        }
        // Make absolute paths relative to the project root.
        $path = str_replace($project_root, '', $path);
        $path = ltrim($path, '/');
        $this->add($path);
    }
}

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