Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nevvermind
Created May 30, 2015 16:24
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 nevvermind/4932a246079f59cea5a8 to your computer and use it in GitHub Desktop.
Save nevvermind/4932a246079f59cea5a8 to your computer and use it in GitHub Desktop.
<?php
public function loadRepository(RepositoryInterface $repo)
{
foreach ($repo->getPackages() as $package) { /** @var PackageInterface $package */
if ($package instanceof AliasPackage) {
continue;
}
switch ($package->getType()) {
case 'composer-plugin':
$requiresComposer = null;
foreach ($package->getRequires() as $link) { /** @var Link $link */
if ($link->getTarget() == 'composer-plugin-api') {
$requiresComposer = $link->getConstraint();
break;
}
}
if (!$requiresComposer) {
throw new \RuntimeException("Plugin ".$package->getName()." is missing a require statement for a version of the composer-plugin-api package.");
}
// if the required Plugin API version is exactly "1.0.0", convert it to "^1.0", to keep BC
if ($requiresComposer->matches(new VersionConstraint('==', $this->versionParser->normalize('1.0.0')))) {
$requiresComposer = $this->versionParser->parseConstraints('^1.0');
}
$currComposerPluginApiConstraint = new VersionConstraint('==', $this->versionParser->normalize(PluginInterface::PLUGIN_API_VERSION));
if (!$requiresComposer->matches($currComposerPluginApiConstraint)) {
$this->io->writeError('<warning>The "'.$package->getName().'" plugin was skipped because it requires a Plugin API version ("'.$requiresComposer->getPrettyString().'") that does not match your Composer installation ("'.PluginInterface::PLUGIN_API_VERSION.'"). You may need to run composer update with the "--no-plugins" option.</warning>');
continue 2;
}
$this->registerPackage($package);
break;
case 'composer-installer': // Backward compatibility
$this->registerPackage($package);
}
}
}
@nevvermind
Copy link
Author

Note that incompatible (version mismatch) plugins are not registered anymore. (line 33)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment