mirror of
https://github.com/composer/composer
synced 2025-05-11 09:32:55 +00:00
Added installer for metapackages
This commit is contained in:
parent
773338a688
commit
528a058e40
4 changed files with 199 additions and 2 deletions
97
src/Composer/Installer/MetapackageInstaller.php
Normal file
97
src/Composer/Installer/MetapackageInstaller.php
Normal file
|
@ -0,0 +1,97 @@
|
|||
<?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 '';
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue