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


PHP Response::setCharset方法代码示例

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


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

示例1: sendResponse

 protected function sendResponse($payload = NULL)
 {
     $this->res->setExpiration(FALSE);
     if (is_null($payload)) {
         $this->res->setStatusCode(204);
     } else {
         $this->res->setCharset('utf8');
         $this->res->headers->set('Content-Type', 'application/json');
         $content = json_encode($payload, JSON_PRETTY_PRINT);
         $this->res->setContent($content);
     }
     $this->res->send();
 }
开发者ID:bazo,项目名称:rest-router,代码行数:13,代码来源:Controller.php

示例2: onEventResponse

 public function onEventResponse(Application $app, Response $response)
 {
     if (null === $response->getCharset()) {
         $response->setCharset($app->getParameter('charset'));
     }
     $response->prepare($app->getRequest());
 }
开发者ID:itlessons,项目名称:php-application,代码行数:7,代码来源:ResponseProvider.php

示例3: indexAction

 public function indexAction(Request $request, $key)
 {
     $userManager = $this->container->get('ilioscore.user.manager');
     $user = $userManager->findUserBy(array('icsFeedKey' => $key));
     if (!$user) {
         throw new NotFoundHttpException();
     }
     $calendar = new ICS\Calendar('Ilios Calendar for ' . $user->getFirstAndLastName());
     $calendar->setPublishedTTL('P1H');
     $from = new \DateTime('-6 months');
     $to = new \DateTime('+6 months');
     $events = $userManager->findEventsForUser($user->getId(), $from, $to);
     foreach ($events as $event) {
         $vEvent = new ICS\Event();
         $vEvent->setDtStart($event->startDate)->setDtEnd($event->endDate)->setSummary($event->name)->setDescription($this->getDescriptionForEvent($event))->setCategories([$event->eventClass])->setLocation($event->location);
         $calendar->addComponent($vEvent);
     }
     $response = new Response();
     $response->setContent($calendar->render());
     $response->setCharset('utf-8');
     $response->headers->set('Content-Type', 'text/calendar');
     $response->headers->set('Content-Disposition', 'attachment; filename="' . $key . '.ics"');
     $response->prepare($request);
     $response->send();
 }
开发者ID:Okami-,项目名称:ilios,代码行数:25,代码来源:IcsController.php

示例4: getSubscriptionAction

 /**
  * Get callback response from paywall/payment provider and proccess it.
  *
  * @Route("/paywall/subscriptions/get", name="paywall_subscribe", options={"expose"=true})
  */
 public function getSubscriptionAction(Request $request)
 {
     $subscriptionService = $this->container->get('paywall.subscription.service');
     $userService = $this->get('user');
     $translator = $this->get('translator');
     $user = $userService->getCurrentUser();
     $em = $this->get('em');
     $response = new Response();
     $response->headers->set('Content-Type', 'text/html');
     $response->setCharset('utf-8');
     $templatesService = $this->get('newscoop.templates.service');
     $chosenSubscription = $em->getRepository('Newscoop\\PaywallBundle\\Entity\\Subscriptions')->findOneByName($request->get('subscription_name'));
     if (!$chosenSubscription) {
         $response->setContent($templatesService->fetchTemplate("_paywall/error.tpl", array('msg' => $translator->trans('paywall.alert.notexists'))));
         return $response;
     }
     $userSubscriptionInactive = $subscriptionService->getOneByUserAndSubscription($user->getId(), $chosenSubscription->getId(), 'N');
     $userSubscription = $subscriptionService->getOneByUserAndSubscription($user->getId(), $chosenSubscription->getId());
     if ($userSubscription || $userSubscriptionInactive) {
         $response->setContent($templatesService->fetchTemplate("_paywall/error.tpl", array('msg' => $translator->trans('paywall.manage.error.exists.subscription'))));
         return $response;
     }
     $specificationArray = $chosenSubscription->getSpecification()->toArray();
     $specification = $specificationArray[0];
     $subscription = $subscriptionService->create();
     $subscriptionData = new SubscriptionData(array('userId' => $user, 'subscriptionId' => $chosenSubscription, 'publicationId' => $request->get('publication_id') ?: $specification->getPublication()->getId(), 'toPay' => $chosenSubscription->getPrice(), 'days' => $chosenSubscription->getRange(), 'currency' => $chosenSubscription->getCurrency(), 'type' => 'T', 'active' => false), $subscription);
     $subscription = $subscriptionService->update($subscription, $subscriptionData);
     $subscriptionService->save($subscription);
     $this->dispatchNotificationEvent(PaywallEvents::ORDER_SUBSCRIPTION, $subscription);
     $response->setContent($templatesService->fetchTemplate("_paywall/success.tpl", array('subscription' => $subscription)));
     return $response;
 }
