protected function attachDefaultListeners() { parent::attachDefaultListeners(); $this->getEventManager()->attach(MvcEvent::EVENT_DISPATCH, function (MvcEvent $event) { $event->getTarget()->layout('layout/frontend/gallery'); }); }
public function dispatch(ZendRequest $request, ZendResponse $response = null) { if (!$request instanceof HttpRequest) { throw new Exception\InvalidArgumentException('Expected an HTTP request'); } $this->restRequest = $this->getServiceLocator()->get('BedRest.Request'); return parent::dispatch($request, $response); }
/** * Dispatch a request * * @events dispatch.pre, dispatch.post * @param Request $request * @param null|Response $response * @return Response|mixed */ public function dispatch(Request $request, Response $response = null) { $this->resourceEntity = $this->getRepository()->findOneByToken($this->params()->fromRoute(static::REMOVE_ROUTE_PARAM)); if (is_null($this->resourceEntity)) { $response = $response ?: new HttpResponse(); $this->getEventManager()->clearListeners(MvcEvent::EVENT_DISPATCH); $response->setStatusCode(404); } parent::dispatch($request, $response); }
/** * Dispatch a request * * @events dispatch.pre, dispatch.post * @param Request $request * @param null|Response $response * @return Response|mixed */ public function dispatch(Request $request, Response $response = null) { $this->request = $request; $this->getDataResourceCreator()->setData(array_merge_recursive($this->params()->fromPost(), $request->getFiles()->toArray())); if (!$this->getDataResourceCreator()->isValid()) { if ($this->disableDefaultErrorHandler) { $response = $response ?: new HttpResponse(); $this->getEventManager()->clearListeners(MvcEvent::EVENT_DISPATCH); $this->getEvent()->setResult(false); $response->setStatusCode(400); } else { $this->getEventManager()->clearListeners(MvcEvent::EVENT_DISPATCH); $this->uploaderModel->setMessages($this->getDataResourceCreator()); $this->getEvent()->setResult($this->uploaderModel); } } parent::dispatch($request, $response); }
/** * Dispatch a request * * If the route match includes an "action" key, then this acts basically like * a standard action controller. Otherwise, it introspects the HTTP method * to determine how to handle the request, and which method to delegate to. * * @events dispatch.pre, dispatch.post * @param Request $request * @param null|Response $response * @return mixed|Response * @throws Exception\InvalidArgumentException */ public function dispatch(Request $request, Response $response = null) { if (!$request instanceof HttpRequest) { throw new Exception\InvalidArgumentException('Expected an HTTP request'); } return parent::dispatch($request, $response); }
/** * Получение метаданных * * @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; }
protected function setController(AbstractController $controller) { $controller->setPluginManager($this->getServiceManager()->get('ControllerPluginManager')); $this->controller = $controller; return $this; }
private function setPermissions(AbstractController $self) { $adminNode = $self->navService->findOneById(Navigation::Admin); $requiresloginNodes = $self->navService->findAllBy("requireslogin", true); $hasIdentity = $self->authService->hasIdentity(); $adminNode->setVisible($hasIdentity); foreach ($requiresloginNodes as $rec) { $self->navService->findOneById($rec->get("id"))->setVisible($hasIdentity); } if (!$hasIdentity) { $controller = strtolower($self->controller); $action = strtolower($self->action); $unauthorizedAttempt = array_filter($requiresloginNodes, function ($item) use($controller, $action) { return strtolower($item->get("controller")) == $controller && strtolower($item->get("action")) == $action; }); if (count($unauthorizedAttempt) > 0) { return $self->redirect()->toUrl("/Admin/index"); } } }
private function setContacts(AbstractController $self) { $wpRepo = $self->getServiceLocator()->get('WordPrRepo'); $args = new SearchArgs(); $args->slug = $self->lang == Lang::AR ? CoreSlugs::ArLayoutContacts : CoreSlugs::EnLayoutContacts; $contacts = $wpRepo->fetchCategoryPosts($args); $self->layout()->setVariable(Layout::Contacts, $contacts); }
/** * @return type */ public function getMethodName() { if (!$this->methodName) { $action = $this->getRouteMatch()->getParam('action', 'not-found'); $this->setMethodName(AbstractController::getMethodFromAction($action)); } return $this->methodName; }
/** * Processes a message and returns the result. * * @param MessageInterface $message The message to process * @return mixed The result. */ public function process(MessageInterface $message) { return $this->worker->forward()->dispatch($message->getContent(), $message->getMetadata()); }
/** * Определение 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; }