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


PHP Request::getHost方法代码示例

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


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

示例1: matches

 public function matches(Request $request)
 {
     if (!$this->language) {
         throw new \LogicException('Unable to match the request as the expression language is not available.');
     }
     return $this->language->evaluate($this->expression, array('request' => $request, 'method' => $request->getMethod(), 'path' => rawurldecode($request->getPathInfo()), 'host' => $request->getHost(), 'ip' => $request->getClientIp(), 'attributes' => $request->attributes->all())) && parent::matches($request);
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:7,代码来源:ExpressionRequestMatcher.php

示例2: matchesHost

 public function matchesHost()
 {
     if (null === ($host = $this->map->getHost())) {
         return true;
     }
     if (!$this->map->getHostIsRegexPattern()) {
         return $host === $this->request->getHost();
     }
     return !$this->map->isHostRegexPatternNegate() == preg_match('#' . $host . '#', $this->request->getHost(), $this->patternMatches);
 }
开发者ID:byteworks-ch,项目名称:AstinaRedirectManagerBundle,代码行数:10,代码来源:Redirect.php

示例3: contains

 public function contains(Request $request, $modifier)
 {
     $baseHost = $this->getBaseHost();
     if (!$baseHost) {
         return false;
     }
     $host = $request->getHost();
     if ($host === $this->getBaseHost()) {
         return false;
     }
     return $this->hostContainsModifier($modifier, $request->getHost());
 }
开发者ID:activelamp,项目名称:purl-d8,代码行数:12,代码来源:SubdomainMethod.php

示例4: getPages

 /**
  * Retrieves the page list based on slugs.
  * Also checks the hierarchy of the different pages.
  *
  * @param array $slugsArray
  *
  * @return Page[]
  */
 protected function getPages(array $slugsArray = array())
 {
     /** @var Page[] $pages */
     $pages = $this->getDoctrine()->getManager()->getRepository('OrbitaleCmsBundle:Page')->findFrontPages($slugsArray, $this->request->getHost(), $this->request->getLocale());
     if (!count($pages) || count($slugsArray) && count($pages) !== count($slugsArray)) {
         if (count($slugsArray)) {
             $msg = 'Page not found';
         } else {
             $msg = 'No homepage has been configured. Please check your existing pages or create a homepage in your application.';
         }
         throw $this->createNotFoundException($msg);
     }
     return $pages;
 }
开发者ID:sfarkas1988,项目名称:CmsBundle,代码行数:22,代码来源:PageController.php

示例5: createCacheKey

 /**
  * Get a good key that varies on method, host, path info etc etc.
  *
  * @param Request $request
  *
  * @return string
  */
 private function createCacheKey(Request $request)
 {
     $key = sprintf('route:%s:%s:%s', $request->getMethod(), $request->getHost(), $request->getPathInfo());
     // This might be optional
     //$key.=':'.$this->implodeRecursive('|', $request->query->all());
     return $key;
 }
开发者ID:aequasi,项目名称:cache-bundle-1,代码行数:14,代码来源:RouterListener.php

示例6: logoutAction

 public function logoutAction(Request $request)
 {
     $response = new Response();
     $response->headers->clearCookie($this->get('vkapikey_authenticator')->getCookieId(), '/', '.' . $request->getHost());
     $response->send();
     return $this->redirect($this->generateUrl('site_homepage'));
 }
开发者ID:pihterev,项目名称:plans,代码行数:7,代码来源:SignupController.php

示例7: __construct

 public function __construct($routes, Request $request, EventDispatcher $dispatcher, ControllerResolver $resolver)
 {
     $this->deflRes = new NodeResponse();
     $this->context = new RequestContext($request->getBaseUrl(), $request->getMethod(), $request->getHost(), $request->getScheme(), $request->getPort(), $request->getPort());
     $this->matcher = new UrlMatcher($routes, $this->context);
     parent::__construct($dispatcher, $resolver);
 }
开发者ID:renyunhuang,项目名称:nodephp,代码行数:7,代码来源:NodeCore.php

示例8: getHost

 /**
  * {@inheritdoc}
  */
 public function getHost()
 {
     if ($this->host !== null) {
         return $this->host;
     }
     return parent::getHost();
 }
开发者ID:phpextra,项目名称:proxy,代码行数:10,代码来源:AbstractRequest.php

示例9: resolveLocale

 /**
  * {@inheritDoc}
  */
 public function resolveLocale(Request $request)
 {
     if ($this->hostMap && isset($this->hostMap[$host = $request->getHost()])) {
         return $this->hostMap[$host];
     }
     return null;
 }
开发者ID:yoyosan,项目名称:BlablacarI18nRoutingBundle,代码行数:10,代码来源:DefaultLocaleResolver.php

示例10: githubAction

 public function githubAction(Application $app, Request $request)
 {
     $clientID = getenv('GITHUB_API_KEY');
     $clientSecret = getenv('GITHUB_API_SECRET');
     $code = $request->query->get('code');
     $redirectUri = $request->getScheme() . '://' . $request->getHost();
     if (80 != $request->getPort()) {
         $redirectUri .= ':' . $request->getPort();
     }
     $redirectUri .= '/auth/github';
     $provider = new Github(['clientId' => $clientID, 'clientSecret' => $clientSecret, 'redirectUri' => $redirectUri, 'scopes' => ['user:email']]);
     if (empty($code)) {
         $authUrl = $provider->getAuthorizationUrl();
         $app['session']->set('oauth2state', $provider->state);
         return $app->redirect($authUrl);
     } else {
         $token = $provider->getAccessToken('authorization_code', ['code' => $code]);
         $userDetails = $provider->getUserDetails($token);
         try {
             $user = $app['user.manager']->fetchUserByGithubUid($userDetails->uid);
         } catch (UserNotFoundException $exception) {
             $email = null;
             foreach ($provider->getUserEmails($token) as $providerEmail) {
                 if ($providerEmail->primary) {
                     $email = $providerEmail->email;
                     break;
                 }
             }
             $user = $app['user.manager']->createUser(['email' => $email, 'roles' => ['ROLE_USER'], 'name' => $userDetails->name, 'githubUid' => $userDetails->uid]);
             $app['user.manager']->saveUser($user);
         }
         $app['session']->set('user', $user);
         return $app->redirect($app['url_generator']->generate('account.profile'));
     }
 }
开发者ID:nickescobedo,项目名称:webapp,代码行数:35,代码来源:AuthController.php

示例11: initializeRequestAttributes

 protected function initializeRequestAttributes(Request $request, $master)
 {
     if ($master) {
         // set the context even if the parsing does not need to be done
         // to have correct link generation
         $this->router->setContext(array('base_url' => $request->getBaseUrl(), 'method' => $request->getMethod(), 'host' => $request->getHost(), 'port' => $request->getPort(), 'is_secure' => $request->isSecure()));
     }
     if ($request->attributes->has('_controller')) {
         // routing is already done
         return;
     }
     // add attributes based on the path info (routing)
     try {
         $parameters = $this->router->match($request->getPathInfo());
         if (null !== $this->logger) {
             $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], json_encode($parameters)));
         }
         $request->attributes->add($parameters);
         if ($locale = $request->attributes->get('_locale')) {
             $request->getSession()->setLocale($locale);
         }
     } catch (NotFoundException $e) {
         $message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getPathInfo());
         if (null !== $this->logger) {
             $this->logger->err($message);
         }
         throw new NotFoundHttpException($message, $e);
     } catch (MethodNotAllowedException $e) {
         $message = sprintf('No route found for "%s %s": Method Not Allowed (Allow: %s)', $request->getMethod(), $request->getPathInfo(), strtoupper(implode(', ', $e->getAllowedMethods())));
         if (null !== $this->logger) {
             $this->logger->err($message);
         }
         throw new MethodNotAllowedHttpException($e->getAllowedMethods(), $message, $e);
     }
 }
