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


PHP Request::getMimeType方法代码示例

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


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

示例1: doKernelResponse

 protected function doKernelResponse(Request $request, Response $response)
 {
     if (!$response instanceof DataResponse) {
         return;
     }
     $routeName = $request->attributes->get('_route');
     $route = $this->routes->get($routeName);
     if (!$route) {
         return;
     }
     $acceptedFormat = $route->getOption(RouteOptions::ACCEPTED_FORMAT);
     if (!$acceptedFormat) {
         $response->setContent('');
         $response->setStatusCode(406);
     }
     if ($this->encoder->supportsEncoding($acceptedFormat) && $acceptedFormat === 'json') {
         $contentType = $request->getMimeType($acceptedFormat);
         $jsonResponse = new JsonResponse($response->getContent());
         $response->setContent($jsonResponse->getContent());
         $response->headers->set('Content-Type', $contentType);
     } elseif ($this->encoder->supportsEncoding($acceptedFormat)) {
         $contentType = $request->getMimeType($acceptedFormat);
         $content = $this->encoder->encode($response->getContent(), $acceptedFormat);
         $response->setContent($content);
         $response->headers->set('Content-Type', $contentType);
     }
 }
开发者ID:bcen,项目名称:silex-dispatcher,代码行数:27,代码来源:Serializer.php

示例2: getBestFormat

 /**
  * Detect the request format based on the priorities and the Accept header
  *
  * Note: Request "_format" parameter is considered the preferred Accept header
  *
  * @param   Request     $request          The request
  * @param   array       $priorities       Ordered array of formats (highest priority first)
  * @param   Boolean     $preferExtension  If to consider the extension last or first
  *
  * @return  void|string                 The format string
  */
 public function getBestFormat(Request $request, array $priorities, $preferExtension = false)
 {
     $mimetypes = $request->splitHttpAcceptHeader($request->headers->get('Accept'));
     $extension = $request->get('_format');
     if (null !== $extension && $request->getMimeType($extension)) {
         $mimetypes[$request->getMimeType($extension)] = $preferExtension ? reset($mimetypes) + 1 : end($mimetypes) - 1;
         arsort($mimetypes);
     }
     if (empty($mimetypes)) {
         return null;
     }
     $catchAllEnabled = in_array('*/*', $priorities);
     return $this->getFormatByPriorities($request, $mimetypes, $priorities, $catchAllEnabled);
 }
开发者ID:hykz,项目名称:Depot,代码行数:25,代码来源:FormatNegotiator.php

示例3: indexAction

 /**
  * indexAction action.
  */
 public function indexAction(Request $request, $_format)
 {
     if (version_compare(Kernel::VERSION, '2.1.0-dev', '<')) {
         if (null !== ($session = $request->getSession())) {
             // keep current flashes for one more request
             $session->setFlashes($session->getFlashes());
         }
     } else {
         $session = $request->getSession();
         if (null !== $session && $session->getFlashBag() instanceof AutoExpireFlashBag) {
             // keep current flashes for one more request if using AutoExpireFlashBag
             $session->getFlashBag()->setAll($session->getFlashBag()->peekAll());
         }
     }
     $cache = new ConfigCache($this->cacheDir . '/fosJsRouting.json', $this->debug);
     if (!$cache->isFresh()) {
         $content = $this->serializer->serialize(new RoutesResponse($this->exposedRoutesExtractor->getBaseUrl(), $this->exposedRoutesExtractor->getRoutes()), 'json');
         $cache->write($content, $this->exposedRoutesExtractor->getResources());
     }
     $content = file_get_contents((string) $cache);
     if ($callback = $request->query->get('callback')) {
         $content = $callback . '(' . $content . ');';
     }
     return new Response($content, 200, array('Content-Type' => $request->getMimeType($_format)));
 }
开发者ID:raymondkadrige,项目名称:FOSJsRoutingBundle,代码行数:28,代码来源:Controller.php

示例4: indexAction

 /**
  * Action point for js translation resource
  *
  * @param Request $request
  * @param string $_locale
  * @return Response
  */
 public function indexAction(Request $request, $_locale)
 {
     $domains = isset($this->options['domains']) ? $this->options['domains'] : [];
     $debug = isset($this->options['debug']) ? (bool) $this->options['debug'] : false;
     $content = $this->renderJsTranslationContent($domains, $_locale, $debug);
     return new Response($content, 200, ['Content-Type' => $request->getMimeType('js')]);
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:14,代码来源:Controller.php

示例5: get

 function get(Request $req)
 {
     $resourceName = $req->get('resource');
     if (!isset($this->module["resourceEntityMappings"][$resourceName])) {
         throw new NotFoundHttpException();
     }
     $entityClass = $this->module["namespace"] . $this->module["resourceEntityMappings"][$resourceName];
     // Filterer entities queried?
     if ($req->getQueryString() != null) {
         $querystring = $req->getQueryString();
         $criteria = array();
         $queryParts = \explode('&', $querystring);
         foreach ($queryParts as $queryPart) {
             $key_value = \explode('=', $queryPart);
             $criteria[$key_value[0]] = urldecode($key_value[1]);
         }
         $entities = $this->em->getRepository($entityClass)->findBy($criteria);
         // Single entity queried?
     } elseif ($req->get('id') != null) {
         $id = $req->get('id');
         $entity = $this->em->getRepository($entityClass)->find($id);
         $entities = array($entity);
     } else {
         $entities = $this->em->getRepository($entityClass)->findAll();
     }
     return new Response($this->serializer->serialize(array($resourceName => $entities), 'json'), 200, array('Content-Type' => $req->getMimeType('json')));
 }
开发者ID:haus23,项目名称:haus23-api,代码行数:27,代码来源:QueryResourceController.php

示例6: toSymfonyResponse

 /**
  * @param ApiResponse $apiResponse to convert to a Symfony Response.
  * @param Request $request that needs this Response.
  *
  * @return Response
  */
 public function toSymfonyResponse(ApiResponse $apiResponse, Request $request)
 {
     $format = $request->getRequestFormat($this->defaultResponseFormat);
     $serialized = $this->serializer->serialize($apiResponse->getData(), $format);
     $response = new Response($serialized, $apiResponse->getStatusCode(), $apiResponse->getHeaders());
     $response->headers->set('Content-Type', $request->getMimeType($format));
     return $response;
 }
开发者ID:alcalyn,项目名称:serializable-api-response,代码行数:14,代码来源:ApiResponseFilter.php

示例7: handle

 /**
  * Deliver the result of the query.
  */
 public function handle(RouteMatchInterface $route_match, Request $request)
 {
     $query = new RestEntityQuery($request, $this->container);
     $serializer = $this->container->get('serializer');
     $format = $request->getMimeType() ?: 'json';
     $headers = ['Content-Type' => $format, 'Access-Control-Allow-Origin' => '*', 'Access-Control-Allow-Methods' => 'GET'];
     $content = $query->execute();
     if ($query->hasError()) {
         return new Response($serializer->serialize($query->getLastError(), $format), 400, $headers);
     }
     return new Response($serializer->serialize($content, 'json'), 200, $headers);
 }
开发者ID:steveworley,项目名称:morphd-drupal,代码行数:15,代码来源:HandleResponse.php

示例8: indexAction

 /**
  * indexAction action.
  */
 public function indexAction(Request $request, $_format)
 {
     $cache = new ConfigCache($this->cacheDir . '/fosJsRouting.json', $this->debug);
     if (!$cache->isFresh()) {
         $content = $this->serializer->serialize(new RoutesResponse($this->exposedRoutesExtractor->getBaseUrl(), $this->exposedRoutesExtractor->getRoutes()), 'json');
         $cache->write($content, $this->exposedRoutesExtractor->getResources());
     }
     $content = file_get_contents((string) $cache);
     if ($callback = $request->query->get('callback')) {
         $content = $callback . '(' . $content . ')';
     }
     return new Response($content, 200, array('Content-Type' => $request->getMimeType($_format)));
 }
开发者ID:radzikowski,项目名称:CraftyComponents,代码行数:16,代码来源:Controller.php

示例9: getBestFormat

 /**
  * Detect the request format based on the priorities and the Accept header
  *
  * Note: Request "_format" parameter is considered the preferred Accept header
  *
  * @param   Request     $request          The request
  * @param   array       $priorities       Ordered array of formats (highest priority first)
  * @param   Boolean     $preferExtension  If to consider the extension last or first
  *
  * @return  void|string                 The format string
  */
 public function getBestFormat(Request $request, array $priorities, $preferExtension = false)
 {
     // BC - Maintain this while 2.0 and 2.1 dont reach their end of life
     // Note: Request::splitHttpAcceptHeader is deprecated since version 2.2, to be removed in 2.3.
     if (class_exists('Symfony\\Component\\HttpFoundation\\AcceptHeader')) {
         $mimetypes = array();
         foreach (AcceptHeader::fromString($request->headers->get('Accept'))->all() as $item) {
             $mimetypes[$item->getValue()] = $item->getQuality();
         }
     } else {
         $mimetypes = $request->splitHttpAcceptHeader($request->headers->get('Accept'));
     }
     $extension = $request->get('_format');
     if (null !== $extension && $request->getMimeType($extension)) {
         $mimetypes[$request->getMimeType($extension)] = $preferExtension ? reset($mimetypes) + 1 : end($mimetypes) - 1;
         arsort($mimetypes);
     }
     if (empty($mimetypes)) {
         return null;
     }
     $catchAllEnabled = in_array('*/*', $priorities);
     return $this->getFormatByPriorities($request, $mimetypes, $priorities, $catchAllEnabled);
 }
开发者ID:shreyans264,项目名称:symfonyPlayGround,代码行数:34,代码来源:FormatNegotiator.php

示例10: prepare

 /**
  * Prepares the Response before it is sent to the client.
  *
  * This method tweaks the Response to ensure that it is
  * compliant with RFC 2616. Most of the changes are based on
  * the Request that is "associated" with this Response.
  *
  * @param Request $request A Request instance
  *
  * @return Response The current response.
  */
 public function prepare(Request $request)
 {
     $headers = $this->headers;
     if ($this->isInformational() || $this->isEmpty()) {
         $this->setContent(null);
         $headers->remove('Content-Type');
         $headers->remove('Content-Length');
     } else {
         // Content-type based on the Request
         if (!$headers->has('Content-Type')) {
             $format = $request->getRequestFormat();
             if (null !== $format && ($mimeType = $request->getMimeType($format))) {
                 $headers->set('Content-Type', $mimeType);
             }
         }
         // Fix Content-Type
         $charset = $this->charset ?: 'UTF-8';
         if (!$headers->has('Content-Type')) {
             $headers->set('Content-Type', 'text/html; charset=' . $charset);
         } elseif (0 === stripos($headers->get('Content-Type'), 'text/') && false === stripos($headers->get('Content-Type'), 'charset')) {
             // add the charset
             $headers->set('Content-Type', $headers->get('Content-Type') . '; charset=' . $charset);
         }
         // Fix Content-Length
         if ($headers->has('Transfer-Encoding')) {
             $headers->remove('Content-Length');
         }
         if ($request->isMethod('HEAD')) {
             // cf. RFC2616 14.13
             $length = $headers->get('Content-Length');
             $this->setContent(null);
             if ($length) {
                 $headers->set('Content-Length', $length);
             }
         }
     }
     // Fix protocol
     if ('HTTP/1.0' != $request->server->get('SERVER_PROTOCOL')) {
         $this->setProtocolVersion('1.1');
     }
     // Check if we need to send extra expire info headers
     if ('1.0' == $this->getProtocolVersion() && 'no-cache' == $this->headers->get('Cache-Control')) {
         $this->headers->set('pragma', 'no-cache');
         $this->headers->set('expires', -1);
     }
     $this->ensureIEOverSSLCompatibility($request);
     return $this;
 }
开发者ID:danielgelling,项目名称:larapress,代码行数:59,代码来源:Response.php

示例11: get

 /**
  * Returns a response containing the given image after applying the given filter on it.
  *
  * @uses FilterManager::applyFilterSet
  *
  * @param Request $request
  * @param string $filter
  * @param ImageInterface $image
  * @param string $localPath
  *
  * @return Response
  */
 public function get(Request $request, $filter, ImageInterface $image, $localPath)
 {
     $config = $this->getFilterConfiguration()->get($filter);
     $image = $this->applyFilter($image, $filter);
     if (empty($config['format'])) {
         $format = pathinfo($localPath, PATHINFO_EXTENSION);
         $format = $format ?: 'png';
     } else {
         $format = $config['format'];
     }
     $quality = empty($config['quality']) ? 100 : $config['quality'];
     $image = $image->get($format, array('quality' => $quality));
     $contentType = $request->getMimeType($format);
     if (empty($contentType)) {
         $contentType = 'image/' . $format;
     }
     return new Response($image, 200, array('Content-Type' => $contentType));
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:30,代码来源:FilterManager.php

示例12: indexAction

 /**
  * @Route("/js/filemanager.{_format}", name="novaway_filemanagement_routing_js", defaults={"_format"="js"})
  */
 public function indexAction(Request $request, $_format)
 {
     $serviceManagerId = $request->get('service_manager');
     if (empty($serviceManagerId)) {
         throw new \RuntimeException('service_manager argument is missing.');
     }
     if (!$this->has($serviceManagerId)) {
         throw new NotFoundHttpException(sprintf('The %s service does not exist.', $serviceManagerId));
     }
     /** @var \Novaway\Bundle\FileManagementBundle\Manager\BaseEntityWithImageManager $manager */
     $manager = $this->get($serviceManagerId);
     if (!$manager instanceof BaseEntityWithImageManager) {
         throw new \RuntimeException('The manager must be an instance of BaseEntityWithImageManager.');
     }
     $content = json_encode(['webpath' => $manager->getWebPath(), 'image_formats' => $manager->getImageFormatChoices()]);
     if (null !== ($jsManager = $request->query->get('manager'))) {
         $content = "var {$jsManager} = new novaway.FileManager(); {$jsManager}.setData({$content});";
     }
     return new Response($content, 200, array('Content-Type' => $request->getMimeType($_format)));
 }
开发者ID:novaway,项目名称:NovawayFileManagementBundle,代码行数:23,代码来源:JavascriptController.php

示例13: indexAction

 /**
  * Main action: renders the image cache and returns it to the browser
  *
  * @param Request $request
  * @param string $format A format name defined in config or a string [width]x[height]
  * @param string $path The path of the source file (@see Manager::downloadExternalImage for more info on external/remote images)
  *
  * @return Response
  */
 public function indexAction(Request $request, $format, $path)
 {
     /** @var $im \Snowcap\ImBundle\Manager */
     $im = $this->get("snowcap_im.manager");
     if (strpos($path, "http/") === 0 || strpos($path, "https/") === 0) {
         $newPath = $im->downloadExternalImage($format, $path);
         $im->mogrify($format, $newPath);
     } else {
         $im->convert($format, $path);
     }
     if (!$im->cacheExists($format, $path)) {
         throw new RuntimeException(sprintf("Caching of image failed for %s in %s format", $path, $format));
     } else {
         $extension = pathinfo($path, PATHINFO_EXTENSION);
         $contentType = $request->getMimeType($extension);
         if (empty($contentType)) {
             $contentType = 'image/' . $extension;
         }
         return new Response($im->getCacheContent($format, $path), 200, array('Content-Type' => $contentType));
     }
 }
开发者ID:LevChurakov,项目名称:SnowcapImBundle,代码行数:30,代码来源:DefaultController.php

示例14: showAction

 public function showAction(Request $request)
 {
     $showid = $request->query->get('showid');
     $type = $request->query->get('type');
     if ($type != 'json') {
         $type = 'xml';
     }
     $repo = $this->getDoctrine()->getManager()->getRepository('ActsCamdramBundle:Show');
     $show = $repo->findOneBySlug($showid);
     if (!$show) {
         if (is_numeric($showid)) {
             $show = $repo->find($showid);
         }
     }
     if (!$show) {
         throw $this->createNotFoundException('That show does not exist.');
     }
     $apiShow = new ApiShow($show, $this->get('router'));
     $serializer = $this->get('jms_serializer');
     $response = new Response($serializer->serialize($apiShow, $type));
     $response->headers->set('content-type', $request->getMimeType($type));
     return $response;
 }
开发者ID:dstansby,项目名称:camdram,代码行数:23,代码来源:LegacyApiController.php

示例15: deleteStatusBitAction

 public function deleteStatusBitAction(Request $request, $databox_id, $bit)
 {
     if (!$request->isXmlHttpRequest() || !array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) {
         $this->app->abort(400, $this->app->trans('Bad request format, only JSON is allowed'));
     }
     if (!$this->getAclForUser()->has_right_on_sbas($databox_id, 'bas_modify_struct')) {
         $this->app->abort(403);
     }
     $databox = $this->findDataboxById($databox_id);
     $error = false;
     try {
         $this->app['status.provider']->deleteStatus($databox->getStatusStructure(), $bit);
     } catch (\Exception $e) {
         $error = true;
     }
     return $this->app->json(['success' => !$error]);
 }
开发者ID:luisbrito,项目名称:Phraseanet,代码行数:17,代码来源:RootController.php


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