/**
* Validate webspace default segment.
*
* @throws Exception\WebspaceDefaultSegmentNotFoundException
* @throws Exception\InvalidWebspaceDefaultSegmentException
*/
protected function validateWebspaceDefaultSegment()
{
// check if there are duplicate defaults in the webspaces segments
$segments = $this->webspace->getSegments();
if ($segments) {
$webspaceDefaultSegmentFound = false;
foreach ($segments as $webspaceSegment) {
if ($webspaceSegment->isDefault()) {
// throw an exception, if a new default segment is found, although there already is one
if ($webspaceDefaultSegmentFound) {
throw new InvalidWebspaceDefaultSegmentException($this->webspace);
}
$webspaceDefaultSegmentFound = true;
}
}
if (!$webspaceDefaultSegmentFound) {
throw new WebspaceDefaultSegmentNotFoundException($this->webspace);
}
}
}