diff --git a/src/Command/RelockCommand.php b/src/Command/RelockCommand.php
index 52d9553..c75140f 100644
--- a/src/Command/RelockCommand.php
+++ b/src/Command/RelockCommand.php
@@ -13,8 +13,7 @@ class RelockCommand extends PatchesCommandBase
protected function configure(): void
{
$this->setName('patches-relock');
- $filename = pathinfo(Patches::getPatchesLockFilePath(), \PATHINFO_BASENAME);
- $this->setDescription("Find all patches defined in the project and re-write $filename.");
+ $this->setDescription("Find all patches defined in the project and re-write the patches lock file.");
$this->setAliases(['prl']);
}
@@ -29,7 +28,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
unlink($plugin->getLockFile()->getPath());
}
$plugin->createNewPatchesLock();
- $output->write(' - patches.lock.json has been recreated successfully.', true);
+ $filename = pathinfo($plugin->getPatchesLockFilePath(), \PATHINFO_BASENAME);
+ $output->write(" - $filename has been recreated successfully.", true);
return 0;
}
}
diff --git a/src/Plugin/Patches.php b/src/Plugin/Patches.php
index 5b74ca1..d4bed5e 100644
--- a/src/Plugin/Patches.php
+++ b/src/Plugin/Patches.php
@@ -85,23 +85,6 @@ class Patches implements PluginInterface, EventSubscriberInterface, Capable
protected JsonFile $lockFile;
- /**
- * Get the path to the current patches lock file.
- */
- public static function getPatchesLockFilePath(): string
- {
- $composer_file = \Composer\Factory::getComposerFile();
-
- $dir = dirname(realpath($composer_file));
- $base = pathinfo($composer_file, \PATHINFO_FILENAME);
-
- if ($base === 'composer') {
- return "$dir/patches.lock.json";
- }
-
- return "$dir/$base-patches.lock.json";
- }
-
/**
* Apply plugin modifications to composer
*
@@ -115,12 +98,6 @@ public function activate(Composer $composer, IOInterface $io): void
$this->executor = new ProcessExecutor($this->io);
$this->patches = array();
$this->installedPatches = array();
- $this->lockFile = new JsonFile(
- static::getPatchesLockFilePath(),
- null,
- $this->io
- );
- $this->locker = new Locker($this->lockFile);
$this->configuration = [
'disable-resolvers' => [
'type' => 'list',
@@ -146,12 +123,41 @@ public function activate(Composer $composer, IOInterface $io): void
'type' => 'string',
'default' => 'patches.json',
],
+ 'patches-lock-file' => [
+ 'type' => 'string',
+ 'default' => 'patches.lock.json',
+ ],
"ignore-dependency-patches" => [
'type' => 'list',
'default' => [],
],
];
$this->configure($this->composer->getPackage()->getExtra(), 'composer-patches');
+ $this->lockFile = new JsonFile(
+ $this->getPatchesLockFilePath(),
+ null,
+ $this->io
+ );
+ $this->locker = new Locker($this->lockFile);
+ }
+
+ /**
+ * Get the path to the current patches lock file.
+ */
+ public function getPatchesLockFilePath(): string
+ {
+ $composer_file = \Composer\Factory::getComposerFile();
+
+ $dir = dirname(realpath($composer_file));
+ $base = pathinfo($composer_file, \PATHINFO_FILENAME);
+
+ $lock_file = $this->getConfig('patches-lock-file');
+
+ if ($base === 'composer') {
+ return "$dir/$lock_file";
+ }
+
+ return "$dir/$base-$lock_file";
}
/**
diff --git a/tests/unit/PatchesPluginTest.php b/tests/unit/PatchesPluginTest.php
index 82e804f..57326cb 100644
--- a/tests/unit/PatchesPluginTest.php
+++ b/tests/unit/PatchesPluginTest.php
@@ -40,12 +40,20 @@ public function testActivate()
*/
public function testGetPatchesLockFilePath()
{
- $path = Patches::getPatchesLockFilePath();
+ $package = new RootPackage('cweagans/composer-patches', '0.0.0.0', '0.0.0');
+ $io = new NullIO();
+ $composer = new Composer();
+ $composer->setPackage($package);
+
+ $plugin = new Patches();
+ $plugin->activate($composer, $io);
+
+ $path = $plugin->getPatchesLockFilePath();
$filename = pathinfo($path, \PATHINFO_BASENAME);
$this->assertEquals('patches.lock.json', $filename);
putenv('COMPOSER=mycomposer.json');
- $path = Patches::getPatchesLockFilePath();
+ $path = $plugin->getPatchesLockFilePath();
$filename = pathinfo($path, \PATHINFO_BASENAME);
$this->assertEquals('mycomposer-patches.lock.json', $filename);
}