Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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

nevvermind commented May 30, 2015

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