setResponse() public method

Sets a new response object
public setResponse ( Response $response )
$response Symfony\Component\HttpFoundation\Response
Esempio n. 1
0
 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);
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * {@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);
     }
 }
Esempio n. 3
0
 public function onKernelResponse(FilterResponseEvent $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $this->setEtagsAndStuff($request, $response);
     $event->setResponse($response);
 }
Esempio n. 4
0
 /**
  * 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()));
     }
 }
Esempio n. 5
0
 public function onKernelResponse(FilterResponseEvent $event)
 {
     if (null != $this->ciudad) {
         $portada = $this->router->generate('portada', array('ciudad' => $this->ciudad));
         $event->setResponse(new RedirectResponse($portada));
     }
 }
 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);
     }
 }
 /**
  * @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);
 }
Esempio n. 8
0
 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);
     }
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
Esempio n. 11
0
 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);
 }
Esempio n. 12
0
 /**
  * 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);
 }
 /**
  * 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());
     }
 }
 /**
  * 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()));
 }
Esempio n. 15
0
 public function onKernelResponse(FilterResponseEvent $event)
 {
     if (null != $this->rol) {
         $ruta = $this->router->generate($this->container->getParameter('sisven.ruta_inicial'));
         $event->setResponse(new RedirectResponse($ruta));
     }
 }
Esempio n. 16
0
 /**
  * @param FilterResponseEvent $event
  */
 public function onResponseLoad(FilterResponseEvent $event)
 {
     if (!$event->getRequest()->attributes->has('AJAX_PROCESSING')) {
         return;
     }
     $event->setResponse(new Response($this->adapter->getResponse($event->getRequest()->attributes->get('ajax_commands'))));
 }
Esempio n. 17
0
    public function onQuickUploadResponse(FilterResponseEvent $event)
    {
        $request = $event->getRequest();
        if ($request->get('responseType') === 'json') {
            return;
        }
        $response = $event->getResponse();
        $funcNum = $request->get('CKEditorFuncNum');
        $funcNum = preg_replace('/[^0-9]/', '', $funcNum);
        if ($response instanceof JsonResponse) {
            $responseData = $response->getData();
            $fileUrl = isset($responseData['url']) ? $responseData['url'] : '';
            $errorMessage = isset($responseData['error']['message']) ? $responseData['error']['message'] : '';
            ob_start();
            ?>
<script type="text/javascript">
    window.parent.CKEDITOR.tools.callFunction(<?php 
            echo json_encode($funcNum);
            ?>
, <?php 
            echo json_encode($fileUrl);
            ?>
, <?php 
            echo json_encode($errorMessage);
            ?>
);
</script>
            <?php 
            $event->setResponse(Response::create(ob_get_clean()));
        }
    }
 /**
  * Checking request and response and decide whether we need a redirect
  *
  * @param FilterResponseEvent $event
  */
 public function onResponse(FilterResponseEvent $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     if ($request->get(self::HASH_NAVIGATION_HEADER) || $request->headers->get(self::HASH_NAVIGATION_HEADER)) {
         $location = '';
         $isFullRedirect = false;
         if ($response->isRedirect()) {
             $location = $response->headers->get('location');
             if ($request->attributes->get('_fullRedirect') || !is_object($this->security->getToken())) {
                 $isFullRedirect = true;
             }
         }
         if ($response->isNotFound() || $response->getStatusCode() == 503 && !$this->isDebug) {
             $location = $request->getUri();
             $isFullRedirect = true;
         }
         if ($location) {
             $response = $this->templating->renderResponse('OroNavigationBundle:HashNav:redirect.html.twig', array('full_redirect' => $isFullRedirect, 'location' => $location));
         }
         // disable cache for ajax navigation pages and change content type to json
         $response->headers->set('Content-Type', 'application/json');
         $response->headers->addCacheControlDirective('no-cache', true);
         $response->headers->addCacheControlDirective('max-age', 0);
         $response->headers->addCacheControlDirective('must-revalidate', true);
         $response->headers->addCacheControlDirective('no-store', true);
         $event->setResponse($response);
     }
 }
 public function onKernelResponse(FilterResponseEvent $event)
 {
     $response = $event->getResponse();
     if ($response instanceof JsonResponse) {
         $response->setEncodingOptions(JSON_UNESCAPED_UNICODE);
         $event->setResponse($response);
     }
 }
 /**
  * @param FilterResponseEvent $event
  */
 public function onRenderAdminProductBefore(FilterResponseEvent $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $html = $this->getHtmlWrapping($request, $response);
     $response->setContent($html);
     $event->setResponse($response);
 }
 /**
  *
  *
  * @param FilterResponseEvent $event
  */
 public function onRenderProductsDetailBefore(FilterResponseEvent $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $html = $this->getModifiedHtml($request, $response);
     $response->setContent($html);
     $event->setResponse($response);
 }
