Refactored Operations in order to fulfill naderman requests
parent
cce4d3af11
commit
123f5fef77
|
@ -21,6 +21,41 @@ use Composer\Package\PackageInterface;
|
||||||
*/
|
*/
|
||||||
class InstallOperation extends SolverOperation
|
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.
|
* Returns job type.
|
||||||
*
|
*
|
||||||
|
|
|
@ -29,18 +29,11 @@ interface OperationInterface
|
||||||
function getJobType();
|
function getJobType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns package instance.
|
* Returns installer type to be used with this operation.
|
||||||
*
|
|
||||||
* @return PackageInterface
|
|
||||||
*/
|
|
||||||
function getPackage();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns package type.
|
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function getPackageType();
|
function getInstallerType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns operation reason.
|
* Returns operation reason.
|
||||||
|
|
|
@ -21,39 +21,16 @@ use Composer\Package\PackageInterface;
|
||||||
*/
|
*/
|
||||||
abstract class SolverOperation implements OperationInterface
|
abstract class SolverOperation implements OperationInterface
|
||||||
{
|
{
|
||||||
protected $package;
|
|
||||||
protected $reason;
|
protected $reason;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes operation.
|
* 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;
|
||||||
$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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,6 +21,41 @@ use Composer\Package\PackageInterface;
|
||||||
*/
|
*/
|
||||||
class UninstallOperation extends SolverOperation
|
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.
|
* Returns job type.
|
||||||
*
|
*
|
||||||
|
|
|
@ -21,6 +21,7 @@ use Composer\Package\PackageInterface;
|
||||||
*/
|
*/
|
||||||
class UpdateOperation extends SolverOperation
|
class UpdateOperation extends SolverOperation
|
||||||
{
|
{
|
||||||
|
protected $initialPackage;
|
||||||
protected $targetPackage;
|
protected $targetPackage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,19 +33,20 @@ class UpdateOperation extends SolverOperation
|
||||||
*/
|
*/
|
||||||
public function __construct(PackageInterface $initial, PackageInterface $target, $reason = null)
|
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;
|
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();
|
$method = $operation->getJobType();
|
||||||
|
|
||||||
if ('update' === $method) {
|
if ('update' === $method) {
|
||||||
$this->$method($operation->getPackage(), $operation->getTargetPackage());
|
$this->$method($operation->getInitialPackage(), $operation->getTargetPackage());
|
||||||
} else {
|
} else {
|
||||||
$this->$method($operation->getPackage());
|
$this->$method($operation->getPackage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,10 +226,17 @@ class SolverTest extends \PHPUnit_Framework_TestCase
|
||||||
$result = array();
|
$result = array();
|
||||||
foreach ($transaction as $operation) {
|
foreach ($transaction as $operation) {
|
||||||
if ('update' === $operation->getJobType()) {
|
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 {
|
} else {
|
||||||
$job = 'uninstall' === $operation->getJobType() ? 'remove' : 'install';
|
$job = ('uninstall' === $operation->getJobType() ? 'remove' : 'install');
|
||||||
$result[] = array('job' => $job, 'package' => $operation->getPackage());
|
$result[] = array(
|
||||||
|
'job' => $job,
|
||||||
|
'package' => $operation->getPackage()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue