1
0
Fork 0

Merge pull request #17 from chEbba/interfaces

Add Dowloader and Installer interfaces
pull/18/head
Jordi Boggiano 2011-09-17 04:16:28 -07:00
commit 89f49e0e14
7 changed files with 104 additions and 7 deletions

View File

@ -12,6 +12,8 @@
namespace Composer;
use Composer\Downloader\DownloaderInterface;
use \Composer\Installer\InstallerInterface;
use Composer\Repository\ComposerRepository;
use Composer\Repository\PlatformRepository;
use Composer\Repository\GitRepository;
@ -33,12 +35,25 @@ class Composer
$this->addRepository('Packagist', array('composer' => 'http://packagist.org'));
}
public function addDownloader($type, $downloader)
/**
* Add downloader for type
*
* @param string $type
* @param DownloaderInterface $downloader
*/
public function addDownloader($type, DownloaderInterface $downloader)
{
$type = strtolower($type);
$this->downloaders[$type] = $downloader;
}
/**
* Get type downloader
*
* @param string $type
*
* @return DownloaderInterface
*/
public function getDownloader($type)
{
$type = strtolower($type);
@ -48,12 +63,25 @@ class Composer
return $this->downloaders[$type];
}
public function addInstaller($type, $installer)
/**
* Add installer for type
*
* @param string $type
* @param InstallerInterface $installer
*/
public function addInstaller($type, InstallerInterface $installer)
{
$type = strtolower($type);
$this->installers[$type] = $installer;
}
/**
* Get type installer
*
* @param string $type
*
* @return InstallerInterface
*/
public function getInstaller($type)
{
$type = strtolower($type);

View File

@ -0,0 +1,35 @@
<?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\Downloader;
use Composer\Package\PackageInterface;
/**
* Package Downloader
*
* @author Kirill chEbba Chebunin <iam@chebba.org>
*/
interface DownloaderInterface
{
/**
* Download package
*
* @param PackageInterface $package Downloaded package
* @param string $path Download to
* @param string $url Download from
* @param string|null $checksum Package checksum
*
* @throws \UnexpectedValueException
*/
function download(PackageInterface $package, $path, $url, $checksum = null);
}

View File

@ -17,7 +17,7 @@ use Composer\Package\PackageInterface;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class GitDownloader
class GitDownloader implements DownloaderInterface
{
protected $clone;

View File

@ -18,7 +18,7 @@ use Composer\Package\PackageInterface;
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class PearDownloader
class PearDownloader implements DownloaderInterface
{
public function download(PackageInterface $package, $path, $url, $checksum = null)
{

View File

@ -17,7 +17,7 @@ use Composer\Package\PackageInterface;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class ZipDownloader
class ZipDownloader implements DownloaderInterface
{
public function download(PackageInterface $package, $path, $url, $checksum = null)
{

View File

@ -0,0 +1,33 @@
<?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\Downloader\DownloaderInterface;
use Composer\Package\PackageInterface;
/**
* Package Installer
*
* @author Kirill chEbba Chebunin <iam@chebba.org>
*/
interface InstallerInterface
{
/**
* Install package
*
* @param PackageInterface $package
* @param DownloaderInterface $downloader
* @param string $type
*/
function install(PackageInterface $package, DownloaderInterface $downloader, $type);
}

View File

@ -12,12 +12,13 @@
namespace Composer\Installer;
use Composer\Downloader\DownloaderInterface;
use Composer\Package\PackageInterface;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class LibraryInstaller
class LibraryInstaller implements InstallerInterface
{
protected $dir;
@ -26,7 +27,7 @@ class LibraryInstaller
$this->dir = $dir;
}
public function install(PackageInterface $package, $downloader, $type)
public function install(PackageInterface $package, DownloaderInterface $downloader, $type)
{
if ($type === 'dist') {
$downloader->download($package, $this->dir, $package->getDistUrl(), $package->getDistSha1Checksum());