From e317b4f8efc765b525cc473220d85cb9d5cc135a Mon Sep 17 00:00:00 2001 From: Kirill chEbba Chebunin Date: Thu, 15 Sep 2011 23:58:00 +0400 Subject: [PATCH] Add Dowloader and Installer interfaces --- src/Composer/Composer.php | 32 +++++++++++++++-- .../Downloader/DownloaderInterface.php | 35 +++++++++++++++++++ src/Composer/Downloader/GitDownloader.php | 2 +- src/Composer/Downloader/PearDownloader.php | 2 +- src/Composer/Downloader/ZipDownloader.php | 2 +- src/Composer/Installer/InstallerInterface.php | 33 +++++++++++++++++ src/Composer/Installer/LibraryInstaller.php | 5 +-- 7 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 src/Composer/Downloader/DownloaderInterface.php create mode 100644 src/Composer/Installer/InstallerInterface.php diff --git a/src/Composer/Composer.php b/src/Composer/Composer.php index 914c1c156..b823a0bae 100644 --- a/src/Composer/Composer.php +++ b/src/Composer/Composer.php @@ -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; @@ -31,12 +33,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); @@ -46,12 +61,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); diff --git a/src/Composer/Downloader/DownloaderInterface.php b/src/Composer/Downloader/DownloaderInterface.php new file mode 100644 index 000000000..6e78ee3c9 --- /dev/null +++ b/src/Composer/Downloader/DownloaderInterface.php @@ -0,0 +1,35 @@ + + * Jordi Boggiano + * + * 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 + */ +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); +} diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index b4193b612..d7a98bed7 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -17,7 +17,7 @@ use Composer\Package\PackageInterface; /** * @author Jordi Boggiano */ -class GitDownloader +class GitDownloader implements DownloaderInterface { protected $clone; diff --git a/src/Composer/Downloader/PearDownloader.php b/src/Composer/Downloader/PearDownloader.php index c36022248..56e45c677 100644 --- a/src/Composer/Downloader/PearDownloader.php +++ b/src/Composer/Downloader/PearDownloader.php @@ -18,7 +18,7 @@ use Composer\Package\PackageInterface; * @author Benjamin Eberlei * @author Jordi Boggiano */ -class PearDownloader +class PearDownloader implements DownloaderInterface { public function download(PackageInterface $package, $path, $url, $checksum = null) { diff --git a/src/Composer/Downloader/ZipDownloader.php b/src/Composer/Downloader/ZipDownloader.php index afbe0c687..1c5fa547a 100644 --- a/src/Composer/Downloader/ZipDownloader.php +++ b/src/Composer/Downloader/ZipDownloader.php @@ -17,7 +17,7 @@ use Composer\Package\PackageInterface; /** * @author Jordi Boggiano */ -class ZipDownloader +class ZipDownloader implements DownloaderInterface { public function download(PackageInterface $package, $path, $url, $checksum = null) { diff --git a/src/Composer/Installer/InstallerInterface.php b/src/Composer/Installer/InstallerInterface.php new file mode 100644 index 000000000..8c63a592a --- /dev/null +++ b/src/Composer/Installer/InstallerInterface.php @@ -0,0 +1,33 @@ + + * Jordi Boggiano + * + * 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 + */ +interface InstallerInterface +{ + /** + * Install package + * + * @param PackageInterface $package + * @param DownloaderInterface $downloader + * @param string $type + */ + public function install(PackageInterface $package, DownloaderInterface $downloader, $type); +} diff --git a/src/Composer/Installer/LibraryInstaller.php b/src/Composer/Installer/LibraryInstaller.php index 9b91a277e..ad3fd451e 100644 --- a/src/Composer/Installer/LibraryInstaller.php +++ b/src/Composer/Installer/LibraryInstaller.php @@ -12,12 +12,13 @@ namespace Composer\Installer; +use Composer\Downloader\DownloaderInterface; use Composer\Package\PackageInterface; /** * @author Jordi Boggiano */ -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());