Uninstall a single package

@param PackageInterface   $package
@param InstallerInterface $installer
329538
public function uninstallPackage(PackageInterface $package, InstallerInterface $installer)
    {
        if (!$this->isPackageInstalled($package)) {
            throw new RuntimeException(sprintf('Package %s is not installed.', $package->getName()));
        }
        $installer->uninstall($package);
    }
899162
public function getInstallPath(PackageInterface $package)
    {
        $flowPackageType = $this->getFlowPackageType($package->getType());
        $camelCasedType = $this->camelCaseFlowPackageType($flowPackageType);
        $flowPackageName = $this->deriveFlowPackageName($package);

        if (isset($this->packageTypeToPathMapping[$flowPackageType])) {
            $installPath = $this->packageTypeToPathMapping[$flowPackageType];
        } else {
            $installPath = $this->packageTypeToPathMapping['*'];
        }

        return $this->replacePlaceholdersInPath($installPath, compact('flowPackageType', 'camelCasedType', 'flowPackageName'));
    }
1203067
protected function getInstallerConfig(PackageInterface $package)
    {
        if ($this->installerConfig !== null) {
            return $this->installerConfig;
        }

        $type       = $package->getType();
        $prettyName = $package->getPrettyName();

        if (strpos($prettyName, '/') !== false) {
            list($vendor, $name) = explode('/', $prettyName);
        } else {
            $vendor = '';
            $name   = $prettyName;
        }

        $extra = $package->getExtra();

        if (!empty($extra['installer-name'])) {
            $name = $extra['installer-name'];
        }

        $loader = 'mu-plugins/' . $name . '.php';

        if (!empty($extra['installer-loader'])) {
            $loader = $extra['installer-loader'];
        }

        return compact('name', 'vendor', 'type', 'loader');
    }
707032
protected function installPatchesForPackage(PackageInterface $package)
    {
        $considerPatchErrorsAsWarnings = $this->considerPatchErrorsAsWarnings();
        $patches = $this->getPatchCollection()->getPatchesFor($package);
        $patcher = $this->getPatcher();
        $appliedPatchesToSave = method_exists($package, 'setExtra') ? array() : null;
        foreach ($patches->getPatches() as $patch) {
            try {
                $patcher->applyPatch($patch, $package);
                if ($appliedPatchesToSave !== null) {
                    $appliedPatchesToSave[] = array(
                        'from-package' => $patch->getFromPackage()->getPrettyString(),
                        'path' => $patch->getOriginalPath(),
                        'description' => $patch->getDescription(),
                    );
                }
            } catch (GenericException $x) {
                $appliedPatchesToSave = null;
                if (!$considerPatchErrorsAsWarnings) {
                    throw $x;
                }
                $this->io->write('<error>'.$x->getMessage().'</error>');
            }
        }
        if ($appliedPatchesToSave !== null) {
            $this->setPatchedPackageData($package, array(
                'hash' => $patches->getHash(),
                'list' => $appliedPatchesToSave,
            ));
        }
    }
891939
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
    {
        parent::uninstall($repo, $package);
        $path = $this->getInstallPath($package);
        $ns = static::primaryNamespace($package);
        $this->updateConfig($ns, null);
    }
922753
public function isPackageExtraneous(PackageInterface $package, $checkInstall = false)
    {
        if ($checkInstall && !$this->isPackageInstalled($package)) {
            return false;
        }

        try {
            $bower = $this->config->getBowerFileContent();
        } catch (RuntimeException $e) { // no bower.json file, package is extraneous
            return true;
        }
        if (!isset($bower['dependencies'])) {
            return true;
        }
        // package is a direct dependencies
        if (isset($bower['dependencies'][$package->getName()])) {
            return false;
        }
        // look for dependencies of dependencies
        foreach ($bower['dependencies'] as $name => $version) {
            $dotBowerJson = $this->filesystem->read($this->config->getInstallDir() . '/' . $name . '/.bower.json');
            $depBower = json_decode($dotBowerJson, true);
            if (isset($depBower['dependencies'][$package->getName()])) {
                return false;
            }
            // look for dependencies of dependencies of dependencies
            if (isset($depBower['dependencies'])) {
                foreach ($depBower['dependencies'] as $name1 => $version1) {
                    $dotBowerJson = $this->filesystem->read($this->config->getInstallDir() . '/' . $name1 . '/.bower.json');
                    $depDepBower = json_decode($dotBowerJson, true);
                    if (isset($depDepBower['dependencies'][$package->getName()])) {
                        return false;
                    }
                }
            }
        }

        return true;
    }
