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


PHP FilterResponseEvent::getResponse方法代码示例

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


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

示例1: onKernelResponse

 /**
  * 输出debugBar,只有当页面有</body>标签时有效。
  *
  * @param FilterResponseEvent $event
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     $response = $event->getResponse();
     $request = $event->getRequest();
     if (!$event->isMasterRequest()) {
         return;
     }
     if ($request->isXmlHttpRequest()) {
         return;
     }
     if ($response->isRedirection() || $response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $request->getRequestFormat()) {
         return;
     }
     $path = null;
     if ($this->app['debug_bar.auto_res']) {
         $scriptName = $event->getRequest()->server->get('SCRIPT_NAME');
         $path = $scriptName . $this->app['debug_bar.path'];
     } else {
         $path = $this->app['debug_bar.path'];
     }
     $render = $this->app['debug_bar']->getJavascriptRenderer($path);
     ob_start();
     echo $render->renderHead();
     echo $render->render();
     $debugContent = ob_get_contents();
     ob_end_clean();
     $content = $response->getContent();
     if (false === strpos($content, '</body>')) {
         $content .= $debugContent;
     } else {
         $content = str_replace("</body>", $debugContent . '</body>', $content);
     }
     $event->getResponse()->setContent($content);
 }
开发者ID:h2lsoft,项目名称:silex-debugbar,代码行数:39,代码来源:DebugBarServiceProvider.php

示例2: onKernelResponse

 /**
  * {@inheritdoc}
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     if (count($this->varyHeaders) === 0) {
         return;
     }
     $event->getResponse()->setVary(array_unique(array_merge($event->getResponse()->getVary(), $this->varyHeaders)));
 }
开发者ID:ibrows,项目名称:rest-bundle,代码行数:10,代码来源:VaryHeaderListener.php

示例3: onKernelResponse

 public function onKernelResponse(FilterResponseEvent $event)
 {
     if ($this->security->isGranted('ROLE_SUPER_ADMIN')) {
         $event->getResponse()->headers->set('Location', $this->router->generate('acme_super_admin_role_homepage'));
     } elseif ($this->security->isGranted('ROLE_LGS')) {
         $event->getResponse()->headers->set('Location', $this->router->generate('acme_lgs_role_homepage'));
     } elseif ($this->security->isGranted('ROLE_ADMIN')) {
         $event->getResponse()->headers->set('Location', $this->router->generate('acme_admin_role_homepage'));
     } elseif ($this->security->isGranted('ROLE_DISTRICT')) {
         $event->getResponse()->headers->set('Location', $this->router->generate('acme_district_role_homepage'));
     } elseif ($this->security->isGranted('ROLE_COUNSELOR')) {
         $event->getResponse()->headers->set('Location', $this->router->generate('acme_counselor_role_homepage'));
     } elseif ($this->security->isGranted('ROLE_TEACHER')) {
         $event->getResponse()->headers->set('Location', $this->router->generate('acme_teacher_role_homepage'));
     } elseif ($this->security->isGranted('ROLE_PARENT')) {
         $event->getResponse()->headers->set('Location', $this->router->generate('acme_parent_role_homepage'));
     } elseif ($this->security->isGranted('ROLE_STUDENT')) {
         $event->getResponse()->headers->set('Location', $this->router->generate('acme_student_role_homepage'));
     } elseif ($this->security->isGranted('ROLE_OTHER')) {
         $event->getResponse()->headers->set('Location', $this->router->generate('acme_other_role_homepage'));
     } elseif ($this->security->isGranted('ROLE_USER')) {
         $event->getResponse()->headers->set('Location', $this->router->generate('acme_user_role_homepage'));
     } else {
         // let the normal response go through
     }
 }
开发者ID:lgstest,项目名称:dylanstest,代码行数:26,代码来源:SecurityListener.php

示例4: onKernelResponse

 public function onKernelResponse(FilterResponseEvent $event)
 {
     $debug = $this->container->getParameter('rest.config')['debug'];
     $arr = $event->getRequest()->headers->get("accept");
     if (!is_array($arr)) {
         $arr = array($arr);
     }
     if (is_array($arr) && (in_array("text/html", $arr) || in_array("*/*", $arr))) {
         return;
     }
     $response = $event->getResponse();
     if (in_array($response->headers->get("content-type"), $arr)) {
         return;
     }
     $error = $response->isServerError() || $event->getResponse()->isClientError();
     if ($error && self::$exception != null) {
         $result = array();
         $result["status"] = $response->getStatusCode();
         if (self::$exception != null) {
             $result["message"] = self::$exception->getMessage();
             if ($debug) {
                 $result["stacktrace"] = self::$exception->getTraceAsString();
             }
         } else {
             $result["message"] = "unknown";
             if ($debug) {
                 $result["stacktrace"] = "";
             }
         }
         $classParser = $this->container->get("rest.internal_class_parser");
         $content = $classParser->serializeObject($result, true);
         $response->setContent($content["result"]);
         $response->headers->add(array("content-type" => $content["type"]));
     }
 }
开发者ID:freefair,项目名称:rest-bundle,代码行数:35,代码来源:ResponseListener.php

示例5: onResponse

 public function onResponse(FilterResponseEvent $event)
 {
     foreach (new \RecursiveIteratorIterator(new \RecursiveArrayIterator($this->versions)) as $version) {
         $event->getResponse()->setEtag($version);
         $event->getResponse()->headers->set($this->key, $version);
     }
 }
开发者ID:docteurklein,项目名称:event-store,代码行数:7,代码来源:Request.php

示例6: onKernelResponse

 public function onKernelResponse(FilterResponseEvent $event)
 {
     $referer = $event->getRequest()->headers->get('referer');
     $event->getResponse()->headers->set('Access-Control-Allow-Methods', 'GET, PUT, DELETE');
     if ($referer) {
         $event->getResponse()->headers->set('Access-Control-Allow-Origin', $referer);
     }
 }
开发者ID:JosephMaxwell,项目名称:PrayerRequests,代码行数:8,代码来源:Headers.php

示例7: onKernelResponse

 /**
  * @Di\Observe("kernel.response", priority=100)
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     if ($event->getResponse()->getStatusCode() == 401) {
         // Removes header to avoid some browsers like chrome to show the
         // authenticate window.
         $event->getResponse()->headers->remove('WWW-Authenticate');
     }
 }
开发者ID:nabelhm,项目名称:api,代码行数:11,代码来源:BasicAuthenticationResponseListener.php

示例8: onKernelResponse

 public function onKernelResponse(FilterResponseEvent $event)
 {
     if ($event->getResponse()->headers->has('Content-Language')) {
         return;
     }
     $locale = $event->getRequest()->getLocale();
     $language = current(explode('_', $locale, 2));
     $event->getResponse()->headers->set('Content-Language', $language);
 }
开发者ID:symfony-cmf,项目名称:seo-bundle,代码行数:9,代码来源:LanguageListener.php

示例9: onKernelResponse

 /**
  * Add some headers to the response to make our application more secure
  * see https://www.owasp.org/index.php/List_of_useful_HTTP_headers
  *
  * @param FilterResponseEvent $event
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     $headers = ['X-Frame-Options' => 'deny', 'X-XSS-Protection' => '1; mode=block', 'X-Content-Type-Options' => 'nosniff'];
     foreach ($headers as $header => $value) {
         if (!$event->getResponse()->headers->has($header)) {
             $event->getResponse()->headers->set($header, $value);
         }
     }
 }
开发者ID:forkcms,项目名称:forkcms,代码行数:15,代码来源:ResponseSecurer.php

示例10: onResponse

 /**
  * Converts relative URLs to absolute URLs.
  *
  * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
  *   The response event.
  */
 public function onResponse(FilterResponseEvent $event)
 {
     // Only care about RSS responses.
     if (stripos($event->getResponse()->headers->get('Content-Type'), 'application/rss+xml') === FALSE) {
         return;
     }
     $response = $event->getResponse();
     $response->setContent($this->transformRootRelativeUrlsToAbsolute($response->getContent(), $event->getRequest()));
 }