开发者ID:riverans,项目名称:plugin-NewscoopPaywallBundle,代码行数:37,代码来源:DefaultController.php

示例5: testGetCharset

 public function testGetCharset()
 {
     $response = new Response();
     $charsetOrigin = 'UTF-8';
     $response->setCharset($charsetOrigin);
     $charset = $response->getCharset();
     $this->assertEquals($charsetOrigin, $charset);
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:8,代码来源:ResponseTest.php

示例6: meOptionsAction

 public function meOptionsAction(Request $request)
 {
     $response = new Response('Go Ahead!', Response::HTTP_OK);
     $response->setCharset('UTF-8');
     $response->prepare($request);
     $response->send();
     return;
 }
开发者ID:Avazanga1,项目名称:OAuth-Server-Demo,代码行数:8,代码来源:SecurityController.php

示例7: getFile

 /**
  * Get a public file
  *
  * @param string Path to file
  * @param string Content-type
  * @return Response
  */
 public function getFile($path, $contentType)
 {
     if (is_file($path)) {
         $response = new Response(file_get_contents($path));
         $response->headers->set('Content-Type', $contentType);
         $response->setCharset('UTF-8');
         return $response;
     }
     return new Response('', 404);
 }
开发者ID:arround,项目名称:silex-swagger-ui,代码行数:17,代码来源:SwaggerUIServiceProvider.php

示例8: testFilterDoesNothingIfCharsetIsOverridden

 public function testFilterDoesNothingIfCharsetIsOverridden()
 {
     $listener = new ResponseListener('ISO-8859-15');
     $this->dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'), 1);
     $response = new Response('foo');
     $response->setCharset('ISO-8859-1');
     $event = new FilterResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response);
     $this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);
     $this->assertEquals('ISO-8859-1', $response->getCharset());
 }
开发者ID:tejdeeps,项目名称:tejcs.com,代码行数:10,代码来源:ResponseListenerTest.php

示例9: notFoundAction

 /**
  * @Route("/{path}", requirements={"path"=".*"})
  *
  * @return Response
  */
 public function notFoundAction(Request $request, $path)
 {
     $url = preg_replace('~\\.\\w+$~', '', $request->getUri()) . '.json';
     $content = $this->translator->trans('not-found', ['%url%' => $url], 'messages') . PHP_EOL . PHP_EOL . $this->translator->trans('help', [], 'messages');
     $response = new Response();
     $response->setStatusCode(404);
     $response->setCharset('UTF-8');
     $response->setContent($content);
     $response->headers->set('Content-Type', 'text/plain; charset=UTF-8');
     return $response;
 }
开发者ID:contao-community-alliance,项目名称:usage-statistic-server,代码行数:16,代码来源:ViewController.php

示例10: getFile

 /**
  * @param string $path Path to the file
  *
  * @return Response
  */
 public function getFile($path)
 {
     if (is_file($path)) {
         $file = new File($path);
         $fileContent = file_get_contents($path);
         $response = new Response($fileContent);
         $response->headers->set('Content-Type', $this->getContentType($file->getExtension()));
         $response->setCharset('UTF-8');
         return $response;
     }
     return new Response('File not found', 404);
 }
开发者ID:Ard-Jan,项目名称:silex-swagger-ui,代码行数:17,代码来源:SwaggerUIServiceProvider.php

示例11: printAction

 /**
  * Mark the given ticket as printed.
  *
  * @param Request $request
  * @param int     $id
  * @param string  $code
  *
  * @return Response
  */
 public function printAction(Request $request, $id, $code)
 {
     $ticket = $this->ticketRepo->getTicketByIdAndCode($id, $code)->getOrThrow(new NotFoundHttpException('Ticket not found.'));
     $updateCommand = new UpdateResourceCommand();
     $updateCommand->class = '\\BCRM\\BackendBundle\\Entity\\Event\\Ticket';
     $updateCommand->id = $id;
     $updateCommand->data = array('printed' => $request->getMethod() === 'PATCH');
     $this->commandBus->handle($updateCommand);
     $response = new Response(json_encode(array('status' => 'OK')));
     $response->setCharset('utf-8');
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }
开发者ID:Ravetracer,项目名称:www,代码行数:22,代码来源:PrintingController.php