开发者ID:nickaggarwal,项目名称:sample-symfony2,代码行数:35,代码来源:RequestListener.php

示例12: index2Action

 /**
  * @Route("/facebook", name="facebook")
  */
 public function index2Action(Request $request)
 {
     $host = 'http://' . $request->getHost();
     if ($this->container->get('kernel')->getEnvironment() == 'dev') {
         $host .= '/app_dev.php';
     }
     #validar que session este inicializado
     if (!session_id()) {
         session_start();
     }
     $fb = new Facebook(['app_id' => '460859080767262', 'app_secret' => '69915f389cdfa981be8dfb98276cbaf2', 'default_graph_version' => 'v2.5']);
     $helper = $fb->getRedirectLoginHelper();
     $permissions = ['email'];
     // Optional permissions
     $loginUrl = $helper->getLoginUrl("{$host}/fb-callback", $permissions);
     $enlaceFacebook = '<a href="' . htmlspecialchars($loginUrl) . '">Log in with Facebook!</a>';
     #obtener datos si esta logeado
     $user = null;
     if (!empty($_SESSION['fb_access_token'])) {
         $fb = new Facebook(['app_id' => '460859080767262', 'app_secret' => '69915f389cdfa981be8dfb98276cbaf2', 'default_graph_version' => 'v2.5']);
         try {
             // Returns a `Facebook\FacebookResponse` object
             $response = $fb->get('/me?fields=id,name,email', $_SESSION['fb_access_token']);
         } catch (FacebookResponseException $e) {
             echo 'Graph returned an error: ' . $e->getMessage();
             exit;
         } catch (FacebookSDKException $e) {
             echo 'Facebook SDK returned an error: ' . $e->getMessage();
             exit;
         }
         $user = $response->getGraphUser();
     }
     // replace this example code with whatever you need
     return $this->render('facebook/index.html.twig', array('base_dir' => realpath($this->container->getParameter('kernel.root_dir') . '/..'), 'enlaceFacebook' => $enlaceFacebook, 'user' => $user));
 }
