Skip to content
Snippets Groups Projects
Commit 388200b0 authored by Tim Plunkett's avatar Tim Plunkett Committed by Adam G-H
Browse files

Issue #3310702 by tim.plunkett: Stage::__construct() should require $path_factory

parent 4846b0f2
No related branches found
No related tags found
1 merge request!483Issue #3310702: Stage::__construct() should require $path_factory
...@@ -4,6 +4,7 @@ namespace Drupal\package_manager; ...@@ -4,6 +4,7 @@ namespace Drupal\package_manager;
use Drupal\Core\Extension\ModuleUninstallValidatorInterface; use Drupal\Core\Extension\ModuleUninstallValidatorInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait; use Symfony\Component\DependencyInjection\ContainerAwareTrait;
...@@ -33,7 +34,8 @@ final class PackageManagerUninstallValidator implements ModuleUninstallValidator ...@@ -33,7 +34,8 @@ final class PackageManagerUninstallValidator implements ModuleUninstallValidator
$this->container->get('file_system'), $this->container->get('file_system'),
$this->container->get('event_dispatcher'), $this->container->get('event_dispatcher'),
$this->container->get('tempstore.shared'), $this->container->get('tempstore.shared'),
$this->container->get('datetime.time') $this->container->get('datetime.time'),
$this->container->get(PathFactoryInterface::class)
); );
if ($stage->isAvailable() || !$stage->isApplying()) { if ($stage->isAvailable() || !$stage->isApplying()) {
return []; return [];
......
...@@ -192,7 +192,7 @@ class Stage { ...@@ -192,7 +192,7 @@ class Stage {
* @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 $path_factory
* (optional) The path factory service. * The path factory service.
*/ */
public function __construct(ConfigFactoryInterface $config_factory, PathLocator $path_locator, BeginnerInterface $beginner, StagerInterface $stager, CommitterInterface $committer, FileSystemInterface $file_system, EventDispatcherInterface $event_dispatcher, SharedTempStoreFactory $shared_tempstore, TimeInterface $time, PathFactoryInterface $path_factory = NULL) { public function __construct(ConfigFactoryInterface $config_factory, PathLocator $path_locator, BeginnerInterface $beginner, StagerInterface $stager, CommitterInterface $committer, FileSystemInterface $file_system, EventDispatcherInterface $event_dispatcher, SharedTempStoreFactory $shared_tempstore, TimeInterface $time, PathFactoryInterface $path_factory = NULL) {
$this->configFactory = $config_factory; $this->configFactory = $config_factory;
...@@ -204,7 +204,11 @@ class Stage { ...@@ -204,7 +204,11 @@ class Stage {
$this->eventDispatcher = $event_dispatcher; $this->eventDispatcher = $event_dispatcher;
$this->time = $time; $this->time = $time;
$this->tempStore = $shared_tempstore->get('package_manager_stage'); $this->tempStore = $shared_tempstore->get('package_manager_stage');
$this->pathFactory = $path_factory ?: new PathFactory(); 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;
} }
/** /**
......
...@@ -10,6 +10,7 @@ use Drupal\package_manager\Event\PreApplyEvent; ...@@ -10,6 +10,7 @@ use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\StageEvent; use Drupal\package_manager\Event\StageEvent;
use Drupal\package_manager\Exception\ApplyFailedException; use Drupal\package_manager\Exception\ApplyFailedException;
use Drupal\package_manager\Exception\StageException; use Drupal\package_manager\Exception\StageException;
use Drupal\package_manager\Stage;
use Drupal\package_manager_bypass\Committer; use Drupal\package_manager_bypass\Committer;
use PhpTuf\ComposerStager\Domain\Exception\InvalidArgumentException; use PhpTuf\ComposerStager\Domain\Exception\InvalidArgumentException;
use PhpTuf\ComposerStager\Domain\Exception\PreconditionException; use PhpTuf\ComposerStager\Domain\Exception\PreconditionException;
...@@ -303,6 +304,26 @@ class StageTest extends PackageManagerKernelTestBase { ...@@ -303,6 +304,26 @@ class StageTest extends PackageManagerKernelTestBase {
$stage->apply(); $stage->apply();
} }
/**
* Tests enforcing that the path factory must be passed to the constructor.
*
* @group legacy
*/
public function testPathFactoryConstructorDeprecation(): void {
$this->expectDeprecation('Calling Drupal\package_manager\Stage::__construct() 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.');
new Stage(
$this->container->get('config.factory'),
$this->container->get('package_manager.path_locator'),
$this->container->get('package_manager.beginner'),
$this->container->get('package_manager.stager'),
$this->container->get('package_manager.committer'),
$this->container->get('file_system'),
$this->container->get('event_dispatcher'),
$this->container->get('tempstore.shared'),
$this->container->get('datetime.time')
);
}
} }
/** /**
......
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