当前位置: 首页>>代码示例>>PHP>>正文


PHP MvcEvent::setResult方法代码示例

本文整理汇总了PHP中Zend\Mvc\MvcEvent::setResult方法的典型用法代码示例。如果您正苦于以下问题:PHP MvcEvent::setResult方法的具体用法?PHP MvcEvent::setResult怎么用?PHP MvcEvent::setResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Mvc\MvcEvent的用法示例。


在下文中一共展示了MvcEvent::setResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onDispatch

 /**
  * @param MvcEvent $e
  * @return mixed|void
  */
 public function onDispatch(MvcEvent $e)
 {
     $viewModel = new ViewModel();
     $valid = $this->collageData->isValid();
     $data = $this->authenticationService->getAuthData();
     $viewModel->setVariable('validInputs', $this->collageData->getValidInput());
     $viewModel->setVariable('user', $data->user);
     if (!$valid) {
         $viewModel->setTemplate('frontend/gallery/error');
         $viewModel->setVariable('messages', $this->collageData->getMessages());
         return $e->setResult($viewModel);
     }
     $uniqueId = md5(serialize($this->collageData->getValues()));
     if ($this->sessionContainer->valuesHash != $uniqueId) {
         $collectionService = $this->collectionFactory->createCollection($this->collageData);
         $images = $collectionService->getImages($this->collageData);
     } else {
         $images = $this->sessionContainer->images;
     }
     $collageHttpPath = $this->collageService->create($images, $uniqueId, $this->collageData->getWidth(), $this->collageData->getHeight(), $this->collageData->getLimit());
     if ($collageHttpPath !== false) {
         $viewModel->setVariable('collageHttpPath', $collageHttpPath);
     }
     $viewModel->setTemplate('frontend/gallery/index');
     return $e->setResult($viewModel);
 }
开发者ID:spalax,项目名称:ua-webchalange-instagram-collage,代码行数:30,代码来源:CollageController.php

示例2: notFoundByRequestedCriteria

 /**
  * @return mixed
  */
 public function notFoundByRequestedCriteria($criteriaErrors)
 {
     $zendResponse = $this->mvcEvent->getResponse();
     $zendResponse->setStatusCode(404);
     $this->viewModel->setVariable('message', 'The requested resource was not found by requested criteria');
     $this->viewModel->setTemplate('error/404');
     $this->mvcEvent->setResult($this->viewModel);
     return $this->viewModel;
 }
开发者ID:sebaks,项目名称:zend-mvc-controller,代码行数:12,代码来源:HtmlError.php

示例3: displayError

 protected function displayError($template, $status = 403)
 {
     $model = new ViewModel();
     $model->setTerminal(false);
     $model->setTemplate($template);
     /** @var $response  \Zend\Http\PhpEnvironment\Response */
     $response = $this->_event->getResponse();
     $response->setStatusCode($status);
     $this->_event->setResponse($response);
     $this->_event->setResult($model);
     return;
 }
开发者ID:klaid83,项目名称:ms,代码行数:12,代码来源:ExceptionStrategy.php

示例4: onDispatch

 /**
  * @param MvcEvent $e
  * @return mixed|void
  */
 public function onDispatch(MvcEvent $e)
 {
     $viewModel = new ViewModel();
     $viewModel->setVariable('loginUri', $this->instagramWrapper->getLoginUrl());
     $viewModel->setTemplate('frontend/index');
     $e->setResult($viewModel);
 }
开发者ID:spalax,项目名称:ua-webchalange-instagram-collage,代码行数:11,代码来源:IndexController.php

示例5: onDispatch

 /**
  * @param MvcEvent $event
  * @return mixed
  * @throws \Exception
  */
 public function onDispatch(MvcEvent $event)
 {
     $routeMatch = $event->getRouteMatch();
     if (!$routeMatch) {
         throw new \DomainException('Missing route matches.');
     }
     $handler = $this->getExceptionHandler();
     $action = $routeMatch->getParam('action', 'not-found');
     if ($this instanceof InitializableInterface) {
         try {
             $this->init();
         } catch (\Exception $e) {
             return $handler->tryHandle($e);
         }
     }
     $method = static::getMethodFromAction($action);
     if (!method_exists($this, $method)) {
         $method = 'notFoundAction';
     }
     try {
         if ($this->protectRequestMethodByPrefix) {
             $this->protectRequestMethod($method);
         }
         $actionResponse = $this->{$method}($this->getRequest(), $this->getResponse());
         $event->setResult($actionResponse);
         return $actionResponse;
     } catch (\Exception $e) {
         return $handler->tryHandle($e);
     }
 }
开发者ID:hanif,项目名称:stokq,代码行数:35,代码来源:Controller.php

示例6: onDispatchError

 /**
  * Get the exception and optionally set status code, reason message and additional errors
  *
  * @internal
  * @param  MvcEvent $event
  * @return void
  */
 public function onDispatchError(MvcEvent $event)
 {
     $exception = $event->getParam('exception');
     if (isset($this->exceptionMap[get_class($exception)])) {
         $exception = $this->createHttpException($exception);
     }
     // We just deal with our Http error codes here !
     if (!$exception instanceof HttpExceptionInterface || $event->getResult() instanceof HttpResponse) {
         return;
     }
     // We clear the response for security purpose
     $response = new HttpResponse();
     $response->getHeaders()->addHeaderLine('Content-Type', 'application/json');
     $exception->prepareResponse($response);
     // NOTE: I'd like to return a JsonModel instead, and let ZF handle the request, but I couldn't make
     // it work because for unknown reasons, the Response get replaced "somewhere" in the MVC workflow,
     // so the simplest is simply to do that
     $content = ['status_code' => $response->getStatusCode(), 'message' => $response->getReasonPhrase()];
     if ($errors = $exception->getErrors()) {
         $content['errors'] = $errors;
     }
     $response->setContent(json_encode($content));
     $event->setResponse($response);
     $event->setResult($response);
     $event->stopPropagation(true);
 }
开发者ID:omusico,项目名称:zfr-rest,代码行数:33,代码来源:HttpExceptionListener.php

示例7: prepareViewModel

 public function prepareViewModel(MvcEvent $event, $action)
 {
     if ($event->getTarget()->forward()->getNumNestedForwards() > 0) {
         return $event->getResult();
     }
     $result = $event->getResult();
     $response = $event->getResponse();
     $response->setStatusCode($result->getStatusCode());
     $response->getHeaders()->addHeaders($result->getHeaders());
     $controller = $event->getTarget();
     $viewModel = $controller->acceptableViewModelSelector($controller->getOptions()->getAcceptCriteria());
     if ($vars = $result->getSerializedModel()) {
         $viewModel->setVariables($vars);
     }
     //set the template
     if ($viewModel instanceof JsonModel && count($viewModel->getVariables()) == 0) {
         if ($response->getStatusCode() == 200) {
             $response->setStatusCode(204);
         }
         return $response;
     } elseif ($viewModel->getTemplate() == null) {
         $viewModel->setTemplate($controller->getOptions()->getTemplates()[$action]);
     }
     $event->setResult($viewModel);
     return $viewModel;
 }
开发者ID:zoopcommerce,项目名称:shard-module,代码行数:26,代码来源:PrepareViewModelListener.php

示例8: handleError

 /**
  * @param MvcEvent $e
  */
 protected function handleError(MvcEvent $e)
 {
     $router = $e->getRouter();
     if ($this->authenticationService->hasIdentity()) {
         if (!$this->options->getRedirectWhenConnected()) {
             return;
         }
         $redirectRoute = $this->options->getRedirectToRouteConnected();
     } else {
         $redirectRoute = $this->options->getRedirectToRouteDisconnected();
     }
     $params = array();
     $options = array('name' => $redirectRoute);
     if ($this->options->getAppendPreviousUri()) {
         $redirectKey = $this->options->getPreviousUriRouteKey();
         $previousUri = $e->getRequest()->getUriString();
         $params = array($redirectKey => $previousUri);
     }
     $uri = $router->assemble($params, $options);
     $response = $e->getResponse() ?: new HttpResponse();
     $response->getHeaders()->addHeaderLine('Location', $uri);
     $response->setStatusCode(302);
     $e->setResponse($response);
     $e->setResult($response);
 }
开发者ID:mhilker,项目名称:usermanager,代码行数:28,代码来源:RedirectStrategy.php

示例9: onError

 /**
  * @private
  * @param  MvcEvent $event
  * @return void
  */
 public function onError(MvcEvent $event)
 {
     // Do nothing if no error or if response is not HTTP response
     if (!$event->getParam('exception') instanceof UnauthorizedExceptionInterface || $event->getResult() instanceof HttpResponse || !$event->getResponse() instanceof HttpResponse) {
         return;
     }
     $router = $event->getRouter();
     if ($this->authenticationService->hasIdentity()) {
         if (!$this->options->getRedirectWhenConnected()) {
             return;
         }
         $redirectRoute = $this->options->getRedirectToRouteConnected();
     } else {
         $redirectRoute = $this->options->getRedirectToRouteDisconnected();
     }
     $uri = $router->assemble([], ['name' => $redirectRoute]);
     if ($this->options->getAppendPreviousUri()) {
         $redirectKey = $this->options->getPreviousUriQueryKey();
         $previousUri = $event->getRequest()->getUriString();
         $uri = $router->assemble([], ['name' => $redirectRoute, 'query' => [$redirectKey => $previousUri]]);
     }
     $response = $event->getResponse() ?: new HttpResponse();
     $response->getHeaders()->addHeaderLine('Location', $uri);
     $response->setStatusCode(302);
     $event->setResponse($response);
     $event->setResult($response);
 }
开发者ID:adamh114,项目名称:zfc-rbac,代码行数:32,代码来源:RedirectStrategy.php

示例10: onInvokation

 protected function onInvokation(MvcEvent $e, $error = false)
 {
     $viewModel = $e->getResult();
     $isJsonModel = $viewModel instanceof JsonModel;
     $routeMatch = $e->getRouteMatch();
     if ($routeMatch && $routeMatch->getParam('forceJson', false) || $isJsonModel || "json" == $e->getRequest()->getQuery('format') || "json" == $e->getRequest()->getPost('format')) {
         if (!$isJsonModel) {
             $model = new JsonModel();
             if ($error) {
                 $model->status = 'error';
                 $model->message = $viewModel->message;
                 if ($viewModel->display_exceptions) {
                     if (isset($viewModel->exception)) {
                         $model->exception = $viewModel->exception->getMessage();
                     }
                 }
             } else {
                 $model->setVariables($viewModel->getVariables());
             }
             $viewModel = $model;
             $e->setResult($model);
             $e->setViewModel($model);
         }
         $viewModel->setTerminal(true);
         $strategy = new \Zend\View\Strategy\JsonStrategy(new \Zend\View\Renderer\JsonRenderer());
         $view = $e->getApplication()->getServiceManager()->get('ViewManager')->getView();
         $view->addRenderingStrategy(array($strategy, 'selectRenderer'), 10);
         $view->addResponseStrategy(array($strategy, 'injectResponse'), 10);
     }
 }
开发者ID:webpants,项目名称:YAWIK,代码行数:30,代码来源:EnforceJsonResponseListener.php

