本文整理汇总了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);
}
}
}
}
示例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);
}
}
示例3: onKernelResponse
public function onKernelResponse(FilterResponseEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
$this->setEtagsAndStuff($request, $response);
$event->setResponse($response);
}
示例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()));
}
}
示例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));
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
}
示例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()));
}
示例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));
}
}