开发者ID:DrupalCamp-NYC,项目名称:dcnyc16,代码行数:15,代码来源:RssResponseRelativeUrlFilter.php

示例11: onKernelResponseTest

 /**
  * Flags the response in case a rebuild indicator is used.
  */
 public function onKernelResponseTest(FilterResponseEvent $event)
 {
     if ($this->container->hasParameter('container_rebuild_indicator')) {
         $event->getResponse()->headers->set('container_rebuild_indicator', $this->container->getParameter('container_rebuild_indicator'));
     }
     if ($this->container->hasParameter('container_rebuild_test_parameter')) {
         $event->getResponse()->headers->set('container_rebuild_test_parameter', $this->container->getParameter('container_rebuild_test_parameter'));
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:12,代码来源:TestClass.php

示例12: onKernelResponse

 /**
  * Add some headers to the response to make our application more secure
  * see https://www.owasp.org/index.php/List_of_useful_HTTP_headers
  *
  * @param FilterResponseEvent $event
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     // provides clickjacking protection
     $event->getResponse()->headers->set('X-Frame-Options', 'deny');
     // enables the XSS filter built into most recent browsers
     $event->getResponse()->headers->set('X-XSS-Protection', '1; mode=block');
     // prevents IE and Chrome from MIME-sniffing
     $event->getResponse()->headers->set('X-Content-Type-Options', 'nosniff');
 }
开发者ID:bwgraves,项目名称:forkcms,代码行数:15,代码来源:ResponseSecurer.php

示例13: onKernelResponse

 /**
  * Sets security headers.
  *
  * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
  *
  * @return void
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     // Can be changed to SAMEORIGIN to allow framing on the same domain.
     $event->getResponse()->headers->set(static::HEADER_X_FRAME_OPTIONS, 'DENY');
     $event->getResponse()->headers->set(static::HEADER_X_CONTENT_TYPE_OPTIONS, 'nosniff');
     $event->getResponse()->headers->set(static::HEADER_X_XSS_PROTECTION, '1; mode=block');
 }
开发者ID:spryker,项目名称:Application,代码行数:17,代码来源:HeadersSecurityServiceProvider.php

示例14: onKernelResponse

 public function onKernelResponse(FilterResponseEvent $event)
 {
     //Check if the current response contains an error. If it does, do not set the cookie as the Locale may not be properly set
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType() || !($event->getResponse()->isSuccessful() || $event->getResponse()->isRedirection())) {
         return;
     }
     $request = $event->getRequest();
     if (!$request->cookies->has($this->cookieName) || $request->cookies->get($this->cookieName) !== $request->getLocale()) {
         $event->getResponse()->headers->setCookie(new Cookie($this->cookieName, $request->getLocale(), time() + $this->cookieLifetime, $this->cookiePath, $this->cookieDomain, $this->cookieSecure, $this->cookieHttponly));
     }
 }
开发者ID:DONIKAN,项目名称:JMSI18nRoutingBundle,代码行数:11,代码来源:CookieSettingListener.php

示例15: onKernelResponse

 public function onKernelResponse(FilterResponseEvent $event)
 {
     if ($event->getResponse()->getStatusCode() == 200) {
         if (preg_match("/\\/api\\//", $event->getRequest()->getUri())) {
             $content = $event->getResponse()->getContent();
             $content = preg_replace("/(\n|\r)*/", "", $content);
             $content = preg_replace("/\\s\\s+/", "", $content);
             $event->getResponse()->setContent($content);
         }
     }
 }
开发者ID:holtchesley,项目名称:Zeega,代码行数:11,代码来源:ApiListener.php


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