Skip to content
Snippets Groups Projects

Issue #3274323: Split ExcludedPathsSubscriber into multiple classes

Compare and Show latest version
3 files
+ 117
66
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -3,14 +3,11 @@
namespace Drupal\package_manager\EventSubscriber;
use Drupal\Core\Database\Connection;
use Drupal\Core\StreamWrapper\LocalStream;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
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;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
/**
@@ -27,20 +24,6 @@ class ExcludedPathsSubscriber implements EventSubscriberInterface {
*/
protected $sitePath;
/**
* The Symfony file system service.
*
* @var \Symfony\Component\Filesystem\Filesystem
*/
protected $fileSystem;
/**
* The stream wrapper manager service.
*
* @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface
*/
protected $streamWrapperManager;
/**
* The database connection.
*
@@ -53,19 +36,13 @@ class ExcludedPathsSubscriber implements EventSubscriberInterface {
*
* @param string $site_path
* The current site path, relative to the Drupal root.
* @param \Symfony\Component\Filesystem\Filesystem $file_system
* The Symfony file system service.
* @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager
* The stream wrapper manager service.
* @param \Drupal\Core\Database\Connection $database
* The database connection.
* @param \Drupal\package_manager\PathLocator $path_locator
* The path locator service.
*/
public function __construct(string $site_path, Filesystem $file_system, StreamWrapperManagerInterface $stream_wrapper_manager, Connection $database, PathLocator $path_locator) {
public function __construct(string $site_path, Connection $database, PathLocator $path_locator) {
$this->sitePath = $site_path;
$this->fileSystem = $file_system;
$this->streamWrapperManager = $stream_wrapper_manager;
$this->database = $database;
$this->pathLocator = $path_locator;
}
@@ -83,23 +60,6 @@ class ExcludedPathsSubscriber implements EventSubscriberInterface {
// project root, and paths that are relative to the web root.
$web = $project = [];
// 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
// the web root.
$files = array_filter([
$this->getFilesPath('public'),
$this->getFilesPath('private'),
]);
foreach ($files as $path) {
if ($this->fileSystem->isAbsolutePath($path)) {
$project[] = $path;
}
else {
$web[] = $path;
}
}
// Ignore site-specific settings files, which are always in the web root.
$settings_files = [
'settings.php',
@@ -153,29 +113,6 @@ class ExcludedPathsSubscriber implements EventSubscriberInterface {
$this->ignoreCommonPaths($event);
}
/**
* Returns the storage path for a stream wrapper.
*
* This will only work for stream wrappers that extend
* \Drupal\Core\StreamWrapper\LocalStream, which includes the stream wrappers
* for public and private files.
*
* @param string $scheme
* The stream wrapper scheme.
*
* @return string|null
* The storage path for files using the given scheme, relative to the Drupal
* root, or NULL if the stream wrapper does not extend
* \Drupal\Core\StreamWrapper\LocalStream.
*/
private function getFilesPath(string $scheme): ?string {
$wrapper = $this->streamWrapperManager->getViaScheme($scheme);
if ($wrapper instanceof LocalStream) {
return $wrapper->getDirectoryPath();
}
return NULL;
}
/**
* {@inheritdoc}
*/
Loading