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


PHP FilterResponseEvent::setResponse方法代码示例

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


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

示例1: onResponse

 public function onResponse(FilterResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $response = $event->getResponse();
     $request = $event->getRequest();
     if (!$this->container->hasParameter('newscoop.gimme.allow_origin')) {
         return false;
     }
     $alowedHosts = $this->container->getParameter('newscoop.gimme.allow_origin');
     if (count($alowedHosts) == 0) {
         return false;
     }
     if (in_array('*', $alowedHosts)) {
         $response->headers->set('Access-Control-Allow-Origin', '*');
         $event->setResponse($response);
     } else {
         foreach ($alowedHosts as $host) {
             if ($request->server->get('HTTP_ORIGIN') == $host) {
                 $response->headers->set('Access-Control-Allow-Origin', $host);
                 $event->setResponse($response);
             }
         }
     }
 }
开发者ID:nidzix,项目名称:Newscoop,代码行数:26,代码来源:AllowOriginListener.php

示例2: onKernelResponse

 /**
  * {@inheritdoc}
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     if ($this->stopwatch->isStarted('controllerHandling')) {
         $this->stopwatch->stop('controllerHandling');
     }
     $response = $event->getResponse();
     if (false !== strpos($response->getContent(), '<!-- ##debug_panel## -->')) {
         $content = str_replace('<!-- ##debug_panel## -->', $this->getDebugView(), $response->getContent());
         $response->setContent($content);
         $event->setResponse($response);
     } elseif (false !== strpos($response->getContent(), '</body>')) {
         $content = str_replace('</body>', $this->getDebugView() . "</body>", $response->getContent());
         $response->setContent($content);
         $event->setResponse($response);
     }
 }
开发者ID:bryanbanda,项目名称:roadiz,代码行数:19,代码来源:DebugPanel.php

示例3: onKernelResponse

 public function onKernelResponse(FilterResponseEvent $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $this->setEtagsAndStuff($request, $response);
     $event->setResponse($response);
 }
开发者ID:broadr,项目名称:server,代码行数:7,代码来源:ResponseListener.php

示例4: onKernelResponse

 /**
  * Modify the response to a json response if the status is not 200.
  * (so this allows any type of 200 answer but only json errors)
  *
  * @param FilterResponseEvent $event
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     $response = $event->getResponse();
     if ($this->env === 'prod' && !$response instanceof JsonResponse && $response->getStatusCode() !== 200) {
         $event->setResponse(new JsonResponse(['error' => $response->getStatusCode()], $response->getStatusCode()));
     }
 }
开发者ID:ci-tron,项目名称:ci-tron,代码行数:13,代码来源:JsonErrorsListener.php

示例5: onKernelResponse

 public function onKernelResponse(FilterResponseEvent $event)
 {
     if (null != $this->ciudad) {
         $portada = $this->router->generate('portada', array('ciudad' => $this->ciudad));
         $event->setResponse(new RedirectResponse($portada));
     }
 }
开发者ID:folmedov,项目名称:cupon.dev,代码行数:7,代码来源:LoginListener.php

示例6: adaptResponse

 public function adaptResponse(\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event)
 {
     if (null !== $this->session && null !== $this->view) {
         $response = $this->responseAdapter->processAdaptation($event->getResponse(), $this->container->get('router')->generate('skcms_tracking_updater', ['id' => $this->view->getId()]));
         $event->setResponse($response);
     }
 }
开发者ID:kokmok,项目名称:SKCMS-Tracking,代码行数:7,代码来源:ViewTrackerListener.php

示例7: onKernelResponse

 /**
  * @param FilterResponseEvent $event
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     if (!$this->wrapApiResponse) {
         return;
     }
     if (!$event->isMasterRequest()) {
         return;
     }
     $request = $event->getRequest();
     // Only send back HTML if the requestor allows it
     if (!$request->headers->has('Accept') || false === strpos($request->headers->get('Accept'), 'text/html')) {
         return;
     }
     $response = $event->getResponse();
     switch ($request->getRequestFormat()) {
         case 'json':
             $prettyprint_lang = 'js';
             $content = json_encode(json_decode($response->getContent()), JSON_PRETTY_PRINT);
             break;
         case 'xml':
             $prettyprint_lang = 'xml';
             $content = $response->getContent();
             break;
         default:
             return;
     }
     $response->setContent('<html><body>' . '<pre class="prettyprint lang-' . $prettyprint_lang . '">' . htmlspecialchars($content) . '</pre>' . '<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>' . '</body></html>');
     // Set the request type to HTML
     $response->headers->set('Content-Type', 'text/html; charset=UTF-8');
     $request->setRequestFormat('html');
     // Overwrite the original response
     $event->setResponse($response);
 }
开发者ID:jpierront,项目名称:parabola-bundle,代码行数:36,代码来源:ConvertToHtmlResponse.php

示例8: onKernelResponse

 public function onKernelResponse(FilterResponseEvent $event)
 {
     $response = $event->getResponse();
     if (null !== $response && $response instanceof PluginResponseInterface) {
         //when a route from a plugin is hit
         if (!$event->getRequest()->attributes->get('_jarves_is_plugin')) {
             //we accept only plugin routes.
             return;
         }
         $pageResponse = $this->pageStack->getPageResponse();
         /** @var $content Content */
         $content = $event->getRequest()->attributes->get('_content');
         //this is later used in ContentTypes\TypePlugin, so it won't execute
         //the same plugin again.
         $pageResponse->setPluginResponse($content->getId(), $response);
         if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
             //when this was a master request, we need to render the actual content of the page,
             //so HttpKernel can return a valid ready rendered response
             //if a plugin route has been successfully requested
             //we need to handle also the Jarves editor
             if ($this->editMode->isEditMode()) {
                 $this->editMode->registerEditor();
             }
             $pageResponse->renderContent();
         }
         //maintain the actual PageResponse
         $event->setResponse($pageResponse);
     }
 }
