Skip to content
Snippets Groups Projects

Issue #3274323: Split ExcludedPathsSubscriber into multiple classes

All threads resolved!
All threads resolved!
Compare and
5 files
+ 183
63
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -18,6 +18,8 @@ use Symfony\Component\Finder\Finder;
*/
class ExcludedPathsSubscriber implements EventSubscriberInterface {
use PathExclusionsTrait;
/**
* The current site path, relative to the Drupal root.
*
@@ -46,13 +48,6 @@ class ExcludedPathsSubscriber implements EventSubscriberInterface {
*/
protected $database;
/**
* The path locator service.
*
* @var \Drupal\package_manager\PathLocator
*/
protected $pathLocator;
/**
* Constructs an ExcludedPathsSubscriber.
*
@@ -75,51 +70,6 @@ class ExcludedPathsSubscriber implements EventSubscriberInterface {
$this->pathLocator = $path_locator;
}
/**
* Flags paths to be excluded, relative to the web root.
*
* This should only be used for paths that, if they exist at all, are
* *guaranteed* to exist within the web root.
*
* @param \Drupal\package_manager\Event\PreCreateEvent|\Drupal\package_manager\Event\PreApplyEvent $event
* The event object.
* @param string[] $paths
* The paths to exclude. These should be relative to the web root, and will
* be made relative to the project root.
*/
protected function excludeInWebRoot(StageEvent $event, array $paths): void {
$web_root = $this->pathLocator->getWebRoot();
if ($web_root) {
$web_root .= '/';
}
foreach ($paths as $path) {
// Make the path relative to the project root by prefixing the web root.
$event->excludePath($web_root . $path);
}
}
/**
* Flags paths to be excluded, relative to the project root.
*
* @param \Drupal\package_manager\Event\PreCreateEvent|\Drupal\package_manager\Event\PreApplyEvent $event
* The event object.
* @param string[] $paths
* The paths to exclude. Absolute paths will be made relative to the project
* root; relative paths will be assumed to already be relative to the
* project root, and excluded as given.
*/
protected function excludeInProjectRoot(StageEvent $event, array $paths): void {
$project_root = $this->pathLocator->getProjectRoot();
foreach ($paths as $path) {
// Make absolute paths relative to the project root.
$path = str_replace($project_root, '', $path);
$path = ltrim($path, '/');
$event->excludePath($path);
}
}
/**
* Excludes common paths from staging operations.
*
@@ -133,17 +83,6 @@ class ExcludedPathsSubscriber implements EventSubscriberInterface {
// project root, and paths that are relative to the web root.
$web = $project = [];
// Always ignore automated test directories. If they exist, they will be in
// the web root.
$web[] = 'sites/simpletest';
// If the core-vendor-hardening plugin (used in the legacy-project template)
// is present, it may have written security hardening files in the vendor
// directory. They should always be ignored.
$vendor_dir = $this->pathLocator->getVendorDirectory();
$project[] = $vendor_dir . '/web.config';
$project[] = $vendor_dir . '/.htaccess';
// Ignore public and private files. These paths could be either absolute or
// relative, depending on site settings. If they are absolute, treat them
// as relative to the project root. Otherwise, treat them as relative to
Loading