本文整理汇总了PHP中Symfony\Component\HttpFoundation\Response::send方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::send方法的具体用法?PHP Response::send怎么用?PHP Response::send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Response
的用法示例。
在下文中一共展示了Response::send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: lastChangeTime
public function lastChangeTime()
{
$user = $this->user;
$em = $this->em;
$response = new Response();
$currentCookieValue = 0;
$currentTime = time();
$maxTime = 60;
$request = Request::createFromGlobals();
$cookies = $request->cookies;
if (!$cookies->has('lastChangeTime')) {
$response->headers->setCookie(new Cookie('lastChangeTime', time(), time() + 3600 * 48));
$response->send();
} else {
$currentCookieValue = $cookies->get('lastChangeTime');
}
if ($currentTime - $currentCookieValue > $maxTime) {
$currentCookieValue = $currentTime;
$response->headers->setCookie(new Cookie('lastChangeTime', $currentCookieValue, time() + 3600 * 48));
$response->send();
$user->setTime(time());
$em->persist($user);
$em->flush();
}
}
示例2: run
public function run()
{
$this->response = $this->kernel->handle($this->request);
$this->response->send();
$this->kernel->terminate($this->request, $this->response);
return $this;
}
示例3: handle
/**
* @param Request $request
* @return mixed|JsonResponse|Response
*/
protected function handle(Request $request = null)
{
try {
$this->response = $this->get('Response');
// dispatch app-start events
$this->eventDispatcher->emit('app-start');
$matchedRoutes = $this->router->match();
if ($matchedRoutes === false) {
// dispatch app-failed-dispatch events
$this->eventDispatcher->emit('app-failed-dispatch', 404);
} else {
// dispatch app-before-dispatch events
$this->eventDispatcher->emit('app-before-dispatch');
list($controller, $action) = explode(":", $matchedRoutes['target']);
$controller = $this->container->get('\\App\\Http\\' . $controller);
$methodResolver = new MethodResolver($controller, $action, $matchedRoutes['params']);
$methodArguments = $methodResolver->getMethodArguments();
$response = call_user_func_array(array($controller, $action), $methodArguments);
$this->processResponseType($response);
// dispatch app-before-dispatch events
$this->eventDispatcher->emit('app-after-dispatch');
}
$this->response->send();
} catch (\Exception $e) {
$this->eventDispatcher->emit('app-error', 500, $e);
}
// dispatch app-start events
$this->eventDispatcher->emit('app-end');
}
示例4: run
/**
* Performs route matching & dispatch and sends the response.
*
* @return $this
*/
public function run()
{
// Route
$match = $this->router->match($this->request->getPathInfo(), $this->request->getMethod(), $this->request->getHttpHost(false));
// Dispatch
$this->dispatch($match);
// Respond
$this->response->send();
}
示例5: 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();
}
示例6: addOrderAction
/**
* @ApiDoc(
* description="Доавить заказ в базу",
* statusCodes={
* 200="Нормальный ответ"
* }
* )
*
* @param int $id
*
* @Route("/addOrder/{id}", name="add_order", defaults={"_format": "json"})
* @Method({"GET"})
*
* @Rest\View()
* @return mixed
*/
public function addOrderAction($id)
{
$user = $this->getUser();
$em = $this->getDoctrine()->getManager();
/** @var Product $product */
$product = $em->getRepository('ShopProductBundle:Product')->findOneById($id);
$order = $em->getRepository("ShopOrderBundle:Order")->findOneBy(['users' => $user->getId(), 'shops' => $product->getShops()->getId(), 'isPay' => false]);
if ($order) {
/** @var OrderItem $orderItem */
$orderItem = $em->getRepository("ShopOrderBundle:OrderItem")->findOneBy(['order' => $order->getId(), 'product' => $id]);
if ($orderItem) {
$orderItem->setNumber($orderItem->getNumber() + 1);
$em->flush();
return "successful";
}
} else {
$order = new Order();
$order->setUsers($user);
$order->setShops($product->getShops());
}
$orderItem = new OrderItem();
$orderItem->setNumber(1);
$orderItem->setProduct($product);
$orderItem->setOrder($order);
$order->addOrderItem($orderItem);
$em->persist($order);
$em->flush();
if (!$this->getUser()) {
$orders = [];
$id = $orderItem->getId();
$response = new Response();
if ($response->headers->has("orders")) {
$orders = json_decode($response->headers->getCookies());
if (!isset($orders[$id])) {
$orders[$id] = 0;
} else {
$orders[$id] = $orders[$id] + 1;
}
} else {
$orders[$id] = 0;
}
$response->headers->setCookie(new Cookie('orders', json_encode($orders), time() + 3600));
$response->prepare($this->get("request"));
$response->send();
return $response->send();
}
return "successful";
}
示例7: writeCookie
/**
* Write identification Cookie
*
* @param AbstractUser $user
* @param bool $remember
*/
private function writeCookie(AbstractUser $user, $remember)
{
if ($remember) {
$this->response->headers->setCookie(new Cookie($this->facade->domain, $user->offsetGet('id') . '::' . $user->offsetGet('token', true), time() + 3600 * 24 * 31));
$this->response->send();
}
}
示例8: 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();
}
示例9: indexAction
/**
* Builds the defult respnse
* @return String
*/
public function indexAction()
{
$response = new Response();
$response->setStatusCode(404);
$response->setContent('Not Found');
return $response->send();
}
示例10: indexAction
/**
* @Route("/recentViewedAjaxAction/{id}/{action}", name="recent_viewed_action", condition="request.isXmlHttpRequest()", options={"expose"=true})
*/
public function indexAction($id, $action, Request $request)
{
$cookies = $request->cookies;
$response = new Response();
if ($cookies->has('recentViewed')) {
$recentViewed = json_decode($cookies->get('recentViewed'), true);
if ($action === 'add') {
if (!in_array($id, $recentViewed)) {
array_push($recentViewed, $id);
}
$response->headers->setCookie(new Cookie('recentViewed', json_encode($recentViewed), time() + 3600 * 48));
$response->send();
return new JsonResponse($cookies->get('recentViewed'));
} else {
$response->headers->clearCookie('recentViewed');
$response->send();
return new JsonResponse('cleared');
}
} else {
$response = new Response();
if ($action === 'add') {
$response->headers->setCookie(new Cookie('recentViewed', json_encode(array($id)), time() + 3600 * 48));
$response->send();
return new JsonResponse($cookies->get('recentViewed'));
} else {
return new JsonResponse('nothing to delete');
}
}
}
示例11: getAvailabilityReport
public function getAvailabilityReport(Request $request)
{
$response = new Response();
$data = array();
$debug = $request->query->get('debug');
$month = $request->query->get('month');
if (!$month) {
$month = date("m");
}
$year = $request->query->get('year');
if (!$year) {
$year = date("Y");
}
$startDate = DateTime::createFromFormat("Y-m-d H:i:s", $year . "-" . $month . "-" . "01 00:00:00");
$endDate = DateTime::createFromFormat("Y-m-d H:i:s", $year . "-" . $month . "-" . "01 00:00:00")->add(new DateInterval("P1M"))->sub(new DateInterval("P1D"));
if ($endDate > new DateTime()) {
$endDate = new DateTime();
}
$availabiltyModel = new AvailabilityFactory($startDate, $endDate);
$serializedData = $availabiltyModel->jsonSerialize();
$metaData = array("debugMode" => $debug);
$printer = new AvailabilityPrinter(array_merge($metaData, $serializedData));
$printer->build();
if (!$debug) {
$response->headers->set("Content-type", "application/vnd.ms-excel");
$disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'report.xlsx');
$response->headers->set("Content-Disposition", $disposition);
$response->send();
$printer->echoContent();
}
return $response;
}
示例12: editTextAction
/**
* @param string $filename
* @return Response
* @throws AccessDeniedException
* @throws \Exception
*/
public function editTextAction($filename = "")
{
$authorizationChecker = $this->get('security.authorization_checker');
if (false === $authorizationChecker->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException();
}
$kernel = $this->get('kernel');
$fileNameDownloaded = $filename;
$filename = $kernel->locateResource(self::ROOT_RESOURCE_FOLDER . $filename . '.fr.json');
if (!file_exists($filename)) {
throw new \Exception('This file ' . $filename . ' doesn\'t exist');
}
$globalFilename = $kernel->locateResource(self::ROOT_RESOURCE_FOLDER . self::GLOBAL_FILENAME);
if (!file_exists($globalFilename)) {
throw new \Exception('This file ' . self::GLOBAL_FILENAME . ' doesn\'t exist');
}
$globalContent = file_get_contents($globalFilename);
$content = file_get_contents($filename);
$newFile = "***** Traduction de la page" . "\n" . $content . "\r" . " " . "\n" . " " . "\n" . "***** Traduction Global" . "\n" . $globalContent;
$response = new Response();
$response->headers->set('Content-Type', 'text/plain');
$response->headers->set('Content-Disposition', 'attachment;filename="' . $fileNameDownloaded . '.fr.txt');
$response->setContent($newFile);
$response->send();
return $response;
}
示例13: indexAction
public function indexAction($category, Request $request)
{
$category = strtolower($category);
$page = $request->query->get('page', 0);
$AjaxRequest = $request->query->get('ajax', 0);
$HealthTopicsManager = $this->get('consult.general');
$CategoryUrlHelper = $this->get('consult.basehelper');
$HealthTopics = $HealthTopicsManager->healthtopics();
$AllowedCategories = $CategoryUrlHelper->GenerateCategoryUrl($HealthTopics, 'url');
if (!in_array($category, $AllowedCategories)) {
throw $this->createNotFoundException();
}
$category = $CategoryUrlHelper->FriendlyUrl($category, 'backward');
$params = array('page' => $page, 'category' => $category);
$FeedFilter = $this->get('consult.feed_filter');
$feeds = $FeedFilter->fetchfeed($params);
if ($page == 0 && $AjaxRequest == 0) {
return $this->render('CwiPageBundle:Feed:feed.html.twig', array('feeds' => $feeds->questions, 'page_title' => 'Category', 'page' => $page));
} else {
$template = $this->get('twig')->render('CwiPageBundle:Feed:feedcontent.html.twig', array('feeds' => $feeds->questions, 'page' => $page));
$ajax_response = array('template' => $template, 'lastpage' => $feeds->lastpage);
$response = new Response();
$response->setContent(json_encode($ajax_response));
$response->setStatusCode(Response::HTTP_OK);
$response->headers->set('Content-Type', 'application/json');
$response->send();
}
}
示例14: onKernelRequest
/**
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
//CONNECTION:
//PAR UNE SESSION, UN COOKIE
$token_session = $this->container->get('session')->get('security_token');
$token_cookie = $request->cookies->get('security_token');
if ($token_session != NULL) {
$this->container->get('security.context')->setToken($token_session);
} else {
if ($token_cookie != NULL) {
$token_cookie = $this->container->get('security.context')->decryptToken($token_cookie);
$this->authenticate($token_cookie);
} else {
if (NULL !== $request->request->get('_username') && NULL !== $request->request->get('_password')) {
$user = $request->request->get('_username');
$pass = $request->request->get('_password');
$remember_me = $request->request->get('_remember_me') != NULL ? true : false;
$unauth_token = new UsernamePasswordToken($user, $pass, $this->container->get('security.parameters')['providers']['keys']['provider_key']);
try {
$this->authenticate($unauth_token);
if ($remember_me) {
$unauth_token_crypted = $this->container->get('security.context')->cryptToken($user, $pass);
$cookie = new Cookie("security_token", $unauth_token_crypted, time() + 3600 * 24 * 7);
$response = new Response();
$response->headers->setCookie($cookie);
$response->send();
}
} catch (AuthenticationException $failed) {
$this->container->get('session')->set('security_login_error', $failed->getMessage());
}
}
}
}
}
示例15: fileAction
/**
* @Route("/folder/contents/{id}", name="get_folder_contents")
*/
public function fileAction($id)
{
$response = new Response();
$response->headers->set('Access-Control-Allow-Origin', '*');
$response->send();
return new JsonResponse($this->fileStructure($id));
}