Newer
Older

Adam G-H
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace Drupal\package_manager\PathExcluder;
use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\StageEvent;
use Drupal\package_manager\PathLocator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Excludes site configuration files from staging areas.
*/
class SiteConfigurationExcluder implements EventSubscriberInterface {
use PathExclusionsTrait;
/**
* The current site path, relative to the Drupal root.
*
* @var string
*/
protected $sitePath;
/**
* Constructs an ExcludedPathsSubscriber.
*
* @param string $site_path
* The current site path, relative to the Drupal root.
* @param \Drupal\package_manager\PathLocator $path_locator
* The path locator service.
*/
public function __construct(string $site_path, PathLocator $path_locator) {
$this->sitePath = $site_path;
$this->pathLocator = $path_locator;
}
/**
* Excludes site configuration files from staging operations.

Adam G-H
committed
*
* @param \Drupal\package_manager\Event\PreApplyEvent|\Drupal\package_manager\Event\PreCreateEvent $event
* The event object.
*
* @see \Drupal\package_manager\Event\ExcludedPathsTrait::excludePath()
*/
public function excludeSiteConfiguration(StageEvent $event): void {

Adam G-H
committed
// Site configuration files are always excluded relative to the web root.
$paths = [];

Adam G-H
committed
// Ignore site-specific settings files, which are always in the web root.
// By default, Drupal core will always try to write-protect these files.

Adam G-H
committed
$settings_files = [
'settings.php',
'settings.local.php',
'services.yml',
];
foreach ($settings_files as $settings_file) {
$paths[] = $this->sitePath . '/' . $settings_file;
$paths[] = 'sites/default/' . $settings_file;

Adam G-H
committed
}
$this->excludeInWebRoot($event, $paths);

Adam G-H
committed
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
PreCreateEvent::class => 'excludeSiteConfiguration',
PreApplyEvent::class => 'excludeSiteConfiguration',