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


PHP View::getResponse方法代码示例

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


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

示例1: handle

 public function handle(RequestConfiguration $requestConfiguration, View $view)
 {
     if ($view->getResponse()->getContent()) {
         return $view->getResponse();
     }
     return parent::handle($requestConfiguration, $view);
 }
开发者ID:enhavo,项目名称:enhavo,代码行数:7,代码来源:ViewHandler.php

示例2: postUserSignInAction

 /**
  * Sign in users by pair username:password.
  *
  * @ApiDoc(
  *     views={"default", "user"},
  *     section="Security API",
  *     resource=true,
  *     resourceDescription="Sign in users by pair username:password.",
  *     statusCodes={
  *         200="Returned when successful",
  *         400="Returned when an error has occurred",
  *     }
  * )
  *
  * @Rest\Route("/sign-in", requirements={
  *     "_format": "json|xml"
  * })
  *
  * @Rest\RequestParam(name="username", requirements="[\w\-]+", nullable=false, description="Username")
  * @Rest\RequestParam(name="password", nullable=false, description="Password")
  *
  * @param ParamFetcherInterface $paramFetcher
  * @return View
  */
 public function postUserSignInAction(ParamFetcherInterface $paramFetcher)
 {
     $username = $paramFetcher->get('username');
     $password = $paramFetcher->get('password');
     /** @var EntityRepository $repository */
     $repository = $this->getDoctrine()->getManager()->getRepository('UserBundle:User');
     /** @var User $user */
     $user = $repository->findOneBy(['username' => $username]);
     if (!$user || !$this->validatePassword($user, $password)) {
         return new View(array('message' => 'User not found.'), 400);
     }
     if (!$user->isEnabled()) {
         return new View(array('message' => 'Account is disabled.'), 400);
     }
     if (!$user->isAccountNonLocked()) {
         return new View(array('message' => 'Account is locked.'), 400);
     }
     if (!$user->isAccountNonExpired()) {
         return new View(array('message' => 'Account is expired.'), 400);
     }
     if (!$user->isCredentialsNonExpired()) {
         return new View(array('message' => 'Credentials is expired.'), 400);
     }
     $this->generateToken($user);
     $this->getDoctrine()->getManager()->flush();
     $headers = array('Token' => $user->getApiToken(), 'ExpireAt' => $user->getApiTokenExpireAt()->format('c'), 'Username' => $user->getUsername());
     $view = new View(array_merge(array('user' => $user->getId()), $headers), 200, $headers);
     $this->setAuthInfoInCookie($headers, $view->getResponse(), $user->getApiTokenExpireAt());
     return $view;
 }
开发者ID:glavweb,项目名称:symfony-rest,代码行数:54,代码来源:SecurityApiController.php

示例3: createResponse

 /**
  * @param ViewHandler   $handler
  * @param View          $view
  * @param Request       $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function createResponse(ViewHandler $handler, View $view, Request $request)
 {
     $format = $view->getFormat() ?: $request->getRequestFormat();
     $data = $view->getData();
     if ($data instanceof Cursor) {
         $view->setData(iterator_to_array($data, false));
         $view->getResponse()->headers->set('X-Total-Count', $data->count());
         return $handler->createResponse($view, $request, $view->getFormat());
     }
     if ($data instanceof Form && Codes::HTTP_BAD_REQUEST === $view->getStatusCode()) {
         $view->setData($this->formatFormErrors($data));
         return $handler->createResponse($view, $request, $format);
     }
     return $handler->createResponse($view, $request, $format);
 }
开发者ID:nass59,项目名称:Lab,代码行数:22,代码来源:PaginatedViewHandler.php

示例4: createRedirectResponse

 /**
  * Create the Response from the view
  *
  * @param View   $view
  * @param string $location
  * @param string $format
  *
  * @return Response
  */
 public function createRedirectResponse(View $view, $location, $format)
 {
     $content = null;
     $response = $view->getResponse();
     if ('html' === $format && isset($this->forceRedirects[$format])) {
         $redirect = new RedirectResponse($location);
         $content = $redirect->getContent();
         $response->setContent($content);
     }
     $code = isset($this->forceRedirects[$format]) ? $this->forceRedirects[$format] : $this->getStatusCode($view, $content);
     $response->setStatusCode($code);
     $response->headers->set('Location', $location);
     return $response;
 }
开发者ID:shreyans264,项目名称:symfonyPlayGround,代码行数:23,代码来源:ViewHandler.php

示例5: doExecute

 /**
  * @param Response     $response
  * @param ParameterBag $parameterBag
  * @return bool|void
  */
 protected function doExecute(Response $response, ParameterBag $parameterBag)
 {
     /** @var Request $request */
     /** @var AbstractType $formType */
     /** @var object $entity */
     /** @var bool $cleanForm */
     /** @var bool $cleanRequestData */
     /** @var bool $getContent */
     /** @var array $formOptions */
     /** @var SerializationContext $serializationContext */
     /** @var \Closure $onPreValidation */
     /** @var \Closure $onPostValidation */
     /** @var \Closure $onPostPersist */
     /** @var \Closure $onSuccess */
     /** @var \Closure $onFailure  */
     $request = $parameterBag->get('request');
     $formType = $parameterBag->get('formType');
     $entity = $parameterBag->get('entity');
     $cleanForm = $parameterBag->get('cleanForm');
     $cleanRequestData = $parameterBag->get('cleanRequestData', true);
     $getContent = $parameterBag->get('getContent');
     $formOptions = $parameterBag->get('formOptions', array());
     $serializationContext = $parameterBag->get('serializationContext');
     $onPreValidation = $parameterBag->get('onPreValidation');
     $onPostValidation = $parameterBag->get('onPostValidation');
     $onPostPersist = $parameterBag->get('onPostPersist');
     $onSuccess = $parameterBag->get('onSuccess');
     $onFailure = $parameterBag->get('onFailure ');
     $view = new View();
     $httpResponse = $view->getResponse();
     $requestData = array_merge($request->request->all(), $request->files->all());
     if ($serializationContext) {
         $view->setSerializationContext($serializationContext);
     }
     $form = $this->getFormFactory()->createNamed(null, get_class($formType), $entity, array_merge(array('csrf_protection' => false), $formOptions));
     if ($cleanRequestData) {
         $requestData = $this->cleanRequestData($requestData, $form);
     }
     if ($cleanForm) {
         $this->cleanForm($requestData, $form);
     }
     $this->prepareFormCollections($request, $form);
     /**
      * Pre validation
      */
     $this->onPreValidation($request, $form, $entity, $httpResponse);
     if ($onPreValidation instanceof \Closure) {
         $onPreValidation($request, $form, $entity, $httpResponse);
     }
     if ($httpResponse->getStatusCode() != HttpResponse::HTTP_OK) {
         $response->response = $view;
         return true;
     }
     $form->submit($requestData);
     if ($form->isValid()) {
         if ($onPostValidation instanceof \Closure) {
             $onPostValidation($request, $form, $entity, $httpResponse);
             if ($httpResponse->getStatusCode() != HttpResponse::HTTP_OK) {
                 $response->response = $view;
                 return true;
             }
         }
         $isEditAction = $entity->getId();
         $statusCode = $isEditAction ? HttpResponse::HTTP_OK : HttpResponse::HTTP_CREATED;
         /** @var \Doctrine\Common\Persistence\ObjectManager $em */
         $em = $this->getDoctrine()->getManager();
         $em->persist($entity);
         if ($onPostPersist instanceof \Closure) {
             $onPostPersist($request, $form, $entity, $httpResponse);
         }
         $em->flush();
         $httpResponse->setStatusCode($statusCode);
         if ($isEditAction) {
             if ($getContent) {
                 $em->refresh($entity);
                 $view->setData($entity);
             }
         } else {
             $view->setData($entity->getId());
         }
         if ($onSuccess instanceof \Closure) {
             $onSuccess($request, $form, $entity, $httpResponse);
         }
         $response->response = $view;
         return true;
     }
     if ($onFailure instanceof \Closure) {
         $onFailure($request, $form, $entity, $httpResponse);
         $response->response = $view;
         return true;
     }
     $response->response = $form;
     return false;
 }
开发者ID:glavweb,项目名称:GlavwebRestBundle,代码行数:99,代码来源:RestFormAction.php

示例6: testGetStatusCodeFromResponse

 public function testGetStatusCodeFromResponse()
 {
     $view = new View();
     $this->assertNull($view->getStatusCode());
     $this->assertEquals(Response::HTTP_OK, $view->getResponse()->getStatusCode());
     // default code of the response.
 }
开发者ID:sblaut,项目名称:FOSRestBundle,代码行数:7,代码来源:ViewTest.php


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