Browse Source

Add Dowloader and Installer interfaces

Kirill chEbba Chebunin 13 years ago
parent
commit
e317b4f8ef

+ 30 - 2
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);

+ 35 - 0
src/Composer/Downloader/DownloaderInterface.php

@@ -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);
+}

+ 1 - 1
src/Composer/Downloader/GitDownloader.php

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

+ 1 - 1
src/Composer/Downloader/PearDownloader.php

@@ -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)
     {

+ 1 - 1
src/Composer/Downloader/ZipDownloader.php

@@ -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)
     {

+ 33 - 0
src/Composer/Installer/InstallerInterface.php

@@ -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);
+}

+ 3 - 2
src/Composer/Installer/LibraryInstaller.php

@@ -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());