Refactored Operations in order to fulfill naderman requests
parent
cce4d3af11
commit
123f5fef77
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue