From f629a4187d5e4ca8049bdcfe664524b13fbc3669 Mon Sep 17 00:00:00 2001 From: Wim Leers <44946-wimleers@users.noreply.drupalcode.org> Date: Tue, 28 Mar 2023 15:00:27 +0000 Subject: [PATCH] =?UTF-8?q?Issue=20#3348122=20by=20yash.rode,=20Wim=20Leer?= =?UTF-8?q?s,=20phenaproxima:=20Autowire=20everything=20everywhere=20all?= =?UTF-8?q?=20at=20once=20=E2=80=A6=20in=20*.services.yml=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- automatic_updates.services.yml | 63 ++----------------- .../automatic_updates_extensions.services.yml | 12 ---- .../src/ExtensionUpdater.php | 48 ++++++++++++-- package_manager/package_manager.services.yml | 4 ++ package_manager/src/StatusCheckTrait.php | 4 +- src/CronUpdater.php | 49 +++++++++++++-- src/Updater.php | 48 ++++++++++++-- src/Validation/StatusChecker.php | 4 +- 8 files changed, 147 insertions(+), 85 deletions(-) diff --git a/automatic_updates.services.yml b/automatic_updates.services.yml index 808ae6e7af..4d07d4d0cc 100644 --- a/automatic_updates.services.yml +++ b/automatic_updates.services.yml @@ -9,57 +9,22 @@ services: automatic_updates.status_checker: class: Drupal\automatic_updates\Validation\StatusChecker arguments: - - '@keyvalue.expirable' - - '@datetime.time' - - '@event_dispatcher' - - '@automatic_updates.updater' - - '@automatic_updates.cron_updater' - - 24 + # @todo Remove this when https://drupal.org/i/3325557 lands. + $key_value_expirable_factory: '@keyvalue.expirable' + $resultsTimeToLive: 24 tags: - { name: event_subscriber } Drupal\automatic_updates\Validation\StatusChecker: '@automatic_updates.status_checker' automatic_updates.status_check_mailer: class: Drupal\automatic_updates\StatusCheckMailer - arguments: - - '@config.factory' - - '@plugin.manager.mail' - - '@language_manager' + Drupal\automatic_updates\StatusCheckMailer: '@automatic_updates.status_check_mailer' automatic_updates.updater: class: Drupal\automatic_updates\Updater - arguments: - - '@package_manager.composer_inspector' - - '@package_manager.path_locator' - - '@package_manager.beginner' - - '@package_manager.stager' - - '@package_manager.committer' - - '@file_system' - - '@event_dispatcher' - - '@tempstore.shared' - - '@datetime.time' - - '@PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface' - - '@package_manager.failure_marker' calls: - ['setLogger', ['@logger.channel.automatic_updates']] Drupal\automatic_updates\Updater: '@automatic_updates.updater' automatic_updates.cron_updater: class: Drupal\automatic_updates\CronUpdater - arguments: - - '@automatic_updates.release_chooser' - - '@plugin.manager.mail' - - '@automatic_updates.status_check_mailer' - - '@state' - - '@config.factory' - - '@package_manager.composer_inspector' - - '@package_manager.path_locator' - - '@package_manager.beginner' - - '@package_manager.stager' - - '@package_manager.committer' - - '@file_system' - - '@event_dispatcher' - - '@tempstore.shared' - - '@datetime.time' - - '@PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface' - - '@package_manager.failure_marker' calls: - ['setLogger', ['@logger.channel.automatic_updates']] Drupal\automatic_updates\CronUpdater: '@automatic_updates.cron_updater' @@ -69,9 +34,6 @@ services: - { name: event_subscriber } automatic_updates.staged_projects_validator: class: Drupal\automatic_updates\Validator\StagedProjectsValidator - arguments: - - '@package_manager.path_locator' - - '@package_manager.composer_inspector' tags: - { name: event_subscriber } Drupal\automatic_updates\Validator\StagedProjectsValidator: '@automatic_updates.staged_projects_validator' @@ -83,29 +45,20 @@ services: automatic_updates.cron_frequency_validator: class: Drupal\automatic_updates\Validator\CronFrequencyValidator arguments: - - '@config.factory' - - '@module_handler' - - '@state' - - '@datetime.time' - - '@automatic_updates.cron_updater' - - '@lock' + $lock: '@lock' tags: - { name: event_subscriber } automatic_updates.validator.staged_database_updates: class: Drupal\automatic_updates\Validator\StagedDatabaseUpdateValidator - arguments: - - '@package_manager.validator.staged_database_updates' tags: - { name: event_subscriber } automatic_updates.validator.version_policy: class: Drupal\automatic_updates\Validator\VersionPolicyValidator - autowire: true tags: - { name: event_subscriber } + Drupal\automatic_updates\Validator\VersionPolicyValidator: '@automatic_updates.validator.version_policy' automatic_updates.config_subscriber: class: Drupal\automatic_updates\EventSubscriber\ConfigSubscriber - arguments: - - '@automatic_updates.status_checker' tags: - { name: event_subscriber } automatic_updates.validator.scaffold_file_permissions: @@ -115,10 +68,6 @@ services: Drupal\automatic_updates\Validator\ScaffoldFilePermissionsValidator: '@automatic_updates.validator.scaffold_file_permissions' automatic_updates.validator.cron_server: class: Drupal\automatic_updates\Validator\CronServerValidator - arguments: - - '@request_stack' - - '@config.factory' - - '@module_handler' tags: - { name: event_subscriber } logger.channel.automatic_updates: diff --git a/automatic_updates_extensions/automatic_updates_extensions.services.yml b/automatic_updates_extensions/automatic_updates_extensions.services.yml index 7c40972b38..45cfaa4c16 100644 --- a/automatic_updates_extensions/automatic_updates_extensions.services.yml +++ b/automatic_updates_extensions/automatic_updates_extensions.services.yml @@ -4,18 +4,6 @@ services: automatic_updates_extensions.updater: class: Drupal\automatic_updates_extensions\ExtensionUpdater - arguments: - - '@package_manager.composer_inspector' - - '@package_manager.path_locator' - - '@package_manager.beginner' - - '@package_manager.stager' - - '@package_manager.committer' - - '@file_system' - - '@event_dispatcher' - - '@tempstore.shared' - - '@datetime.time' - - '@PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface' - - '@package_manager.failure_marker' Drupal\automatic_updates_extensions\ExtensionUpdater: '@automatic_updates_extensions.updater' automatic_updates_extensions.validator.target_release: class: Drupal\automatic_updates_extensions\Validator\UpdateReleaseValidator diff --git a/automatic_updates_extensions/src/ExtensionUpdater.php b/automatic_updates_extensions/src/ExtensionUpdater.php index fc3813f67f..aebb4718f6 100644 --- a/automatic_updates_extensions/src/ExtensionUpdater.php +++ b/automatic_updates_extensions/src/ExtensionUpdater.php @@ -4,10 +4,20 @@ declare(strict_types = 1); namespace Drupal\automatic_updates_extensions; +use Drupal\Component\Datetime\TimeInterface; +use Drupal\Core\File\FileSystemInterface; use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\Core\TempStore\SharedTempStoreFactory; use Drupal\package_manager\ComposerInspector; +use Drupal\package_manager\FailureMarker; use Drupal\package_manager\LegacyVersionUtility; +use Drupal\package_manager\PathLocator; use Drupal\package_manager\Stage; +use PhpTuf\ComposerStager\Domain\Core\Beginner\BeginnerInterface; +use PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface; +use PhpTuf\ComposerStager\Domain\Core\Stager\StagerInterface; +use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * Defines a service to perform updates for modules and themes. @@ -23,11 +33,41 @@ class ExtensionUpdater extends Stage { * * @param \Drupal\package_manager\ComposerInspector $composerInspector * The Composer inspector service. - * @param mixed ...$arguments - * Additional arguments to pass to the parent constructor. + * @param \Drupal\package_manager\PathLocator $pathLocator + * The path locator service. + * @param \PhpTuf\ComposerStager\Domain\Core\Beginner\BeginnerInterface $beginner + * The beginner service. + * @param \PhpTuf\ComposerStager\Domain\Core\Stager\StagerInterface $stager + * The stager service. + * @param \PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface $committer + * The committer service. + * @param \Drupal\Core\File\FileSystemInterface $fileSystem + * The file system service. + * @param \Symfony\Contracts\EventDispatcher\EventDispatcherInterface $eventDispatcher + * The event dispatcher service. + * @param \Drupal\Core\TempStore\SharedTempStoreFactory $tempStoreFactory + * The shared tempstore factory. + * @param \Drupal\Component\Datetime\TimeInterface $time + * The time service. + * @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $pathFactory + * The path factory service. + * @param \Drupal\package_manager\FailureMarker $failureMarker + * The failure marker service. */ - public function __construct(protected ComposerInspector $composerInspector, mixed ...$arguments) { - parent::__construct(...$arguments); + public function __construct( + protected ComposerInspector $composerInspector, + PathLocator $pathLocator, + BeginnerInterface $beginner, + StagerInterface $stager, + CommitterInterface $committer, + FileSystemInterface $fileSystem, + EventDispatcherInterface $eventDispatcher, + SharedTempStoreFactory $tempStoreFactory, + TimeInterface $time, + PathFactoryInterface $pathFactory, + FailureMarker $failureMarker, + ) { + parent::__construct($pathLocator, $beginner, $stager, $committer, $fileSystem, $eventDispatcher, $tempStoreFactory, $time, $pathFactory, $failureMarker); } /** diff --git a/package_manager/package_manager.services.yml b/package_manager/package_manager.services.yml index 04eedd84d0..dc1a3c984d 100644 --- a/package_manager/package_manager.services.yml +++ b/package_manager/package_manager.services.yml @@ -26,10 +26,13 @@ services: # Services provided to Drupal by Package Manager. package_manager.beginner: class: PhpTuf\ComposerStager\Domain\Core\Beginner\Beginner + PhpTuf\ComposerStager\Domain\Core\Beginner\BeginnerInterface: '@package_manager.beginner' package_manager.stager: class: PhpTuf\ComposerStager\Domain\Core\Stager\Stager + PhpTuf\ComposerStager\Domain\Core\Stager\StagerInterface: '@package_manager.stager' package_manager.committer: class: PhpTuf\ComposerStager\Domain\Core\Committer\Committer + PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface: '@package_manager.committer' package_manager.path_locator: class: Drupal\package_manager\PathLocator arguments: @@ -115,6 +118,7 @@ services: class: Drupal\package_manager\Validator\StagedDBUpdateValidator tags: - { name: event_subscriber } + Drupal\package_manager\Validator\StagedDBUpdateValidator: '@package_manager.validator.staged_database_updates' package_manager.test_site_excluder: class: Drupal\package_manager\PathExcluder\TestSiteExcluder tags: diff --git a/package_manager/src/StatusCheckTrait.php b/package_manager/src/StatusCheckTrait.php index 5c1da0eac2..78e585b1d1 100644 --- a/package_manager/src/StatusCheckTrait.php +++ b/package_manager/src/StatusCheckTrait.php @@ -6,7 +6,7 @@ namespace Drupal\package_manager; use Drupal\package_manager\Event\CollectIgnoredPathsEvent; use Drupal\package_manager\Event\StatusCheckEvent; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * Contains helper methods to run status checks on a stage. @@ -23,7 +23,7 @@ trait StatusCheckTrait { * * @param \Drupal\package_manager\Stage $stage * The stage to run the status check for. - * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher + * @param \Symfony\Contracts\EventDispatcher\EventDispatcherInterface $event_dispatcher * (optional) The event dispatcher service. * * @return \Drupal\package_manager\ValidationResult[] diff --git a/src/CronUpdater.php b/src/CronUpdater.php index e3624b7bbb..982e0c575e 100644 --- a/src/CronUpdater.php +++ b/src/CronUpdater.php @@ -4,16 +4,27 @@ declare(strict_types = 1); namespace Drupal\automatic_updates; +use Drupal\Component\Datetime\TimeInterface; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Mail\MailManagerInterface; use Drupal\Core\State\StateInterface; +use Drupal\Core\TempStore\SharedTempStoreFactory; use Drupal\Core\Url; +use Drupal\package_manager\ComposerInspector; use Drupal\package_manager\Exception\ApplyFailedException; use Drupal\package_manager\Exception\StageEventException; +use Drupal\package_manager\FailureMarker; +use Drupal\package_manager\PathLocator; use Drupal\package_manager\ProjectInfo; use Drupal\update\ProjectRelease; use GuzzleHttp\Psr7\Uri as GuzzleUri; +use PhpTuf\ComposerStager\Domain\Core\Beginner\BeginnerInterface; +use PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface; +use PhpTuf\ComposerStager\Domain\Core\Stager\StagerInterface; +use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface; use Symfony\Component\HttpFoundation\Response; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * Defines a service that updates via cron. @@ -60,8 +71,28 @@ class CronUpdater extends Updater { * The state service. * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory * The config factory service. - * @param mixed ...$arguments - * Additional arguments to pass to the parent constructor. + * @param \Drupal\package_manager\ComposerInspector $composerInspector + * The Composer inspector service. + * @param \Drupal\package_manager\PathLocator $pathLocator + * The path locator service. + * @param \PhpTuf\ComposerStager\Domain\Core\Beginner\BeginnerInterface $beginner + * The beginner service. + * @param \PhpTuf\ComposerStager\Domain\Core\Stager\StagerInterface $stager + * The stager service. + * @param \PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface $committer + * The committer service. + * @param \Drupal\Core\File\FileSystemInterface $fileSystem + * The file system service. + * @param \Symfony\Contracts\EventDispatcher\EventDispatcherInterface $eventDispatcher + * The event dispatcher service. + * @param \Drupal\Core\TempStore\SharedTempStoreFactory $tempStoreFactory + * The shared tempstore factory. + * @param \Drupal\Component\Datetime\TimeInterface $time + * The time service. + * @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $pathFactory + * The path factory service. + * @param \Drupal\package_manager\FailureMarker $failureMarker + * The failure marker service. */ public function __construct( protected ReleaseChooser $releaseChooser, @@ -69,9 +100,19 @@ class CronUpdater extends Updater { protected StatusCheckMailer $statusCheckMailer, protected StateInterface $state, protected ConfigFactoryInterface $configFactory, - mixed ...$arguments, + ComposerInspector $composerInspector, + PathLocator $pathLocator, + BeginnerInterface $beginner, + StagerInterface $stager, + CommitterInterface $committer, + FileSystemInterface $fileSystem, + EventDispatcherInterface $eventDispatcher, + SharedTempStoreFactory $tempStoreFactory, + TimeInterface $time, + PathFactoryInterface $pathFactory, + FailureMarker $failureMarker, ) { - parent::__construct(...$arguments); + parent::__construct($composerInspector, $pathLocator, $beginner, $stager, $committer, $fileSystem, $eventDispatcher, $tempStoreFactory, $time, $pathFactory, $failureMarker); } /** diff --git a/src/Updater.php b/src/Updater.php index bb08bb525a..d1c47a80cc 100644 --- a/src/Updater.php +++ b/src/Updater.php @@ -4,9 +4,19 @@ declare(strict_types = 1); namespace Drupal\automatic_updates; +use Drupal\Component\Datetime\TimeInterface; +use Drupal\Core\File\FileSystemInterface; use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\Core\TempStore\SharedTempStoreFactory; use Drupal\package_manager\ComposerInspector; +use Drupal\package_manager\FailureMarker; +use Drupal\package_manager\PathLocator; use Drupal\package_manager\Stage; +use PhpTuf\ComposerStager\Domain\Core\Beginner\BeginnerInterface; +use PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface; +use PhpTuf\ComposerStager\Domain\Core\Stager\StagerInterface; +use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * Defines a service to perform updates. @@ -23,11 +33,41 @@ class Updater extends Stage { * * @param \Drupal\package_manager\ComposerInspector $composerInspector * The Composer inspector service. - * @param mixed ...$arguments - * Additional arguments to pass to the parent constructor. + * @param \Drupal\package_manager\PathLocator $pathLocator + * The path locator service. + * @param \PhpTuf\ComposerStager\Domain\Core\Beginner\BeginnerInterface $beginner + * The beginner service. + * @param \PhpTuf\ComposerStager\Domain\Core\Stager\StagerInterface $stager + * The stager service. + * @param \PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface $committer + * The committer service. + * @param \Drupal\Core\File\FileSystemInterface $fileSystem + * The file system service. + * @param \Symfony\Contracts\EventDispatcher\EventDispatcherInterface $eventDispatcher + * The event dispatcher service. + * @param \Drupal\Core\TempStore\SharedTempStoreFactory $tempStoreFactory + * The shared tempstore factory. + * @param \Drupal\Component\Datetime\TimeInterface $time + * The time service. + * @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $pathFactory + * The path factory service. + * @param \Drupal\package_manager\FailureMarker $failureMarker + * The failure marker service. */ - public function __construct(protected ComposerInspector $composerInspector, mixed ...$arguments) { - parent::__construct(...$arguments); + public function __construct( + protected ComposerInspector $composerInspector, + PathLocator $pathLocator, + BeginnerInterface $beginner, + StagerInterface $stager, + CommitterInterface $committer, + FileSystemInterface $fileSystem, + EventDispatcherInterface $eventDispatcher, + SharedTempStoreFactory $tempStoreFactory, + TimeInterface $time, + PathFactoryInterface $pathFactory, + FailureMarker $failureMarker, + ) { + parent::__construct($pathLocator, $beginner, $stager, $committer, $fileSystem, $eventDispatcher, $tempStoreFactory, $time, $pathFactory, $failureMarker); } /** diff --git a/src/Validation/StatusChecker.php b/src/Validation/StatusChecker.php index c98f561c20..366c7e4437 100644 --- a/src/Validation/StatusChecker.php +++ b/src/Validation/StatusChecker.php @@ -10,7 +10,7 @@ use Drupal\automatic_updates\Updater; use Drupal\Component\Datetime\TimeInterface; use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface; use Drupal\package_manager\Event\PostApplyEvent; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -34,7 +34,7 @@ final class StatusChecker implements EventSubscriberInterface { * The key/value expirable factory. * @param \Drupal\Component\Datetime\TimeInterface $time * The time service. - * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher + * @param \Symfony\Contracts\EventDispatcher\EventDispatcherInterface $eventDispatcher * The event dispatcher service. * @param \Drupal\automatic_updates\Updater $updater * The updater service. -- GitLab