public function parse($wId, $definition, $source)
{
if (empty($wId)) {
throw new WorkflowValidationException("Missing argument : workflow Id");
}
if (!\is_array($definition)) {
throw new WorkflowValidationException("Workflow definition must be provided as an array");
}
if (!ArrayHelper::isAssociative($definition)) {
throw new WorkflowValidationException("Workflow definition must be provided as associative array");
}
$initialStatusId = null;
$normalized = [];
$startStatusIdIndex = [];
$endStatusIdIndex = [];
foreach ($definition as $id => $targetStatusList) {
list($workflowId, $statusId) = $source->parseStatusId($id, $wId);
$absoluteStatusId = $workflowId . WorkflowFileSource::SEPARATOR_STATUS_NAME . $statusId;
if ($workflowId != $wId) {
throw new WorkflowValidationException('Status must belong to workflow : ' . $absoluteStatusId);
}
if (count($normalized) == 0) {
$initialStatusId = $absoluteStatusId;
$normalized['initialStatusId'] = $initialStatusId;
$normalized[WorkflowFileSource::KEY_NODES] = [];
}
$startStatusIdIndex[] = $absoluteStatusId;
$endStatusIds = [];
if (\is_string($targetStatusList)) {
$ids = array_map('trim', explode(',', $targetStatusList));
$endStatusIds = $this->normalizeStatusIds($ids, $wId, $source);
} elseif (\is_array($targetStatusList)) {
if (ArrayHelper::isAssociative($targetStatusList, false)) {
throw new WorkflowValidationException("Associative array not supported (status : {$absoluteStatusId})");
}
$endStatusIds = $this->normalizeStatusIds($targetStatusList, $wId, $source);
} elseif ($targetStatusList === null) {
$endStatusIds = [];
} else {
throw new WorkflowValidationException('End status list must be an array for status : ' . $absoluteStatusId);
}
if (count($endStatusIds)) {
$normalized[WorkflowFileSource::KEY_NODES][$absoluteStatusId] = ['transition' => array_fill_keys($endStatusIds, [])];
$endStatusIdIndex = \array_merge($endStatusIdIndex, $endStatusIds);
} else {
$normalized[WorkflowFileSource::KEY_NODES][$absoluteStatusId] = null;
}
}
$this->validate($wId, $source, $initialStatusId, $startStatusIdIndex, $endStatusIdIndex);
return $normalized;
}