921801
public function dropNewFiles(PackageInterface $package){

    //Gather all information for dropin directives
    $info = array();

    //Composer doesn't care about uppercase and so shouldn't we
    $info['package'] = strtolower($package->getName());
    $info['vendor'] = substr($info['package'], 0, strpos($info['package'], '/'));
    $info['type'] = $package->getType();

    #Locate absolute urls
    $projectDir = getcwd();

    #Get directives from composer.json
    $extra = $this->composer->getPackage()->getExtra();

    if (isset($extra['dropin-paths'])) {
      $paths = self::getPaths($extra['dropin-paths']);
    } else {
      //Stop here if dropin-paths is not defined.
      return;
    }

    $dest = self::installPath($info);

    //If dropin has nothing to do with this package just end it now
    if (!$dest) {
      return;
    }else {
      $dest = "{$projectDir}/{$dest}"; //Update to full path
    }

    //Compatibility with composer/installers
    if (class_exists('\\Composer\\Installers\\Installer')) {
      $installer = new Installer($this->io,$this->composer);
    } else {
      //System default
      $installer = new LibraryInstaller($this->io,$this->composer);
    }

    try {
      $src = realpath($installer->getInstallPath($package));
    } catch (\InvalidArgumentException $e) {
      // We will end up here if composer/installers doesn't recognise the type
      // In this case it's the default installation folder in vendor
      $vendorDir = $this->composer->getConfig()->get('vendor-dir');
      $vendorDir = realpath($vendorDir);
      $src = "{$vendorDir}/{$info['package']}";
    }

    $config = $this->composer->getPackage()->getConfig();
    $shouldCopy = isset($config['dropin-installer']) && $config['dropin-installer'] === 'copy';

    $installFiles = self::getFilesToInstall($info);
    if ($shouldCopy) {
      $this->io->write("    Copying dropin files...\n");
      if ($installFiles == "*") {
        self::rcopy($src, $dest);
      } else {
        foreach ($installFiles as $file) {
          self::copy("{$src}/{$file}", $dest);
        }
      }
    } else {
      $this->io->write("    Moving dropin files...\n");
      if ($installFiles == "*") {
        self::rmove($src, $dest);
      } else {
        foreach ($installFiles as $file) {
          self::move("{$src}/{$file}", $dest);
        }
      }
    }
  }
559820
public function updatePackage(PackageInterface $package, InstallerInterface $installer)
    {
        if (!$this->isPackageInstalled($package)) {
            throw new RuntimeException(sprintf('Package %s is not installed.', $package->getName()));
        }
        if (is_null($package->getRequiredVersion())) {
            $decode = $this->config->getBowerFileContent();
            if (empty($decode['dependencies']) || empty($decode['dependencies'][$package->getName()])) {
                throw new InvalidArgumentException(sprintf('Package %s not found in bower.json', $package->getName()));
            }
            $package->setRequiredVersion($decode['dependencies'][$package->getName()]);
        }

        $bower = $this->config->getPackageBowerFileContent($package);
        $package->setInfo($bower);
        $package->setVersion($bower['version']);
        $package->setRequires(isset($bower['dependencies']) ? $bower['dependencies'] : null);

        $packageTag = $this->getPackageTag($package);
        $this->output->writelnInfoPackage($package, 'validate', sprintf('%s against %s#%s', $packageTag, $package->getName(), $package->getRequiredVersion()));

        $package->setRepository($this->repository);
        if ($packageTag == $package->getVersion()) {
            // if version is fully matching, there's no need to update
            return;
        }
        $package->setVersion($packageTag);

        $this->cachePackage($package);

        $this->output->writelnUpdatingPackage($package);
        $installer->update($package);

        $overrides = $this->config->getOverrideFor($package->getName());
        if (array_key_exists('dependencies', $overrides)) {
            $dependencies = $overrides['dependencies'];
        } else {
            $dependencies = $package->getRequires();
        }
        if (!empty($dependencies)) {
            foreach ($dependencies as $name => $requiredVersion) {
                $depPackage = new Package($name, $requiredVersion);
                if (!$this->isPackageInstalled($depPackage)) {
                    $this->installPackage($depPackage, $installer, true);
                } elseif ($this->isNeedUpdate($depPackage)) {
                    $this->updatePackage($depPackage, $installer);
                }
            }
        }
    }
69654
protected static function isAsset(PackageInterface $package)
    {
        foreach (Assets::getTypes() as $type) {
            $type = Assets::createType($type);

            if ($package->getType() === $type->getComposerType()) {
                return true;
            }
        }

        return false;
    }
