This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Workflow/TransitionBlockerList.php

76 lines
1.5 KiB
PHP
Raw Normal View History

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.
*
* @author Grégoire Pineau <lyrixx@lyrixx.info>
2017-10-29 17:58:58 +00:00
*/
final class TransitionBlockerList implements \IteratorAggregate, \Countable
2017-10-29 17:58:58 +00:00
{
private $blockers;
2017-10-29 17:58:58 +00:00
/**
* @param TransitionBlocker[] $blockers
*/
2019-01-16 18:24:45 +00:00
public function __construct(array $blockers = [])
2017-10-29 17:58:58 +00:00
{
2019-01-16 18:24:45 +00:00
$this->blockers = [];
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;
}
public function clear(): void
2017-10-29 17:58:58 +00:00
{
2019-01-16 18:24:45 +00:00
$this->blockers = [];
2017-10-29 17:58:58 +00:00
}
public function isEmpty(): bool
2017-10-29 17:58:58 +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
{
return \count($this->blockers);
2017-10-29 17:58:58 +00:00
}
}