1
0
Fork 0

Add Dowloader and Installer interfaces

pull/17/head
Kirill chEbba Chebunin 2011-09-15 23:58:00 +04:00
parent 07e181c6eb
commit e317b4f8ef
7 changed files with 104 additions and 7 deletions

View File

@ -12,6 +12,8 @@
namespace Composer; namespace Composer;
use Composer\Downloader\DownloaderInterface;
use \Composer\Installer\InstallerInterface;
use Composer\Repository\ComposerRepository; use Composer\Repository\ComposerRepository;
use Composer\Repository\PlatformRepository; use Composer\Repository\PlatformRepository;
use Composer\Repository\GitRepository; use Composer\Repository\GitRepository;
@ -31,12 +33,25 @@ class Composer
$this->addRepository('Packagist', array('composer' => 'http://packagist.org')); $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); $type = strtolower($type);
$this->downloaders[$type] = $downloader; $this->downloaders[$type] = $downloader;
} }
/**
* Get type downloader
*
* @param string $type
*
* @return DownloaderInterface
*/
public function getDownloader($type) public function getDownloader($type)
{ {
$type = strtolower($type); $type = strtolower($type);
@ -46,12 +61,25 @@ class Composer
return $this->downloaders[$type]; 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); $type = strtolower($type);
$this->installers[$type] = $installer; $this->installers[$type] = $installer;
} }
/**
* Get type installer
*
* @param string $type
*
* @return InstallerInterface
*/
public function getInstaller($type) public function getInstaller($type)
{ {
$type = strtolower($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
*/
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> * @author Jordi Boggiano <j.boggiano@seld.be>
*/ */
class GitDownloader class GitDownloader implements DownloaderInterface
{ {
protected $clone; protected $clone;

View File

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

View File

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