load($file))
throw new InvalidArgumentException('Cannot load file ' . htmlspecialchars($file) . '');
$this->XML = $XML;
foreach($XML->getElementsByTagName('group') as $group)
{
if($group->hasAttribute('id') && $group->hasAttribute('name'))
{
$groupData = array();
$groupData['id'] = $group->getAttribute('id');
$groupData['name'] = $group->getAttribute('name');
$this->groups[$groupData['id']] = new Group($groupData);
}
else
throw new RuntimeException('Cannot load group. id or/and name parameter is missing');
}
}
/*
* Get group
*/
public function getGroup($id)
{
if(isset($this->groups[$id]))
return $this->groups[$id];
return false;
}
/*
* Get group name without getting group
*/
public function getGroupName($id)
{
if($group = self::getGroup($id))
return $group->getName();
return false;
}
public function current(): mixed
{
return $this->groups[$this->iterator];
}
public function rewind(): void
{
$this->iterator = 0;
}
public function next(): void
{
++$this->iterator;
}
public function key(): mixed
{
return $this->iterator;
}
public function valid(): bool
{
return isset($this->groups[$this->iterator]);
}
public function count(): int
{
return count($this->groups);
}
}