Skip to content

Instantly share code, notes, and snippets.

@thomscode
Last active November 15, 2017 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomscode/8ad286a97ce9efbdf5829ba9e79fcb85 to your computer and use it in GitHub Desktop.
Save thomscode/8ad286a97ce9efbdf5829ba9e79fcb85 to your computer and use it in GitHub Desktop.
Disable individual Composer/Installers
From b2b3e213896d7eb41a83b0b0011aa64171a917cc Mon Sep 17 00:00:00 2001
From: Thom Williams <thomscode@gmail.com>
Date: Tue, 7 Nov 2017 04:47:43 -0800
Subject: [PATCH] Add ability to disable individual or all installers
---
src/Composer/Installers/Installer.php | 64 +++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/src/Composer/Installers/Installer.php b/src/Composer/Installers/Installer.php
index 691a2e5..01693eb 100644
--- a/src/Composer/Installers/Installer.php
+++ b/src/Composer/Installers/Installer.php
@@ -103,6 +103,30 @@ class Installer extends LibraryInstaller
);
/**
+ * Installer constructor.
+ *
+ * Disables installers specified in main composer extra installer-disable
+ * list
+ *
+ * @param IOInterface $io
+ * @param \Composer\Composer $composer
+ * @param string $type
+ * @param \Composer\Util\Filesystem|null $filesystem
+ * @param \Composer\Installer\BinaryInstaller|null $binaryInstaller
+ */
+ public function __construct(
+ \Composer\IO\IOInterface $io,
+ \Composer\Composer $composer,
+ $type = 'library',
+ \Composer\Util\Filesystem $filesystem = null,
+ \Composer\Installer\BinaryInstaller $binaryInstaller = null
+ ) {
+ parent::__construct($io, $composer, $type, $filesystem,
+ $binaryInstaller);
+ $this->removeDisabledInstallers();
+ }
+
+ /**
* {@inheritDoc}
*/
public function getInstallPath(PackageInterface $package)
@@ -197,4 +221,44 @@ class Installer extends LibraryInstaller
{
return $this->io;
}
+
+ /**
+ * Look for installers set to be disabled in composer's extra config and
+ * remove them from the list of supported installers.
+ * Uses true, "all", and "*" as global values to disable all installers.
+ *
+ * @return void
+ */
+ protected function removeDisabledInstallers()
+ {
+ $extra = $this->composer->getPackage()->getExtra();
+
+ if (!isset($extra['installer-disable'])) {
+ // No installers are disabled
+ return;
+ }
+
+ // Get installers to disable
+ $disable = $extra['installer-disable'];
+
+ // Ensure $disabled is an array
+ if (!is_array($disable)) {
+ $disable = array($disable);
+ }
+
+ // Check which installers should be disabled
+ $all = array(true, "all", "*");
+ $intersect = array_intersect($all, $disable);
+ if (!empty($intersect)) {
+ // Disable all installers
+ $this->supportedTypes = array();
+ } else {
+ // Disable specified installers
+ foreach ($disable as $key => $installer) {
+ if (key_exists($installer, $this->supportedTypes)) {
+ unset($this->supportedTypes[$installer]);
+ }
+ }
+ }
+ }
}
--
2.13.5 (Apple Git-94)
From ee686c90679adf206cabf968164baa397ed5b88e Mon Sep 17 00:00:00 2001
From: Thom Williams <thomscode@gmail.com>
Date: Tue, 7 Nov 2017 05:48:23 -0800
Subject: [PATCH] Enforce installers are specified as strings
---
src/Composer/Installers/Installer.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Composer/Installers/Installer.php b/src/Composer/Installers/Installer.php
index c62f004..1861e2a 100644
--- a/src/Composer/Installers/Installer.php
+++ b/src/Composer/Installers/Installer.php
@@ -264,7 +264,7 @@ class Installer extends LibraryInstaller
} else {
// Disable specified installers
foreach ($disable as $key => $installer) {
- if (key_exists($installer, $this->supportedTypes)) {
+ if (is_string($installer) && key_exists($installer, $this->supportedTypes)) {
unset($this->supportedTypes[$installer]);
}
}
--
2.13.5 (Apple Git-94)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment