/**
  * Обработчик содержащий логику получения entryId
  *
  * @param ResolveEntryIdEventInterface $resolveEntryIdEvent
  *
  *
  * @return null|string
  *
  * @throws \OldTown\Workflow\ZF2\Toolkit\EntryToObjects\Exception\InvalidGetEntryByObjectsInfoException
  * @throws \OldTown\Workflow\ZF2\Toolkit\WorkflowRunParams\Exception\InvalidWorkflowEntryToObjectMetadataException
  * @throws \Zend\Serializer\Exception\ExceptionInterface
  */
 public function onResolveEntryId(ResolveEntryIdEventInterface $resolveEntryIdEvent)
 {
     $this->getLog()->info('Getting "entryId" Workflow to run, based on the data of the object bound to the process');
     $index = $this->getIndexMetadata();
     $managerName = $resolveEntryIdEvent->getManagerName();
     $managerAlias = $resolveEntryIdEvent->getManagerAlias();
     $workflowName = $resolveEntryIdEvent->getWorkflowName();
     $routeMatch = $this->getMvcEvent()->getRouteMatch();
     $routerName = $routeMatch->getMatchedRouteName();
     $indexKeys = $this->buildIndexKeys($routerName, $workflowName, $managerName, $managerAlias);
     $metadata = null;
     foreach ($indexKeys as $indexKey) {
         if (array_key_exists($indexKey, $index)) {
             $metadata = $index[$indexKey];
             break;
         }
     }
     if (null === $metadata) {
         $this->getLog()->info('Metadata for "entryId" not found');
         return null;
     }
     $objectsInfo = [];
     foreach ($metadata as $entityClassName => $metadataItem) {
         $objectsInfo[$entityClassName] = [];
         foreach ($metadataItem as $propertyName => $info) {
             $mode = $info[static::MODE];
             $paramName = $info[static::PARAM_NAME];
             $idValue = null;
             if (static::MODE_ROUTER_PARAM === $mode) {
                 $idValue = $routeMatch->getParam($paramName, null);
             }
             if (static::MODE_QUERY === $mode) {
                 $request = $this->getMvcEvent()->getRequest();
                 if ($request instanceof Request) {
                     $idValue = $request->getQuery($paramName, null);
                 }
             }
             if (null === $idValue) {
                 $errMsg = sprintf('Error getting the primary identifier for the entity\'s key. Source: %s. Value: %s', $mode, $paramName);
                 throw new Exception\InvalidWorkflowEntryToObjectMetadataException($errMsg);
             }
             $objectsInfo[$entityClassName][$propertyName] = $idValue;
         }
     }
     $entry = $this->getEntryToObjectsService()->getEntryByObjectsInfo($managerName, $workflowName, $objectsInfo);
     if (null === $entry) {
         return null;
     }
     return $entry->getId();
 }
 /**
  * Определение entryId на основе параметров роута
  *
  * @param ResolveEntryIdEventInterface $event
  *
  * @return integer|null
  *
  * @throws Exception\InvalidMetadataException
  */
 public function onResolveEntryIdHandler(ResolveEntryIdEventInterface $event)
 {
     $this->getLog()->info('Getting the value "entryId" to run the Workflow based on the router settings');
     $mvcEvent = $event->getWorkflowDispatchEvent()->getMvcEvent();
     $controller = $mvcEvent->getTarget();
     if (!$controller instanceof AbstractController) {
         $this->getLog()->notice('Unable to get the value of "entryId" to start the workflow. No controller object in the property "target" MvcEvent.');
         return null;
     }
     $routeMatch = $mvcEvent->getRouteMatch();
     if (!$routeMatch) {
         return null;
     }
     $action = $routeMatch->getParam('action', 'not-found');
     $actionMethod = AbstractController::getMethodFromAction($action);
     if (!method_exists($controller, $actionMethod)) {
         $this->getLog()->notice('Unable to get the value of "entryId" to start the workflow. Do not set RouteMatch');
         return null;
     }
     $controllerClassName = get_class($controller);
     $metadata = $this->getMetadataReader()->loadMetadataForAction($controllerClassName, $actionMethod);
     if (!$metadata instanceof MetadataInterface) {
         $errMsg = sprintf('Metadata not implement %s', MetadataInterface::class);
         throw new Exception\InvalidMetadataException($errMsg);
     }
     $entryIdParam = $metadata->getEntryIdRouterParam();
     $entryId = $routeMatch->getParam($entryIdParam, null);
     $this->getLog()->info('Meaning "entryId" to run the Workflow based on the router settings', ['entryId' => $entryId]);
     return $entryId;
 }