1
0
Fork 0
composer/src/Composer/Installer/MetapackageInstaller.php

84 lines
2.0 KiB
PHP
Raw Normal View History

2012-01-25 12:40:16 +00:00
<?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\Repository\WritableRepositoryInterface;
use Composer\Package\PackageInterface;
/**
* Metapackage installation manager.
*
* @author Martin Hasoň <martin.hason@gmail.com>
*/
class MetapackageInstaller implements InstallerInterface
{
/**
* {@inheritDoc}
*/
public function supports($packageType)
{
return $packageType === 'metapackage';
}
/**
* {@inheritDoc}
*/
2012-04-14 13:45:25 +00:00
public function isInstalled(WritableRepositoryInterface $repo, PackageInterface $package)
2012-01-25 12:40:16 +00:00
{
2012-04-14 13:45:25 +00:00
return $repo->hasPackage($package);
2012-01-25 12:40:16 +00:00
}
/**
* {@inheritDoc}
*/
2012-04-14 13:45:25 +00:00
public function install(WritableRepositoryInterface $repo, PackageInterface $package)
2012-01-25 12:40:16 +00:00
{
2012-04-14 13:45:25 +00:00
$repo->addPackage(clone $package);
2012-01-25 12:40:16 +00:00
}
/**
* {@inheritDoc}
*/
2012-04-14 13:45:25 +00:00
public function update(WritableRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
2012-01-25 12:40:16 +00:00
{
2012-04-14 13:45:25 +00:00
if (!$repo->hasPackage($initial)) {
2012-01-25 12:40:16 +00:00
throw new \InvalidArgumentException('Package is not installed: '.$initial);
}
2012-04-14 13:45:25 +00:00
$repo->removePackage($initial);
$repo->addPackage(clone $target);
2012-01-25 12:40:16 +00:00
}
/**
* {@inheritDoc}
*/
2012-04-14 13:45:25 +00:00
public function uninstall(WritableRepositoryInterface $repo, PackageInterface $package)
2012-01-25 12:40:16 +00:00
{
2012-04-14 13:45:25 +00:00
if (!$repo->hasPackage($package)) {
2012-01-25 12:40:16 +00:00
// 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);
}
2012-04-14 13:45:25 +00:00
$repo->removePackage($package);
2012-01-25 12:40:16 +00:00
}
/**
* {@inheritDoc}
*/
public function getInstallPath(PackageInterface $package)
{
return '';
}
}