Esempio n. 22
0
 /**
  * Processes attachments for HtmlResponse responses.
  *
  * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
  *   The event to process.
  */
 public function onRespond(FilterResponseEvent $event)
 {
     $response = $event->getResponse();
     if (!$response instanceof HtmlResponse) {
         return;
     }
     $event->setResponse($this->htmlResponseAttachmentsProcessor->processAttachments($response));
 }
 public function onKernelResponse(FilterResponseEvent $event)
 {
     $response = $event->getResponse();
     if ($response->getContent() === 'I come from the controller') {
         $newResponse = new Response('Interception OK');
         $event->setResponse($newResponse);
     }
 }
 /**
  * Checks if a redirect rules action was executed.
  *
  * Redirects to the provided url if there is one.
  *
  * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
  *   The response event.
  */
 public function checkRedirectIssued(FilterResponseEvent $event)
 {
     $request = $event->getRequest();
     $redirect_url = $request->attributes->get('_rules_redirect_action_url');
     if (isset($redirect_url)) {
         $event->setResponse(new RedirectResponse($redirect_url));
     }
 }
Esempio n. 25
0
 function it_should_not_transform_if_response_is_json(FilterResponseEvent $event, JsonResponse $response)
 {
     $this->beConstructedWith('prod');
     $event->getResponse()->willReturn($response);
     $event->setResponse()->shouldNotBeCalled();
     $response->getStatusCode()->willReturn(200);
     $this->onKernelResponse($event);
 }
Esempio n. 26
0
 /**
  * 商品一覧ページのレンダリングイベント
  * Crawler から取得した HTML をそのまま渡すだけ
  *
  * @param FilterResponseEvent $event
  */
 public function onRenderProductListBefore(FilterResponseEvent $event)
 {
     $response = $event->getResponse();
     $html = $response->getContent();
     $crawler = new Crawler($html);
     $html = $this->getHtml($crawler);
     $response->setContent($html);
     $event->setResponse($response);
 }
Esempio n. 27
0
 /**
  * @param FilterResponseEvent $event
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     $response = $event->getResponse();
     $response->headers->set('X-Proudly-Crafted-By', 'twitter.com/libertic, lespolypodes.com & friends');
     // It's nerdy, I know that.
     $response->headers->set('X-Open-Source', 'https://github.com/LiberTIC/ODEV2');
     $response->headers->set('Server', "It's a honeypot.");
     $event->setResponse($response);
 }
 /**
  * 受注マスター表示、検索ボタンクリック時のEvent Fock.
  * 下記の項目を追加する.
  * ・検索結果一覧のコンボボックスに「帳票出力」を追加
  * ・検索結果一覧の上部に「一括帳票出力を追加
  *
  * @param FilterResponseEvent $event
  */
 public function onRenderAdminOrderPdfBefore(FilterResponseEvent $event)
 {
     $app = $this->app;
     $request = $event->getRequest();
     $response = $event->getResponse();
     $id = $request->attributes->get('id');
     $response->setContent($this->getHtml($request, $response, $id));
     $event->setResponse($response);
 }
 /**
  * @param FilterResponseEvent $event
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $response = $event->getResponse();
     $this->getPreflightResponse($event->getRequest(), $response);
     $event->setResponse($response);
 }
 public function onRenderAdminProductEditBefore(FilterResponseEvent $event)
 {
     $app = $this->app;
     $request = $event->getRequest();
     $response = $event->getResponse();
     // メーカーマスタから有効なメーカー情報を取得
     $repos = $app['eccube.plugin.mail_magazine.repository.mail_magazine'];
     $MailMagazines = $repos->findAll();
     if (is_null($MailMagazines)) {
         $MailMagazines = new \Plugin\MailMagazine\Entity\MailMagazine();
     }
     // 商品登録・編集画面のHTMLを取得し、DOM化
     $crawler = new Crawler($response->getContent());
     $form = $app['form.factory']->createBuilder('admin_product_mail_magazine')->getForm();
     $form->get('mail_magazine')->setData($MailMagazines);
     $form->handleRequest($request);
     $parts = $app->renderView('MailMagazine/View/admin/product_mail_magazine.twig', array('form' => $form->createView()));
     // form1の最終項目に追加(レイアウトに依存(時間無いのでベタ))
     $html = $crawler->html();
     $form = $crawler->filter('#form1 .accordion')->last()->html();
     $new_form = $form . $parts;
     $html = str_replace($form, $new_form, $html);
     $response->setContent($html);
     $event->setResponse($response);
 }