CBPRuntime::CreateWorkflow: Bitrix method

      
<?php 
//  CBPRuntime :: CreateWorkflow()
//  /dist/bitrix/modules/bizproc/classes/general/runtime.php:223

    
public function CreateWorkflow($workflowTemplateId$documentId$workflowParameters = array(), $parentWorkflow null)
    {
        
$workflowTemplateId intval($workflowTemplateId);
        if (
$workflowTemplateId <= 0)
            throw new 
Exception("workflowTemplateId");

        
$arDocumentId CBPHelper::ParseDocumentId($documentId);

        
$limit = \Bitrix\Main\Config\Option::get("bizproc""limit_simultaneous_processes""0");
        
$ignoreLimits = !empty($workflowParameters[CBPDocument::PARAM_IGNORE_SIMULTANEOUS_PROCESSES_LIMIT]);
        if (!
$ignoreLimits && intval($limit) > 0)
        {
            if (
CBPStateService::CountDocumentWorkflows($documentId) >= $limit)
                throw new 
Exception(GetMessage("BPCGDOC_LIMIT_SIMULTANEOUS_PROCESSES", array("#NUM#" => $limit)));
        }
        unset(
$workflowParameters[CBPDocument::PARAM_IGNORE_SIMULTANEOUS_PROCESSES_LIMIT]);

        if (!
$this->isStarted)
            
$this->StartRuntime();

        
$workflowId uniqid(""true);

        if (
$parentWorkflow)
        {
            
$this->addWorkflowToChain($workflowId$parentWorkflow);
            if (
$this->checkWorkflowRecursion($workflowId$workflowTemplateId))
                throw new 
Exception(GetMessage("BPCGDOC_WORKFLOW_RECURSION_LOCK"));
        }

        
$workflow = new CBPWorkflow($workflowId$this);

        
$loader CBPWorkflowTemplateLoader::GetLoader();

        list(
$rootActivity$workflowVariablesTypes$workflowParametersTypes) = $loader->LoadWorkflow($workflowTemplateId);

        if (
$rootActivity == null)
            throw new 
Exception("EmptyRootActivity");
        
//if (!is_a($rootActivity, "IBPRootActivity"))
        //    throw new Exception("RootActivityIsNotAIBPRootActivity");

        
foreach(GetModuleEvents("bizproc""OnCreateWorkflow"true)  as $arEvent)
        {
            
ExecuteModuleEventEx($arEvent, [$workflowTemplateId$documentId, &$workflowParameters$workflowId]);
        }

        
$workflow->Initialize($rootActivity$arDocumentId$workflowParameters$workflowVariablesTypes$workflowParametersTypes$workflowTemplateId);

        
$starterUserId 0;
        if (isset(
$workflowParameters[CBPDocument::PARAM_TAGRET_USER]))
        {
            
$starterUserId intval(substr($workflowParameters[CBPDocument::PARAM_TAGRET_USER], strlen("user_")));
        }

        
$this->GetService("StateService")->AddWorkflow($workflowId$workflowTemplateId$arDocumentId$starterUserId);

        
$this->arWorkflows[$workflowId] = $workflow;
        return 
$workflow;
    }