* Jordi Boggiano * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Composer\Installer; use Composer\IO\IOInterface; use Composer\Repository\WritableRepositoryInterface; use Composer\Package\PackageInterface; /** * Metapackage installation manager. * * @author Martin HasoĊˆ */ class MetapackageInstaller implements InstallerInterface { protected $repository; protected $io; /** * @param WritableRepositoryInterface $repository repository controller * @param IOInterface $io io instance */ public function __construct(WritableRepositoryInterface $repository, IOInterface $io) { $this->repository = $repository; $this->io = $io; } /** * {@inheritDoc} */ public function supports($packageType) { return $packageType === 'metapackage'; } /** * {@inheritDoc} */ public function isInstalled(PackageInterface $package) { return $this->repository->hasPackage($package); } /** * {@inheritDoc} */ public function install(PackageInterface $package) { $this->repository->addPackage(clone $package); } /** * {@inheritDoc} */ public function update(PackageInterface $initial, PackageInterface $target) { if (!$this->repository->hasPackage($initial)) { throw new \InvalidArgumentException('Package is not installed: '.$initial); } $this->repository->removePackage($initial); $this->repository->addPackage(clone $target); } /** * {@inheritDoc} */ public function uninstall(PackageInterface $package) { if (!$this->repository->hasPackage($package)) { // TODO throw exception again here, when update is fixed and we don't have to remove+install (see #125) return; throw new \InvalidArgumentException('Package is not installed: '.$package); } $this->repository->removePackage($package); } /** * {@inheritDoc} */ public function getInstallPath(PackageInterface $package) { return ''; } }