本文整理汇总了PHP中Symfony\Component\Routing\RequestContext::getHost方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestContext::getHost方法的具体用法?PHP RequestContext::getHost怎么用?PHP RequestContext::getHost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\RequestContext
的用法示例。
在下文中一共展示了RequestContext::getHost方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
*
* @param \Swift_Mailer $mailer
* @param UrlGeneratorInterface $router
* @param \Twig_Environment $twig
* @param Logger $logger
* @param Translator $translator
* @param array $parameters
* @param \Swift_Mailer $immediateMailer
*/
public function __construct(\Swift_Mailer $mailer, UrlGeneratorInterface $router, \Twig_Environment $twig, Logger $logger, Translator $translator, TemplateProviderInterface $templateProvider, EntityManager $entityManager, array $parameters, \Swift_Mailer $immediateMailer = null)
{
parent::__construct($mailer, $router, $twig, $parameters);
$this->immediateMailer = $immediateMailer;
$this->logger = $logger;
$this->translator = $translator;
$this->templateProvider = $templateProvider;
$this->entityManager = $entityManager;
$this->noReplyEmail = $parameters[AzineEmailExtension::NO_REPLY][AzineEmailExtension::NO_REPLY_EMAIL_ADDRESS];
$this->noReplyName = $parameters[AzineEmailExtension::NO_REPLY][AzineEmailExtension::NO_REPLY_EMAIL_NAME];
$this->routerContext = $router->getContext();
$this->currentHost = $this->routerContext->getHost();
$this->encodedItemIdPattern = "/^cid:.*@/";
}
示例2: __construct
/**
*
* @param \Swift_Mailer $mailer
* @param UrlGeneratorInterface $router
* @param \Twig_Environment $twig
* @param Translator $translator
* @param TemplateProviderInterface $templateProvider
* @param ManagerRegistry $managerRegistry
* @param EmailOpenTrackingCodeBuilderInterface $emailOpenTrackingCodeBuilder
* @param AzineEmailTwigExtension $emailTwigExtension
* @param array $parameters
* @param \Swift_Mailer $immediateMailer
*/
public function __construct(\Swift_Mailer $mailer, UrlGeneratorInterface $router, \Twig_Environment $twig, Translator $translator, TemplateProviderInterface $templateProvider, ManagerRegistry $managerRegistry, EmailOpenTrackingCodeBuilderInterface $emailOpenTrackingCodeBuilder, AzineEmailTwigExtension $emailTwigExtension, array $parameters, \Swift_Mailer $immediateMailer = null)
{
parent::__construct($mailer, $router, $twig, $parameters);
$this->immediateMailer = $immediateMailer;
$this->translator = $translator;
$this->templateProvider = $templateProvider;
$this->managerRegistry = $managerRegistry;
$this->noReplyEmail = $parameters[AzineEmailExtension::NO_REPLY][AzineEmailExtension::NO_REPLY_EMAIL_ADDRESS];
$this->noReplyName = $parameters[AzineEmailExtension::NO_REPLY][AzineEmailExtension::NO_REPLY_EMAIL_NAME];
$this->emailOpenTrackingCodeBuilder = $emailOpenTrackingCodeBuilder;
$this->routerContext = $router->getContext();
$this->currentHost = $this->routerContext->getHost();
$this->encodedItemIdPattern = "/^cid:.*@/";
$this->emailTwigExtension = $emailTwigExtension;
}
示例3: rebuildRequest
/**
* Rebuild the request object from a URL with the help of the RequestContext.
*
* If the request context is not set, this simply returns the request object built from $uri.
*
* @param string $uri
*
* @return Request
*/
private function rebuildRequest($uri)
{
if (!$this->context) {
return Request::create($uri);
}
$server = array();
if ($this->context->getHost()) {
$server['SERVER_NAME'] = $this->context->getHost();
$server['HTTP_HOST'] = $this->context->getHost();
}
if ($this->context->getBaseUrl()) {
$uri = $this->context->getBaseUrl() . $uri;
$server['SCRIPT_FILENAME'] = $this->context->getBaseUrl();
$server['PHP_SELF'] = $this->context->getBaseUrl();
}
if ('https' === $this->context->getScheme()) {
$server['HTTPS'] = 'on';
$server['SERVER_PORT'] = $this->context->getHttpsPort();
if (443 !== $this->context->getHttpsPort()) {
// this is parsed from the host by symfony request
// https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Request.php#L971
$server['HTTP_HOST'] .= ':' . $this->context->getHttpsPort();
}
} else {
$server['SERVER_PORT'] = $this->context->getHttpPort();
if (80 !== $this->context->getHttpPort()) {
// this is parsed from the host by symfony request
// https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Request.php#L971
$server['HTTP_HOST'] .= ':' . $this->context->getHttpPort();
}
}
return Request::create($uri, $this->context->getMethod(), $this->context->getParameters(), array(), array(), $server);
}
示例4: decorateUrl
/**
* Decorates an URL with url context and query.
*
* @param string $url Relative URL
* @param array $parameters An array of parameters
* @param bool|string $referenceType The type of reference to be generated (one of the constants)
*
* @return string
*
* @throws \RuntimeException
*/
protected function decorateUrl($url, array $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
{
if (!$this->context) {
throw new \RuntimeException('No context associated to the CmsPageRouter');
}
$schemeAuthority = '';
if ($this->context->getHost() && (self::ABSOLUTE_URL === $referenceType || self::NETWORK_PATH === $referenceType)) {
$port = '';
if ('http' === $this->context->getScheme() && 80 != $this->context->getHttpPort()) {
$port = sprintf(':%s', $this->context->getHttpPort());
} elseif ('https' === $this->context->getScheme() && 443 != $this->context->getHttpsPort()) {
$port = sprintf(':%s', $this->context->getHttpsPort());
}
$schemeAuthority = self::NETWORK_PATH === $referenceType ? '//' : sprintf('%s://', $this->context->getScheme());
$schemeAuthority = sprintf('%s%s%s', $schemeAuthority, $this->context->getHost(), $port);
}
if (self::RELATIVE_PATH === $referenceType) {
$url = $this->getRelativePath($this->context->getPathInfo(), $url);
} else {
$url = sprintf('%s%s%s', $schemeAuthority, $this->context->getBaseUrl(), $url);
}
if (count($parameters) > 0) {
return sprintf('%s?%s', $url, http_build_query($parameters, '', '&'));
}
return $url;
}
示例5: getHost
/**
* {@inheritdoc}
*/
public function getHost()
{
$site = $this->selector->retrieve();
if ($site && !$site->isLocalhost()) {
return $site->getHost();
}
return parent::getHost();
}
示例6: buildUrl
/**
* @param string $pathInfo
* @param bool|string $referenceType
*
* @return string
*/
private function buildUrl($pathInfo, $referenceType)
{
$scheme = $this->getScheme();
$port = $this->getPortPart($scheme);
$schemeAuthority = self::NETWORK_PATH === $referenceType ? '//' : "{$scheme}://";
$schemeAuthority .= $this->context->getHost() . $port;
return $schemeAuthority . $this->context->getBaseUrl() . $pathInfo;
}
示例7: getBaseUrl
/**
* Return the base URL, either the base_url defined in Config, or the URL
* of the current language, if 'one_domain_foreach_lang' is enabled.
*
* @param bool $scheme_only if true, only the scheme will be returned. If false, the complete base URL, including path, is returned.
*
* @return string the base URL, with a trailing '/'
*/
public function getBaseUrl($scheme_only = false)
{
if (null === $this->baseUrlScheme) {
$scheme = "http";
$port = 80;
if ($host = $this->requestContext->getHost()) {
$scheme = $this->requestContext->getScheme();
$port = '';
if ('http' === $scheme && 80 != $this->requestContext->getHttpPort()) {
$port = ':' . $this->requestContext->getHttpPort();
} elseif ('https' === $scheme && 443 != $this->requestContext->getHttpsPort()) {
$port = ':' . $this->requestContext->getHttpsPort();
}
}
$this->baseUrlScheme = "{$scheme}://{$host}" . "{$port}";
}
return $scheme_only ? $this->baseUrlScheme : $this->baseUrlScheme . $this->requestContext->getBaseUrl();
}
示例8: getHostUrl
/**
* Get host url (scheme, host, port)
*
* @return string Host url
*/
private function getHostUrl()
{
$url = $this->requestContext->getScheme() . '://' . $this->requestContext->getHost();
if ($this->requestContext->getScheme() == 'http' && $this->requestContext->getHttpPort() && $this->requestContext->getHttpPort() != 80) {
$url .= ':' . $this->requestContext->getHttpPort();
} elseif ($this->requestContext->getScheme() == 'https' && $this->requestContext->getHttpsPort() && $this->requestContext->getHttpsPort() != 443) {
$url .= ':' . $this->requestContext->getHttpsPort();
}
return $url;
}
示例9: generateI18nRouteFromCurrentRequest
public function generateI18nRouteFromCurrentRequest($culture, $referenceType = self::ABSOLUTE_PATH, $scheme = null)
{
$result = $this->match($this->context->getPathInfo(), $this->context->getHost(), $this->context->getScheme(), $this->context->getMethod());
$route = $result['_route'];
if (strpos($route, ':i18n:') != false) {
list(, , $route) = explode(':', $route, 3);
}
$result['_culture'] = $culture;
unset($result['_route']);
$parameters = new ArrayObject($result);
$this->eventDispatcher->dispatch('Routing.preGenrateI18nRouteFromCurrentRequest', $this, compact('culture', 'referenceType', 'scheme', 'parameters'));
return $this->generate($route, $parameters->getArrayCopy(), $referenceType, $scheme);
}
示例10: getBaseUrl
/**
* Returns base URL, with scheme, host and port, for current request context.
* If no delivery URL is configured for current SiteAccess, will return base URL from current RequestContext.
*
* @return string
*/
protected function getBaseUrl()
{
$port = '';
if ($this->requestContext->getScheme() === 'https' && $this->requestContext->getHttpsPort() != 443) {
$port = ":{$this->requestContext->getHttpsPort()}";
}
if ($this->requestContext->getScheme() === 'http' && $this->requestContext->getHttpPort() != 80) {
$port = ":{$this->requestContext->getHttpPort()}";
}
$baseUrl = $this->requestContext->getBaseUrl();
if (substr($this->requestContext->getBaseUrl(), -4) === '.php') {
$baseUrl = pathinfo($this->requestContext->getBaseurl(), PATHINFO_DIRNAME);
}
$baseUrl = rtrim($baseUrl, '/\\');
return sprintf('%s://%s%s%s', $this->requestContext->getScheme(), $this->requestContext->getHost(), $port, $baseUrl);
}
示例11: getAbsoluteUrlPic
/**
* Get absolute path of a given pic url
*
* @param string $picUrl
* @return string
*/
private function getAbsoluteUrlPic($picUrl = '')
{
if ($picUrl) {
if ("/" == $picUrl[0]) {
$scheme = $this->context->getScheme();
$host = $this->context->getHost();
$port = '';
if ('http' === $scheme && 80 != $this->context->getHttpPort()) {
$port = ':' . $this->context->getHttpPort();
} elseif ('https' === $scheme && 443 != $this->context->getHttpsPort()) {
$port = ':' . $this->context->getHttpsPort();
}
return $scheme . "://" . $host . $port . $picUrl;
}
}
return $picUrl;
}
示例12: matchCollection
/**
* Tries to match a URL with a set of routes.
*
* @param string $pathinfo The path info to be parsed
* @param RouteCollection $routes The set of routes
*
* @return array An array of parameters
*
* @throws ResourceNotFoundException If the resource could not be found
* @throws MethodNotAllowedException If the resource was found but the request method is not allowed
*/
protected function matchCollection($pathinfo, RouteCollection $routes)
{
foreach ($routes as $name => $route) {
if ($route instanceof RouteCollection) {
if (false === strpos($route->getPrefix(), '{') && $route->getPrefix() !== substr($pathinfo, 0, strlen($route->getPrefix()))) {
continue;
}
if (!($ret = $this->matchCollection($pathinfo, $route))) {
continue;
}
return $ret;
}
$compiledRoute = $route->compile();
// check the static prefix of the URL first. Only use the more expensive preg_match when it matches
if ('' !== $compiledRoute->getStaticPrefix() && 0 !== strpos($pathinfo, $compiledRoute->getStaticPrefix())) {
continue;
}
if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
continue;
}
$hostnameMatches = array();
if ($compiledRoute->getHostnameRegex() && !preg_match($compiledRoute->getHostnameRegex(), $this->context->getHost(), $hostnameMatches)) {
continue;
}
// check HTTP method requirement
if ($req = $route->getRequirement('_method')) {
// HEAD and GET are equivalent as per RFC
if ('HEAD' === ($method = $this->context->getMethod())) {
$method = 'GET';
}
if (!in_array($method, $req = explode('|', strtoupper($req)))) {
$this->allow = array_merge($this->allow, $req);
continue;
}
}
$status = $this->handleRouteRequirements($pathinfo, $name, $route);
if (self::ROUTE_MATCH === $status[0]) {
return $status[1];
}
if (self::REQUIREMENT_MISMATCH === $status[0]) {
continue;
}
return $this->mergeDefaults(array_replace($matches, $hostnameMatches, array('_route' => $name)), $route->getDefaults());
}
}
示例13: testFromRequest
public function testFromRequest()
{
$request = Request::create('https://test.com:444/foo?bar=baz');
$requestContext = new RequestContext();
$requestContext->setHttpPort(123);
$requestContext->fromRequest($request);
$this->assertEquals('', $requestContext->getBaseUrl());
$this->assertEquals('GET', $requestContext->getMethod());
$this->assertEquals('test.com', $requestContext->getHost());
$this->assertEquals('https', $requestContext->getScheme());
$this->assertEquals('/foo', $requestContext->getPathInfo());
$this->assertEquals('bar=baz', $requestContext->getQueryString());
$this->assertSame(123, $requestContext->getHttpPort());
$this->assertSame(444, $requestContext->getHttpsPort());
$request = Request::create('http://test.com:8080/foo?bar=baz');
$requestContext = new RequestContext();
$requestContext->setHttpsPort(567);
$requestContext->fromRequest($request);
$this->assertSame(8080, $requestContext->getHttpPort());
$this->assertSame(567, $requestContext->getHttpsPort());
}
示例14: decorateUrl
/**
* Decorates an URL with url context and query
*
* @param string $url Relative URL
* @param array $parameters An array of parameters
* @param boolean $absolute Whether to generate an absolute path or not
*
* @return string
*
* @throws \RuntimeException
*/
protected function decorateUrl($url, array $parameters = array(), $absolute = false)
{
if (!$this->context) {
throw new \RuntimeException('No context associated to the CmsPageRouter');
}
$url = sprintf('%s%s', $this->context->getBaseUrl(), $url);
if ($absolute && $this->context->getHost()) {
$scheme = $this->context->getScheme();
$port = '';
if ('http' === $scheme && 80 != $this->context->getHttpPort()) {
$port = ':' . $this->context->getHttpPort();
} elseif ('https' === $scheme && 443 != $this->context->getHttpsPort()) {
$port = ':' . $this->context->getHttpsPort();
}
$url = $scheme . '://' . $this->context->getHost() . $port . $url;
}
if (count($parameters) > 0) {
return sprintf('%s?%s', $url, http_build_query($parameters, '', '&'));
}
return $url;
}
示例15: rebuildRequest
/**
* Rebuild the request object from a URL with the help of the RequestContext.
*
* If the request context is not set, this simply returns the request object built from $uri.
*
* @param string $pathinfo
*
* @return Request
*/
private function rebuildRequest($pathinfo)
{
if (!$this->context) {
return Request::create('http://localhost' . $pathinfo);
}
$uri = $pathinfo;
$server = array();
if ($this->context->getBaseUrl()) {
$uri = $this->context->getBaseUrl() . $pathinfo;
$server['SCRIPT_FILENAME'] = $this->context->getBaseUrl();
$server['PHP_SELF'] = $this->context->getBaseUrl();
}
$host = $this->context->getHost() ?: 'localhost';
if ('https' === $this->context->getScheme() && 443 !== $this->context->getHttpsPort()) {
$host .= ':' . $this->context->getHttpsPort();
}
if ('http' === $this->context->getScheme() && 80 !== $this->context->getHttpPort()) {
$host .= ':' . $this->context->getHttpPort();
}
$uri = $this->context->getScheme() . '://' . $host . $uri . '?' . $this->context->getQueryString();
return Request::create($uri, $this->context->getMethod(), $this->context->getParameters(), array(), array(), $server);
}