cweagans\Composer\Patches::checkPatches PHP Method

checkPatches() public method

Before running composer install,
public checkPatches ( Composer\Script\Event $event )
$event Composer\Script\Event
    public function checkPatches(Event $event)
    {
        if (!$this->isPatchingEnabled()) {
            return;
        }
        try {
            $repositoryManager = $this->composer->getRepositoryManager();
            $localRepository = $repositoryManager->getLocalRepository();
            $installationManager = $this->composer->getInstallationManager();
            $packages = $localRepository->getPackages();
            $tmp_patches = $this->grabPatches();
            if ($tmp_patches == FALSE) {
                $this->io->write('<info>No patches supplied.</info>');
                return;
            }
            foreach ($packages as $package) {
                $extra = $package->getExtra();
                if (isset($extra['patches'])) {
                    $this->installedPatches[$package->getName()] = $extra['patches'];
                }
                $patches = isset($extra['patches']) ? $extra['patches'] : array();
                $tmp_patches = array_merge_recursive($tmp_patches, $patches);
            }
            // Remove packages for which the patch set has changed.
            foreach ($packages as $package) {
                if (!$package instanceof AliasPackage) {
                    $package_name = $package->getName();
                    $extra = $package->getExtra();
                    $has_patches = isset($tmp_patches[$package_name]);
                    $has_applied_patches = isset($extra['patches_applied']);
                    if ($has_patches && !$has_applied_patches || !$has_patches && $has_applied_patches || $has_patches && $has_applied_patches && $tmp_patches[$package_name] !== $extra['patches_applied']) {
                        $uninstallOperation = new UninstallOperation($package, 'Removing package so it can be re-installed and re-patched.');
                        $this->io->write('<info>Removing package ' . $package_name . ' so that it can be re-installed and re-patched.</info>');
                        $installationManager->uninstall($localRepository, $uninstallOperation);
                    }
                }
            }
        } catch (\LogicException $e) {
            return;
        }
    }