<?php
namespace App\ServerArbiter;
use App\ServerArbiter\Rules\Rule;
/**
* Class RuleSet
*
* @package App\ServerArbiter
*/
class RuleSet implements \Iterator
{
/**
* @var Rule[] An array of Rule objects
*/
private $rules;
/**
* @var int Iterator position key
*/
private $position = 0;
/**
* @constructor
*/
public function __construct()
{
$this->position = 0;
}
/**
* Add a Rule to the RuleSet
*
* @param Rule $rule
*/
public function addRule(Rule $rule)
{
if (!in_array($rule, $this->rules))
{
$this->rules[] = $rule;
}
}
/**
* Remove a Rule from the RuleSet by it's key
*
* @param int $ruleKey The numeric key within the rules array to unset
*
* @throws \OutOfBoundsException When a non-existant key is provided
* @throws \InvalidArgumentException When a non-integer parameter is provided
*/
public function removeRule($ruleKey)
{
if (is_int($ruleKey))
{
if (array_key_exists($ruleKey, $this->rules))
{
unset($this->rules[$ruleKey]);
}
else
{
throw new \OutOfBoundsException(sprintf(
"%s was passed a out of bounds array key: %s does not exist in this ruleset", __METHOD__, $ruleKey
));
}
}
else
{
throw new \InvalidArgumentException(sprintf(
"%s expected an integer ruleKey parameter, got: '%s' instead", __METHOD__, $ruleKey
));
}
}
/**
* {@inheritdoc}
*
* @return Rule
*/
public function current()
{
return $this->rules[$this->position];
}
/**
* {@inheritdoc}
*/
public function next()
{
++$this->position;
}
/**
* {@inheritdoc}
*/
public function key()
{
return $this->position;
}
/**
* {@inheritdoc}
*/
public function valid()
{
return isset($this->rules[$this->position]);
}
/**
* {@inheritdoc}
*/
public function rewind()
{
$this->position = 0;
}
}
Deprecated: Return type of App\ServerArbiter\RuleSet::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/VnDHR on line 81
Deprecated: Return type of App\ServerArbiter\RuleSet::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/VnDHR on line 89
Deprecated: Return type of App\ServerArbiter\RuleSet::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/VnDHR on line 97
Deprecated: Return type of App\ServerArbiter\RuleSet::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/VnDHR on line 105
Deprecated: Return type of App\ServerArbiter\RuleSet::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/VnDHR on line 113