public function createSection(SectionCreateStruct $sectionCreateStruct)
{
if (!is_string($sectionCreateStruct->name) || empty($sectionCreateStruct->name)) {
throw new InvalidArgumentValue('name', $sectionCreateStruct->name, 'SectionCreateStruct');
}
if (!is_string($sectionCreateStruct->identifier) || empty($sectionCreateStruct->identifier)) {
throw new InvalidArgumentValue('identifier', $sectionCreateStruct->identifier, 'SectionCreateStruct');
}
if ($this->repository->hasAccess('section', 'edit') !== true) {
throw new UnauthorizedException('section', 'edit');
}
try {
$existingSection = $this->loadSectionByIdentifier($sectionCreateStruct->identifier);
if ($existingSection !== null) {
throw new InvalidArgumentException('sectionCreateStruct', 'section with specified identifier already exists');
}
} catch (APINotFoundException $e) {
// Do nothing
}
$this->repository->beginTransaction();
try {
$spiSection = $this->sectionHandler->create($sectionCreateStruct->name, $sectionCreateStruct->identifier);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
return $this->buildDomainSectionObject($spiSection);
}