You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.3 KiB
PHTML

<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* 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ň <martin.hason@gmail.com>
*/
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 '';
}
}