示例12: createResponse

 /**
  * Serialize the data in the requested format and create a response object.
  *
  * @param Request $request
  * @param mixed   $data
  *
  * @return Response
  */
 protected function createResponse(Request $request, $result)
 {
     $response = new Response();
     $response->setCharset('UTF-8');
     $response->headers->set('Access-Control-Allow-Origin', '*');
     $response->headers->set('Access-Control-Allow-Methods', '*');
     $dataFormat = $request->getRequestFormat('json');
     // labels = list of months
     // series = [version: [month-1, month-2, ...]]
     $data = ['labels' => [], 'series' => []];
     foreach ($result as $row) {
         $label = $row['year'] . '-' . $row['month'];
         $version = implode('.', array_slice(explode('.', $row['value']), 0, 2));
         if (!in_array($label, $data['labels'])) {
             $data['labels'][] = $label;
         }
         $column = array_search($label, $data['labels']);
         if (!isset($data['series'][$version])) {
             $data['series'][$version] = array_fill(0, count($data['labels']), 0);
         }
         if (!isset($data['series'][$version][$column])) {
             $data['series'][$version][$column] = 0;
         }
         $data['series'][$version][$column] += $row['summary'];
     }
     // Now normalize the table - we might have empty cells.
     foreach (array_keys($data['series']) as $version) {
         foreach (array_keys($data['labels']) as $column) {
             if (!isset($data['series'][$version][$column])) {
                 $data['series'][$version][$column] = 0;
             }
         }
     }
     ksort($data['series']);
     switch ($dataFormat) {
         case 'json':
             $serialized = $this->serializer->serialize($data, 'json');
             $response->headers->set('Content-Type', sprintf('application/json; charset=UTF-8'));
             $response->setContent($serialized);
             break;
         case 'yml':
             $serialized = $this->serializer->serialize($data, 'yml');
             $response->headers->set('Content-Type', sprintf('text/yaml; charset=UTF-8'));
             $response->setContent($serialized);
             break;
         default:
             throw new FileNotFoundException($request->getPathInfo());
     }
     return $response;
 }
开发者ID:contao-community-alliance,项目名称:usage-statistic-server,代码行数:58,代码来源:CoreVersionsOverTimeController.php

示例13: getResponse

 /**
  * @return Response
  */
 public function getResponse()
 {
     if (null !== $this->response) {
         $this->response->setPublic();
         $this->response->setPrivate();
         $this->response->setMaxAge($this->configuration->getTtl());
         $this->response->setSharedMaxAge($this->configuration->getTtl());
         $this->response->setCharset('UTF-8');
         $this->response->prepare($this->request);
         return $this->response;
     } else {
         throw new \RuntimeException("Request had not been handled. Use handle() method before getResponse()", 1);
     }
 }
开发者ID:ambroisemaupate,项目名称:intervention-request,代码行数:17,代码来源:InterventionRequest.php

示例14: getAction

 /**
  * @Route("/get", name="aslak_doc_get")
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function getAction()
 {
     $extracted = $this->get('doc.extractor')->extract();
     $final = $this->get('doc.parser')->parse($extracted);
     $encoders = array(new JsonEncoder());
     $normalizer = new ObjectNormalizer();
     $serializer = new Serializer([$normalizer], $encoders);
     $json = $serializer->serialize($final, 'json');
     $response = new Response($json);
     $response->headers->set('Content-Type', 'application/json; charset=UTF-8');
     $response->setCharset('UTF-8');
     $response->setStatusCode(200);
     return $response;
 }
开发者ID:PasturelP,项目名称:AslakDocBundle,代码行数:18,代码来源:DefaultController.php

示例15: getResponse

 public function getResponse()
 {
     $response = new Response($this->content);
     $disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $this->getFilename());
     $response->headers->set('Content-Description', 'File Transfer');
     $response->headers->set('Content-Disposition', $disposition);
     $response->headers->set('Content-Type', 'application/vnd.ms-excel');
     $response->headers->set('Content-Transfer-Encoding', 'binary');
     $response->headers->set('Expires', '0');
     $response->headers->set('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
     $response->headers->set('Pragma', 'public');
     $response->headers->set('Content-Length', strlen($this->content));
     $response->setCharset('UTF-8');
     return $response;
 }
开发者ID:ppatrik,项目名称:PropelDatagridBundle,代码行数:15,代码来源:CsvExport.php


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