开发者ID:jarves,项目名称:jarves,代码行数:29,代码来源:PluginResponseListener.php

示例9: onKernelResponse

 /**
  * add a rel=self Link header to the response
  *
  * @param FilterResponseEvent $event response listener event
  *
  * @return void
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     $languages = $event->getRequest()->attributes->get('languages', array());
     $response = $event->getResponse();
     $response->headers->set('Content-Language', implode(', ', $languages));
     $event->setResponse($response);
 }
开发者ID:alebon,项目名称:graviton,代码行数:14,代码来源:ContentLanguageResponseListener.php

示例10: onKernelResponse

 /**
  * Add rel=schema Link header for most routes
  *
  * This does not add a link to routes used by the schema bundle
  * itself.
  *
  * @param FilterResponseEvent $event response event
  *
  * @return void
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $type = $response->headers->get('Content-Type');
     if ($type !== null && substr(strtolower($type), 0, 16) !== 'application/json') {
         return;
     }
     // build content-type string
     $contentType = 'application/json; charset=UTF-8';
     if ($request->get('_route') != 'graviton.core.static.main.all') {
         try {
             $schemaRoute = SchemaUtils::getSchemaRouteName($request->get('_route'));
             $contentType .= sprintf('; profile=%s', $this->router->generate($schemaRoute, array(), true));
         } catch (\Exception $e) {
             return true;
         }
     }
     // replace content-type if a schema was requested
     if ($request->attributes->get('schemaRequest')) {
         $contentType = 'application/schema+json';
     }
     $response->headers->set('Content-Type', $contentType);
     $event->setResponse($response);
 }
开发者ID:alebon,项目名称:graviton,代码行数:35,代码来源:SchemaContentTypeResponseListener.php

示例11: processCount

 public function processCount(FilterResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $connecte = new Connecte();
     $ip = $this->container->get('request')->getClientIp();
     $times = time();
     $doctrine = $this->container->get('doctrine.orm.entity_manager');
     $listIp = $this->doctrine->getRepository('SNSysNewsBundle:Connecte')->findAll();
     if (!in_array($ip, $listIp)) {
         $connecte->setIp($ip);
         $connecte->setTimes($times);
         $doctrine->persist($connecte);
         $doctrine->flush();
     } else {
         $times = time();
         $connecte->setTimes($times);
         $doctrine->persist($connecte);
         $doctrine->flush();
     }
     $time_5 = time() - 60 * 5;
     if ($times < $time_5) {
         $connecte = $this->doctrine->getRepository('SNSysNewsBundle:Connecte')->findOneByTimes($times);
         $doctrine->remove($connecte);
         $doctrine->flush();
     }
     $nbvisit = $doctrine->getRepository('SNSysNewsBundle:Connecte')->getcountnumbervisit();
     $rep = $this->counthtml->viewNbVisit($event->getResponse(), $nbvisit);
     $event->setResponse($rep);
 }
开发者ID:houssem9,项目名称:SysNews,代码行数:31,代码来源:CountListener.php

示例12: onKernelResponse

 /**
  * Modifies the response to apply HTTP expiration header fields.
  *
  * @param FilterResponseEvent $event The notified event
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     if (!($configuration = $event->getRequest()->attributes->get('_cache'))) {
         return;
     }
     $response = $event->getResponse();
     if (!$response->isCacheable()) {
         return;
     }
     if (null !== $configuration->getSMaxAge()) {
         $response->setSharedMaxAge($configuration->getSMaxAge());
     }
     if (null !== $configuration->getMaxAge()) {
         $response->setMaxAge($configuration->getMaxAge());
     }
     if (null !== $configuration->getExpires()) {
         $date = \DateTime::createFromFormat('U', strtotime($configuration->getExpires()), new \DateTimeZone('UTC'));
         $response->setExpires($date);
     }
     if (null !== $configuration->getVary()) {
         $response->setVary($configuration->getVary());
     }
     if ($configuration->isPublic()) {
         $response->setPublic();
     }
     $event->setResponse($response);
 }
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:32,代码来源:CacheListener.php

示例13: onKernelResponse

 /**
  * Unwraps an enforced response.
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     $response = $event->getResponse();
     if ($response instanceof EnforcedResponse && $event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
         $event->setResponse($response->getResponse());
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:10,代码来源:EnforcedFormResponseSubscriber.php

示例14: onKernelResponse

 /**
  * Adds the Contao headers to the Symfony response.
  *
  * @param FilterResponseEvent $event The event object
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     if (!$this->contaoFramework->isInitialized()) {
         return;
     }
     $event->setResponse($this->mergeHttpHeaders($event->getResponse()));
 }
开发者ID:bytehead,项目名称:core-bundle,代码行数:12,代码来源:MergeHttpHeadersListener.php

示例15: onKernelResponse

 public function onKernelResponse(FilterResponseEvent $event)
 {
     if (null != $this->rol) {
         $ruta = $this->router->generate($this->container->getParameter('sisven.ruta_inicial'));
         $event->setResponse(new RedirectResponse($ruta));
     }
 }
开发者ID:mmarco1909,项目名称:GestionServicio,代码行数:7,代码来源:LoginListener.php


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