示例11: onDispatch

 public function onDispatch(MvcEvent $e)
 {
     $routeMatch = $e->getRouteMatch();
     $contentNegotiationParams = $e->getParam('ZFContentNegotiationParameterData');
     if ($contentNegotiationParams) {
         $routeParameters = $contentNegotiationParams->getRouteParams();
     } else {
         $routeParameters = $routeMatch->getParams();
     }
     $parameterMatcher = new ParameterMatcher($e);
     // match route params to dispatchable parameters
     if ($this->wrappedCallable instanceof \Closure) {
         $callable = $this->wrappedCallable;
     } elseif (is_array($this->wrappedCallable) && is_callable($this->wrappedCallable)) {
         $callable = $this->wrappedCallable;
     } elseif (is_object($this->wrappedCallable) || is_null($this->wrappedCallable)) {
         $action = $routeMatch->getParam('action', 'not-found');
         $method = static::getMethodFromAction($action);
         $callable = is_null($this->wrappedCallable) && get_class($this) != __CLASS__ ? $this : $this->wrappedCallable;
         if (!method_exists($callable, $method)) {
             $method = 'notFoundAction';
         }
         $callable = [$callable, $method];
     } else {
         throw new \Exception('RPC Controller Not Understood');
     }
     $dispatchParameters = $parameterMatcher->getMatchedParameters($callable, $routeParameters);
     $result = call_user_func_array($callable, $dispatchParameters);
     $e->setParam('ZFContentNegotiationFallback', ['Zend\\View\\Model\\JsonModel' => ['application/json']]);
     $e->setResult($result);
 }
开发者ID:gstearmit,项目名称:EshopVegeTable,代码行数:31,代码来源:RpcController.php

示例12: testDoNotSetTemplateIfNotResourceViewModel

 public function testDoNotSetTemplateIfNotResourceViewModel()
 {
     $model = $this->getMock(ModelInterface::class);
     $model->expects($this->never())->method('setTemplate');
     $mvcEvent = new MvcEvent();
     $mvcEvent->setResult($model);
     $this->resourceStrategy->setTemplate($mvcEvent);
 }
开发者ID:omusico,项目名称:zfr-rest,代码行数:8,代码来源:ResourceStrategyTest.php

示例13: onDispatch

 public function onDispatch(MvcEvent $e)
 {
     if (!$e->getRequest() instanceof ConsoleRequest) {
         throw new RuntimeException('You can only use this action from a console!');
     }
     $version = $e->getRequest()->getParam('version');
     $force = $e->getRequest()->getParam('force');
     $down = $e->getRequest()->getParam('down');
     if (is_null($version) && $force) {
         $response = "Can't force migration apply without migration version explicitly set.\n";
         $e->setResult($response);
         return $response;
     }
     $this->migration->migrate($version, $force, $down);
     $response = "Migrations applied!\n";
     $e->setResult($response);
     return $response;
 }
开发者ID:t4web,项目名称:migrations,代码行数:18,代码来源:ApplyController.php

示例14: onDispatch

 /**
  * @param MvcEvent $e
  * @return mixed|void
  */
 public function onDispatch(MvcEvent $e)
 {
     $viewModel = new ViewModel();
     $data = $this->authenticationService->getAuthData();
     $viewModel->setVariable('user', $data->user);
     $viewModel->setVariable('configure', true);
     $viewModel->setTemplate('frontend/gallery/index');
     $e->setResult($viewModel);
 }
开发者ID:spalax,项目名称:ua-webchalange-instagram-collage,代码行数:13,代码来源:ConfigureController.php

示例15: onDispatch

 public function onDispatch(MvcEvent $e)
 {
     if (!$e->getRequest() instanceof ConsoleRequest) {
         throw new RuntimeException('You can only use this action from a console!');
     }
     $response = sprintf("Current version %s\n", $this->table->getCurrentVersion());
     $e->setResult($response);
     return $response;
 }
开发者ID:t4web,项目名称:migrations,代码行数:9,代码来源:VersionController.php


注:本文中的Zend\Mvc\MvcEvent::setResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。