本文整理汇总了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);
}
示例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);
}
示例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());
}
示例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;
}
示例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;
}
示例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'));
}
示例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);
}
示例8: getHost
/**
* {@inheritdoc}
*/
public function getHost()
{
if ($this->host !== null) {
return $this->host;
}
return parent::getHost();
}
示例9: resolveLocale
/**
* {@inheritDoc}
*/
public function resolveLocale(Request $request)
{
if ($this->hostMap && isset($this->hostMap[$host = $request->getHost()])) {
return $this->hostMap[$host];
}
return null;
}
示例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'));
}
}
示例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);
}
}
示例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));
}
示例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;
}
示例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;
}
示例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));
}