开发者ID:lokitold,项目名称:symfony16,代码行数:38,代码来源:FacebookController.php

示例13: packagesAction

 /**
  * @Template()
  * @Route("/packages.json", name="packages", defaults={"_format" = "json"})
  */
 public function packagesAction(Request $req)
 {
     // fallback if any of the dumped files exist
     $rootJson = $this->container->getParameter('kernel.root_dir') . '/../web/packages_root.json';
     if (file_exists($rootJson)) {
         return new Response(file_get_contents($rootJson));
     }
     $rootJson = $this->container->getParameter('kernel.root_dir') . '/../web/packages.json';
     if (file_exists($rootJson)) {
         return new Response(file_get_contents($rootJson));
     }
     if ($req->getHost() === 'packagist.org') {
         $this->get('logger')->alert('packages.json is missing and the fallback controller is being hit');
         return new Response('Horrible misconfiguration or the dumper script messed up', 404);
     }
     $em = $this->get('doctrine')->getManager();
     gc_enable();
     $packages = $em->getRepository('Packagist\\WebBundle\\Entity\\Package')->getFullPackages();
     $notifyUrl = $this->generateUrl('track_download', array('name' => 'VND/PKG'));
     $data = array('notify' => str_replace('VND/PKG', '%package%', $notifyUrl), 'packages' => array());
     foreach ($packages as $package) {
         $versions = array();
         foreach ($package->getVersions() as $version) {
             $versions[$version->getVersion()] = $version->toArray();
             $em->detach($version);
         }
         $data['packages'][$package->getName()] = $versions;
         $em->detach($package);
     }
     unset($versions, $package, $packages);
     $response = new Response(json_encode($data), 200);
     $response->setSharedMaxAge(120);
     return $response;
 }
开发者ID:enriquesomolinos,项目名称:packagist,代码行数:38,代码来源:ApiController.php

示例14: switchLocaleForRequest

 /**
  * Chooses a language for a request
  *
  * @return $response or null
  **/
 public function switchLocaleForRequest(Request $request)
 {
     $session = $request->getSession();
     $parts = explode('.', $request->getHost());
     if (count($parts) === 3) {
         $locale = $parts[0];
         if ($locale == $session->getLocale()) {
             return;
         }
         if ($this->manager->isAvailable($locale)) {
             $session->setLocale($locale);
             $preferred = $request->getPreferredLanguage($this->manager->getAvailableLanguageCodes());
             if ($preferred != $locale) {
                 $session->setFlash('locale_change_adjust', $preferred);
             } else {
                 $session->setFlash('locale_change_contribute', $locale);
             }
             return;
         }
         $host = $parts[1] . '.' . $parts[2];
     } else {
         $host = $parts[0] . '.' . $parts[1];
     }
     $locale = $request->getPreferredLanguage($this->manager->getAvailableLanguageCodes());
     $url = sprintf('http://%s.%s%s', $locale, $host, $request->getRequestUri());
     $response = new RedirectResponse($url);
     $preferredLanguage = $this->getRequestPreferredLanguage($request);
     if ($preferredLanguage && $locale != $preferredLanguage) {
         $allLanguageCodes = array_keys($this->manager->getLanguages());
         if (in_array($preferredLanguage, $allLanguageCodes)) {
             $session->setFlash('locale_missing', $preferredLanguage);
         }
     }
     return $response;
 }
开发者ID:hafeez3000,项目名称:lichess,代码行数:40,代码来源:Switcher.php

示例15: signAction

 /**
  * @Route("/sign", name="_sign")
  */
 public function signAction(Request $request)
 {
     if (null == $request->get('url')) {
         return new Response('');
     }
     //$url = urldecode($request->get('url'));
     $appId = $this->container->getParameter('wechat_appid');
     $appSecret = $this->container->getParameter('wechat_secret');
     $wechat = new Wechat\Wechat($appId, $appSecret);
     $wx = (array) $wechat->getSignPackage(urldecode($request->get('url')));
     //var_dump($wx);
     $wx['shareTitle'] = '谁来一起coffe time?和互联网大咖面对面,机会千载难逢!';
     $wx['shareDesc'] = '谁来一起coffe time?和互联网大咖面对面,机会千载难逢!';
     $wx['shareUrl'] = 'http://' . $request->getHost() . '/';
     $wx['imgUrl'] = 'http://' . $request->getHost() . '/images/share.jpg';
     return new Response(json_encode($wx));
 }
开发者ID:alexa0503,项目名称:dori,代码行数:20,代码来源:DefaultController.php


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