diff --git a/package_manager/package_manager.services.yml b/package_manager/package_manager.services.yml index 621212c56f2627be153ea1ed45f42d1f5f688020..d68e2cffb0abf81411a7732478c9f65709f9aadc 100644 --- a/package_manager/package_manager.services.yml +++ b/package_manager/package_manager.services.yml @@ -138,9 +138,8 @@ services: Drupal\package_manager\PackageManagerUninstallValidator: tags: - { name: module_install.uninstall_validator } - parent: container.trait - calls: - - ['setContainer', ['@service_container']] + arguments: + $eventDispatcher: '@event_dispatcher' lazy: true Drupal\package_manager\Validator\SettingsValidator: tags: diff --git a/package_manager/src/PackageManagerUninstallValidator.php b/package_manager/src/PackageManagerUninstallValidator.php index 20e186710d6c828dc125568bc62ffc67871ecc68..1a83088927b7a8cd367cfec0827275600fc5f806 100644 --- a/package_manager/src/PackageManagerUninstallValidator.php +++ b/package_manager/src/PackageManagerUninstallValidator.php @@ -4,15 +4,16 @@ declare(strict_types = 1); namespace Drupal\package_manager; +use Drupal\Component\Datetime\TimeInterface; use Drupal\Core\Extension\ModuleUninstallValidatorInterface; use Drupal\Core\Queue\QueueFactory; use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\Core\TempStore\SharedTempStoreFactory; use PhpTuf\ComposerStager\API\Core\BeginnerInterface; use PhpTuf\ComposerStager\API\Core\CommitterInterface; use PhpTuf\ComposerStager\API\Core\StagerInterface; use PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerAwareTrait; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Prevents any module from being uninstalled if update is in process. @@ -22,26 +23,62 @@ use Symfony\Component\DependencyInjection\ContainerAwareTrait; * at any time without warning. External code should not interact with this * class. */ -final class PackageManagerUninstallValidator implements ModuleUninstallValidatorInterface, ContainerAwareInterface { +final class PackageManagerUninstallValidator implements ModuleUninstallValidatorInterface { - use ContainerAwareTrait; use StringTranslationTrait; + /** + * Constructs a new PackageManagerUninstallValidator object. + * + * @param \Drupal\package_manager\PathLocator $pathLocator + * The path locator service. + * @param \PhpTuf\ComposerStager\API\Core\BeginnerInterface $beginner + * The beginner service. + * @param \PhpTuf\ComposerStager\API\Core\StagerInterface $stager + * The stager service. + * @param \PhpTuf\ComposerStager\API\Core\CommitterInterface $committer + * The committer service. + * @param \Drupal\Core\Queue\QueueFactory $queueFactory + * The queue factory service. + * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher + * The event dispatcher service. + * @param \Drupal\Core\TempStore\SharedTempStoreFactory $sharedTempStoreFactory + * The shared temp store factory service. + * @param \Drupal\Component\Datetime\TimeInterface $time + * The time service. + * @param \PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface $pathFactory + * The path factory service. + * @param \Drupal\package_manager\FailureMarker $failureMarker + * The failure marker service. + */ + public function __construct( + private readonly PathLocator $pathLocator, + private readonly BeginnerInterface $beginner, + private readonly StagerInterface $stager, + private readonly CommitterInterface $committer, + private readonly QueueFactory $queueFactory, + private readonly EventDispatcherInterface $eventDispatcher, + private readonly SharedTempStoreFactory $sharedTempStoreFactory, + private readonly TimeInterface $time, + private readonly PathFactoryInterface $pathFactory, + private readonly FailureMarker $failureMarker + ) {} + /** * {@inheritdoc} */ public function validate($module) { $stage = new class( - $this->container->get(PathLocator::class), - $this->container->get(BeginnerInterface::class), - $this->container->get(StagerInterface::class), - $this->container->get(CommitterInterface::class), - $this->container->get(QueueFactory::class), - $this->container->get('event_dispatcher'), - $this->container->get('tempstore.shared'), - $this->container->get('datetime.time'), - $this->container->get(PathFactoryInterface::class), - $this->container->get(FailureMarker::class)) extends StageBase {}; + $this->pathLocator, + $this->beginner, + $this->stager, + $this->committer, + $this->queueFactory, + $this->eventDispatcher, + $this->sharedTempStoreFactory, + $this->time, + $this->pathFactory, + $this->failureMarker) extends StageBase {}; if ($stage->isAvailable() || !$stage->isApplying()) { return []; }