Refactored solver result array. Now it returns array of operation objects which are much nicer to work with
parent
5b0d17cc13
commit
0a1e7320b0
@ -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\DependencyResolver\Operation;
|
||||||
|
|
||||||
|
use Composer\Package\PackageInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Solver install operation.
|
||||||
|
*
|
||||||
|
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||||
|
*/
|
||||||
|
class InstallOperation extends SolverOperation
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns job type.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getJobType()
|
||||||
|
{
|
||||||
|
return 'install';
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Solver operation interface.
|
||||||
|
*
|
||||||
|
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||||
|
*/
|
||||||
|
interface OperationInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns job type.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function getJobType();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns package instance.
|
||||||
|
*
|
||||||
|
* @return PackageInterface
|
||||||
|
*/
|
||||||
|
function getPackage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns package type.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function getPackageType();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns operation reason.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function getReason();
|
||||||
|
}
|
@ -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 solver operation class.
|
||||||
|
*
|
||||||
|
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||||
|
*/
|
||||||
|
abstract class SolverOperation implements OperationInterface
|
||||||
|
{
|
||||||
|
protected $package;
|
||||||
|
protected $reason;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes operation.
|
||||||
|
*
|
||||||
|
* @param PackageInterface $package package instance
|
||||||
|
* @param string $reason operation reason
|
||||||
|
*/
|
||||||
|
public function __construct(PackageInterface $package, $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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns operation reason.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getReason()
|
||||||
|
{
|
||||||
|
return $this->reason;
|
||||||
|
}
|
||||||
|
}
|
@ -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\DependencyResolver\Operation;
|
||||||
|
|
||||||
|
use Composer\Package\PackageInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Solver uninstall operation.
|
||||||
|
*
|
||||||
|
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||||
|
*/
|
||||||
|
class UninstallOperation extends SolverOperation
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns job type.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getJobType()
|
||||||
|
{
|
||||||
|
return 'uninstall';
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Solver update operation.
|
||||||
|
*
|
||||||
|
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||||
|
*/
|
||||||
|
class UpdateOperation extends SolverOperation
|
||||||
|
{
|
||||||
|
protected $targetPackage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes update operation.
|
||||||
|
*
|
||||||
|
* @param PackageInterface $initial initial package
|
||||||
|
* @param PackageInterface $target target package (updated)
|
||||||
|
* @param string $reason update reason
|
||||||
|
*/
|
||||||
|
public function __construct(PackageInterface $initial, PackageInterface $target, $reason = null)
|
||||||
|
{
|
||||||
|
parent::__construct($initial, $reason);
|
||||||
|
|
||||||
|
$this->targetPackage = $target;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns job type.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getJobType()
|
||||||
|
{
|
||||||
|
return 'update';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns target package.
|
||||||
|
*
|
||||||
|
* @return PackageInterface
|
||||||
|
*/
|
||||||
|
public function getTargetPackage()
|
||||||
|
{
|
||||||
|
return $this->targetPackage;
|
||||||
|
}
|
||||||
|
}
|
@ -1,57 +0,0 @@
|
|||||||
<?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\Installer\InstallerInterface;
|
|
||||||
use Composer\Package\PackageInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Installer operation command
|
|
||||||
*
|
|
||||||
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
|
||||||
*/
|
|
||||||
class Operation
|
|
||||||
{
|
|
||||||
private $installer;
|
|
||||||
private $type;
|
|
||||||
private $package;
|
|
||||||
|
|
||||||
public function __construct(InstallerInterface $installer, $type, PackageInterface $package)
|
|
||||||
{
|
|
||||||
$type = strtolower($type);
|
|
||||||
if (!in_array($type, array('install', 'update', 'remove'))) {
|
|
||||||
throw new \UnexpectedValueException('Unhandled operation type: ' . $type);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->installer = $installer;
|
|
||||||
$this->type = $type;
|
|
||||||
$this->package = $package;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getType()
|
|
||||||
{
|
|
||||||
return $this->type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPackage()
|
|
||||||
{
|
|
||||||
return $this->package;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function execute()
|
|
||||||
{
|
|
||||||
$method = $this->getType();
|
|
||||||
|
|
||||||
return $this->installer->$method($this->getPackage());
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue