public function gatherPatches(PackageEvent $event)
{
// If we've already done this, then don't do it again.
if (isset($this->patches['_patchesGathered'])) {
$this->io->write('<info>Patches already gathered. Skipping</info>');
return;
} elseif (!$this->isPatchingEnabled()) {
$this->io->write('<info>Patching is disabled. Skipping.</info>');
return;
}
$this->patches = $this->grabPatches();
if (empty($this->patches)) {
$this->io->write('<info>No patches supplied.</info>');
}
$extra = $this->composer->getPackage()->getExtra();
$patches_ignore = isset($extra['patches-ignore']) ? $extra['patches-ignore'] : [];
// Now add all the patches from dependencies that will be installed.
$operations = $event->getOperations();
$this->io->write('<info>Gathering patches for dependencies. This might take a minute.</info>');
foreach ($operations as $operation) {
if ($operation->getJobType() == 'install' || $operation->getJobType() == 'update') {
$package = $this->getPackageFromOperation($operation);
$extra = $package->getExtra();
if (isset($extra['patches'])) {
if (isset($patches_ignore[$package->getName()])) {
foreach ($patches_ignore[$package->getName()] as $package => $patches) {
if (isset($extra['patches'][$package])) {
$extra['patches'][$package] = array_diff($extra['patches'][$package], $patches);
}
}
}
$this->patches = array_merge_recursive($this->patches, $extra['patches']);
}
// Unset installed patches for this package
if (isset($this->installedPatches[$package->getName()])) {
unset($this->installedPatches[$package->getName()]);
}
}
}
// Merge installed patches from dependencies that did not receive an update.
foreach ($this->installedPatches as $patches) {
$this->patches = array_merge_recursive($this->patches, $patches);
}
// If we're in verbose mode, list the projects we're going to patch.
if ($this->io->isVerbose()) {
foreach ($this->patches as $package => $patches) {
$number = count($patches);
$this->io->write('<info>Found ' . $number . ' patches for ' . $package . '.</info>');
}
}
// Make sure we don't gather patches again. Extra keys in $this->patches
// won't hurt anything, so we'll just stash it there.
$this->patches['_patchesGathered'] = TRUE;
}