/** * @return type */ public function getMethodName() { if (!$this->methodName) { $action = $this->getRouteMatch()->getParam('action', 'not-found'); $this->setMethodName(AbstractController::getMethodFromAction($action)); } return $this->methodName; }
/** * Получение метаданных * * @param WorkflowDispatchEventInterface $e * * @return MetadataInterface|null */ public function onLoadMetadataHandler(WorkflowDispatchEventInterface $e) { $mvcEvent = $e->getMvcEvent(); $controller = $mvcEvent->getTarget(); if (!$controller instanceof AbstractController) { $this->getLog()->notice('Unable to retrieve the metadata for scheduling workflow. No controller object in the property "target" MvcEvent.'); return null; } $routeMatch = $mvcEvent->getRouteMatch(); if (!$routeMatch) { $this->getLog()->notice('Unable to retrieve the metadata for scheduling workflow. Do not set RouteMatch'); return null; } $action = $routeMatch->getParam('action', 'not-found'); $actionMethod = AbstractController::getMethodFromAction($action); if (!method_exists($controller, $actionMethod)) { $this->getLog()->notice(sprintf('Unable to retrieve the metadata for scheduling workflow. There is no action(%s) in controller(%s)', $actionMethod, get_class($controller))); return null; } $controllerClassName = get_class($controller); $metadata = $this->getMetadataReader()->loadMetadataForAction($controllerClassName, $actionMethod); return $metadata; }
/** * Определение 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; }