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.

97 lines
2.7 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;
/**
* @author Nils Adermann <naderman@naderman.de>
*/
class RuleWatchGraph
{
protected $watches = array();
/**
* Alters watch chains for a rule.
*
*/
public function insert(RuleWatchNode $node)
{
if ($node->getRule()->isAssertion()) {
return;
}
foreach (array($node->watch1, $node->watch2) as $literal) {
if (!isset($this->watches[$literal])) {
$this->watches[$literal] = new RuleWatchChain;
}
$this->watches[$literal]->unshift($node);
}
}
public function contains($literalId)
{
return isset($this->watches[$literalId]);
}
public function walkLiteral($literalId, $level, $skipCallback, $conflictCallback, $decideCallback)
{
if (!isset($this->watches[$literalId])) {
return null;
}
$this->watches[$literalId]->rewind();
while ($this->watches[$literalId]->valid()) {
$node = $this->watches[$literalId]->current();
$otherWatch = $node->getOtherWatch($literalId);
if (!$node->getRule()->isDisabled() && !call_user_func($skipCallback, $otherWatch)) {
$ruleLiterals = $node->getRule()->getLiterals();
12 years ago
foreach ($ruleLiterals as $ruleLiteral) {
$ruleLiteralId = $ruleLiteral->getId();
12 years ago
if ($literalId !== $ruleLiteralId &&
$otherWatch !== $ruleLiteralId &&
!call_user_func($conflictCallback, $ruleLiteralId)) {
12 years ago
$this->moveWatch($literalId, $ruleLiteralId, $node);
continue 2;
}
}
if (call_user_func($conflictCallback, $otherWatch)) {
return $node->getRule();
}
call_user_func($decideCallback, $otherWatch, $level, $node->getRule());
}
$this->watches[$literalId]->next();
}
return null;
}
protected function moveWatch($fromLiteral, $toLiteral, $node)
{
if (!isset($this->watches[$toLiteral])) {
$this->watches[$toLiteral] = new RuleWatchChain;
}
$node->moveWatch($fromLiteral, $toLiteral);
$this->watches[$fromLiteral]->remove();
$this->watches[$toLiteral]->unshift($node);
}
}