本文整理汇总了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);
}
示例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)));
}
示例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
}
}
示例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"]));
}
}
示例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);
}
}
示例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);
}
}
示例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');
}
}
示例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);
}
示例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);
}
}
}
示例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()));
}
示例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'));
}
}
示例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');
}
示例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');
}
示例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));
}
}
示例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);
}
}
}