installer refactoring
parent
5f4d46f7ae
commit
6caa77fbbf
|
@ -13,11 +13,17 @@
|
|||
namespace Composer\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command as BaseCommand;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Composer\DependencyResolver\Request;
|
||||
use Composer\DependencyResolver\Solver;
|
||||
use Composer\Installer\Operation;
|
||||
|
||||
/**
|
||||
* Base class for Composer commands
|
||||
*
|
||||
* @author Ryan Weaver <ryan@knplabs.com>
|
||||
* @authro Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
*/
|
||||
abstract class Command extends BaseCommand
|
||||
{
|
||||
|
@ -28,4 +34,17 @@ abstract class Command extends BaseCommand
|
|||
{
|
||||
return $this->getApplication()->getComposer();
|
||||
}
|
||||
|
||||
protected function solveDependencies(Request $request, Solver $solver)
|
||||
{
|
||||
$operations = array();
|
||||
foreach ($solver->solve($request) as $task) {
|
||||
$installer = $this->getComposer()->getInstaller($task['package']->getType());
|
||||
$operation = new Operation($installer, $task['job'], $task['package']);
|
||||
|
||||
$operations[] = $operation;
|
||||
}
|
||||
|
||||
return $operations;
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Composer\Console\Package;
|
||||
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Composer\Package\PackageInterface;
|
||||
use Composer\Package\Manager;
|
||||
|
||||
class VerboseManager extends Manager
|
||||
{
|
||||
private $output;
|
||||
|
||||
public function __construct(Composer $composer, OutputInterface $output)
|
||||
{
|
||||
parent::__construct($output);
|
||||
|
||||
$this->composer = $composer;
|
||||
}
|
||||
|
||||
public function install(PackageInterface $package)
|
||||
{
|
||||
$this->output->writeln('> Installing '.$package->getName());
|
||||
|
||||
parent::install($package);
|
||||
}
|
||||
|
||||
public function update(PackageInterface $package)
|
||||
{
|
||||
$this->output->writeln('> Updating '.$package->getName());
|
||||
|
||||
parent::update($package);
|
||||
}
|
||||
|
||||
public function remove(PackageInterface $package)
|
||||
{
|
||||
$this->output->writeln('> Removing '.$package->getName());
|
||||
|
||||
parent::remove($package);
|
||||
}
|
||||
}
|
|
@ -12,22 +12,18 @@
|
|||
|
||||
namespace Composer\Installer;
|
||||
|
||||
use Composer\Downloader\DownloaderInterface;
|
||||
use Composer\Package\PackageInterface;
|
||||
use Composer\Composer;
|
||||
|
||||
/**
|
||||
* Package Installer
|
||||
*
|
||||
* @author Kirill chEbba Chebunin <iam@chebba.org>
|
||||
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
*/
|
||||
interface InstallerInterface
|
||||
class InstallerInterface
|
||||
{
|
||||
/**
|
||||
* Install package
|
||||
*
|
||||
* @param PackageInterface $package
|
||||
* @param DownloaderInterface $downloader
|
||||
* @param string $type
|
||||
*/
|
||||
function install(PackageInterface $package, DownloaderInterface $downloader, $type);
|
||||
function setComposer(Composer $composer);
|
||||
|
||||
function isInstalled(PackageInterface $package);
|
||||
function install(PackageInterface $package);
|
||||
function update(PackageInterface $package);
|
||||
function remove(PackageInterface $package);
|
||||
}
|
||||
|
|
|
@ -14,42 +14,60 @@ namespace Composer\Installer;
|
|||
|
||||
use Composer\Downloader\DownloaderInterface;
|
||||
use Composer\Package\PackageInterface;
|
||||
use Composer\Composer;
|
||||
|
||||
/**
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
class LibraryInstaller implements InstallerInterface
|
||||
{
|
||||
protected $dir;
|
||||
private $dir;
|
||||
private $composer;
|
||||
|
||||
public function __construct($dir = 'vendor')
|
||||
{
|
||||
$this->dir = $dir;
|
||||
}
|
||||
|
||||
public function install(PackageInterface $package, DownloaderInterface $downloader, $type)
|
||||
public function setComposer(Composer $composer)
|
||||
{
|
||||
if ($type === 'dist') {
|
||||
$downloader->download($package, $this->dir, $package->getDistUrl(), $package->getDistSha1Checksum());
|
||||
} elseif ($type === 'source') {
|
||||
$downloader->download($package, $this->dir, $package->getSourceUrl());
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Type must be one of (dist, source), '.$type.' given.');
|
||||
$this->composer = $composer;
|
||||
}
|
||||
|
||||
public function install(PackageInterface $package)
|
||||
{
|
||||
if ($package->getDistType()) {
|
||||
|
||||
$this->composer->getDownloader($package->getDistType())->download(
|
||||
$package, $this->dir, $package->getDistUrl(), $package->getDistSha1Checksum()
|
||||
);
|
||||
|
||||
} elseif ($package->getSourceType()) {
|
||||
|
||||
$this->composer->getDownloader($package->getSourceType())->download(
|
||||
$package, $this->dir, $package->getSourceUrl()
|
||||
);
|
||||
|
||||
} else {
|
||||
throw new \InvalidArgumentException(
|
||||
'Type must be one of (dist, source), '.$type.' given.'
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isInstalled(PackageInterface $package, $downloader, $type)
|
||||
public function isInstalled(PackageInterface $package)
|
||||
{
|
||||
// TODO: implement installation check
|
||||
}
|
||||
|
||||
public function update(PackageInterface $package, $downloader, $type)
|
||||
public function update(PackageInterface $package)
|
||||
{
|
||||
// TODO: implement package update
|
||||
}
|
||||
|
||||
public function remove(PackageInterface $package, $downloader, $type)
|
||||
public function remove(PackageInterface $package)
|
||||
{
|
||||
// TODO: implement package removal
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
<?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\Installer\InstallerInterface;
|
||||
use Composer\Package\PackageInterface;
|
||||
|
||||
/**
|
||||
* Installer operation command
|
||||
*
|
||||
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
*/
|
||||
class Operation
|
||||
{
|
||||
private $installer;
|
||||
private $type;
|
||||
private $package;
|
||||
|
||||
public function __construct(InstallerInterface $installer, $type, PackageInterface $package)
|
||||
{
|
||||
$type = strtolower($type);
|
||||
if (!in_array($type, array('install', 'update', 'remove'))) {
|
||||
throw new \UnexpectedValueException('Unhandled operation type: ' . $type);
|
||||
}
|
||||
|
||||
$this->installer = $installer;
|
||||
$this->type = $type;
|
||||
$this->package = $package;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getPackage()
|
||||
{
|
||||
return $this->package;
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$method = $this->getType();
|
||||
|
||||
return $this->installer->$method($this->getPackage());
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Composer\Package;
|
||||
|
||||
use Composer\Package\PackageInterface;
|
||||
|
||||
class Manager
|
||||
{
|
||||
private $composer;
|
||||
|
||||
public function __construct(Composer $composer)
|
||||
{
|
||||
$this->composer = $composer;
|
||||
}
|
||||
|
||||
public function isInstalled(PackageInterface $package)
|
||||
{
|
||||
$installer = $this->composer->getInstaller($package->getType());
|
||||
$downloader = $this->getDownloaderForPackage($package);
|
||||
$packageType = $this->getTypeForPackage($package);
|
||||
|
||||
return $installer->isInstalled($package, $downloader, $packageType);
|
||||
}
|
||||
|
||||
public function install(PackageInterface $package)
|
||||
{
|
||||
$installer = $this->composer->getInstaller($package->getType());
|
||||
$downloader = $this->getDownloaderForPackage($package);
|
||||
$packageType = $this->getTypeForPackage($package);
|
||||
|
||||
if (!$installer->install($package, $downloader, $packageType)) {
|
||||
throw new \LogicException($package->getName().' could not be installed.');
|
||||
}
|
||||
}
|
||||
|
||||
public function update(PackageInterface $package)
|
||||
{
|
||||
$installer = $this->composer->getInstaller($package->getType());
|
||||
$downloader = $this->getDownloaderForPackage($package);
|
||||
$packageType = $this->getTypeForPackage($package);
|
||||
|
||||
if (!$installer->update($package, $downloader, $packageType)) {
|
||||
throw new \LogicException($package->getName().' could not be updated.');
|
||||
}
|
||||
}
|
||||
|
||||
public function remove(PackageInterface $package)
|
||||
{
|
||||
$installer = $this->composer->getInstaller($package->getType());
|
||||
$downloader = $this->getDownloaderForPackage($package);
|
||||
$packageType = $this->getTypeForPackage($package);
|
||||
|
||||
if (!$installer->remove($package, $downloader, $packageType)) {
|
||||
throw new \LogicException($package->getName().' could not be removed.');
|
||||
}
|
||||
}
|
||||
|
||||
private function getDownloaderForPackage(PackageInterface $package)
|
||||
{
|
||||
if ($package->getDistType()) {
|
||||
$downloader = $this->composer->getDownloader($package->getDistType);
|
||||
} elseif ($package->getSourceType()) {
|
||||
$downloader = $this->copmoser->getDownloader($package->getSourceType());
|
||||
} else {
|
||||
throw new \UnexpectedValueException(
|
||||
'Package '.$package->getName().' has no source or dist URL.'
|
||||
);
|
||||
}
|
||||
|
||||
return $downloader;
|
||||
}
|
||||
|
||||
private function getTypeForPackage(PackageInterface $package)
|
||||
{
|
||||
if ($package->getDistType()) {
|
||||
$type = 'dist';
|
||||
} elseif ($package->getSourceType()) {
|
||||
$type = 'source';
|
||||
} else {
|
||||
throw new \UnexpectedValueException(
|
||||
'Package '.$package->getName().' has no source or dist URL.'
|
||||
);
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue