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


PHP GetResponseEvent::hasResponse方法代码示例

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


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

示例1: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     $this->logger->debug('Entity builder listener: catch kernel.request event');
     // If this is not a master request, skip handling
     if (!$event->isMasterRequest()) {
         $this->logger->debug('Entity builder listener: this is not master request, skip');
         return;
     }
     // If content already prepared
     if ($event->hasResponse()) {
         $this->logger->debug('Entity builder listener: event already has response, skip');
         return;
     }
     // Getting request
     $request = $event->getRequest();
     // Getting action
     $apiServerAction = $event->getRequest()->attributes->get('apiAction');
     /* @var $apiServerAction ApiServerAction */
     // Something wrong
     if (!$apiServerAction) {
         $this->logger->error('Request parser listener: request has no apiAction attribute, throwing access denied exception');
         throw new AccessDeniedHttpException();
     }
     // Creating request data entity
     try {
         $apiEntity = $apiServerAction->getRequestedEntity($request->attributes->get('apiData'));
     } catch (\Exception $e) {
         $this->logger->notice(sprintf('Request parser listener: unable to convert apiData to entity ("%s"), apiEntity set tu null', $e->getMessage()));
         $apiEntity = null;
     }
     // Setting request attributes
     $request->attributes->set('requestData', $apiEntity);
     // Cleaning request attributes
     $request->attributes->remove('apiData');
 }
开发者ID:leoza,项目名称:api-server-bundle,代码行数:35,代码来源:EntityBuilder.php

示例2: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     $this->logger->debug('Request parser listener: catch kernel.request event');
     // If this is not a master request, skip handling
     if (!$event->isMasterRequest()) {
         $this->logger->debug('Request parser listener: this is not master request, skip');
         return;
     }
     // If content already prepared
     if ($event->hasResponse()) {
         $this->logger->debug('Request parser listener: event already has response, skip');
         return;
     }
     // getting request
     $request = $event->getRequest();
     // getting content
     $content = $request->getContent();
     $this->logger->debug(sprintf('Request parser listener: request content >>> %s', $content));
     $content = @json_decode($content, true);
     if (!is_array($content)) {
         $this->logger->notice('Request parser listener: request content is not in the JSON format, throwing access denied exception');
         throw new AccessDeniedHttpException();
     }
     // creating ApiRequest
     $apiRequest = new ApiRequest($content);
     $this->logger->debug(sprintf('Request parser listener: request params. Token: "%s", user token: "%s", action: "%s"', $apiRequest->getToken(), $apiRequest->getUserToken(), $apiRequest->getAction()));
     if (!$apiRequest->getToken()) {
         $this->logger->notice('Request parser listener: request has no token, throwing access denied exception');
         throw new AccessDeniedHttpException();
     }
     // Calculating interface name
     $host = strtolower($request->server->get('SERVER_NAME'));
     $interfaceName = array_key_exists($host, $this->interfacesHosts) ? $this->interfacesHosts[$host] : $this->defaultInterface;
     if (!$interfaceName) {
         $this->logger->notice(sprintf('Request parser listener: interface for hostname "%s" not detected, throwing access denied exception', $host));
         throw new AccessDeniedHttpException();
     }
     $this->logger->debug(sprintf('Request parser listener: "%s" interface selected for handling connection from "%s"', $interfaceName, $host));
     // Building interface
     $apiServerInterface = $this->apiServerInterfaceFactory->buildInterface($interfaceName);
     // Building action
     $apiServerAction = $apiServerInterface->buildAction($apiRequest->getAction());
     $this->logger->debug(sprintf('Request parser listener: action route selected >>> %s', $apiServerAction->getActionRoute()));
     // Setting request attributes
     $request->attributes->set('apiClientToken', $apiRequest->getToken());
     $request->attributes->set('apiUserToken', $apiRequest->getUserToken());
     $request->attributes->set('apiAction', $apiServerAction);
     $request->attributes->set('apiData', $apiRequest->getData());
     // Setting route
     $request->attributes->set('_controller', $apiServerAction->getActionRoute());
 }
开发者ID:leoza,项目名称:api-server-bundle,代码行数:51,代码来源:RequestParser.php

示例3: testOnKernelRequestUserHash

 public function testOnKernelRequestUserHash()
 {
     $hash = '123abc';
     $this->hashGenerator->expects($this->once())->method('generate')->will($this->returnValue($hash));
     $this->request->headers->add(array('X-HTTP-Override' => 'AUTHENTICATE', 'Accept' => Kernel::USER_HASH_ACCEPT_HEADER));
     $this->request->expects($this->once())->method('hasSession')->will($this->returnValue(true));
     $this->assertNull($this->requestEventListener->onKernelRequestUserHash($this->event));
     $this->assertTrue($this->event->isPropagationStopped());
     $this->assertTrue($this->event->hasResponse());
     $response = $this->event->getResponse();
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
     $this->assertTrue($response->headers->has('X-User-Hash'));
     $this->assertSame($hash, $response->headers->get('X-User-Hash'));
 }
开发者ID:masev,项目名称:ezpublish-kernel,代码行数:14,代码来源:RequestEventListenerTest.php


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