1285004
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
    {
        parent::install($repo, $package);
        foreach ($this->getSupportedHooks() as $gitHookName) {
            $installedHookFilePath = $this->getInstallPath($package) . DIRECTORY_SEPARATOR . $gitHookName;

            if (file_exists($installedHookFilePath)) {
                $hookDestinationPath = $this->getGitHooksPath() . DIRECTORY_SEPARATOR . $gitHookName;
                if (!copy($installedHookFilePath, $hookDestinationPath)) {
                    echo sprintf(
                        'GitHookInstallerPlugin failed to copy %s to %s!',
                        $installedHookFilePath,
                        $hookDestinationPath
                    );
                }
                chmod($hookDestinationPath, 0755);
            }
        }

        // clean up temporary data
        exec('rm -rf ' . $this->getHooksInstallationPath());
    }
493956
public function isSharedPackage(PackageInterface $package)
    {
        $prettyName = $package->getPrettyName();

        // Avoid putting this package into dependencies folder, because on the first installation the package won't be
        // installed in dependencies folder but in the vendor folder.
        // So I prefer keeping this behavior for further installs.
        if (SharedPackageInstaller::PACKAGE_PRETTY_NAME === $prettyName) {
            return false;
        }

        if ($this->areAllShared || SharedPackageInstaller::PACKAGE_TYPE === $package->getType()) {
            return true;
        }

        foreach ($this->packageCallbacks as $equalityCallback) {
            if ($equalityCallback($prettyName)) {
                return true;
            }
        }

        return false;
    }
421726
protected function removeAssets(PackageInterface $package)
    {
        $assets = $this->getPackageAssetsDir($package);
        if (!$assets) {
            return;
        }

        $target = $this->getAssetsInstallPath($package);
        if (file_exists($target)) {
            $this->io->write(
                sprintf('  - Removing <info>%s</info> assets from <info>%s</info>',
                    $package->getPrettyName(),
                    str_replace(dirname($this->assets_dir) . '/', '', $target)
                )
            );
            $this->filesystem->remove($target);
            Dispatch::unregisterPackage($package, $this);
            $this->io->write('');
        } else {
            Error::thrower(
                sprintf('Unable to find assets from package "%s"', $package->getPrettyName()),
                '\InvalidArgumentException', __CLASS__, __METHOD__, __LINE__
            );
        }
    }
608745
public static function registerPackage(PackageInterface $package, $target, AssetsInstallerInterface $installer = null)
    {
        self::$__autoloader->registerPackage($package, $target, $installer);
    }
385585
public static function registerPackage(PackageInterface $package, $target, AssetsInstallerInterface $installer = null)
    {
        $_this = self::getInstance($installer);
        $_this->addPackage($package, $target);
    }
230528
public static function enablePackage(PackageInterface $package)
    {
        $packageRepository = Factory::makePackageRepository($package);
        $bundleFactory = Factory::makeBundleFactory();
        $kernelManipulator = Factory::makeKernelManipulator();

        $composerPackage = $packageRepository->findOneByName($package->getName());
        $bundle = $bundleFactory->make($composerPackage->namespace);

        $kernelManipulator->addBundle($bundle->fullyQualifiedClassname);
    }
839947
protected function installAssets(PackageInterface $package)
    {
        $assets = $this->getPackageAssetsDir($package);
        if (!$assets) {
            return;
        }

        $from = $this->getPackageBasePath($package) . '/' . $assets;
        $target = $this->getAssetsInstallPath($package);
        if (file_exists($from)) {
            $this->io->write(
                sprintf('  - Installing <info>%s</info> assets to <info>%s</info>',
                    $package->getPrettyName(),
                    str_replace(dirname($this->assets_dir) . '/', '', $target)
                )
            );
            $this->filesystem->copy($from, $target);
            Dispatch::registerPackage($package, $target, $this);
            $this->io->write('');
        } else {
            Error::thrower(
                sprintf('Unable to find assets in package "%s"', $package->getPrettyName()),
                '\InvalidArgumentException', __CLASS__, __METHOD__, __LINE__
            );
        }
    }
935205
public function writelnInstalledPackage(PackageInterface $package)
    {
        $this->output->writeln(sprintf('bower <info>%s</info> <fg=cyan>%s</fg=cyan>',
            str_pad($package->getName() . '#' . $package->getVersion(), 21, ' ', STR_PAD_RIGHT),
            str_pad('install', 10, ' ', STR_PAD_LEFT)
        ));
    }