You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.1 KiB
PHTML

<?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;
use Composer\Package\Package;
use Composer\Package\PackageInterface;
use Composer\Package\RootAliasPackage;
use Composer\Repository\LockArrayRepository;
use Composer\Semver\Constraint\ConstraintInterface;
/**
* @author Nils Adermann <naderman@naderman.de>
*/
class Request
{
protected $lockedRepository;
protected $jobs = array();
protected $fixedPackages = array();
protected $unlockables = array();
public function __construct(LockArrayRepository $lockedRepository = null)
{
$this->lockedRepository = $lockedRepository;
}
public function install($packageName, ConstraintInterface $constraint = null)
{
$this->addJob($packageName, 'install', $constraint);
}
/**
* Mark an existing package as being installed and having to remain installed
*
* @param bool $lockable if set to false, the package will not be written to the lock file
*/
public function fixPackage(PackageInterface $package, $lockable = true)
{
$this->fixedPackages[spl_object_hash($package)] = $package;
if (!$lockable) {
$this->unlockables[] = $package;
}
}
protected function addJob($packageName, $cmd, ConstraintInterface $constraint = null)
{
$packageName = strtolower($packageName);
$this->jobs[] = array(
'cmd' => $cmd,
'packageName' => $packageName,
'constraint' => $constraint,
);
}
public function getJobs()
{
return $this->jobs;
}
public function getFixedPackages()
{
return $this->fixedPackages;
}
public function isFixedPackage(PackageInterface $package)
{
return isset($this->fixedPackages[spl_object_hash($package)]);
}
// TODO look into removing the packageIds option, the only place true is used is for the installed map in the solver problems
// some locked packages may not be in the pool so they have a package->id of -1
public function getPresentMap($packageIds = false)
{
$presentMap = array();
if ($this->lockedRepository) {
foreach ($this->lockedRepository->getPackages() as $package) {
$presentMap[$packageIds ? $package->id : spl_object_hash($package)] = $package;
}
}
foreach ($this->fixedPackages as $package) {
$presentMap[$packageIds ? $package->id : spl_object_hash($package)] = $package;
}
return $presentMap;
}
public function getUnlockableMap()
{
$unlockableMap = array();
foreach ($this->unlockables as $package) {
$unlockableMap[$package->id] = $package;
}
return $unlockableMap;
}
public function getLockedRepository()
{
return $this->lockedRepository;
}
}