Skip to content
Snippets Groups Projects
Commit 68d32b2e authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3321474 by phenaproxima, tedbow: Adopt PHP 8.1-only capabilities such...

Issue #3321474 by phenaproxima, tedbow: Adopt PHP 8.1-only capabilities such as constructor property promotion + drop BC layers
parent 4e350a4c
No related branches found
No related tags found
No related merge requests found
Showing
with 77 additions and 533 deletions
...@@ -22,24 +22,16 @@ final class GitExcluder implements EventSubscriberInterface { ...@@ -22,24 +22,16 @@ final class GitExcluder implements EventSubscriberInterface {
use PathExclusionsTrait; use PathExclusionsTrait;
/**
* The file system service.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/** /**
* Constructs a GitExcluder object. * Constructs a GitExcluder object.
* *
* @param \Drupal\package_manager\PathLocator $path_locator * @param \Drupal\package_manager\PathLocator $path_locator
* The path locator service. * The path locator service.
* @param \Drupal\Core\File\FileSystemInterface $file_system * @param \Drupal\Core\File\FileSystemInterface $fileSystem
* The file system service. * The file system service.
*/ */
public function __construct(PathLocator $path_locator, FileSystemInterface $file_system) { public function __construct(PathLocator $path_locator, protected FileSystemInterface $fileSystem) {
$this->pathLocator = $path_locator; $this->pathLocator = $path_locator;
$this->fileSystem = $file_system;
} }
/** /**
......
...@@ -5,7 +5,6 @@ declare(strict_types = 1); ...@@ -5,7 +5,6 @@ declare(strict_types = 1);
namespace Drupal\package_manager\PathExcluder; namespace Drupal\package_manager\PathExcluder;
use Drupal\package_manager\Event\CollectIgnoredPathsEvent; use Drupal\package_manager\Event\CollectIgnoredPathsEvent;
use Drupal\package_manager\Event\StageEvent;
/** /**
* Contains methods for excluding paths from stage operations. * Contains methods for excluding paths from stage operations.
...@@ -31,7 +30,7 @@ trait PathExclusionsTrait { ...@@ -31,7 +30,7 @@ trait PathExclusionsTrait {
* The paths to exclude. These should be relative to the web root, and will * The paths to exclude. These should be relative to the web root, and will
* be made relative to the project root. * be made relative to the project root.
*/ */
protected function excludeInWebRoot(StageEvent $event, array $paths): void { protected function excludeInWebRoot(CollectIgnoredPathsEvent $event, array $paths): void {
$web_root = $this->pathLocator->getWebRoot(); $web_root = $this->pathLocator->getWebRoot();
if ($web_root) { if ($web_root) {
$web_root .= '/'; $web_root .= '/';
...@@ -39,15 +38,7 @@ trait PathExclusionsTrait { ...@@ -39,15 +38,7 @@ trait PathExclusionsTrait {
foreach ($paths as $path) { foreach ($paths as $path) {
// Make the path relative to the project root by prefixing the web root. // Make the path relative to the project root by prefixing the web root.
$path = $web_root . $path; $event->add([$web_root . $path]);
if ($event instanceof CollectIgnoredPathsEvent) {
$event->add([$path]);
}
else {
@trigger_error('Passing ' . get_class($event) . ' to ' . __METHOD__ . ' is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. See https://www.drupal.org/node/3317862.', E_USER_DEPRECATED);
$event->excludePath($web_root . $path);
}
} }
} }
...@@ -61,7 +52,7 @@ trait PathExclusionsTrait { ...@@ -61,7 +52,7 @@ trait PathExclusionsTrait {
* root; relative paths will be assumed to already be relative to the * root; relative paths will be assumed to already be relative to the
* project root, and excluded as given. * project root, and excluded as given.
*/ */
protected function excludeInProjectRoot(StageEvent $event, array $paths): void { protected function excludeInProjectRoot(CollectIgnoredPathsEvent $event, array $paths): void {
$project_root = $this->pathLocator->getProjectRoot(); $project_root = $this->pathLocator->getProjectRoot();
foreach ($paths as $path) { foreach ($paths as $path) {
...@@ -74,14 +65,7 @@ trait PathExclusionsTrait { ...@@ -74,14 +65,7 @@ trait PathExclusionsTrait {
// Make absolute paths relative to the project root. // Make absolute paths relative to the project root.
$path = str_replace($project_root, '', $path); $path = str_replace($project_root, '', $path);
$path = ltrim($path, '/'); $path = ltrim($path, '/');
$event->add([$path]);
if ($event instanceof CollectIgnoredPathsEvent) {
$event->add([$path]);
}
else {
@trigger_error('Passing ' . get_class($event) . ' to ' . __METHOD__ . ' is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. See https://www.drupal.org/node/3317862.', E_USER_DEPRECATED);
$event->excludePath($path);
}
} }
} }
......
...@@ -20,23 +20,15 @@ class SiteConfigurationExcluder implements EventSubscriberInterface { ...@@ -20,23 +20,15 @@ class SiteConfigurationExcluder implements EventSubscriberInterface {
use PathExclusionsTrait; use PathExclusionsTrait;
/**
* The current site path, relative to the Drupal root.
*
* @var string
*/
protected $sitePath;
/** /**
* Constructs an ExcludedPathsSubscriber. * Constructs an ExcludedPathsSubscriber.
* *
* @param string $site_path * @param string $sitePath
* The current site path, relative to the Drupal root. * The current site path, relative to the Drupal root.
* @param \Drupal\package_manager\PathLocator $path_locator * @param \Drupal\package_manager\PathLocator $path_locator
* The path locator service. * The path locator service.
*/ */
public function __construct(string $site_path, PathLocator $path_locator) { public function __construct(protected string $sitePath, PathLocator $path_locator) {
$this->sitePath = $site_path;
$this->pathLocator = $path_locator; $this->pathLocator = $path_locator;
} }
......
...@@ -23,34 +23,18 @@ final class SiteFilesExcluder implements EventSubscriberInterface { ...@@ -23,34 +23,18 @@ final class SiteFilesExcluder implements EventSubscriberInterface {
use PathExclusionsTrait; use PathExclusionsTrait;
/**
* The stream wrapper manager service.
*
* @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface
*/
protected $streamWrapperManager;
/**
* The Symfony file system service.
*
* @var \Symfony\Component\Filesystem\Filesystem
*/
protected $fileSystem;
/** /**
* Constructs a SiteFilesExcluder object. * Constructs a SiteFilesExcluder object.
* *
* @param \Drupal\package_manager\PathLocator $path_locator * @param \Drupal\package_manager\PathLocator $path_locator
* The path locator service. * The path locator service.
* @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager * @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $streamWrapperManager
* The stream wrapper manager service. * The stream wrapper manager service.
* @param \Symfony\Component\Filesystem\Filesystem $file_system * @param \Symfony\Component\Filesystem\Filesystem $fileSystem
* The Symfony file system service. * The Symfony file system service.
*/ */
public function __construct(PathLocator $path_locator, StreamWrapperManagerInterface $stream_wrapper_manager, Filesystem $file_system) { public function __construct(PathLocator $path_locator, protected StreamWrapperManagerInterface $streamWrapperManager, protected Filesystem $fileSystem) {
$this->pathLocator = $path_locator; $this->pathLocator = $path_locator;
$this->streamWrapperManager = $stream_wrapper_manager;
$this->fileSystem = $file_system;
} }
/** /**
......
...@@ -21,13 +21,6 @@ class SqliteDatabaseExcluder implements EventSubscriberInterface { ...@@ -21,13 +21,6 @@ class SqliteDatabaseExcluder implements EventSubscriberInterface {
use PathExclusionsTrait; use PathExclusionsTrait;
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/** /**
* Constructs a SqliteDatabaseExcluder object. * Constructs a SqliteDatabaseExcluder object.
* *
...@@ -36,9 +29,8 @@ class SqliteDatabaseExcluder implements EventSubscriberInterface { ...@@ -36,9 +29,8 @@ class SqliteDatabaseExcluder implements EventSubscriberInterface {
* @param \Drupal\Core\Database\Connection $database * @param \Drupal\Core\Database\Connection $database
* The database connection. * The database connection.
*/ */
public function __construct(PathLocator $path_locator, Connection $database) { public function __construct(PathLocator $path_locator, protected Connection $database) {
$this->pathLocator = $path_locator; $this->pathLocator = $path_locator;
$this->database = $database;
} }
/** /**
......
...@@ -13,50 +13,21 @@ use Drupal\Core\File\FileSystemInterface; ...@@ -13,50 +13,21 @@ use Drupal\Core\File\FileSystemInterface;
*/ */
class PathLocator { class PathLocator {
/**
* The absolute path of the running Drupal code base.
*
* @var string
*/
protected $appRoot;
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The file system service.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/** /**
* Constructs a PathLocator object. * Constructs a PathLocator object.
* *
* @param string $app_root * @param string $appRoot
* The absolute path of the running Drupal code base. * The absolute path of the running Drupal code base.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The config factory service. * The config factory service.
* @param \Drupal\Core\File\FileSystemInterface $file_system * @param \Drupal\Core\File\FileSystemInterface $fileSystem
* The file system service. * The file system service.
*/ */
public function __construct(string $app_root, ConfigFactoryInterface $config_factory = NULL, FileSystemInterface $file_system = NULL) { public function __construct(
$this->appRoot = $app_root; protected string $appRoot,
if (empty($config_factory)) { protected ConfigFactoryInterface $configFactory,
@trigger_error('Calling ' . __METHOD__ . '() without the $config_factory argument is deprecated in automatic_updates:8.x-2.1 and will be required before automatic_updates:3.0.0. See https://www.drupal.org/node/3300008.', E_USER_DEPRECATED); protected FileSystemInterface $fileSystem,
$config_factory = \Drupal::configFactory(); ) {}
}
$this->configFactory = $config_factory;
if (empty($file_system)) {
@trigger_error('Calling ' . __METHOD__ . '() without the $file_system argument is deprecated in automatic_updates:8.x-2.1 and will be required before automatic_updates:3.0.0. See https://www.drupal.org/node/3300008.', E_USER_DEPRECATED);
$file_system = \Drupal::service('file_system');
}
$this->fileSystem = $file_system;
}
/** /**
* Returns the absolute path of the project root. * Returns the absolute path of the project root.
......
...@@ -29,32 +29,16 @@ final class ProcessFactory implements ProcessFactoryInterface { ...@@ -29,32 +29,16 @@ final class ProcessFactory implements ProcessFactoryInterface {
*/ */
private $decorated; private $decorated;
/**
* The file system service.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
private $fileSystem;
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
private $configFactory;
/** /**
* Constructs a ProcessFactory object. * Constructs a ProcessFactory object.
* *
* @param \Drupal\Core\File\FileSystemInterface $file_system * @param \Drupal\Core\File\FileSystemInterface $fileSystem
* The file system service. * The file system service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The config factory service. * The config factory service.
*/ */
public function __construct(FileSystemInterface $file_system, ConfigFactoryInterface $config_factory) { public function __construct(private FileSystemInterface $fileSystem, private ConfigFactoryInterface $configFactory) {
$this->decorated = new StagerProcessFactory(); $this->decorated = new StagerProcessFactory();
$this->fileSystem = $file_system;
$this->configFactory = $config_factory;
} }
/** /**
......
...@@ -21,21 +21,13 @@ use Drupal\update\UpdateManagerInterface; ...@@ -21,21 +21,13 @@ use Drupal\update\UpdateManagerInterface;
*/ */
final class ProjectInfo { final class ProjectInfo {
/**
* The project name.
*
* @var string
*/
protected $name;
/** /**
* Constructs a ProjectInfo object. * Constructs a ProjectInfo object.
* *
* @param string $name * @param string $name
* The project name. * The project name.
*/ */
public function __construct(string $name) { public function __construct(protected string $name) {
$this->name = $name;
} }
/** /**
......
...@@ -6,7 +6,6 @@ namespace Drupal\package_manager; ...@@ -6,7 +6,6 @@ namespace Drupal\package_manager;
use Drupal\Component\Datetime\TimeInterface; use Drupal\Component\Datetime\TimeInterface;
use Drupal\Component\Utility\Crypt; use Drupal\Component\Utility\Crypt;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\File\Exception\FileException; use Drupal\Core\File\Exception\FileException;
use Drupal\Core\File\FileSystemInterface; use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
...@@ -32,7 +31,6 @@ use PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface; ...@@ -32,7 +31,6 @@ use PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface;
use PhpTuf\ComposerStager\Domain\Core\Stager\StagerInterface; use PhpTuf\ComposerStager\Domain\Core\Stager\StagerInterface;
use PhpTuf\ComposerStager\Domain\Exception\InvalidArgumentException; use PhpTuf\ComposerStager\Domain\Exception\InvalidArgumentException;
use PhpTuf\ComposerStager\Domain\Exception\PreconditionException; use PhpTuf\ComposerStager\Domain\Exception\PreconditionException;
use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactory;
use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface; use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface;
use PhpTuf\ComposerStager\Infrastructure\Value\PathList\PathList; use PhpTuf\ComposerStager\Infrastructure\Value\PathList\PathList;
use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareInterface;
...@@ -74,14 +72,14 @@ class Stage implements LoggerAwareInterface { ...@@ -74,14 +72,14 @@ class Stage implements LoggerAwareInterface {
* *
* @var string * @var string
*/ */
protected const TEMPSTORE_LOCK_KEY = 'lock'; final protected const TEMPSTORE_LOCK_KEY = 'lock';
/** /**
* The tempstore key under which to store arbitrary metadata for this stage. * The tempstore key under which to store arbitrary metadata for this stage.
* *
* @var string * @var string
*/ */
protected const TEMPSTORE_METADATA_KEY = 'metadata'; final protected const TEMPSTORE_METADATA_KEY = 'metadata';
/** /**
* The tempstore key under which to store the path of stage root directory. * The tempstore key under which to store the path of stage root directory.
...@@ -122,83 +120,6 @@ class Stage implements LoggerAwareInterface { ...@@ -122,83 +120,6 @@ class Stage implements LoggerAwareInterface {
*/ */
private const TEMPSTORE_DESTROYED_STAGES_INFO_PREFIX = 'TEMPSTORE_DESTROYED_STAGES_INFO'; private const TEMPSTORE_DESTROYED_STAGES_INFO_PREFIX = 'TEMPSTORE_DESTROYED_STAGES_INFO';
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The path locator service.
*
* @var \Drupal\package_manager\PathLocator
*/
protected $pathLocator;
/**
* The beginner service.
*
* @var \PhpTuf\ComposerStager\Domain\Core\Beginner\BeginnerInterface
*/
protected $beginner;
/**
* The stager service.
*
* @var \PhpTuf\ComposerStager\Domain\Core\Stager\StagerInterface
*/
protected $stager;
/**
* The committer service.
*
* @var \PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface
*/
protected $committer;
/**
* The file system service.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/**
* The event dispatcher service.
*
* @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* The shared temp store factory.
*
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
*/
protected $tempStoreFactory;
/**
* The shared temp store.
*
* @var \Drupal\Core\TempStore\SharedTempStore
*/
protected $tempStore;
/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* The path factory service.
*
* @var \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface
*/
protected $pathFactory;
/** /**
* The lock info for the stage. * The lock info for the stage.
* *
...@@ -208,19 +129,10 @@ class Stage implements LoggerAwareInterface { ...@@ -208,19 +129,10 @@ class Stage implements LoggerAwareInterface {
*/ */
private $lock; private $lock;
/**
* The failure marker service.
*
* @var \Drupal\package_manager\FailureMarker
*/
protected $failureMarker;
/** /**
* Constructs a new Stage object. * Constructs a new Stage object.
* *
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * @param \Drupal\package_manager\PathLocator $pathLocator
* The config factory service.
* @param \Drupal\package_manager\PathLocator $path_locator
* The path locator service. * The path locator service.
* @param \PhpTuf\ComposerStager\Domain\Core\Beginner\BeginnerInterface $beginner * @param \PhpTuf\ComposerStager\Domain\Core\Beginner\BeginnerInterface $beginner
* The beginner service. * The beginner service.
...@@ -228,55 +140,33 @@ class Stage implements LoggerAwareInterface { ...@@ -228,55 +140,33 @@ class Stage implements LoggerAwareInterface {
* The stager service. * The stager service.
* @param \PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface $committer * @param \PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface $committer
* The committer service. * The committer service.
* @param \Drupal\Core\File\FileSystemInterface $file_system * @param \Drupal\Core\File\FileSystemInterface $fileSystem
* The file system service. * The file system service.
* @param \Symfony\Contracts\EventDispatcher\EventDispatcherInterface $event_dispatcher * @param \Symfony\Contracts\EventDispatcher\EventDispatcherInterface $eventDispatcher
* The event dispatcher service. * The event dispatcher service.
* @param \Drupal\Core\TempStore\SharedTempStoreFactory $temp_store_factory * @param \Drupal\Core\TempStore\SharedTempStoreFactory $tempStoreFactory
* The shared tempstore factory. * The shared tempstore factory.
* @param \Drupal\Component\Datetime\TimeInterface $time * @param \Drupal\Component\Datetime\TimeInterface $time
* The time service. * The time service.
* @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $path_factory * @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $pathFactory
* The path factory service. * The path factory service.
* @param \Drupal\package_manager\FailureMarker $failure_marker * @param \Drupal\package_manager\FailureMarker $failureMarker
* The failure marker service. * The failure marker service.
*/ */
public function __construct(ConfigFactoryInterface $config_factory, PathLocator $path_locator, BeginnerInterface $beginner, StagerInterface $stager, CommitterInterface $committer, FileSystemInterface $file_system, EventDispatcherInterface $event_dispatcher, SharedTempStoreFactory $temp_store_factory, TimeInterface $time, PathFactoryInterface $path_factory = NULL, FailureMarker $failure_marker = NULL) { public function __construct(
$this->configFactory = $config_factory; protected PathLocator $pathLocator,
$this->pathLocator = $path_locator; protected BeginnerInterface $beginner,
$this->beginner = $beginner; protected StagerInterface $stager,
$this->stager = $stager; protected CommitterInterface $committer,
$this->committer = $committer; protected FileSystemInterface $fileSystem,
$this->fileSystem = $file_system; protected EventDispatcherInterface $eventDispatcher,
$this->eventDispatcher = $event_dispatcher; protected SharedTempStoreFactory $tempStoreFactory,
$this->time = $time; protected TimeInterface $time,
$this->tempStoreFactory = $temp_store_factory; protected PathFactoryInterface $pathFactory,
$this->tempStore = $temp_store_factory->get('package_manager_stage'); protected FailureMarker $failureMarker,
if (!$config_factory instanceof UnusedConfigFactory) { ) {
// @todo Remove this in https://www.drupal.org/i/3303167 $this->tempStore = $tempStoreFactory->get('package_manager_stage');
@trigger_error('Calling ' . __METHOD__ . '() with the $config_factory argument is deprecated in automatic_updates:8.x-2.6 and will be removed in automatic_updates:3.0.0. See https://www.drupal.org/node/3325718.', E_USER_DEPRECATED);
}
if (empty($path_factory)) {
@trigger_error('Calling ' . __METHOD__ . '() without the $path_factory argument is deprecated in automatic_updates:8.x-2.3 and will be required before automatic_updates:3.0.0. See https://www.drupal.org/node/3310706.', E_USER_DEPRECATED);
$path_factory = new PathFactory();
}
$this->pathFactory = $path_factory;
if (empty($failure_marker)) {
@trigger_error('Calling ' . __METHOD__ . '() without the $failure_marker argument is deprecated in automatic_updates:8.x-2.3 and will be required before automatic_updates:3.0.0. See https://www.drupal.org/node/3311257.', E_USER_DEPRECATED);
$failure_marker = \Drupal::service('package_manager.failure_marker');
}
$this->failureMarker = $failure_marker;
$this->setLogger(new NullLogger()); $this->setLogger(new NullLogger());
if (self::TEMPSTORE_METADATA_KEY !== static::TEMPSTORE_METADATA_KEY) {
@trigger_error('Overriding ' . __CLASS__ . '::TEMPSTORE_METADATA_KEY is deprecated in automatic_updates:8.x-2.5 and will not be possible in automatic_updates:3.0.0. There is no replacement. See https://www.drupal.org/node/3317450.', E_USER_DEPRECATED);
\Drupal::logger('package_manager')
->error(__CLASS__ . '::TEMPSTORE_METADATA_KEY is overridden by ' . static::class . '. This is deprecated because it can cause errors or other unexpected behavior. It is strongly recommended to stop overriding this constant. See https://www.drupal.org/node/3317450 for more information.');
}
if (self::TEMPSTORE_LOCK_KEY !== static::TEMPSTORE_LOCK_KEY) {
@trigger_error('Overriding ' . __CLASS__ . '::TEMPSTORE_LOCK_KEY is deprecated in automatic_updates:8.x-2.5 and will not be possible in automatic_updates:3.0.0. There is no replacement. See https://www.drupal.org/node/3317450.', E_USER_DEPRECATED);
\Drupal::logger('package_manager')
->error(__CLASS__ . '::TEMPSTORE_LOCK_KEY is overridden by ' . static::class . '. This is deprecated because it can cause errors or other unexpected behavior. It is strongly recommended to stop overriding this constant. See https://www.drupal.org/node/3317450 for more information.');
}
} }
/** /**
...@@ -583,7 +473,7 @@ class Stage implements LoggerAwareInterface { ...@@ -583,7 +473,7 @@ class Stage implements LoggerAwareInterface {
$this->fileSystem->chmod($path, 0777); $this->fileSystem->chmod($path, 0777);
}); });
} }
catch (FileException $e) { catch (FileException) {
// Deliberately swallow the exception so that the stage will be marked // Deliberately swallow the exception so that the stage will be marked
// as available and the post-destroy event will be fired, even if the // as available and the post-destroy event will be fired, even if the
// stage directory can't actually be deleted. The file system service // stage directory can't actually be deleted. The file system service
......
...@@ -4,7 +4,6 @@ declare(strict_types = 1); ...@@ -4,7 +4,6 @@ declare(strict_types = 1);
namespace Drupal\package_manager; namespace Drupal\package_manager;
use Drupal\automatic_updates\Event\ReadinessCheckEvent;
use Drupal\package_manager\Event\CollectIgnoredPathsEvent; use Drupal\package_manager\Event\CollectIgnoredPathsEvent;
use Drupal\package_manager\Event\StatusCheckEvent; use Drupal\package_manager\Event\StatusCheckEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
...@@ -26,15 +25,12 @@ trait StatusCheckTrait { ...@@ -26,15 +25,12 @@ trait StatusCheckTrait {
* The stage to run the status check for. * The stage to run the status check for.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* (optional) The event dispatcher service. * (optional) The event dispatcher service.
* @param bool $do_readiness_check
* (optional) Whether to also Rerun readiness checks for the stage
* (deprecated). Defaults to FALSE.
* *
* @return \Drupal\package_manager\ValidationResult[] * @return \Drupal\package_manager\ValidationResult[]
* The results of the status check. If a readiness check was also done, * The results of the status check. If a readiness check was also done,
* its results will be included. * its results will be included.
*/ */
protected function runStatusCheck(Stage $stage, EventDispatcherInterface $event_dispatcher = NULL, bool $do_readiness_check = FALSE): array { protected function runStatusCheck(Stage $stage, EventDispatcherInterface $event_dispatcher = NULL): array {
$event_dispatcher ??= \Drupal::service('event_dispatcher'); $event_dispatcher ??= \Drupal::service('event_dispatcher');
try { try {
$ignored_paths = new CollectIgnoredPathsEvent($stage); $ignored_paths = new CollectIgnoredPathsEvent($stage);
...@@ -47,14 +43,7 @@ trait StatusCheckTrait { ...@@ -47,14 +43,7 @@ trait StatusCheckTrait {
$event = new StatusCheckEvent($stage, $ignored_paths->getAll()); $event = new StatusCheckEvent($stage, $ignored_paths->getAll());
$event_dispatcher->dispatch($event); $event_dispatcher->dispatch($event);
$results = $event->getResults(); return $event->getResults();
if ($do_readiness_check && class_exists(ReadinessCheckEvent::class) && $event_dispatcher->hasListeners(ReadinessCheckEvent::class)) {
$event = new ReadinessCheckEvent($stage);
$event_dispatcher->dispatch($event);
$results = array_merge($results, $event->getResults());
}
return $results;
} }
} }
<?php
declare(strict_types = 1);
namespace Drupal\package_manager;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
/**
* Dummy Class.
*
* @internal
*
* @todo Remove this in https://www.drupal.org/i/3303167
*/
final class UnusedConfigFactory implements ConfigFactoryInterface {
/**
* {@inheritdoc}
*/
public function get($name) {
throw new \LogicException();
}
/**
* {@inheritdoc}
*/
public function getEditable($name) {
throw new \LogicException();
}
/**
* {@inheritdoc}
*/
public function loadMultiple(array $names) {
throw new \LogicException();
}
/**
* {@inheritdoc}
*/
public function reset($name = NULL) {
throw new \LogicException();
}
/**
* {@inheritdoc}
*/
public function rename($old_name, $new_name) {
throw new \LogicException();
}
/**
* {@inheritdoc}
*/
public function getCacheKeys() {
throw new \LogicException();
}
/**
* {@inheritdoc}
*/
public function clearStaticCache() {
throw new \LogicException();
}
/**
* {@inheritdoc}
*/
public function listAll($prefix = '') {
throw new \LogicException();
}
/**
* {@inheritdoc}
*/
public function addOverride(ConfigFactoryOverrideInterface $config_factory_override) {
throw new \LogicException();
}
}
...@@ -12,27 +12,6 @@ use Drupal\system\SystemManager; ...@@ -12,27 +12,6 @@ use Drupal\system\SystemManager;
*/ */
final class ValidationResult { final class ValidationResult {
/**
* A succinct summary of the results.
*
* @var \Drupal\Core\StringTranslation\TranslatableMarkup
*/
protected $summary;
/**
* The error messages.
*
* @var \Drupal\Core\StringTranslation\TranslatableMarkup[]|string[]
*/
protected $messages;
/**
* The severity of the result.
*
* @var int
*/
protected $severity;
/** /**
* Creates a ValidationResult object. * Creates a ValidationResult object.
* *
...@@ -44,16 +23,13 @@ final class ValidationResult { ...@@ -44,16 +23,13 @@ final class ValidationResult {
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $summary * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $summary
* The errors summary. * The errors summary.
*/ */
private function __construct(int $severity, array $messages, ?TranslatableMarkup $summary = NULL) { private function __construct(protected int $severity, protected array $messages, protected ?TranslatableMarkup $summary = NULL) {
if (empty($messages)) { if (empty($messages)) {
throw new \InvalidArgumentException('At least one message is required.'); throw new \InvalidArgumentException('At least one message is required.');
} }
if (count($messages) > 1 && !$summary) { if (count($messages) > 1 && !$summary) {
throw new \InvalidArgumentException('If more than one message is provided, a summary is required.'); throw new \InvalidArgumentException('If more than one message is provided, a summary is required.');
} }
$this->summary = $summary;
$this->messages = $messages;
$this->severity = $severity;
} }
/** /**
......
...@@ -11,7 +11,6 @@ use Drupal\package_manager\Event\PreApplyEvent; ...@@ -11,7 +11,6 @@ use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\PreOperationStageEvent; use Drupal\package_manager\Event\PreOperationStageEvent;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\package_manager\Event\StatusCheckEvent; use Drupal\package_manager\Event\StatusCheckEvent;
use PhpTuf\ComposerStager\Domain\Exception\ExceptionInterface; use PhpTuf\ComposerStager\Domain\Exception\ExceptionInterface;
use PhpTuf\ComposerStager\Domain\Exception\PreconditionException; use PhpTuf\ComposerStager\Domain\Exception\PreconditionException;
...@@ -40,55 +39,24 @@ class ComposerExecutableValidator implements EventSubscriberInterface { ...@@ -40,55 +39,24 @@ class ComposerExecutableValidator implements EventSubscriberInterface {
*/ */
public const MINIMUM_COMPOSER_VERSION_CONSTRAINT = '~2.2.12 || ^2.3.5'; public const MINIMUM_COMPOSER_VERSION_CONSTRAINT = '~2.2.12 || ^2.3.5';
/**
* The Composer runner.
*
* @var \PhpTuf\ComposerStager\Domain\Service\ProcessRunner\ComposerRunnerInterface
*/
protected $composer;
/**
* The "Composer is available" precondition service.
*
* @var \PhpTuf\ComposerStager\Domain\Service\Precondition\ComposerIsAvailableInterface
*/
protected $composerIsAvailable;
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The path factory service.
*
* @var \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface
*/
protected $pathFactory;
/** /**
* Constructs a ComposerExecutableValidator object. * Constructs a ComposerExecutableValidator object.
* *
* @param \PhpTuf\ComposerStager\Domain\Service\ProcessRunner\ComposerRunnerInterface $composer * @param \PhpTuf\ComposerStager\Domain\Service\ProcessRunner\ComposerRunnerInterface $composer
* The Composer runner. * The Composer runner.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* The module handler service. * The module handler service.
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation * @param \PhpTuf\ComposerStager\Domain\Service\Precondition\ComposerIsAvailableInterface $composerIsAvailable
* The translation service.
* @param \PhpTuf\ComposerStager\Domain\Service\Precondition\ComposerIsAvailableInterface $composer_is_available
* The "Composer is available" precondition service. * The "Composer is available" precondition service.
* @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $path_factory * @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $pathFactory
* The path factory service. * The path factory service.
*/ */
public function __construct(ComposerRunnerInterface $composer, ModuleHandlerInterface $module_handler, TranslationInterface $translation, ComposerIsAvailableInterface $composer_is_available, PathFactoryInterface $path_factory) { public function __construct(
$this->composer = $composer; protected ComposerRunnerInterface $composer,
$this->moduleHandler = $module_handler; protected ModuleHandlerInterface $moduleHandler,
$this->setStringTranslation($translation); protected ComposerIsAvailableInterface $composerIsAvailable,
$this->composerIsAvailable = $composer_is_available; protected PathFactoryInterface $pathFactory,
$this->pathFactory = $path_factory; ) {}
}
/** /**
* {@inheritdoc} * {@inheritdoc}
......
...@@ -5,7 +5,6 @@ declare(strict_types = 1); ...@@ -5,7 +5,6 @@ declare(strict_types = 1);
namespace Drupal\package_manager\Validator; namespace Drupal\package_manager\Validator;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreApplyEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreCreateEvent;
...@@ -25,24 +24,13 @@ final class ComposerJsonExistsValidator implements EventSubscriberInterface { ...@@ -25,24 +24,13 @@ final class ComposerJsonExistsValidator implements EventSubscriberInterface {
use StringTranslationTrait; use StringTranslationTrait;
/**
* The path locator service.
*
* @var \Drupal\package_manager\PathLocator
*/
protected $pathLocator;
/** /**
* Constructs a ComposerJsonExistsValidator object. * Constructs a ComposerJsonExistsValidator object.
* *
* @param \Drupal\package_manager\PathLocator $path_locator * @param \Drupal\package_manager\PathLocator $pathLocator
* The path locator service. * The path locator service.
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation
* The string translation service.
*/ */
public function __construct(PathLocator $path_locator, TranslationInterface $translation) { public function __construct(protected PathLocator $pathLocator) {
$this->pathLocator = $path_locator;
$this->setStringTranslation($translation);
} }
/** /**
......
...@@ -24,31 +24,15 @@ final class ComposerMinimumStabilityValidator implements EventSubscriberInterfac ...@@ -24,31 +24,15 @@ final class ComposerMinimumStabilityValidator implements EventSubscriberInterfac
use StringTranslationTrait; use StringTranslationTrait;
/**
* The path locator service.
*
* @var \Drupal\package_manager\PathLocator
*/
protected PathLocator $pathLocator;
/**
* The Composer inspector service.
*
* @var \Drupal\package_manager\ComposerInspector
*/
protected ComposerInspector $inspector;
/** /**
* Constructs a ComposerMinimumStabilityValidator object. * Constructs a ComposerMinimumStabilityValidator object.
* *
* @param \Drupal\package_manager\PathLocator $path_locator * @param \Drupal\package_manager\PathLocator $pathLocator
* The path locator service. * The path locator service.
* @param \Drupal\package_manager\ComposerInspector $inspector * @param \Drupal\package_manager\ComposerInspector $inspector
* The Composer inspector service. * The Composer inspector service.
*/ */
public function __construct(PathLocator $path_locator, ComposerInspector $inspector) { public function __construct(protected PathLocator $pathLocator, protected ComposerInspector $inspector) {
$this->pathLocator = $path_locator;
$this->inspector = $inspector;
} }
/** /**
......
...@@ -45,21 +45,13 @@ final class ComposerPatchesValidator implements EventSubscriberInterface { ...@@ -45,21 +45,13 @@ final class ComposerPatchesValidator implements EventSubscriberInterface {
*/ */
private const PLUGIN_NAME = 'cweagans/composer-patches'; private const PLUGIN_NAME = 'cweagans/composer-patches';
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
private ModuleHandlerInterface $moduleHandler;
/** /**
* Constructs a ComposerPatchesValidator object. * Constructs a ComposerPatchesValidator object.
* *
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* The module handler service. * The module handler service.
*/ */
public function __construct(ModuleHandlerInterface $module_handler) { public function __construct(private ModuleHandlerInterface $moduleHandler) {
$this->moduleHandler = $module_handler;
} }
/** /**
...@@ -77,7 +69,7 @@ final class ComposerPatchesValidator implements EventSubscriberInterface { ...@@ -77,7 +69,7 @@ final class ComposerPatchesValidator implements EventSubscriberInterface {
[$plugin_installed_in_stage, $is_stage_root_requirement, $stage_configuration_ok] = $this->computePatcherStatus($stage->getStageComposer()); [$plugin_installed_in_stage, $is_stage_root_requirement, $stage_configuration_ok] = $this->computePatcherStatus($stage->getStageComposer());
$has_staged_update = TRUE; $has_staged_update = TRUE;
} }
catch (\LogicException $e) { catch (\LogicException) {
// No staged update exists. // No staged update exists.
$has_staged_update = FALSE; $has_staged_update = FALSE;
} }
......
...@@ -99,20 +99,6 @@ final class ComposerPluginsValidator implements EventSubscriberInterface { ...@@ -99,20 +99,6 @@ final class ComposerPluginsValidator implements EventSubscriberInterface {
*/ */
protected array $additionalTrustedComposerPlugins; protected array $additionalTrustedComposerPlugins;
/**
* The Composer inspector service.
*
* @var \Drupal\package_manager\ComposerInspector
*/
protected ComposerInspector $inspector;
/**
* The path locator service.
*
* @var \Drupal\package_manager\PathLocator
*/
protected PathLocator $pathLocator;
/** /**
* Constructs a new ComposerPluginsValidator. * Constructs a new ComposerPluginsValidator.
* *
...@@ -120,17 +106,19 @@ final class ComposerPluginsValidator implements EventSubscriberInterface { ...@@ -120,17 +106,19 @@ final class ComposerPluginsValidator implements EventSubscriberInterface {
* The config factory. * The config factory.
* @param \Drupal\package_manager\ComposerInspector $inspector * @param \Drupal\package_manager\ComposerInspector $inspector
* The Composer inspector service. * The Composer inspector service.
* @param \Drupal\package_manager\PathLocator $path_locator * @param \Drupal\package_manager\PathLocator $pathLocator
* The path locator service. * The path locator service.
*/ */
public function __construct(ConfigFactoryInterface $config_factory, ComposerInspector $inspector, PathLocator $path_locator) { public function __construct(
ConfigFactoryInterface $config_factory,
protected ComposerInspector $inspector,
protected PathLocator $pathLocator,
) {
$settings = $config_factory->get('package_manager.settings'); $settings = $config_factory->get('package_manager.settings');
$this->additionalTrustedComposerPlugins = array_map( $this->additionalTrustedComposerPlugins = array_map(
[__CLASS__, 'normalizePackageName'], [__CLASS__, 'normalizePackageName'],
$settings->get('additional_trusted_composer_plugins') $settings->get('additional_trusted_composer_plugins')
); );
$this->inspector = $inspector;
$this->pathLocator = $path_locator;
} }
/** /**
......
...@@ -5,7 +5,6 @@ declare(strict_types = 1); ...@@ -5,7 +5,6 @@ declare(strict_types = 1);
namespace Drupal\package_manager\Validator; namespace Drupal\package_manager\Validator;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\package_manager\ComposerInspector; use Drupal\package_manager\ComposerInspector;
use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreCreateEvent;
...@@ -26,34 +25,15 @@ final class ComposerSettingsValidator implements EventSubscriberInterface { ...@@ -26,34 +25,15 @@ final class ComposerSettingsValidator implements EventSubscriberInterface {
use StringTranslationTrait; use StringTranslationTrait;
/**
* The Composer inspector service.
*
* @var \Drupal\package_manager\ComposerInspector
*/
protected ComposerInspector $inspector;
/**
* The path locator service.
*
* @var \Drupal\package_manager\PathLocator
*/
protected PathLocator $pathLocator;
/** /**
* Constructs a ComposerSettingsValidator object. * Constructs a ComposerSettingsValidator object.
* *
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation
* The string translation service.
* @param \Drupal\package_manager\ComposerInspector $inspector * @param \Drupal\package_manager\ComposerInspector $inspector
* The Composer inspector service. * The Composer inspector service.
* @param \Drupal\package_manager\PathLocator $path_locator * @param \Drupal\package_manager\PathLocator $pathLocator
* The path locator service. * The path locator service.
*/ */
public function __construct(TranslationInterface $translation, ComposerInspector $inspector, PathLocator $path_locator) { public function __construct(protected ComposerInspector $inspector, protected PathLocator $pathLocator) {
$this->setStringTranslation($translation);
$this->inspector = $inspector;
$this->pathLocator = $path_locator;
} }
/** /**
......
...@@ -10,7 +10,6 @@ use Drupal\package_manager\Event\PreOperationStageEvent; ...@@ -10,7 +10,6 @@ use Drupal\package_manager\Event\PreOperationStageEvent;
use Drupal\Component\FileSystem\FileSystem; use Drupal\Component\FileSystem\FileSystem;
use Drupal\Component\Utility\Bytes; use Drupal\Component\Utility\Bytes;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\package_manager\Event\StatusCheckEvent; use Drupal\package_manager\Event\StatusCheckEvent;
use Drupal\package_manager\PathLocator; use Drupal\package_manager\PathLocator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
...@@ -27,24 +26,13 @@ class DiskSpaceValidator implements EventSubscriberInterface { ...@@ -27,24 +26,13 @@ class DiskSpaceValidator implements EventSubscriberInterface {
use StringTranslationTrait; use StringTranslationTrait;
/**
* The path locator service.
*
* @var \Drupal\package_manager\PathLocator
*/
protected $pathLocator;
/** /**
* Constructs a DiskSpaceValidator object. * Constructs a DiskSpaceValidator object.
* *
* @param \Drupal\package_manager\PathLocator $path_locator * @param \Drupal\package_manager\PathLocator $pathLocator
* The path locator service. * The path locator service.
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation
* The translation service.
*/ */
public function __construct(PathLocator $path_locator, TranslationInterface $translation) { public function __construct(protected PathLocator $pathLocator) {
$this->pathLocator = $path_locator;
$this->setStringTranslation($translation);
} }
/** /**
......
...@@ -22,21 +22,13 @@ class DuplicateInfoFileValidator implements EventSubscriberInterface { ...@@ -22,21 +22,13 @@ class DuplicateInfoFileValidator implements EventSubscriberInterface {
use StringTranslationTrait; use StringTranslationTrait;
/**
* The path locator service.
*
* @var \Drupal\package_manager\PathLocator
*/
protected $pathLocator;
/** /**
* Constructs a DuplicateInfoFileValidator object. * Constructs a DuplicateInfoFileValidator object.
* *
* @param \Drupal\package_manager\PathLocator $path_locator * @param \Drupal\package_manager\PathLocator $pathLocator
* The path locator service. * The path locator service.
*/ */
public function __construct(PathLocator $path_locator) { public function __construct(protected PathLocator $pathLocator) {
$this->pathLocator = $path_locator;
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment