Refactor Operation classes to use constants instead of strings for comparison
parent
e7d99c37b3
commit
9a5121ed27
|
@ -19,39 +19,9 @@ use Composer\Package\PackageInterface;
|
||||||
*
|
*
|
||||||
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||||
*/
|
*/
|
||||||
class InstallOperation implements OperationInterface
|
class InstallOperation extends Operation implements OperationInterface
|
||||||
{
|
{
|
||||||
protected $package;
|
const TYPE = 'install';
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes operation.
|
|
||||||
*
|
|
||||||
* @param PackageInterface $package package instance
|
|
||||||
*/
|
|
||||||
public function __construct(PackageInterface $package)
|
|
||||||
{
|
|
||||||
$this->package = $package;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns package instance.
|
|
||||||
*
|
|
||||||
* @return PackageInterface
|
|
||||||
*/
|
|
||||||
public function getPackage()
|
|
||||||
{
|
|
||||||
return $this->package;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns operation type.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getOperationType()
|
|
||||||
{
|
|
||||||
return 'install';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
|
@ -65,12 +35,4 @@ class InstallOperation implements OperationInterface
|
||||||
{
|
{
|
||||||
return ($lock ? 'Locking ' : 'Installing ').'<info>'.$package->getPrettyName().'</info> (<comment>'.$package->getFullPrettyVersion().'</comment>)';
|
return ($lock ? 'Locking ' : 'Installing ').'<info>'.$package->getPrettyName().'</info> (<comment>'.$package->getFullPrettyVersion().'</comment>)';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
return $this->show(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,9 @@ use Composer\Package\PackageInterface;
|
||||||
*
|
*
|
||||||
* @author Nils Adermann <naderman@naderman.de>
|
* @author Nils Adermann <naderman@naderman.de>
|
||||||
*/
|
*/
|
||||||
class MarkAliasInstalledOperation implements OperationInterface
|
class MarkAliasInstalledOperation extends Operation implements OperationInterface
|
||||||
{
|
{
|
||||||
protected $package;
|
const TYPE = 'markAliasInstalled';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes operation.
|
* Initializes operation.
|
||||||
|
@ -31,27 +31,7 @@ class MarkAliasInstalledOperation implements OperationInterface
|
||||||
*/
|
*/
|
||||||
public function __construct(AliasPackage $package)
|
public function __construct(AliasPackage $package)
|
||||||
{
|
{
|
||||||
$this->package = $package;
|
parent::__construct($package);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns package instance.
|
|
||||||
*
|
|
||||||
* @return PackageInterface
|
|
||||||
*/
|
|
||||||
public function getPackage()
|
|
||||||
{
|
|
||||||
return $this->package;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns operation type.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getOperationType()
|
|
||||||
{
|
|
||||||
return 'markAliasInstalled';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,12 +41,4 @@ class MarkAliasInstalledOperation implements OperationInterface
|
||||||
{
|
{
|
||||||
return 'Marking <info>'.$this->package->getPrettyName().'</info> (<comment>'.$this->package->getFullPrettyVersion().'</comment>) as installed, alias of <info>'.$this->package->getAliasOf()->getPrettyName().'</info> (<comment>'.$this->package->getAliasOf()->getFullPrettyVersion().'</comment>)';
|
return 'Marking <info>'.$this->package->getPrettyName().'</info> (<comment>'.$this->package->getFullPrettyVersion().'</comment>) as installed, alias of <info>'.$this->package->getAliasOf()->getPrettyName().'</info> (<comment>'.$this->package->getAliasOf()->getFullPrettyVersion().'</comment>)';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
return $this->show(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,9 @@ use Composer\Package\PackageInterface;
|
||||||
*
|
*
|
||||||
* @author Nils Adermann <naderman@naderman.de>
|
* @author Nils Adermann <naderman@naderman.de>
|
||||||
*/
|
*/
|
||||||
class MarkAliasUninstalledOperation implements OperationInterface
|
class MarkAliasUninstalledOperation extends Operation implements OperationInterface
|
||||||
{
|
{
|
||||||
protected $package;
|
const TYPE = 'markAliasUninstalled';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes operation.
|
* Initializes operation.
|
||||||
|
@ -31,27 +31,7 @@ class MarkAliasUninstalledOperation implements OperationInterface
|
||||||
*/
|
*/
|
||||||
public function __construct(AliasPackage $package)
|
public function __construct(AliasPackage $package)
|
||||||
{
|
{
|
||||||
$this->package = $package;
|
parent::__construct($package);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns package instance.
|
|
||||||
*
|
|
||||||
* @return PackageInterface
|
|
||||||
*/
|
|
||||||
public function getPackage()
|
|
||||||
{
|
|
||||||
return $this->package;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns operation type.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getOperationType()
|
|
||||||
{
|
|
||||||
return 'markAliasUninstalled';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,12 +41,4 @@ class MarkAliasUninstalledOperation implements OperationInterface
|
||||||
{
|
{
|
||||||
return 'Marking <info>'.$this->package->getPrettyName().'</info> (<comment>'.$this->package->getFullPrettyVersion().'</comment>) as uninstalled, alias of <info>'.$this->package->getAliasOf()->getPrettyName().'</info> (<comment>'.$this->package->getAliasOf()->getFullPrettyVersion().'</comment>)';
|
return 'Marking <info>'.$this->package->getPrettyName().'</info> (<comment>'.$this->package->getFullPrettyVersion().'</comment>) as uninstalled, alias of <info>'.$this->package->getAliasOf()->getPrettyName().'</info> (<comment>'.$this->package->getAliasOf()->getFullPrettyVersion().'</comment>)';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
return $this->show(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
<?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\DependencyResolver\Operation;
|
||||||
|
|
||||||
|
use Composer\Package\PackageInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract operation class.
|
||||||
|
*
|
||||||
|
* @author Aleksandr Bezpiatov <aleksandr.bezpiatov@spryker.com>
|
||||||
|
*/
|
||||||
|
abstract class Operation implements OperationInterface
|
||||||
|
{
|
||||||
|
const TYPE = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var PackageInterface
|
||||||
|
*/
|
||||||
|
protected $package;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes operation.
|
||||||
|
*
|
||||||
|
* @param PackageInterface $package package instance
|
||||||
|
*/
|
||||||
|
public function __construct(PackageInterface $package)
|
||||||
|
{
|
||||||
|
$this->package = $package;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns package instance.
|
||||||
|
*
|
||||||
|
* @return PackageInterface
|
||||||
|
*/
|
||||||
|
public function getPackage()
|
||||||
|
{
|
||||||
|
return $this->package;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns operation type.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getOperationType()
|
||||||
|
{
|
||||||
|
return static::TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return $this->show(false);
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,39 +19,9 @@ use Composer\Package\PackageInterface;
|
||||||
*
|
*
|
||||||
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||||
*/
|
*/
|
||||||
class UninstallOperation implements OperationInterface
|
class UninstallOperation extends Operation implements OperationInterface
|
||||||
{
|
{
|
||||||
protected $package;
|
const TYPE = 'uninstall';
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes operation.
|
|
||||||
*
|
|
||||||
* @param PackageInterface $package package instance
|
|
||||||
*/
|
|
||||||
public function __construct(PackageInterface $package)
|
|
||||||
{
|
|
||||||
$this->package = $package;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns package instance.
|
|
||||||
*
|
|
||||||
* @return PackageInterface
|
|
||||||
*/
|
|
||||||
public function getPackage()
|
|
||||||
{
|
|
||||||
return $this->package;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns operation type.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getOperationType()
|
|
||||||
{
|
|
||||||
return 'uninstall';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
|
@ -65,12 +35,4 @@ class UninstallOperation implements OperationInterface
|
||||||
{
|
{
|
||||||
return 'Removing <info>'.$package->getPrettyName().'</info> (<comment>'.$package->getFullPrettyVersion().'</comment>)';
|
return 'Removing <info>'.$package->getPrettyName().'</info> (<comment>'.$package->getFullPrettyVersion().'</comment>)';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
return $this->show(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,10 @@ use Composer\Package\Version\VersionParser;
|
||||||
*
|
*
|
||||||
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||||
*/
|
*/
|
||||||
class UpdateOperation implements OperationInterface
|
class UpdateOperation extends Operation implements OperationInterface
|
||||||
{
|
{
|
||||||
|
const TYPE = 'update';
|
||||||
|
|
||||||
protected $initialPackage;
|
protected $initialPackage;
|
||||||
protected $targetPackage;
|
protected $targetPackage;
|
||||||
|
|
||||||
|
@ -34,7 +36,7 @@ class UpdateOperation implements OperationInterface
|
||||||
public function __construct(PackageInterface $initial, PackageInterface $target)
|
public function __construct(PackageInterface $initial, PackageInterface $target)
|
||||||
{
|
{
|
||||||
$this->initialPackage = $initial;
|
$this->initialPackage = $initial;
|
||||||
$this->targetPackage = $target;
|
parent::__construct($target);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,17 +56,7 @@ class UpdateOperation implements OperationInterface
|
||||||
*/
|
*/
|
||||||
public function getTargetPackage()
|
public function getTargetPackage()
|
||||||
{
|
{
|
||||||
return $this->targetPackage;
|
return $this->getPackage();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns operation type.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getOperationType()
|
|
||||||
{
|
|
||||||
return 'update';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,12 +84,4 @@ class UpdateOperation implements OperationInterface
|
||||||
|
|
||||||
return $actionName.' <info>'.$initialPackage->getPrettyName().'</info> (<comment>'.$fromVersion.'</comment> => <comment>'.$toVersion.'</comment>)';
|
return $actionName.' <info>'.$initialPackage->getPrettyName().'</info> (<comment>'.$fromVersion.'</comment> => <comment>'.$toVersion.'</comment>)';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
return $this->show(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue