2017-10-29 17:58:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Component\Workflow;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of transition blockers.
|
2018-02-07 15:57:22 +00:00
|
|
|
*
|
|
|
|
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
2017-10-29 17:58:58 +00:00
|
|
|
*/
|
2018-02-07 15:57:22 +00:00
|
|
|
final class TransitionBlockerList implements \IteratorAggregate, \Countable
|
2017-10-29 17:58:58 +00:00
|
|
|
{
|
2018-02-07 15:57:22 +00:00
|
|
|
private $blockers;
|
2017-10-29 17:58:58 +00:00
|
|
|
|
2018-02-07 15:57:22 +00:00
|
|
|
/**
|
|
|
|
* @param TransitionBlocker[] $blockers
|
|
|
|
*/
|
2017-10-29 17:58:58 +00:00
|
|
|
public function __construct(array $blockers = array())
|
|
|
|
{
|
2018-02-07 15:57:22 +00:00
|
|
|
$this->blockers = array();
|
|
|
|
|
2017-10-29 17:58:58 +00:00
|
|
|
foreach ($blockers as $blocker) {
|
|
|
|
$this->add($blocker);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function add(TransitionBlocker $blocker): void
|
|
|
|
{
|
|
|
|
$this->blockers[] = $blocker;
|
|
|
|
}
|
|
|
|
|
2018-11-08 13:40:02 +00:00
|
|
|
public function has(string $code): bool
|
|
|
|
{
|
|
|
|
foreach ($this->blockers as $blocker) {
|
|
|
|
if ($code === $blocker->getCode()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-29 17:31:06 +01:00
|
|
|
public function clear(): void
|
2017-10-29 17:58:58 +00:00
|
|
|
{
|
2018-02-07 15:57:22 +00:00
|
|
|
$this->blockers = array();
|
2017-10-29 17:58:58 +00:00
|
|
|
}
|
|
|
|
|
2018-02-07 15:57:22 +00:00
|
|
|
public function isEmpty(): bool
|
2017-10-29 17:58:58 +00:00
|
|
|
{
|
2018-02-07 15:57:22 +00:00
|
|
|
return !$this->blockers;
|
2017-10-29 17:58:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*
|
|
|
|
* @return \ArrayIterator|TransitionBlocker[]
|
|
|
|
*/
|
|
|
|
public function getIterator()
|
|
|
|
{
|
|
|
|
return new \ArrayIterator($this->blockers);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function count(): int
|
|
|
|
{
|
2018-02-07 15:57:22 +00:00
|
|
|
return \count($this->blockers);
|
2017-10-29 17:58:58 +00:00
|
|
|
}
|
|
|
|
}
|