Procházet zdrojové kódy

Refactored Operations in order to fulfill naderman requests

everzet před 13 roky
rodič
revize
123f5fef77

+ 35 - 0
src/Composer/DependencyResolver/Operation/InstallOperation.php

@@ -21,6 +21,41 @@ use Composer\Package\PackageInterface;
  */
 class InstallOperation extends SolverOperation
 {
+    protected $package;
+
+    /**
+     * Initializes operation.
+     *
+     * @param   PackageInterface    $package    package instance
+     * @param   string              $reason     operation reason
+     */
+    public function __construct(PackageInterface $package, $reason = null)
+    {
+        parent::__construct($reason);
+
+        $this->package = $package;
+    }
+
+    /**
+     * Returns package instance.
+     *
+     * @return  PackageInterface
+     */
+    public function getPackage()
+    {
+        return $this->package;
+    }
+
+    /**
+     * Returns installer type to be used with this operation.
+     *
+     * @return  string
+     */
+    public function getInstallerType()
+    {
+        return $this->package->getType();
+    }
+
     /**
      * Returns job type.
      *

+ 2 - 9
src/Composer/DependencyResolver/Operation/OperationInterface.php

@@ -29,18 +29,11 @@ interface OperationInterface
     function getJobType();
 
     /**
-     * Returns package instance.
-     *
-     * @return  PackageInterface
-     */
-    function getPackage();
-
-    /**
-     * Returns package type.
+     * Returns installer type to be used with this operation.
      *
      * @return  string
      */
-    function getPackageType();
+    function getInstallerType();
 
     /**
      * Returns operation reason.

+ 3 - 26
src/Composer/DependencyResolver/Operation/SolverOperation.php

@@ -21,39 +21,16 @@ use Composer\Package\PackageInterface;
  */
 abstract class SolverOperation implements OperationInterface
 {
-    protected $package;
     protected $reason;
 
     /**
      * Initializes operation.
      *
-     * @param   PackageInterface    $package    package instance
-     * @param   string              $reason     operation reason
+     * @param   string  $reason     operation reason
      */
-    public function __construct(PackageInterface $package, $reason = null)
+    public function __construct($reason = null)
     {
-        $this->package = $package;
-        $this->reason  = $reason;
-    }
-
-    /**
-     * Returns package instance.
-     *
-     * @return  PackageInterface
-     */
-    public function getPackage()
-    {
-        return $this->package;
-    }
-
-    /**
-     * Returns package type.
-     *
-     * @return  string
-     */
-    public function getPackageType()
-    {
-        return $this->package->getType();
+        $this->reason = $reason;
     }
 
     /**

+ 35 - 0
src/Composer/DependencyResolver/Operation/UninstallOperation.php

@@ -21,6 +21,41 @@ use Composer\Package\PackageInterface;
  */
 class UninstallOperation extends SolverOperation
 {
+    protected $package;
+
+    /**
+     * Initializes operation.
+     *
+     * @param   PackageInterface    $package    package instance
+     * @param   string              $reason     operation reason
+     */
+    public function __construct(PackageInterface $package, $reason = null)
+    {
+        parent::__construct($reason);
+
+        $this->package = $package;
+    }
+
+    /**
+     * Returns package instance.
+     *
+     * @return  PackageInterface
+     */
+    public function getPackage()
+    {
+        return $this->package;
+    }
+
+    /**
+     * Returns installer type to be used with this operation.
+     *
+     * @return  string
+     */
+    public function getInstallerType()
+    {
+        return $this->package->getType();
+    }
+
     /**
      * Returns job type.
      *

+ 29 - 6
src/Composer/DependencyResolver/Operation/UpdateOperation.php

@@ -21,6 +21,7 @@ use Composer\Package\PackageInterface;
  */
 class UpdateOperation extends SolverOperation
 {
+    protected $initialPackage;
     protected $targetPackage;
 
     /**
@@ -32,19 +33,20 @@ class UpdateOperation extends SolverOperation
      */
     public function __construct(PackageInterface $initial, PackageInterface $target, $reason = null)
     {
-        parent::__construct($initial, $reason);
+        parent::__construct($reason);
 
-        $this->targetPackage = $target;
+        $this->initialPackage = $initial;
+        $this->targetPackage  = $target;
     }
 
     /**
-     * Returns job type.
+     * Returns initial package.
      *
-     * @return  string
+     * @return  PackageInterface
      */
-    public function getJobType()
+    public function getInitialPackage()
     {
-        return 'update';
+        return $this->initialPackage;
     }
 
     /**
@@ -56,4 +58,25 @@ class UpdateOperation extends SolverOperation
     {
         return $this->targetPackage;
     }
+
+    /**
+     * Returns installer type to be used with this operation.
+     *
+     * @return  string
+     */
+    public function getInstallerType()
+    {
+        return $this->targetPackage->getType();
+    }
+
+
+    /**
+     * Returns job type.
+     *
+     * @return  string
+     */
+    public function getJobType()
+    {
+        return 'update';
+    }
 }

+ 1 - 1
src/Composer/Installer/LibraryInstaller.php

@@ -81,7 +81,7 @@ class LibraryInstaller implements InstallerInterface
         $method = $operation->getJobType();
 
         if ('update' === $method) {
-            $this->$method($operation->getPackage(), $operation->getTargetPackage());
+            $this->$method($operation->getInitialPackage(), $operation->getTargetPackage());
         } else {
             $this->$method($operation->getPackage());
         }

+ 10 - 3
tests/Composer/Test/DependencyResolver/SolverTest.php

@@ -226,10 +226,17 @@ class SolverTest extends \PHPUnit_Framework_TestCase
         $result = array();
         foreach ($transaction as $operation) {
             if ('update' === $operation->getJobType()) {
-                $result[] = array('job' => 'update', 'from' => $operation->getPackage(), 'to' => $operation->getTargetPackage());
+                $result[] = array(
+                    'job'  => 'update',
+                    'from' => $operation->getInitialPackage(),
+                    'to'   => $operation->getTargetPackage()
+                );
             } else {
-                $job = 'uninstall' === $operation->getJobType() ? 'remove' : 'install';
-                $result[] = array('job' => $job, 'package' => $operation->getPackage());
+                $job = ('uninstall' === $operation->getJobType() ? 'remove' : 'install');
+                $result[] = array(
+                    'job'     => $job,
+                    'package' => $operation->getPackage()
+                );
             }
         }