本文整理汇总了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();
}
示例2: onEventResponse
public function onEventResponse(Application $app, Response $response)
{
if (null === $response->getCharset()) {
$response->setCharset($app->getParameter('charset'));
}
$response->prepare($app->getRequest());
}
示例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();
}
示例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;
}
示例5: testGetCharset
public function testGetCharset()
{
$response = new Response();
$charsetOrigin = 'UTF-8';
$response->setCharset($charsetOrigin);
$charset = $response->getCharset();
$this->assertEquals($charsetOrigin, $charset);
}
示例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;
}
示例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);
}
示例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());
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}